forked from sergeych/crypto2
Universal keys. fixed bugs with keys serialization and equality
This commit is contained in:
1 parent
9027bb0e88
commit
f64412fdc7
18 files changed
+593
-26
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import net.sergeych.bintools.toDump
|
||||
import net.sergeych.bipack.BipackDecoder
|
||||
import net.sergeych.bipack.BipackEncoder
|
||||
import net.sergeych.crypto2.*
|
||||
import kotlin.test.*
|
||||
|
||||
class RingTest {
|
||||
|
||||
@Test
|
||||
fun testCreationAndSerialization() = runTest {
|
||||
initCrypto()
|
||||
|
||||
val y1 = SymmetricKey("1234567890Hello,dolly.here-we-go".encodeToUByteArray())
|
||||
val y2 = SymmetricKey("1234567890Hello,dolly.here-we-go".encodeToUByteArray())
|
||||
assertEquals(y1, y2)
|
||||
|
||||
val e1 = Asymmetric.randomSecretKey()
|
||||
val e2: Asymmetric.SecretKey = BipackDecoder.decode(BipackEncoder.encode(e1))
|
||||
assertEquals(e1, e2)
|
||||
|
||||
val k1 = UniversalKey.from(SymmetricKey("1234567890Hello,dolly.here-we-go".encodeToUByteArray()))
|
||||
val k11 = UniversalKey.from(SymmetricKey("1234567890Hello,dolly.here-we-go".encodeToUByteArray()))
|
||||
|
||||
assertEquals(k1, k11)
|
||||
|
||||
|
||||
val k2 = UniversalKey.from(Asymmetric.randomSecretKey())
|
||||
val k3 = UniversalKey.from(Asymmetric.randomSecretKey())
|
||||
//
|
||||
val r = UniversalRing(k1, k2)
|
||||
// val r = UniversalRing(k1)
|
||||
assertContains(r, k2)
|
||||
assertContains(r, k1)
|
||||
assertFalse { k3 in r }
|
||||
|
||||
println(Asymmetric.randomSecretKey().keyBytes.size)
|
||||
println(BipackEncoder.encode(Asymmetric.randomSecretKey()).size)
|
||||
val encoded = BipackEncoder.encode(r)
|
||||
println(encoded.toDump())
|
||||
println(encoded.size)
|
||||
assertTrue { encoded.size < 80 }
|
||||
val r2: UniversalRing = BipackDecoder.decode(encoded)
|
||||
assertContains(r2, k2)
|
||||
assertContains(r2, k1)
|
||||
assertFalse { k3 in r2 }
|
||||
|
||||
println(r)
|
||||
println(r2)
|
||||
|
||||
assertEquals(r, r2)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user