crypto2 as a separate library
This commit is contained in:
1 parent
67c0009b5b
commit
ae3af68dab
23 files changed
+13
-730
No files matched your search
@@ -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 })
|
||||
|
||||
@@ -171,8 +171,8 @@ class TransportTest {
|
||||
// Log.defaultLevel = Log.Level.DEBUG
|
||||
val (d1, d2) = createTestDevice()
|
||||
|
||||
val serverId = SigningKey.Secret.pair()
|
||||
val clientId = SigningKey.Secret.pair()
|
||||
val serverId = SigningKey.pair()
|
||||
val clientId = SigningKey.pair()
|
||||
|
||||
val serverInterface = KiloInterface<String>().apply {
|
||||
on(cmdPing) {
|
||||
@@ -193,13 +193,13 @@ class TransportTest {
|
||||
registerError { IllegalStateException() }
|
||||
registerError { IllegalArgumentException(it) }
|
||||
}
|
||||
val kiloServerConnection = KiloServerConnection(serverInterface, d1, "server session", serverId.signing)
|
||||
val kiloServerConnection = KiloServerConnection(serverInterface, d1, "server session", serverId.secretKey)
|
||||
launch { kiloServerConnection.run() }
|
||||
|
||||
var cnt = 0
|
||||
val client = KiloClient {
|
||||
session { "client session!" }
|
||||
secretIdKey = clientId.signing
|
||||
secretIdKey = clientId.secretKey
|
||||
local {
|
||||
on(cmdPush) {
|
||||
"server push: $it"
|
||||
|
||||
Reference in new issue
Block a user