Missing initializer in test

This commit is contained in:
Ugljesa Jovanovic 2021-07-27 12:33:22 +02:00
parent 9f11aa8af9
commit 65af7143fc
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F

View File

@ -67,52 +67,54 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
} }
@Test @Test
fun testEmptyAssociatedData() { fun testEmptyAssociatedData() = runTest {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + LibsodiumInitializer.initializeWithCallback {
"only one tip for the future, sunscreen would be it.").encodeToUByteArray() val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " +
"only one tip for the future, sunscreen would be it.").encodeToUByteArray()
val associatedData = ubyteArrayOf() val associatedData = ubyteArrayOf()
val key = ubyteArrayOf( val key = ubyteArrayOf(
0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U, 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U,
0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU, 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU,
0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U, 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U,
0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU, 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU,
) )
val nonce = ubyteArrayOf( val nonce = ubyteArrayOf(
0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U,
0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU,
0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U,
) )
val encrypted = AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfEncrypt( val encrypted = AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfEncrypt(
message, message,
associatedData,
nonce,
key
)
val decrypted = AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfDecrypt(
encrypted,
associatedData,
nonce,
key
)
assertTrue {
message.contentEquals(decrypted)
}
assertFailsWith(AeadCorrupedOrTamperedDataException::class) {
val tamperedTag = encrypted.copyOf()
tamperedTag[3] = 0U
tamperedTag[1] = 0U
tamperedTag[0] = 0U
AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfDecrypt(
tamperedTag,
associatedData, associatedData,
nonce, nonce,
key key
) )
val decrypted = AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfDecrypt(
encrypted,
associatedData,
nonce,
key
)
assertTrue {
message.contentEquals(decrypted)
}
assertFailsWith(AeadCorrupedOrTamperedDataException::class) {
val tamperedTag = encrypted.copyOf()
tamperedTag[3] = 0U
tamperedTag[1] = 0U
tamperedTag[0] = 0U
AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfDecrypt(
tamperedTag,
associatedData,
nonce,
key
)
}
} }
} }