diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 7a906c0..5a204fc 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -23,7 +23,7 @@ object Versions { val dokkaPlugin = "0.11.0-dev-44" val taskTreePlugin = "1.5" - val kotlinBigNumVersion = "0.1.6-1.4-M2-2-SNAPSHOT" + val kotlinBigNumVersion = "0.1.6-1.4-M2-3-SNAPSHOT" val lazySodium = "4.2.6" val jna = "5.5.0" diff --git a/multiplatform-crypto-api/build.gradle.kts b/multiplatform-crypto-api/build.gradle.kts index 4ec7aba..2f72099 100644 --- a/multiplatform-crypto-api/build.gradle.kts +++ b/multiplatform-crypto-api/build.gradle.kts @@ -69,7 +69,6 @@ kotlin { } } - //Not supported in OFFICIAL coroutines at the moment linuxArm64() { binaries { staticLib { @@ -77,7 +76,6 @@ kotlin { } } - //Not supported in OFFICAL coroutines at the moment linuxArm32Hfp() { binaries { staticLib { diff --git a/multiplatform-crypto-delegated/build.gradle.kts b/multiplatform-crypto-delegated/build.gradle.kts index ddfc8a8..257a7a9 100644 --- a/multiplatform-crypto-delegated/build.gradle.kts +++ b/multiplatform-crypto-delegated/build.gradle.kts @@ -131,7 +131,6 @@ kotlin { } - //Not supported in OFFICIAL coroutines at the moment (we're running a custom build) runningOnLinuxArm64 { println("Configuring Linux Arm 64 targets") @@ -249,7 +248,6 @@ kotlin { dependencies { implementation(kotlin(Deps.Common.stdLib)) implementation(kotlin(Deps.Common.test)) - implementation(Deps.Common.coroutines) implementation(Deps.Common.kotlinBigNum) api(project(Deps.Common.apiProject)) } @@ -262,7 +260,6 @@ kotlin { } val nativeDependencies = independentDependencyBlock { - implementation(Deps.Native.coroutines) } val nativeMain by creating { @@ -281,7 +278,6 @@ kotlin { kotlin.setSrcDirs(emptySet()) } dependencies { - implementation(Deps.Native.coroutines) } } @@ -420,7 +416,6 @@ kotlin { implementation(kotlin(Deps.Jvm.stdLib)) implementation(kotlin(Deps.Jvm.test)) implementation(kotlin(Deps.Jvm.testJUnit)) - implementation(Deps.Jvm.coroutinesCore) //lazysodium implementation(Deps.Jvm.Delegated.lazysodium) @@ -431,20 +426,17 @@ kotlin { dependencies { implementation(kotlin(Deps.Jvm.test)) implementation(kotlin(Deps.Jvm.testJUnit)) - implementation(Deps.Jvm.coroutinesTest) implementation(kotlin(Deps.Jvm.reflection)) } } val jsMain by getting { dependencies { implementation(kotlin(Deps.Js.stdLib)) - implementation(Deps.Js.coroutines) implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second)) } } val jsTest by getting { dependencies { - implementation(Deps.Js.coroutines) implementation(kotlin(Deps.Js.test)) implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second)) } diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Crypto.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Crypto.kt index ffc7640..f18e655 100644 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Crypto.kt +++ b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Crypto.kt @@ -164,7 +164,8 @@ object Crypto { } override fun createMultipartDecryptor(key: SymmetricKey, header: MultipartEncryptionHeader) : MultipartAuthenticatedDecryption { - val decryptor = XChaCha20Poly1305Delegated(key.value, header.nonce) + val decryptor = XChaCha20Poly1305Delegated() + decryptor.initializeForDecryption(key.value, header.nonce) return MultipartAuthenticatedDecryptor(decryptor) } @@ -174,8 +175,11 @@ object Crypto { class MultipartAuthenticatedEncryptor internal constructor(val key : SymmetricKey) : MultipartAuthenticatedEncryption { - val header = MultipartEncryptionHeader(SRNG.getRandomBytes(24)) - val primitive = XChaCha20Poly1305Delegated(key.value, header.nonce) + val header : MultipartEncryptionHeader + val primitive = XChaCha20Poly1305Delegated() + init { + header = MultipartEncryptionHeader(primitive.initializeForEncryption(key.value)) + } override fun startEncryption(): MultipartEncryptionHeader { return header diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/DelegatedXChaCha20Poly1305.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/DelegatedXChaCha20Poly1305.kt index 9eaa9ce..3e5a955 100644 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/DelegatedXChaCha20Poly1305.kt +++ b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/DelegatedXChaCha20Poly1305.kt @@ -6,13 +6,14 @@ package com.ionspin.kotlin.crypto.authenticated * ugljesa.jovanovic@ionspin.com * on 14-Jun-2020 */ -expect class XChaCha20Poly1305Delegated constructor(key: UByteArray, nonce: UByteArray) { - internal constructor(key: UByteArray, nonce: UByteArray, testState : UByteArray, testHeader: UByteArray) +expect class XChaCha20Poly1305Delegated internal constructor() { + internal constructor(key: UByteArray, testState : UByteArray, testHeader: UByteArray) companion object { fun encrypt(key: UByteArray, nonce: UByteArray, message: UByteArray, additionalData: UByteArray) : UByteArray fun decrypt(key: UByteArray, nonce: UByteArray, ciphertext: UByteArray, additionalData: UByteArray) : UByteArray } - + fun initializeForEncryption(key: UByteArray) : UByteArray + fun initializeForDecryption(key: UByteArray, header: UByteArray) fun encrypt(data: UByteArray, additionalData: UByteArray = ubyteArrayOf()) : UByteArray fun decrypt(data: UByteArray, additionalData: UByteArray = ubyteArrayOf()) : UByteArray diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt index 63757ef..3957621 100644 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt +++ b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt @@ -209,7 +209,7 @@ class XChaCha20Poly1305Test { 0xDEU, 0xFBU, 0x5CU, 0x7FU, 0x1CU, 0x26U, 0x32U, 0x2CU, 0x51U, 0xF6U, 0xEFU, 0xC6U, 0x34U, 0xC4U, 0xACU, 0x6CU, 0xE8U, 0xF9U, 0x4BU, 0xABU, 0xA3U, ) - val xcha = XChaCha20Poly1305Delegated(key, ubyteArrayOf(), state, header) + val xcha = XChaCha20Poly1305Delegated(key, state, header) val data = UByteArray(100) { 0U } val result = xcha.encrypt(data) // assertTrue { diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt index ae5e010..2068b0f 100644 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt +++ b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt @@ -22,7 +22,8 @@ class Sha256Test { } @Test - fun statelessSimpleTest() { + fun statelessSimpleTest() = testBlocking { + Initializer.initialize() val expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" val result = CryptoPrimitives.Sha256.stateless("test".encodeToUByteArray()).toHexString() // println("Result: $result") @@ -32,7 +33,8 @@ class Sha256Test { //This is a bad test since it's not larger than one block //but for now I'm testing that the platform library is being correctly called @Test - fun updateableSimpleTest() { + fun updateableSimpleTest() = testBlocking { + Initializer.initialize() val expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" val sha256 = CryptoPrimitives.Sha256.updateable() sha256.update("t".encodeToUByteArray()) diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt index 14eec63..44a0375 100644 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt +++ b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt @@ -22,7 +22,8 @@ class Sha512Test { } @Test - fun statelessSimpleTest() { + fun statelessSimpleTest() = testBlocking { + Initializer.initialize() val expected = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67" + "b143732c304cc5fa9ad8e6f57f50028a8ff" val result = CryptoPrimitives.Sha512.stateless("test".encodeToUByteArray()).toHexString() @@ -33,7 +34,8 @@ class Sha512Test { //This is a bad test since it's not larger than one block //but for now I'm testing that the platform library is being correctly called @Test - fun updateableSimpleTest() { + fun updateableSimpleTest() = testBlocking { + Initializer.initialize() val expected = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67" + "b143732c304cc5fa9ad8e6f57f50028a8ff" val sha512 = CryptoPrimitives.Sha512.updateable() diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt index ab0598d..65ce4a0 100644 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt +++ b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt @@ -16,11 +16,20 @@ package com.ionspin.kotlin.crypto.util -import kotlinx.coroutines.CoroutineScope +import kotlin.coroutines.Continuation +import kotlin.coroutines.EmptyCoroutineContext +import kotlin.coroutines.startCoroutine + /** * Created by Ugljesa Jovanovic * ugljesa.jovanovic@ionspin.com * on 20-Jul-2019 */ -expect fun testBlocking(block : suspend () -> Unit) \ No newline at end of file +fun testBlocking(block : suspend () -> Unit) { + val continuation = Continuation(EmptyCoroutineContext) { + //Do nothing + println("Done") + } + block.startCoroutine(continuation) +} diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt index db3c856..d0fa4c6 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt @@ -44,7 +44,12 @@ interface JsSodiumInterface { fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, additionalData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array //XChaCha20Poly1305 + //encrypt + fun crypto_secretstream_xchacha20poly1305_init_push(header: Uint8Array) : dynamic + fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, additionalData: Uint8Array, tag: Char) : Uint8Array + //decrypt + fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic } diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt index c0f361a..5a0611c 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt @@ -16,7 +16,7 @@ import org.khronos.webgl.Uint8Array * ugljesa.jovanovic@ionspin.com * on 14-Jun-2020 */ -actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonce: UByteArray) { +actual class XChaCha20Poly1305Delegated internal actual constructor() { actual companion object { actual fun encrypt( key: UByteArray, @@ -51,16 +51,25 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc } } - init { -// val state = + var state : dynamic = null + + actual fun initializeForEncryption(key: UByteArray) : UByteArray { + val stateAndHeader = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array()) + val state = stateAndHeader.state + val header = stateAndHeader.header + console.log(state) + console.log(header) + return header + } + + actual fun initializeForDecryption(key: UByteArray, header: UByteArray) { } internal actual constructor( key: UByteArray, - nonce: UByteArray, testState: UByteArray, testHeader: UByteArray - ) : this(key, nonce) { + ) : this() { } @@ -73,4 +82,6 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc TODO("not implemented yet") } + + } diff --git a/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt b/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt index 2df4151..a366756 100644 --- a/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt +++ b/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt @@ -15,14 +15,14 @@ */ package com.ionspin.kotlin.crypto.util - -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.promise - - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 20-Jul-2019 - */ -actual fun testBlocking(block: suspend ()-> Unit) : dynamic = GlobalScope.promise { block() } \ No newline at end of file +// +//import kotlinx.coroutines.GlobalScope +//import kotlinx.coroutines.promise +// +// +///** +// * Created by Ugljesa Jovanovic +// * ugljesa.jovanovic@ionspin.com +// * on 20-Jul-2019 +// */ +//actual fun testBlocking(block: suspend ()-> Unit) : dynamic = GlobalScope.promise { block() } diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt index 17c988e..6125162 100644 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt +++ b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt @@ -7,7 +7,7 @@ import com.goterl.lazycode.lazysodium.SodiumJava * ugljesa.jovanovic@ionspin.com * on 14-Jun-2020 */ -actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonce: UByteArray) { +actual class XChaCha20Poly1305Delegated internal actual constructor() { actual companion object { actual fun encrypt( key: UByteArray, @@ -56,13 +56,19 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc internal actual constructor( key: UByteArray, - nonce: UByteArray, testState: UByteArray, testHeader: UByteArray - ) : this(key, ubyteArrayOf()) { + ) : this() { } + actual fun initializeForEncryption(key: UByteArray) : UByteArray { + TODO() + } + + actual fun initializeForDecryption(key: UByteArray, header: UByteArray) { + } + actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray { TODO("not implemented yet") } @@ -72,4 +78,6 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc } + + } diff --git a/multiplatform-crypto-delegated/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt b/multiplatform-crypto-delegated/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt index 8fb509a..5c561f7 100644 --- a/multiplatform-crypto-delegated/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt +++ b/multiplatform-crypto-delegated/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt @@ -16,12 +16,19 @@ package com.ionspin.kotlin.crypto.util -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.runBlocking +import kotlin.coroutines.Continuation +import kotlin.coroutines.EmptyCoroutineContext +import kotlin.coroutines.startCoroutine /** * Created by Ugljesa Jovanovic * ugljesa.jovanovic@ionspin.com * on 20-Jul-2019 */ -actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() } \ No newline at end of file +//actual fun testBlocking(block: suspend () -> Unit) { +// val continuation = Continuation(EmptyCoroutineContext) { +// println("Done") +// } +// block.startCoroutine(continuation) +// +//} diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt index a3b61df..1b809f0 100644 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt +++ b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt @@ -10,7 +10,7 @@ import platform.posix.malloc * ugljesa.jovanovic@ionspin.com * on 14-Jun-2020 */ -actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray, val nonce: UByteArray) { +actual class XChaCha20Poly1305Delegated internal actual constructor() { actual companion object { actual fun encrypt( key: UByteArray, @@ -61,13 +61,18 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray, } } + var state = + malloc(crypto_secretstream_xchacha20poly1305_state.size.convert())!! + .reinterpret() + .pointed + + val header = UByteArray(crypto_secretstream_xchacha20poly1305_HEADERBYTES.toInt()) { 0U } actual internal constructor( key: UByteArray, - nonce: UByteArray, testState: UByteArray, testHeader: UByteArray - ) : this(key, nonce) { + ) : this() { val pointer = state.ptr.reinterpret() for (i in 0 until crypto_secretstream_xchacha20poly1305_state.size.toInt()) { pointer[i] = testState[i] @@ -81,14 +86,9 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray, println("header after setting-----------") } - var state = - malloc(crypto_secretstream_xchacha20poly1305_state.size.convert())!! - .reinterpret() - .pointed - val header = UByteArray(crypto_secretstream_xchacha20poly1305_HEADERBYTES.toInt()) { 0U } - init { + actual fun initializeForEncryption(key: UByteArray) : UByteArray { val pinnedHeader = header.pin() crypto_secretstream_xchacha20poly1305_init_push(state.ptr, pinnedHeader.addressOf(0), key.toCValues()) println("state-----------") @@ -97,9 +97,15 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray, println("--------header-----------") header.hexColumsPrint() println("--------header-----------") + pinnedHeader.unpin() + return header + } + + actual fun initializeForDecryption(key: UByteArray, header: UByteArray) { } + actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray { val ciphertextWithTag = UByteArray(data.size + crypto_secretstream_xchacha20poly1305_ABYTES.toInt()) val ciphertextWithTagPinned = ciphertextWithTag.pin() @@ -125,4 +131,6 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray, } + + } diff --git a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt index 8fb509a..8101dca 100644 --- a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt +++ b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt @@ -14,14 +14,14 @@ * limitations under the License. */ -package com.ionspin.kotlin.crypto.util - -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.runBlocking - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 20-Jul-2019 - */ -actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() } \ No newline at end of file +//package com.ionspin.kotlin.crypto.util +// +//import kotlinx.coroutines.CoroutineScope +//import kotlinx.coroutines.runBlocking +// +///** +// * Created by Ugljesa Jovanovic +// * ugljesa.jovanovic@ionspin.com +// * on 20-Jul-2019 +// */ +//actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() } diff --git a/multiplatform-crypto/build.gradle.kts b/multiplatform-crypto/build.gradle.kts index f11341a..658036b 100644 --- a/multiplatform-crypto/build.gradle.kts +++ b/multiplatform-crypto/build.gradle.kts @@ -197,7 +197,6 @@ kotlin { dependencies { implementation(kotlin(Deps.Common.stdLib)) implementation(kotlin(Deps.Common.test)) - implementation(Deps.Common.coroutines) implementation(Deps.Common.kotlinBigNum) implementation(project(Deps.Common.apiProject)) } @@ -213,7 +212,6 @@ kotlin { val nativeMain by creating { dependsOn(commonMain) dependencies { - implementation(Deps.Native.coroutines) } isRunningInIdea { kotlin.setSrcDirs(emptySet()) @@ -224,7 +222,6 @@ kotlin { val nativeTest by creating { dependsOn(commonTest) dependencies { - implementation(Deps.Native.coroutines) } } @@ -257,26 +254,22 @@ kotlin { implementation(kotlin(Deps.Jvm.stdLib)) implementation(kotlin(Deps.Jvm.test)) implementation(kotlin(Deps.Jvm.testJUnit)) - implementation(Deps.Jvm.coroutinesCore) } } val jvmTest by getting { dependencies { implementation(kotlin(Deps.Jvm.test)) implementation(kotlin(Deps.Jvm.testJUnit)) - implementation(Deps.Jvm.coroutinesTest) implementation(kotlin(Deps.Jvm.reflection)) } } val jsMain by getting { dependencies { implementation(kotlin(Deps.Js.stdLib)) - implementation(Deps.Js.coroutines) } } val jsTest by getting { dependencies { - implementation(Deps.Js.coroutines) implementation(kotlin(Deps.Js.test)) } } @@ -355,7 +348,6 @@ kotlin { // val mingwX86Main by getting { // dependsOn(commonMain) // dependencies { -// implementation(Deps.Native.coroutines) // } // } @@ -367,7 +359,6 @@ kotlin { val mingwX64Main by getting { dependsOn(commonMain) dependencies { - implementation(Deps.Native.coroutines) } } diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/parallelization/Coroutines14.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/parallelization/Coroutines14.kt deleted file mode 100644 index 6a05cbb..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/parallelization/Coroutines14.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2019 Ugljesa Jovanovic - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.ionspin.kotlin.crypto.parallelization - -import kotlin.time.ExperimentalTime - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-May-2020 - */ -@ExperimentalTime -object Coroutines14 { - fun argonParallel() : Array { -// val argon = Argon2() -// argon - println("Placeholder") - return emptyArray() - } -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/parallelization/CoroutinesDebugTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/parallelization/CoroutinesDebugTest.kt deleted file mode 100644 index a6a0f05..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/parallelization/CoroutinesDebugTest.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2019 Ugljesa Jovanovic - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.ionspin.kotlin.crypto.parallelization - -import com.ionspin.kotlin.crypto.util.testBlocking -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch -import kotlin.test.Test -import kotlin.time.ExperimentalTime - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-May-2020 - */ -@ExperimentalTime -class CoroutinesDebugTest { - - @Test - fun debugTest() = testBlocking { - Coroutines14.argonParallel() - } -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt index ab0598d..9b061e7 100644 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt +++ b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt @@ -16,11 +16,19 @@ package com.ionspin.kotlin.crypto.util -import kotlinx.coroutines.CoroutineScope +import kotlin.coroutines.Continuation +import kotlin.coroutines.EmptyCoroutineContext +import kotlin.coroutines.startCoroutine /** * Created by Ugljesa Jovanovic * ugljesa.jovanovic@ionspin.com * on 20-Jul-2019 */ -expect fun testBlocking(block : suspend () -> Unit) \ No newline at end of file +fun testBlocking(block : suspend () -> Unit) { + val continuation = Continuation(EmptyCoroutineContext) { + //Do nothing + println("Done") + } + block.startCoroutine(continuation) +} diff --git a/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt b/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt deleted file mode 100644 index 2df4151..0000000 --- a/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019 Ugljesa Jovanovic - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.ionspin.kotlin.crypto.util - -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.promise - - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 20-Jul-2019 - */ -actual fun testBlocking(block: suspend ()-> Unit) : dynamic = GlobalScope.promise { block() } \ No newline at end of file diff --git a/multiplatform-crypto/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt b/multiplatform-crypto/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt deleted file mode 100644 index 8fb509a..0000000 --- a/multiplatform-crypto/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2019 Ugljesa Jovanovic - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.ionspin.kotlin.crypto.util - -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.runBlocking - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 20-Jul-2019 - */ -actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() } \ No newline at end of file diff --git a/multiplatform-crypto/src/nativeTest/kotlin/com/ionspin/kotlin/bignum/crypto/util/testBlocking.kt b/multiplatform-crypto/src/nativeTest/kotlin/com/ionspin/kotlin/bignum/crypto/util/testBlocking.kt deleted file mode 100644 index 8fb509a..0000000 --- a/multiplatform-crypto/src/nativeTest/kotlin/com/ionspin/kotlin/bignum/crypto/util/testBlocking.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2019 Ugljesa Jovanovic - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.ionspin.kotlin.crypto.util - -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.runBlocking - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 20-Jul-2019 - */ -actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() } \ No newline at end of file diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 96cfab1..e8a6a73 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -143,7 +143,6 @@ kotlin { dependencies { implementation(kotlin(Deps.Common.stdLib)) implementation(kotlin(Deps.Common.test)) - implementation(Deps.Common.coroutines) implementation(Deps.Common.kotlinBigNum) implementation(project(":multiplatform-crypto-delegated")) } @@ -159,14 +158,12 @@ kotlin { val nativeMain by creating { dependsOn(commonMain) dependencies { - implementation(Deps.Native.coroutines) } } val nativeTest by creating { dependsOn(commonTest) dependencies { - implementation(Deps.Native.coroutines) } } @@ -176,26 +173,22 @@ kotlin { implementation(kotlin(Deps.Jvm.stdLib)) implementation(kotlin(Deps.Jvm.test)) implementation(kotlin(Deps.Jvm.testJUnit)) - implementation(Deps.Jvm.coroutinesCore) } } val jvmTest by getting { dependencies { implementation(kotlin(Deps.Jvm.test)) implementation(kotlin(Deps.Jvm.testJUnit)) - implementation(Deps.Jvm.coroutinesTest) implementation(kotlin(Deps.Jvm.reflection)) } } val jsMain by getting { dependencies { implementation(kotlin(Deps.Js.stdLib)) - implementation(Deps.Js.coroutines) } } val jsTest by getting { dependencies { - implementation(Deps.Js.coroutines) implementation(kotlin(Deps.Js.test)) } }