- BinaryId is now open

- Container returns data on the keys used to decrypt it
This commit is contained in:
sergeych committed 2024-08-28 09:24:33 +02:00
1 parent d0fa74e089
commit 14a63a05c2
8 files changed
+109 -17

No files matched your search

+30 -1
View File
@@ -50,11 +50,40 @@ class ContainerTest {
assertNotNull(d)
assertContentEquals(data, d)
assertTrue { c1.isDecrypted }
assertEquals(p2.publicKey.id, c1.decryptedWithKeyId)
assertEquals(p1.publicKey, c1.authorisedByKey)
val data2 = "To push unpushinable".encodeToUByteArray()
val c2 = Container.decode(c.updateData(data2).encoded)
assertFalse { c2.isDecrypted }
assertContentEquals(data2, c2.decryptWith(p2.secretKey))
}
@Test
fun testMultiplePair() = runTest {
initCrypto()
val p1 = Asymmetric.generateKeys()
val p2 = Asymmetric.generateKeys()
val p3 = Asymmetric.generateKeys()
val p4 = Asymmetric.generateKeys()
val data = "sergeych, ohm many.".encodeToUByteArray()
val c = Container.createWith(data, p1.secretKey to p2.publicKey, p1.secretKey to p4.publicKey)
assertTrue { c.isDecrypted }
val c1 = Container.decode(c.encoded)
assertFalse { c1.isDecrypted }
assertNull(c1.decryptWith(p3.secretKey, p1.secretKey))
val d = c1.decryptWith(p3.secretKey, p4.secretKey)
assertNotNull(d)
assertContentEquals(data, d)
assertTrue { c1.isDecrypted }
assertEquals(p4.publicKey.id, c1.decryptedWithKeyId)
assertEquals(p1.publicKey, c1.authorisedByKey)
val data2 = "To push unpushinable".encodeToUByteArray()
val c2 = Container.decode(c.updateData(data2).encoded)
assertFalse { c2.isDecrypted }
}
@Test
+4 -1
View File
@@ -164,7 +164,9 @@ class KeysTest {
assertContentEquals(pk1.keyBytes, pk1.id.binaryTag.take(32).toUByteArray())
assertContentEquals(pk1.keyBytes, sk1.id.binaryTag.take(32).toUByteArray())
assertEquals(pk1, pk1.id.id.asPublicKey)
}
@Test
fun asymmetricKeySerializationTest() = runTest {
initCrypto()
@@ -271,6 +273,7 @@ class KeysTest {
// not hashed!
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)
}
}