+Multikey.AnyKey
This commit is contained in:
1 parent
1191de284e
commit
4cbc17334c
2 files changed
+58
-32
No files matched your search
@@ -15,9 +15,9 @@ class KeysTest {
|
||||
@Test
|
||||
fun testSigningCreationAndMap() = runTest {
|
||||
initCrypto()
|
||||
val (stk,pbk) = SigningSecretKey.generatePair()
|
||||
val (stk, pbk) = SigningSecretKey.generatePair()
|
||||
|
||||
val x = mapOf( stk to "STK!", pbk to "PBK!")
|
||||
val x = mapOf(stk to "STK!", pbk to "PBK!")
|
||||
assertEquals("STK!", x[stk])
|
||||
val s1 = SigningSecretKey(stk.keyBytes)
|
||||
assertEquals(stk, s1)
|
||||
@@ -52,7 +52,7 @@ class KeysTest {
|
||||
fun testNonDeterministicSeals() = runTest {
|
||||
initCrypto()
|
||||
val data = "Welcome to the crazy new world!".encodeToUByteArray()
|
||||
val (sk,_) = SigningSecretKey.generatePair()
|
||||
val (sk, _) = SigningSecretKey.generatePair()
|
||||
val t = now()
|
||||
val s1 = Seal.create(sk, data, createdAt = t)
|
||||
val s2 = Seal.create(sk, data, createdAt = t)
|
||||
@@ -60,11 +60,11 @@ class KeysTest {
|
||||
val s3 = Seal.create(sk, data, createdAt = t, nonDeterministic = true)
|
||||
val s4 = Seal.create(sk, data, createdAt = t, nonDeterministic = true)
|
||||
|
||||
for( seal in listOf(s1,s2,s3,s4)) {
|
||||
for (seal in listOf(s1, s2, s3, s4)) {
|
||||
assertTrue { seal.isValid(data) }
|
||||
assertTrue { Seal.unpack(seal.packed).isValid(data) }
|
||||
}
|
||||
assertFalse { s2bad.isValid(data)}
|
||||
assertFalse { s2bad.isValid(data) }
|
||||
assertContentEquals(s1.packed, s2.packed)
|
||||
assertFalse { s1.packed contentEquals s3.packed }
|
||||
assertFalse { s4.packed contentEquals s3.packed }
|
||||
@@ -97,7 +97,7 @@ class KeysTest {
|
||||
assertContentEquals(src, k1.decryptWithNonce(k1.encryptWithNonce(src, nonce), nonce))
|
||||
assertThrows<DecryptionFailedException> {
|
||||
val n2 = nonce.copyOf()
|
||||
n2[4] = n2[4].inv()
|
||||
n2[4] = n2[4].inv()
|
||||
k1.decryptWithNonce(k1.encryptWithNonce(src, nonce), n2)
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ class KeysTest {
|
||||
val (sk0, pk0) = Asymmetric.generateKeys()
|
||||
|
||||
// println(sk0.publicKey)
|
||||
val j = Json { prettyPrint = true}
|
||||
val j = Json { prettyPrint = true }
|
||||
|
||||
val sk1 = j.decodeFromString<SecretKey>(j.encodeToString(sk0))
|
||||
assertEquals(sk0, sk1)
|
||||
@@ -274,11 +274,11 @@ class KeysTest {
|
||||
assertContentEquals(k.verifyingKey.keyBytes, dk2.id.binaryTag.take(32).toUByteArray())
|
||||
assertContentEquals(k.verifyingKey.keyBytes, dk1.id.binaryTag.take(32).toUByteArray())
|
||||
// and restored from id should be the same:
|
||||
assertEquals( k.verifyingKey, dk2.id.id.asVerifyingKey)
|
||||
assertEquals(k.verifyingKey, dk2.id.id.asVerifyingKey)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun multiKeyTestSom() = runTest {
|
||||
fun multiKeyTestSome() = runTest {
|
||||
initCrypto()
|
||||
val k1 = SigningSecretKey.new()
|
||||
val k2 = SigningSecretKey.new()
|
||||
@@ -301,7 +301,7 @@ class KeysTest {
|
||||
println(pack(mk23).toDump())
|
||||
println(pack(mk23).size)
|
||||
|
||||
val smk23: Multikey = Multikey.someOf(2, k1.verifyingKey, k2.verifyingKey, k3.verifyingKey)
|
||||
val smk23: Multikey = Multikey.someOf(2, k1.verifyingKey, k2.verifyingKey, k3.verifyingKey)
|
||||
// val smk13: Multikey = Multikey.Keys(1, setOf(k1.verifyingKey, k2.verifyingKey, k3.verifyingKey))
|
||||
|
||||
assertTrue { smk23.check(k1.verifyingKey, k2.verifyingKey, k4.verifyingKey) }
|
||||
@@ -342,6 +342,22 @@ class KeysTest {
|
||||
assertFalse { s3.check(k1.verifyingKey) }
|
||||
assertFalse { s3.check(k2.verifyingKey) }
|
||||
assertFalse { s3.check(k1.verifyingKey, k4.verifyingKey) }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun multiKeyTestAny() = runTest {
|
||||
initCrypto()
|
||||
val k1 = SigningSecretKey.new()
|
||||
val k2 = SigningSecretKey.new()
|
||||
val k3 = SigningSecretKey.new()
|
||||
val k4 = SigningSecretKey.new()
|
||||
val k5 = SigningSecretKey.new()
|
||||
// val k6 = SigningSecretKey.new()
|
||||
val mk: Multikey = Multikey.AnyKey
|
||||
assertTrue { mk.check(k1.verifyingKey) }
|
||||
assertTrue { mk.check(k2.verifyingKey) }
|
||||
assertTrue { mk.check(k3.verifyingKey) }
|
||||
assertTrue { mk.check(k4.verifyingKey) }
|
||||
assertTrue { mk.check(k5.verifyingKey) }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user