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: variables:
GIT_SUBMODULE_STRATEGY: recursive GIT_SUBMODULE_STRATEGY: recursive
CHROME_BIN: "chromium"
simpleCheck: simpleCheck:
stage: prepare 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 Before using the wrapper you need to initialize the underlying libsodium library. You can use either a callback or coroutines approach
``` ```
= runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initializeWithCallback {
// Libsodium initialized // Libsodium initialized
} }

View File

@ -48,7 +48,7 @@ object Deps {
val stdLib = "stdlib-common" val stdLib = "stdlib-common"
val test = "test-common" val test = "test-common"
val testAnnotation = "test-annotations-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 serialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.kotlinSerialization}"
val atomicfu = "com.ionspin.kotlin.atomicfu:atomicfu:${Versions.atomicfu}" val atomicfu = "com.ionspin.kotlin.atomicfu:atomicfu:${Versions.atomicfu}"

View File

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

View File

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

View File

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

@ -3,7 +3,9 @@ package com.ionspin.kotlin.crypto.hash
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.hexStringToUByteArray 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.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,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" +
@ -31,8 +34,8 @@ class HashTest {
@Test @Test
fun hashTestSha256() { fun hashTestSha256() = runTest {
LibsodiumInitializer.initializeWithCallback { LibsodiumInitializer.initialize()
val input = ("Input for various hash functions").encodeToUByteArray() val input = ("Input for various hash functions").encodeToUByteArray()
val expected = ("2bb078ec5993b5428355ba49bf030b1ac7" + val expected = ("2bb078ec5993b5428355ba49bf030b1ac7" +
"1519e635aebc2f28124fac2aef9264").hexStringToUByteArray() "1519e635aebc2f28124fac2aef9264").hexStringToUByteArray()
@ -48,12 +51,12 @@ class HashTest {
assertTrue { assertTrue {
multipartResult.contentEquals(expected) multipartResult.contentEquals(expected)
} }
}
} }
@Test @Test
fun hashTestSha512() { fun hashTestSha512() = 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)

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

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