Check recovery password is hex if its not a mnemonic

This commit is contained in:
Andrew 2024-06-28 12:43:40 +09:30
parent 17fbe5403c
commit 3cc00caeab
2 changed files with 11 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package org.session.libsignal.crypto
import org.session.libsignal.utilities.Hex
import org.session.libsignal.utilities.isHex
import java.util.zip.CRC32
/**
@ -126,6 +127,7 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) {
fun decodeMnemonicOrHexAsByteArray(mnemonicOrHex: String): ByteArray = try {
decode(mnemonic = mnemonicOrHex).let(Hex::fromStringCondensed)
} catch (decodeException: Exception) {
if (mnemonicOrHex.isHex()) throw decodeException
try {
Hex.fromStringCondensed(mnemonicOrHex)
} catch (_: Exception) {

View File

@ -0,0 +1,9 @@
package org.session.libsignal.utilities
private val HEX_CHARS = buildSet {
addAll('0'..'9')
addAll('a'..'f')
addAll('A'..'F')
}
fun String.isHex() = all { it in HEX_CHARS }