mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 04:25:18 +00:00
Prefer to fail with InputTooShort over InvalidWord
This commit is contained in:
parent
30ee3946ef
commit
b453f69bfd
@ -35,14 +35,14 @@ class MnemonicCodecTest {
|
||||
|
||||
@Test
|
||||
fun `decode one invalid word that is too short`() {
|
||||
assertThrows(InvalidWord::class.java) {
|
||||
assertThrows(InputTooShort::class.java) {
|
||||
codec.decode("a")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `decode one invalid word`() {
|
||||
assertThrows(InvalidWord::class.java) {
|
||||
assertThrows(InputTooShort::class.java) {
|
||||
codec.decode("abcd")
|
||||
}
|
||||
}
|
||||
@ -99,7 +99,7 @@ class MnemonicCodecTest {
|
||||
|
||||
@Test
|
||||
fun `decodeMnemonicOrHexAsByteArray with account id throws`() {
|
||||
assertThrows(InvalidWord::class.java) {
|
||||
assertThrows(InputTooShort::class.java) {
|
||||
codec.decodeMnemonicOrHexAsByteArray("0582e1421da6f584a4795d30b654b4f25fed860afdf081075cb26a2b997e492f14").let(Hex::toStringCondensed)
|
||||
}
|
||||
}
|
||||
@ -109,7 +109,7 @@ class MnemonicCodecTest {
|
||||
// throws InvalidWord as 0f2ccde528622876b8f16e14db97dafcg is not a valid word on the english wordlist.
|
||||
// It is also not a valid hex string, but we assume that a non-hex string is a recovery password.
|
||||
|
||||
assertThrows(InvalidWord::class.java) {
|
||||
assertThrows(InputTooShort::class.java) {
|
||||
codec.decodeMnemonicOrHexAsByteArray("0f2ccde528622876b8f16e14db97dafcg").let(Hex::toStringCondensed)
|
||||
}
|
||||
}
|
||||
|
@ -83,8 +83,8 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) {
|
||||
val prefixLength = languageConfiguration.prefixLength
|
||||
val n = truncatedWordSet.size.toLong()
|
||||
|
||||
if (mnemonic.isEmpty()) throw DecodingError.InputTooShort
|
||||
if (words.isEmpty()) throw DecodingError.InputTooShort
|
||||
// Check preconditions
|
||||
if (words.size < 13) throw DecodingError.InputTooShort
|
||||
|
||||
fun String.prefix() = substring(0 until prefixLength)
|
||||
|
||||
@ -96,9 +96,6 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) {
|
||||
val wordIndexes = wordPrefixes.map { truncatedWordSet.indexOf(it) }
|
||||
.onEach { if (it < 0) throw DecodingError.InvalidWord }
|
||||
|
||||
// Check preconditions
|
||||
if (words.size < 13) throw DecodingError.InputTooShort
|
||||
|
||||
// Verify checksum
|
||||
val checksumIndex = determineChecksumIndex(words.dropLast(1), prefixLength)
|
||||
val expectedChecksumWord = words[checksumIndex]
|
||||
|
Loading…
Reference in New Issue
Block a user