Make all tests use runTest coroutine wrapper

This commit is contained in:
Ugljesa Jovanovic 2021-02-09 14:45:45 +01:00
parent 8e295feb46
commit 9e46cbc7ea
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
19 changed files with 69 additions and 51 deletions

View File

@ -18,7 +18,8 @@ The libsodium binding library is not published yet, once the sample showing the
Before using the wrapper you need to initialize the underlying libsodium library. You can use either a callback or coroutines approach Before using the wrapper you need to initialize the underlying libsodium library. You can use either a callback or coroutines approach
``` ```
LibsodiumInitializer.initializeWithCallback { = runTest {
LibsodiumInitializer.initializeWithCallback {
// Libsodium initialized // Libsodium initialized
} }
``` ```

View File

@ -4,6 +4,7 @@ import com.ionspin.kotlin.crypto.generichash.GenericHash
import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.testBlocking import com.ionspin.kotlin.crypto.util.testBlocking
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue

View File

@ -2,6 +2,7 @@ package com.ionspin.kotlin.crypto.aead
import com.ionspin.kotlin.crypto.LibsodiumInitializer import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -13,7 +14,7 @@ import kotlin.test.assertTrue
*/ */
class AuthenticatedEncryptionWithAssociatedDataTest { class AuthenticatedEncryptionWithAssociatedDataTest {
@Test @Test
fun testXChaCha20Poly1305Ieft() { fun testXChaCha20Poly1305Ieft() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + 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() "only one tip for the future, sunscreen would be it.").encodeToUByteArray()
@ -66,7 +67,7 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
} }
@Test @Test
fun testXChaCha20Poly1305IeftDetached() { fun testXChaCha20Poly1305IeftDetached() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + 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() "only one tip for the future, sunscreen would be it.").encodeToUByteArray()
@ -121,7 +122,7 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
} }
@Test @Test
fun testChaCha20Poly1305Ieft() { fun testChaCha20Poly1305Ieft() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + 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() "only one tip for the future, sunscreen would be it.").encodeToUByteArray()
@ -173,7 +174,7 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
} }
@Test @Test
fun testChaCha20Poly1305IeftDetached() { fun testChaCha20Poly1305IeftDetached() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + 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() "only one tip for the future, sunscreen would be it.").encodeToUByteArray()
@ -227,7 +228,7 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
} }
@Test @Test
fun testChaCha20Poly1305() { fun testChaCha20Poly1305() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + 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() "only one tip for the future, sunscreen would be it.").encodeToUByteArray()
@ -278,7 +279,7 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
} }
@Test @Test
fun testChaCha20Poly1305Detached() { fun testChaCha20Poly1305Detached() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + 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() "only one tip for the future, sunscreen would be it.").encodeToUByteArray()

View File

