migrated to crypto2 and kitlin2, no direct libsodium. Better session
This commit is contained in:
1 parent
51873aa9b1
commit
9660379891
20 files changed
+90
-298
No files matched your search
@@ -1,8 +1,6 @@
|
||||
import com.ionspin.kotlin.crypto.secretbox.SecretBox
|
||||
import com.ionspin.kotlin.crypto.util.decodeFromUByteArray
|
||||
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import net.sergeych.crypto2.*
|
||||
import net.sergeych.kiloparsec.encodeToUByteArray
|
||||
import net.sergeych.utools.pack
|
||||
import net.sergeych.utools.unpack
|
||||
import kotlin.test.*
|
||||
@@ -23,35 +21,24 @@ class KeysTest {
|
||||
val data = "8 rays dev!".encodeToUByteArray()
|
||||
val data1 = "8 rays dev!".encodeToUByteArray()
|
||||
val s = stk.seal(data)
|
||||
assertTrue(s.verify(data))
|
||||
assertTrue(s.isValid(data))
|
||||
|
||||
data1[0] = 0x01u
|
||||
assertFalse(s.verify(data1))
|
||||
assertFalse(s.isValid(data1))
|
||||
val p2 = SigningKey.pair()
|
||||
val p3 = SigningKey.pair()
|
||||
|
||||
val ms = SignedBox(data, s1) + p2.secretKey
|
||||
val ms = SealedBox(data, s1) + p2.secretKey
|
||||
|
||||
// non tampered:
|
||||
val ms1 = unpack<SignedBox>(pack(ms))
|
||||
val ms1 = unpack<SealedBox>(pack(ms))
|
||||
assertContentEquals(data, ms1.message)
|
||||
assertTrue(pbk in ms1)
|
||||
assertTrue(p2.publicKey in ms1)
|
||||
assertTrue(p3.publicKey !in ms1)
|
||||
|
||||
assertThrows<IllegalSignatureException> {
|
||||
unpack<SignedBox>(pack(ms).also { it[3] = 1u })
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun secretEncryptTest() = runTest {
|
||||
initCrypto()
|
||||
val key = SecretBox.keygen()
|
||||
val key1 = SecretBox.keygen()
|
||||
assertEquals("hello", decrypt(key, encrypt(key, "hello".encodeToUByteArray())).decodeFromUByteArray())
|
||||
assertThrows<DecryptionFailedException> {
|
||||
decrypt(key, encrypt(key1, "hello".encodeToUByteArray())).decodeFromUByteArray()
|
||||
unpack<SealedBox>(pack(ms).also { it[3] = 1u })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user