mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 12:07:26 +00:00
Ignore extra spaces and special characters in Recovery Password entry
This commit is contained in:
@@ -114,8 +114,15 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) {
|
||||
}.joinToString(separator = "") { it }
|
||||
}
|
||||
|
||||
fun sanitizeAndDecodeAsByteArray(mnemonic: String): ByteArray = sanitizeRecoveryPhrase(mnemonic).let(::decode).let(Hex::fromStringCondensed)
|
||||
fun decodeAsByteArray(mnemonic: String): ByteArray = decode(mnemonic = mnemonic).let(Hex::fromStringCondensed)
|
||||
|
||||
private fun sanitizeRecoveryPhrase(rawMnemonic: String): String = rawMnemonic
|
||||
.replace("[^\\w]+".toRegex(), " ") // replace any sequence of non-word characters with a space
|
||||
.trim() // remove leading and trailing whitespace (which may have been from prior special chars)
|
||||
.split("\\s+".toRegex()) // split on the now properly positioned spaces
|
||||
.joinToString(" ") // reassemble
|
||||
|
||||
fun decodeMnemonicOrHexAsByteArray(mnemonicOrHex: String): ByteArray = try {
|
||||
decode(mnemonic = mnemonicOrHex).let(Hex::fromStringCondensed)
|
||||
} catch (decodeException: Exception) {
|
||||
|
Reference in New Issue
Block a user