Skip to content

Commit

Permalink
fix: Apple crash when creating seed with empty string passphrase (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamada147 authored Feb 21, 2024
1 parent 7d38213 commit ce739dd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ actual object PBKDF2SHA512 {
algorithm = kCCPBKDF2,
password = p,
passwordLen = p.length.convert(),
salt = saltPin.addressOf(0),
salt = if (saltPin.get().isNotEmpty()) saltPin.addressOf(0) else null,
saltLen = saltPin.get().size.convert(),
prf = kCCPRFHmacAlgSHA512,
rounds = rounds,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.iohk.atala.prism.apollo.derivation

import kotlin.test.Test
import kotlin.test.fail

class MnemonicTests {
@Test
fun testCreatingSeedWithEmptyPassphrase() {
val words = listOf(
"bicycle",
"monster",
"swap",
"cave",
"bulk",
"fossil",
"nominee",
"crisp",
"tail",
"parent",
"fossil",
"eyebrow",
"fold",
"manage",
"custom",
"burst",
"flight",
"lawn",
"survey",
"snake",
"brown",
"bridge",
"hard",
"perfect"
)
val passphrase = ""

assertDoesNotThrow {
MnemonicHelper.Companion.createSeed(words, passphrase)
}
}
}

/**
* Asserts that the given executable does not throw an exception.
*
* @param block The executable function to be tested.
* @throws AssertionError if the executable throws any exception.
*/
inline fun assertDoesNotThrow(block: () -> Unit) {
try {
block()
} catch (e: Exception) {
fail("Expected no exception to be thrown, but got ${e.stackTraceToString()}")
}
}

0 comments on commit ce739dd

Please sign in to comment.