@ -4,6 +4,7 @@ import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.hexStringToUByteArray import com.ionspin.kotlin.crypto.util.hexStringToUByteArray
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertFalse import kotlin.test.assertFalse
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -15,7 +16,7 @@ import kotlin.test.assertTrue
*/ */
class AuthTest { class AuthTest {
@Test @Test
fun testAuth() { fun testAuth() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("I wonder if it would be possible" + val message = ("I wonder if it would be possible" +
" to get some lyrics in these tests").encodeToUByteArray() " to get some lyrics in these tests").encodeToUByteArray()
@ -41,7 +42,7 @@ class AuthTest {
} }
@Test @Test
fun testAuthHmacSha256() { fun testAuthHmacSha256() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("I wonder if it would be possible" + val message = ("I wonder if it would be possible" +
" to get some lyrics in these tests").encodeToUByteArray() " to get some lyrics in these tests").encodeToUByteArray()
@ -66,7 +67,7 @@ class AuthTest {
} }
@Test @Test
fun testAuthHmacSha512() { fun testAuthHmacSha512() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("I wonder if it would be possible" + val message = ("I wonder if it would be possible" +
" to get some lyrics in these tests").encodeToUByteArray() " to get some lyrics in these tests").encodeToUByteArray()
@ -93,7 +94,7 @@ class AuthTest {
} }
@Test @Test
fun simpleKeygenTest() { fun simpleKeygenTest() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val authKey = Auth.authKeygen() val authKey = Auth.authKeygen()
assertTrue { authKey.size == crypto_auth_KEYBYTES } assertTrue { authKey.size == crypto_auth_KEYBYTES }

View File

@ -4,6 +4,7 @@ import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import kotlin.random.Random import kotlin.random.Random
import kotlin.random.nextUBytes import kotlin.random.nextUBytes
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -15,7 +16,7 @@ import kotlin.test.assertTrue
*/ */
class BoxTest { class BoxTest {
@Test @Test
fun keypairTest() { fun keypairTest() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val keypair = Box.keypair() val keypair = Box.keypair()
assertTrue { assertTrue {
@ -28,7 +29,7 @@ class BoxTest {
} }
@Test @Test
fun testBoxEasy() { fun testBoxEasy() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = "Message message message".encodeToUByteArray() val message = "Message message message".encodeToUByteArray()
val senderKeypair = Box.keypair() val senderKeypair = Box.keypair()
@ -49,7 +50,7 @@ class BoxTest {
} }
@Test @Test
fun testBoxEasyDetached() { fun testBoxEasyDetached() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = "Message message message".encodeToUByteArray() val message = "Message message message".encodeToUByteArray()
val senderKeypair = Box.keypair() val senderKeypair = Box.keypair()
@ -82,7 +83,7 @@ class BoxTest {
} }
@Test @Test
fun testBeforeNonceAndMessage() { fun testBeforeNonceAndMessage() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = "Message message message".encodeToUByteArray() val message = "Message message message".encodeToUByteArray()
val senderKeypair = Box.keypair() val senderKeypair = Box.keypair()
@ -109,7 +110,7 @@ class BoxTest {
} }
@Test @Test
fun testSeal() { fun testSeal() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = "Message message message".encodeToUByteArray() val message = "Message message message".encodeToUByteArray()
val recipientKeypair = Box.keypair() val recipientKeypair = Box.keypair()

View File

@ -5,6 +5,7 @@ import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.testBlocking import com.ionspin.kotlin.crypto.util.testBlocking
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import kotlin.test.BeforeTest import kotlin.test.BeforeTest
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -17,7 +18,7 @@ class GenericHashTest {
@Test @Test
fun testGenericHash() { fun testGenericHash() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val inputString = "1234567890" val inputString = "1234567890"
val inputStringBuilder = StringBuilder() val inputStringBuilder = StringBuilder()
@ -46,7 +47,7 @@ class GenericHashTest {
} }
@Test @Test
fun testGenericHashMultipart() { fun testGenericHashMultipart() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val updates = 14 val updates = 14
val input = "1234567890" val input = "1234567890"

View File

@ -5,6 +5,7 @@ import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.hexStringToUByteArray import com.ionspin.kotlin.crypto.util.hexStringToUByteArray
import com.ionspin.kotlin.crypto.util.runTest import com.ionspin.kotlin.crypto.util.runTest
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -17,6 +18,7 @@ class HashTest {
//Not present in Lazy sodium //Not present in Lazy sodium
// @Test // @Test
// fun hashTest() { // fun hashTest() {
// = runTest {
// LibsodiumInitializer.initializeWithCallback { // LibsodiumInitializer.initializeWithCallback {
// val input = ("Input for various hash functions").encodeToUByteArray() // val input = ("Input for various hash functions").encodeToUByteArray()
// val expected = ("34fcbcdcfe9e6aa3e6d5a64649afcfafb449c4b8435a65e5e7b7c2b6af3b04da350acee" + // val expected = ("34fcbcdcfe9e6aa3e6d5a64649afcfafb449c4b8435a65e5e7b7c2b6af3b04da350acee" +

View File

@ -1,6 +1,7 @@
package com.ionspin.kotlin.crypto.kdf package com.ionspin.kotlin.crypto.kdf
import com.ionspin.kotlin.crypto.LibsodiumInitializer import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertFails import kotlin.test.assertFails
import kotlin.test.assertFalse import kotlin.test.assertFalse
@ -11,7 +12,7 @@ import kotlin.test.assertTrue
*/ */
class KdfTest { class KdfTest {
@Test @Test
fun testKdf() { fun testKdf() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val masterKey = Kdf.keygen() val masterKey = Kdf.keygen()
val subkey1 = Kdf.deriveFromKey(1, crypto_kdf_BYTES_MAX, "test1234", masterKey) val subkey1 = Kdf.deriveFromKey(1, crypto_kdf_BYTES_MAX, "test1234", masterKey)
@ -31,4 +32,4 @@ class KdfTest {
} }
} }
} }
} }

View File

@ -2,6 +2,7 @@ package com.ionspin.kotlin.crypto.keyexchange
import com.ionspin.kotlin.crypto.LibsodiumInitializer import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -12,7 +13,7 @@ import kotlin.test.assertTrue
*/ */
class KeyExchangeTest { class KeyExchangeTest {
@Test @Test
fun testKeyExchange() { fun testKeyExchange() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val keypairClient = KeyExchange.keypair() val keypairClient = KeyExchange.keypair()
val keypairServer = KeyExchange.keypair() val keypairServer = KeyExchange.keypair()
@ -40,7 +41,7 @@ class KeyExchangeTest {
} }
@Test @Test
fun testKeyExchangeSeeded() { fun testKeyExchangeSeeded() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val seed = UByteArray(crypto_kx_SEEDBYTES) { 7U } val seed = UByteArray(crypto_kx_SEEDBYTES) { 7U }
val keypairClient = KeyExchange.seedKeypair(seed) val keypairClient = KeyExchange.seedKeypair(seed)

View File

@ -4,6 +4,7 @@ import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import kotlin.random.Random import kotlin.random.Random
import kotlin.random.nextUBytes import kotlin.random.nextUBytes
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -14,7 +15,7 @@ import kotlin.test.assertTrue
*/ */
class PasswordHashTest { class PasswordHashTest {
@Test @Test
fun testPasswordHash() { fun testPasswordHash() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val randomBytes = Random(0).nextUBytes(crypto_pwhash_SALTBYTES) val randomBytes = Random(0).nextUBytes(crypto_pwhash_SALTBYTES)
val password = "correct horse battery staple" val password = "correct horse battery staple"
@ -35,8 +36,7 @@ class PasswordHashTest {
} }
@Test @Test
fun testPasswordHashForStorage() { fun testPasswordHashForStorage() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val password = "correct horse battery staple" val password = "correct horse battery staple"
val hashedPassword = PasswordHash.str( val hashedPassword = PasswordHash.str(

View File

@ -2,6 +2,7 @@ package com.ionspin.kotlin.crypto.scalarmult
import com.ionspin.kotlin.crypto.LibsodiumInitializer import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -29,7 +30,7 @@ class ScalarMultiplicationTest {
val expectedSharedSecretString = "4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742" val expectedSharedSecretString = "4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742"
@Test @Test
fun testScalarMultiplication() { fun testScalarMultiplication() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val alicePublicKey = ScalarMultiplication.scalarMultiplicationBase(aliceSecretKey) val alicePublicKey = ScalarMultiplication.scalarMultiplicationBase(aliceSecretKey)
assertTrue { assertTrue {

View File

@ -3,6 +3,7 @@ package com.ionspin.kotlin.crypto.secretbox
import com.ionspin.kotlin.crypto.LibsodiumInitializer import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -15,7 +16,7 @@ import kotlin.test.assertTrue
class SecretBoxTest { class SecretBoxTest {
@Test @Test
fun secretBoxTestEasy() { fun secretBoxTestEasy() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + 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() "only one tip for the future, sunscreen would be it.").encodeToUByteArray()
@ -50,7 +51,7 @@ class SecretBoxTest {
} }
@Test @Test
fun secretBoxTestDetached() { fun secretBoxTestDetached() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + 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() "only one tip for the future, sunscreen would be it.").encodeToUByteArray()

View File

@ -4,6 +4,7 @@ import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint
import com.ionspin.kotlin.crypto.LibsodiumInitializer import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.testBlocking import com.ionspin.kotlin.crypto.util.testBlocking
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -17,7 +18,7 @@ class SecretStreamTest {
@Test @Test
fun testSecretStream() = testBlocking { fun testSecretStream() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + 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() "only one tip for the future, sunscreen would be it.").encodeToUByteArray()

View File

@ -5,6 +5,7 @@ import com.ionspin.kotlin.crypto.shortinputhash.ShortHash
import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.hexStringToUByteArray import com.ionspin.kotlin.crypto.util.hexStringToUByteArray
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -16,7 +17,7 @@ import kotlin.test.assertTrue
class ShortHashTest { class ShortHashTest {
@Test @Test
fun testShortHash() { fun testShortHash() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val expected = "00e5d509c14e81bb".hexStringToUByteArray() val expected = "00e5d509c14e81bb".hexStringToUByteArray()
val input = "Libsodium test" val input = "Libsodium test"
@ -30,7 +31,7 @@ class ShortHashTest {
} }
@Test @Test
fun testKeygen() { fun testKeygen() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
assertTrue { assertTrue {
val key = ShortHash.shortHashKeygen() val key = ShortHash.shortHashKeygen()

View File

@ -2,6 +2,7 @@ package com.ionspin.kotlin.crypto.signature
import com.ionspin.kotlin.crypto.LibsodiumInitializer import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -12,7 +13,7 @@ import kotlin.test.assertTrue
class SignatureTest { class SignatureTest {
@Test @Test
fun testSignAndVerify() { fun testSignAndVerify() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val keys = Signature.keypair() val keys = Signature.keypair()
val message = "Some text that will be signed".encodeToUByteArray() val message = "Some text that will be signed".encodeToUByteArray()
@ -33,7 +34,7 @@ class SignatureTest {
} }
@Test @Test
fun testDetachedSignAndVerify() { fun testDetachedSignAndVerify() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val keys = Signature.keypair() val keys = Signature.keypair()
val message = "Some text that will be signed".encodeToUByteArray() val message = "Some text that will be signed".encodeToUByteArray()
@ -51,7 +52,7 @@ class SignatureTest {
} }
@Test @Test
fun testMultipart() { fun testMultipart() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val keys = Signature.keypair() val keys = Signature.keypair()
val message1 = "Some text that ".encodeToUByteArray() val message1 = "Some text that ".encodeToUByteArray()

View File

@ -7,6 +7,7 @@ import com.ionspin.kotlin.crypto.util.randombytes_SEEDBYTES
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import kotlin.random.Random import kotlin.random.Random
import kotlin.random.nextUBytes import kotlin.random.nextUBytes
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -20,7 +21,7 @@ class StreamTest {
val seed = UByteArray(randombytes_SEEDBYTES) { 0U } val seed = UByteArray(randombytes_SEEDBYTES) { 0U }
@Test @Test
fun testChaCha20Stream() { fun testChaCha20Stream() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = "This is a cha cha message".encodeToUByteArray() val message = "This is a cha cha message".encodeToUByteArray()
val nonce = LibsodiumRandom.bufDeterministic(crypto_stream_chacha20_NONCEBYTES, seed) val nonce = LibsodiumRandom.bufDeterministic(crypto_stream_chacha20_NONCEBYTES, seed)
@ -47,7 +48,7 @@ class StreamTest {
} }
@Test @Test
fun testChaCha20IetfStream() { fun testChaCha20IetfStream() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val message = "This is a cha cha message".encodeToUByteArray() val message = "This is a cha cha message".encodeToUByteArray()
val nonce = LibsodiumRandom.bufDeterministic(crypto_stream_chacha20_ietf_NONCEBYTES, seed) val nonce = LibsodiumRandom.bufDeterministic(crypto_stream_chacha20_ietf_NONCEBYTES, seed)

View File

@ -1,6 +1,7 @@
package com.ionspin.kotlin.crypto.util package com.ionspin.kotlin.crypto.util
import com.ionspin.kotlin.crypto.LibsodiumInitializer import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertFalse import kotlin.test.assertFalse
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -13,7 +14,7 @@ import kotlin.test.assertTrue
class LibsodiumRandomTest { class LibsodiumRandomTest {
@Test @Test
fun testRandom() { fun testRandom()= runTest {
//This is just a sanity test, it should fail on occasion though, with probability of 1/2^32 //This is just a sanity test, it should fail on occasion though, with probability of 1/2^32
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val random = LibsodiumRandom.random() val random = LibsodiumRandom.random()
@ -23,7 +24,7 @@ class LibsodiumRandomTest {
} }
@Test @Test
fun testRandomUniform() { fun testRandomUniform() = runTest {
//This is just a sanity test, it should fail on occasion though, with probability of 1/2^31 //This is just a sanity test, it should fail on occasion though, with probability of 1/2^31
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val random = LibsodiumRandom.uniform(UInt.MAX_VALUE / 2U) val random = LibsodiumRandom.uniform(UInt.MAX_VALUE / 2U)
@ -32,7 +33,7 @@ class LibsodiumRandomTest {
} }
@Test @Test
fun testRandomBuffer() { fun testRandomBuffer() = runTest {
//This is just a sanity test, it should fail on occasion though, with probability of 1/2^52 //This is just a sanity test, it should fail on occasion though, with probability of 1/2^52
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val result = LibsodiumRandom.buf(20) val result = LibsodiumRandom.buf(20)
@ -42,7 +43,7 @@ class LibsodiumRandomTest {
} }
@Test @Test
fun testRandomBufferDeterministic() { fun testRandomBufferDeterministic() = runTest {
//This is just a sanity test, it should fail on occasion though, with probability of 1/2^52 //This is just a sanity test, it should fail on occasion though, with probability of 1/2^52
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val seed = UByteArray(randombytes_SEEDBYTES) { 1U } val seed = UByteArray(randombytes_SEEDBYTES) { 1U }

View File

@ -3,6 +3,7 @@ package com.ionspin.kotlin.crypto.util
import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint
import com.ionspin.kotlin.crypto.LibsodiumInitializer import com.ionspin.kotlin.crypto.LibsodiumInitializer
import kotlin.math.exp import kotlin.math.exp
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertFalse import kotlin.test.assertFalse
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -15,7 +16,7 @@ import kotlin.test.assertTrue
class LibsodiumUtilTest { class LibsodiumUtilTest {
@Test @Test
fun testMemzero() { fun testMemzero() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U) val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U)
LibsodiumUtil.memzero(input) LibsodiumUtil.memzero(input)
@ -26,7 +27,7 @@ class LibsodiumUtilTest {
} }
@Test @Test
fun testMemcmp() { fun testMemcmp() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U) val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U)
val input2 = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U) val input2 = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U)
@ -41,7 +42,7 @@ class LibsodiumUtilTest {
} }
@Test @Test
fun testPadding() { fun testPadding() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U) val input = ubyteArrayOf(1U, 2U)
val blocksize = 16 val blocksize = 16
@ -57,7 +58,7 @@ class LibsodiumUtilTest {
} }
@Test @Test
fun testPaddingChars() { fun testPaddingChars() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val input = charArrayOf('a', 'b', 'c', 'd').map { it.toByte().toUByte() }.toUByteArray() val input = charArrayOf('a', 'b', 'c', 'd').map { it.toByte().toUByte() }.toUByteArray()
val blocksize = 4 val blocksize = 4
@ -73,7 +74,7 @@ class LibsodiumUtilTest {
} }
@Test @Test
fun testPaddingAligned() { fun testPaddingAligned() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U) val input = ubyteArrayOf(1U, 2U)
val blocksize = 2 val blocksize = 2
@ -91,7 +92,7 @@ class LibsodiumUtilTest {
} }
@Test @Test
fun testPaddingMultiblock() { fun testPaddingMultiblock() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 6U) val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 6U)
val blocksize = 4 val blocksize = 4
@ -109,7 +110,7 @@ class LibsodiumUtilTest {
} }
@Test @Test
fun testToBase64() { fun testToBase64() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U) val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U)
val expected = "AQIDBAUgQID_" val expected = "AQIDBAUgQID_"
@ -128,7 +129,7 @@ class LibsodiumUtilTest {
} }
@Test @Test
fun testToBase64Unaligned() { fun testToBase64Unaligned() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U, 128U) val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U, 128U)
val expected = "AQIDBAUgQID_gA" val expected = "AQIDBAUgQID_gA"
@ -147,7 +148,7 @@ class LibsodiumUtilTest {
} }
@Test @Test
fun toHex() { fun toHex() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U, 128U) val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U, 128U)
val hex = LibsodiumUtil.toHex(input) val hex = LibsodiumUtil.toHex(input)

View File

@ -11,7 +11,7 @@ import kotlin.browser.window
fun main() { fun main() {
val runningOnNode = jsTypeOf(window) == "undefined" val runningOnNode = jsTypeOf(window) == "undefined"
if (!runningOnNode) { if (!runningOnNode) = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
render(document.getElementById("root")) { render(document.getElementById("root")) {
app { app {
@ -19,7 +19,7 @@ fun main() {
} }
} }
} }
} else { } else = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
val hash = Hash.sha512("123".encodeToUByteArray()) val hash = Hash.sha512("123".encodeToUByteArray())
println("Hash (SHA512) of 123: ${hash.toHexString()}") println("Hash (SHA512) of 123: ${hash.toHexString()}")