forked from sergeych/crypto2
add general support from encoding to string and restoring from string various keys formats. + docs.
This commit is contained in:
1 parent
e8fa634640
commit
cef7e4abed
7 files changed
+165
-4
No files matched your search
@@ -416,4 +416,45 @@ class KeysTest {
|
||||
assertEquals(x, BipackDecoder.decode<SecretKey>(y))
|
||||
assertContentEquals(x.keyBytes, BipackDecoder.decode<SecretKey>(y).keyBytes)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStringRepresentationAndParse() = runTest {
|
||||
initCrypto()
|
||||
val k1 = SigningSecretKey.new()
|
||||
val k2 = k1.verifyingKey
|
||||
val k3 = SecretKey.new()
|
||||
val k4 = k3.publicKey
|
||||
|
||||
val k5 = UniversalPrivateKey.new()
|
||||
val k6 = k5.publicKey
|
||||
|
||||
assertEquals(32, k2.keyBytes.size)
|
||||
assertContentEquals(k2.keyBytes, k2.id.id.body)
|
||||
|
||||
val k7 = SymmetricKey.new()
|
||||
val k8 = KDF.Complexity.Interactive.derive("super")
|
||||
|
||||
fun testToString(k: UniversalKey) {
|
||||
val s = k.toString()
|
||||
val kx = UniversalKey.parseString(s)
|
||||
assertEquals(kx::class, k::class)
|
||||
assertContentEquals(k.keyBytes, kx.keyBytes)
|
||||
assertEquals(k.id, kx.id)
|
||||
assertEquals(k, kx)
|
||||
}
|
||||
|
||||
fun testAsString(k: UniversalKey) {
|
||||
val s = k.asString()
|
||||
val kx = UniversalKey.parseString(s)
|
||||
assertEquals(kx::class, k::class)
|
||||
assertContentEquals(k.keyBytes, kx.keyBytes)
|
||||
assertEquals(k.id, kx.id)
|
||||
assertEquals(k, kx)
|
||||
}
|
||||
|
||||
testToString(k2)
|
||||
testToString(k4)
|
||||
|
||||
for( i in listOf(k1, k2, k3, k4, k5, k6, k7, k8)) testAsString(i)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user