Merge pull request #7 from ionspin/js-both

Js both
This commit is contained in:
Ugljesa Jovanovic 2021-02-20 10:37:16 +00:00 committed by GitHub
commit 5228614fce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 133 additions and 70 deletions

View File

@ -11,6 +11,7 @@ workflow:
variables:
GIT_SUBMODULE_STRATEGY: recursive
CHROME_BIN: "chromium"
simpleCheck:
stage: prepare

View File

@ -18,6 +18,7 @@ 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
```
= runTest {
LibsodiumInitializer.initializeWithCallback {
// Libsodium initialized
}

View File

@ -48,7 +48,7 @@ object Deps {
val stdLib = "stdlib-common"
val test = "test-common"
val testAnnotation = "test-annotations-common"
val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:${Versions.kotlinCoroutines}"
val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinCoroutines}"
val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.kotlinSerialization}"
val atomicfu = "com.ionspin.kotlin.atomicfu:atomicfu:${Versions.atomicfu}"

View File

@ -17,7 +17,6 @@ org.gradle.parallel=true
kotlin.code.style=official
kotlin.js.compiler=ir
#kotlin.js.experimental.generateKotlinExternals=true
#kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.disableCompilerDaemon=true

View File

@ -44,7 +44,7 @@ kotlin {
val hostOsName = getHostOsName()
runningOnLinuxx86_64 {
jvm()
js {
js() {
browser {
testTask {
enabled = false //Until I sort out testing on travis
@ -284,12 +284,12 @@ tasks {
}
}
val jsNodeTest by getting(KotlinJsTest::class) {
testLogging {
events("PASSED", "FAILED", "SKIPPED")
showStandardStreams = true
}
}
// val jsNodeTest by getting(KotlinJsTest::class) {
// testLogging {
// events("PASSED", "FAILED", "SKIPPED")
// showStandardStreams = true
// }
// }
// val legacyjsNodeTest by getting(KotlinJsTest::class) {
//

View File

@ -83,14 +83,11 @@ kotlin {
runningOnLinuxx86_64 {
println("Configuring Linux X86-64 targets")
jvm()
js {
js(IR) {
browser {
testTask {
isRunningInGitlabCi {
enabled = false //Until I sort out testing on travis
}
useKarma {
useChrome()
useChromeHeadless()
}
}
}
@ -258,6 +255,7 @@ kotlin {
dependencies {
implementation(kotlin(Deps.Common.test))
implementation(kotlin(Deps.Common.testAnnotation))
implementation(Deps.Common.coroutines)
}
}
@ -627,7 +625,6 @@ tasks {
showStackTraces = true
}
}
val jsNodeTest by getting(KotlinJsTest::class) {
testLogging {
events("PASSED", "FAILED", "SKIPPED")
@ -653,6 +650,20 @@ tasks {
showStandardStreams = true
}
}
// val jsLegacyBrowserTest by getting(KotlinJsTest::class) {
// testLogging {
// events("PASSED", "FAILED", "SKIPPED")
// showStandardStreams = true
// }
// }
//
// val jsIrBrowserTest by getting(KotlinJsTest::class) {
// testLogging {
// events("PASSED", "FAILED", "SKIPPED")
// showStandardStreams = true
// }
// }
}
if (getHostOsName() == "windows") {

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.testBlocking
import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
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.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
@ -13,7 +14,7 @@ import kotlin.test.assertTrue
*/
class AuthenticatedEncryptionWithAssociatedDataTest {
@Test
fun testXChaCha20Poly1305Ieft() {
fun testXChaCha20Poly1305Ieft() = runTest {
LibsodiumInitializer.initializeWithCallback {
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()
@ -66,7 +67,7 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
}
@Test
fun testXChaCha20Poly1305IeftDetached() {
fun testXChaCha20Poly1305IeftDetached() = runTest {
LibsodiumInitializer.initializeWithCallback {
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()
@ -121,7 +122,7 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
}
@Test
fun testChaCha20Poly1305Ieft() {
fun testChaCha20Poly1305Ieft() = runTest {
LibsodiumInitializer.initializeWithCallback {
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()
@ -173,7 +174,7 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
}
@Test
fun testChaCha20Poly1305IeftDetached() {
fun testChaCha20Poly1305IeftDetached() = runTest {
LibsodiumInitializer.initializeWithCallback {
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()
@ -227,7 +228,7 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
}
@Test
fun testChaCha20Poly1305() {
fun testChaCha20Poly1305() = runTest {
LibsodiumInitializer.initializeWithCallback {
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()
@ -278,7 +279,7 @@ class AuthenticatedEncryptionWithAssociatedDataTest {
}
@Test
fun testChaCha20Poly1305Detached() {
fun testChaCha20Poly1305Detached() = runTest {
LibsodiumInitializer.initializeWithCallback {
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()

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.hexStringToUByteArray
import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@ -15,7 +16,7 @@ import kotlin.test.assertTrue
*/
class AuthTest {
@Test
fun testAuth() {
fun testAuth() = runTest {
LibsodiumInitializer.initializeWithCallback {
val message = ("I wonder if it would be possible" +
" to get some lyrics in these tests").encodeToUByteArray()
@ -41,7 +42,7 @@ class AuthTest {
}
@Test
fun testAuthHmacSha256() {
fun testAuthHmacSha256() = runTest {
LibsodiumInitializer.initializeWithCallback {
val message = ("I wonder if it would be possible" +
" to get some lyrics in these tests").encodeToUByteArray()
@ -66,7 +67,7 @@ class AuthTest {
}
@Test
fun testAuthHmacSha512() {
fun testAuthHmacSha512() = runTest {
LibsodiumInitializer.initializeWithCallback {
val message = ("I wonder if it would be possible" +
" to get some lyrics in these tests").encodeToUByteArray()
@ -93,7 +94,7 @@ class AuthTest {
}
@Test
fun simpleKeygenTest() {
fun simpleKeygenTest() = runTest {
LibsodiumInitializer.initializeWithCallback {
val authKey = Auth.authKeygen()
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 kotlin.random.Random
import kotlin.random.nextUBytes
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
@ -15,7 +16,7 @@ import kotlin.test.assertTrue
*/
class BoxTest {
@Test
fun keypairTest() {
fun keypairTest() = runTest {
LibsodiumInitializer.initializeWithCallback {
val keypair = Box.keypair()
assertTrue {
@ -28,7 +29,7 @@ class BoxTest {
}
@Test
fun testBoxEasy() {
fun testBoxEasy() = runTest {
LibsodiumInitializer.initializeWithCallback {
val message = "Message message message".encodeToUByteArray()
val senderKeypair = Box.keypair()
@ -49,7 +50,7 @@ class BoxTest {
}
@Test
fun testBoxEasyDetached() {
fun testBoxEasyDetached() = runTest {
LibsodiumInitializer.initializeWithCallback {
val message = "Message message message".encodeToUByteArray()
val senderKeypair = Box.keypair()
@ -82,7 +83,7 @@ class BoxTest {
}
@Test
fun testBeforeNonceAndMessage() {
fun testBeforeNonceAndMessage() = runTest {
LibsodiumInitializer.initializeWithCallback {
val message = "Message message message".encodeToUByteArray()
val senderKeypair = Box.keypair()
@ -109,7 +110,7 @@ class BoxTest {
}
@Test
fun testSeal() {
fun testSeal() = runTest {
LibsodiumInitializer.initializeWithCallback {
val message = "Message message message".encodeToUByteArray()
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.toHexString
import kotlin.test.BeforeTest
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertTrue
@ -17,7 +18,7 @@ class GenericHashTest {
@Test
fun testGenericHash() {
fun testGenericHash() = runTest {
LibsodiumInitializer.initializeWithCallback {
val inputString = "1234567890"
val inputStringBuilder = StringBuilder()
@ -46,7 +47,7 @@ class GenericHashTest {
}
@Test
fun testGenericHashMultipart() {
fun testGenericHashMultipart() = runTest {
LibsodiumInitializer.initializeWithCallback {
val updates = 14
val input = "1234567890"

View File

@ -3,7 +3,9 @@ package com.ionspin.kotlin.crypto.hash
import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.hexStringToUByteArray
import com.ionspin.kotlin.crypto.util.runTest
import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertTrue
@ -16,6 +18,7 @@ class HashTest {
//Not present in Lazy sodium
// @Test
// fun hashTest() {
// = runTest {
// LibsodiumInitializer.initializeWithCallback {
// val input = ("Input for various hash functions").encodeToUByteArray()
// val expected = ("34fcbcdcfe9e6aa3e6d5a64649afcfafb449c4b8435a65e5e7b7c2b6af3b04da350acee" +
@ -31,8 +34,8 @@ class HashTest {
@Test
fun hashTestSha256() {
LibsodiumInitializer.initializeWithCallback {
fun hashTestSha256() = runTest {
LibsodiumInitializer.initialize()
val input = ("Input for various hash functions").encodeToUByteArray()
val expected = ("2bb078ec5993b5428355ba49bf030b1ac7" +
"1519e635aebc2f28124fac2aef9264").hexStringToUByteArray()
@ -48,12 +51,12 @@ class HashTest {
assertTrue {
multipartResult.contentEquals(expected)
}
}
}
@Test
fun hashTestSha512() {
fun hashTestSha512() = runTest {
LibsodiumInitializer.initializeWithCallback {
val input = ("Input for various hash functions").encodeToUByteArray()
val expected = ("34fcbcdcfe9e6aa3e6d5a64649afcfafb449c4b8435a65e5e7b7c2b6af3b04da350acee" +

View File

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

View File

@ -2,6 +2,7 @@ package com.ionspin.kotlin.crypto.keyexchange
import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertTrue
@ -12,7 +13,7 @@ import kotlin.test.assertTrue
*/
class KeyExchangeTest {
@Test
fun testKeyExchange() {
fun testKeyExchange() = runTest {
LibsodiumInitializer.initializeWithCallback {
val keypairClient = KeyExchange.keypair()
val keypairServer = KeyExchange.keypair()
@ -40,7 +41,7 @@ class KeyExchangeTest {
}
@Test
fun testKeyExchangeSeeded() {
fun testKeyExchangeSeeded() = runTest {
LibsodiumInitializer.initializeWithCallback {
val seed = UByteArray(crypto_kx_SEEDBYTES) { 7U }
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 kotlin.random.Random
import kotlin.random.nextUBytes
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertTrue
@ -14,7 +15,7 @@ import kotlin.test.assertTrue
*/
class PasswordHashTest {
@Test
fun testPasswordHash() {
fun testPasswordHash() = runTest {
LibsodiumInitializer.initializeWithCallback {
val randomBytes = Random(0).nextUBytes(crypto_pwhash_SALTBYTES)
val password = "correct horse battery staple"
@ -35,8 +36,7 @@ class PasswordHashTest {
}
@Test
fun testPasswordHashForStorage() {
fun testPasswordHashForStorage() = runTest {
LibsodiumInitializer.initializeWithCallback {
val password = "correct horse battery staple"
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.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertTrue
@ -29,7 +30,7 @@ class ScalarMultiplicationTest {
val expectedSharedSecretString = "4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742"
@Test
fun testScalarMultiplication() {
fun testScalarMultiplication() = runTest {
LibsodiumInitializer.initializeWithCallback {
val alicePublicKey = ScalarMultiplication.scalarMultiplicationBase(aliceSecretKey)
assertTrue {

View File

@ -3,6 +3,7 @@ package com.ionspin.kotlin.crypto.secretbox
import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
@ -15,7 +16,7 @@ import kotlin.test.assertTrue
class SecretBoxTest {
@Test
fun secretBoxTestEasy() {
fun secretBoxTestEasy() = runTest {
LibsodiumInitializer.initializeWithCallback {
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()
@ -50,7 +51,7 @@ class SecretBoxTest {
}
@Test
fun secretBoxTestDetached() {
fun secretBoxTestDetached() = runTest {
LibsodiumInitializer.initializeWithCallback {
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()

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.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.testBlocking
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
@ -17,7 +18,7 @@ class SecretStreamTest {
@Test
fun testSecretStream() = testBlocking {
fun testSecretStream() = runTest {
LibsodiumInitializer.initializeWithCallback {
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()

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.hexStringToUByteArray
import com.ionspin.kotlin.crypto.util.toHexString
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertTrue
@ -16,7 +17,7 @@ import kotlin.test.assertTrue
class ShortHashTest {
@Test
fun testShortHash() {
fun testShortHash() = runTest {
LibsodiumInitializer.initializeWithCallback {
val expected = "00e5d509c14e81bb".hexStringToUByteArray()
val input = "Libsodium test"
@ -30,7 +31,7 @@ class ShortHashTest {
}
@Test
fun testKeygen() {
fun testKeygen() = runTest {
LibsodiumInitializer.initializeWithCallback {
assertTrue {
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.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
@ -12,7 +13,7 @@ import kotlin.test.assertTrue
class SignatureTest {
@Test
fun testSignAndVerify() {
fun testSignAndVerify() = runTest {
LibsodiumInitializer.initializeWithCallback {
val keys = Signature.keypair()
val message = "Some text that will be signed".encodeToUByteArray()
@ -33,7 +34,7 @@ class SignatureTest {
}
@Test
fun testDetachedSignAndVerify() {
fun testDetachedSignAndVerify() = runTest {
LibsodiumInitializer.initializeWithCallback {
val keys = Signature.keypair()
val message = "Some text that will be signed".encodeToUByteArray()
@ -51,7 +52,7 @@ class SignatureTest {
}
@Test
fun testMultipart() {
fun testMultipart() = runTest {
LibsodiumInitializer.initializeWithCallback {
val keys = Signature.keypair()
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 kotlin.random.Random
import kotlin.random.nextUBytes
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertTrue
@ -20,7 +21,7 @@ class StreamTest {
val seed = UByteArray(randombytes_SEEDBYTES) { 0U }
@Test
fun testChaCha20Stream() {
fun testChaCha20Stream() = runTest {
LibsodiumInitializer.initializeWithCallback {
val message = "This is a cha cha message".encodeToUByteArray()
val nonce = LibsodiumRandom.bufDeterministic(crypto_stream_chacha20_NONCEBYTES, seed)
@ -47,7 +48,7 @@ class StreamTest {
}
@Test
fun testChaCha20IetfStream() {
fun testChaCha20IetfStream() = runTest {
LibsodiumInitializer.initializeWithCallback {
val message = "This is a cha cha message".encodeToUByteArray()
val nonce = LibsodiumRandom.bufDeterministic(crypto_stream_chacha20_ietf_NONCEBYTES, seed)

View File

@ -1,6 +1,7 @@
package com.ionspin.kotlin.crypto.util
import com.ionspin.kotlin.crypto.LibsodiumInitializer
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@ -13,7 +14,7 @@ import kotlin.test.assertTrue
class LibsodiumRandomTest {
@Test
fun testRandom() {
fun testRandom()= runTest {
//This is just a sanity test, it should fail on occasion though, with probability of 1/2^32
LibsodiumInitializer.initializeWithCallback {
val random = LibsodiumRandom.random()
@ -23,7 +24,7 @@ class LibsodiumRandomTest {
}
@Test
fun testRandomUniform() {
fun testRandomUniform() = runTest {
//This is just a sanity test, it should fail on occasion though, with probability of 1/2^31
LibsodiumInitializer.initializeWithCallback {
val random = LibsodiumRandom.uniform(UInt.MAX_VALUE / 2U)
@ -32,7 +33,7 @@ class LibsodiumRandomTest {
}
@Test
fun testRandomBuffer() {
fun testRandomBuffer() = runTest {
//This is just a sanity test, it should fail on occasion though, with probability of 1/2^52
LibsodiumInitializer.initializeWithCallback {
val result = LibsodiumRandom.buf(20)
@ -42,7 +43,7 @@ class LibsodiumRandomTest {
}
@Test
fun testRandomBufferDeterministic() {
fun testRandomBufferDeterministic() = runTest {
//This is just a sanity test, it should fail on occasion though, with probability of 1/2^52
LibsodiumInitializer.initializeWithCallback {
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.crypto.LibsodiumInitializer
import kotlin.math.exp
import com.ionspin.kotlin.crypto.util.runTest
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@ -15,7 +16,7 @@ import kotlin.test.assertTrue
class LibsodiumUtilTest {
@Test
fun testMemzero() {
fun testMemzero() = runTest {
LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U)
LibsodiumUtil.memzero(input)
@ -26,7 +27,7 @@ class LibsodiumUtilTest {
}
@Test
fun testMemcmp() {
fun testMemcmp() = runTest {
LibsodiumInitializer.initializeWithCallback {
val input = 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
fun testPadding() {
fun testPadding() = runTest {
LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U)
val blocksize = 16
@ -57,7 +58,7 @@ class LibsodiumUtilTest {
}
@Test
fun testPaddingChars() {
fun testPaddingChars() = runTest {
LibsodiumInitializer.initializeWithCallback {
val input = charArrayOf('a', 'b', 'c', 'd').map { it.toByte().toUByte() }.toUByteArray()
val blocksize = 4
@ -73,7 +74,7 @@ class LibsodiumUtilTest {
}
@Test
fun testPaddingAligned() {
fun testPaddingAligned() = runTest {
LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U)
val blocksize = 2
@ -91,7 +92,7 @@ class LibsodiumUtilTest {
}
@Test
fun testPaddingMultiblock() {
fun testPaddingMultiblock() = runTest {
LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 6U)
val blocksize = 4
@ -109,7 +110,7 @@ class LibsodiumUtilTest {
}
@Test
fun testToBase64() {
fun testToBase64() = runTest {
LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U)
val expected = "AQIDBAUgQID_"
@ -128,7 +129,7 @@ class LibsodiumUtilTest {
}
@Test
fun testToBase64Unaligned() {
fun testToBase64Unaligned() = runTest {
LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U, 128U)
val expected = "AQIDBAUgQID_gA"
@ -147,7 +148,7 @@ class LibsodiumUtilTest {
}
@Test
fun toHex() {
fun toHex() = runTest {
LibsodiumInitializer.initializeWithCallback {
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U, 128U)
val hex = LibsodiumUtil.toHex(input)

View File

@ -16,6 +16,7 @@
package com.ionspin.kotlin.crypto.util
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.Continuation
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.startCoroutine
@ -35,4 +36,6 @@ fun testBlocking(block : suspend () -> Unit) {
block.startCoroutine(continuation)
}
expect fun runTest(block: suspend (scope : CoroutineScope) -> Unit)

View File

@ -0,0 +1,9 @@
package com.ionspin.kotlin.crypto.debug
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 08-Feb-2021
*/
class DebugTest {
}

View File

@ -0,0 +1,7 @@
package com.ionspin.kotlin.crypto.util
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.promise
actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit): dynamic = GlobalScope.promise { block(this) }

View File

@ -0,0 +1,7 @@
package com.ionspin.kotlin.crypto.util
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) }

View File

@ -0,0 +1,7 @@
package com.ionspin.kotlin.crypto.util
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) }

View File

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