fix: KDF selection #2640

This commit is contained in:
J-Jamet committed 2026-08-22 13:09:43 +02:00
1 parent 5a46fa4c4a
commit e9da2c19ff
2 files changed
+27

No files matched your search

@@ -204,6 +204,16 @@ abstract class KdfEngine : Serializable {
open val maxParallelism: Long
get() = UInt.MAX_VALUE.toLong()
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is KdfEngine) return false
return uuid != null && uuid == other.uuid
}
override fun hashCode(): Int {
return uuid?.hashCode() ?: 0
}
companion object {
const val UNKNOWN_LONG_VALUE: Long = 0L
const val UNKNOWN_ULONG_VALUE: ULong = 0u
@@ -83,6 +83,23 @@ class KdfSerializationTest {
assertEquals(2L, deserialized.getParallelism())
}
@Test
fun testKdfEngineEquality() {
val aes1 = AesKdf()
aes1.setKeyRounds(100u)
val aes2 = AesKdf()
aes2.setKeyRounds(200u)
assertEquals(aes1, aes2)
assertEquals(aes1.hashCode(), aes2.hashCode())
val argonD = Argon2Kdf(Argon2Kdf.Type.ARGON2_D)
val argonId = Argon2Kdf(Argon2Kdf.Type.ARGON2_ID)
org.junit.Assert.assertNotEquals(argonD, argonId)
org.junit.Assert.assertNotEquals(aes1, argonD)
}
private fun serialize(obj: Any): ByteArray {
val bos = ByteArrayOutputStream()
val oos = ObjectOutputStream(bos)