mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 10:05:15 +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
|
package org.session.libsignal.crypto
|
||||||
|
|
||||||
import org.session.libsignal.utilities.Hex
|
import org.session.libsignal.utilities.Hex
|
||||||
|
import org.session.libsignal.utilities.isHex
|
||||||
import java.util.zip.CRC32
|
import java.util.zip.CRC32
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,6 +127,7 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) {
|
|||||||
fun decodeMnemonicOrHexAsByteArray(mnemonicOrHex: String): ByteArray = try {
|
fun decodeMnemonicOrHexAsByteArray(mnemonicOrHex: String): ByteArray = try {
|
||||||
decode(mnemonic = mnemonicOrHex).let(Hex::fromStringCondensed)
|
decode(mnemonic = mnemonicOrHex).let(Hex::fromStringCondensed)
|
||||||
} catch (decodeException: Exception) {
|
} catch (decodeException: Exception) {
|
||||||
|
if (mnemonicOrHex.isHex()) throw decodeException
|
||||||
try {
|
try {
|
||||||
Hex.fromStringCondensed(mnemonicOrHex)
|
Hex.fromStringCondensed(mnemonicOrHex)
|
||||||
} catch (_: Exception) {
|
} 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…
Reference in New Issue
Block a user