From 71f04678cfc252ab0c3083a1a3f38adea7e24853 Mon Sep 17 00:00:00 2001 From: bemusementpark Date: Wed, 10 Jul 2024 23:38:07 +0930 Subject: [PATCH] Error-out when you scan an account id when trying to recover an account --- .../org/session/libsignal/crypto/MnemonicCodec.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libsignal/src/main/java/org/session/libsignal/crypto/MnemonicCodec.kt b/libsignal/src/main/java/org/session/libsignal/crypto/MnemonicCodec.kt index 8999638edb..cb81af0fda 100644 --- a/libsignal/src/main/java/org/session/libsignal/crypto/MnemonicCodec.kt +++ b/libsignal/src/main/java/org/session/libsignal/crypto/MnemonicCodec.kt @@ -128,13 +128,12 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) { decode(mnemonic = mnemonicOrHex).let(Hex::fromStringCondensed) } catch (decodeException: Exception) { // It's not a valid mnemonic, if it's pure-hexadecimal then we'll interpret it as a - // hexadecimal-byte encoded mnemonic. - if (!mnemonicOrHex.isHex()) throw decodeException - try { - Hex.fromStringCondensed(mnemonicOrHex) - } catch (_: Exception) { - throw decodeException - } + // hexadecimal-byte encoded mnemonic... unless it's 66 chars or longer, then it could be + // an account id. + mnemonicOrHex.takeIf { it.length < 66 && it.isHex() } + .runCatching { Hex.fromStringCondensed(this) } + .getOrNull() + ?: throw decodeException } }