mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Check recovery password is hex if its not a mnemonic
This commit is contained in:
parent
17fbe5403c
commit
3cc00caeab
@ -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) {
|
||||
|
@ -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 }
|
Loading…
x
Reference in New Issue
Block a user