crypto2 as a separate library

This commit is contained in:
sergeych committed 2023-11-23 01:01:44 +03:00
1 parent 67c0009b5b
commit ae3af68dab
23 files changed
+13 -730

No files matched your search

+7 -7
View File
@@ -11,7 +11,7 @@ class KeysTest {
@Test
fun testCreationAndMap() = runTest {
initCrypto()
val (stk,pbk) = SigningKey.Secret.pair()
val (stk,pbk) = SigningKey.pair()
val x = mapOf( stk to "STK!", pbk to "PBK!")
assertEquals("STK!", x[stk])
@@ -22,22 +22,22 @@ class KeysTest {
val data = "8 rays dev!".encodeToUByteArray()
val data1 = "8 rays dev!".encodeToUByteArray()
val s = SignedBox.Seal.create(stk, data)
val s = stk.seal(data)
assertTrue(s.verify(data))
data1[0] = 0x01u
assertFalse(s.verify(data1))
val p2 = SigningKey.Secret.pair()
val p3 = SigningKey.Secret.pair()
val p2 = SigningKey.pair()
val p3 = SigningKey.pair()
val ms = SignedBox(data, s1) + p2.signing
val ms = SignedBox(data, s1) + p2.secretKey
// non tampered:
val ms1 = unpack<SignedBox>(pack(ms))
assertContentEquals(data, ms1.message)
assertTrue(pbk in ms1)
assertTrue(p2.aPublic in ms1)
assertTrue(p3.aPublic !in ms1)
assertTrue(p2.publicKey in ms1)
assertTrue(p3.publicKey !in ms1)
assertThrows<IllegalSignatureException> {
unpack<SignedBox>(pack(ms).also { it[3] = 1u })