From d1a910b965e1ff2fe358fd855eb9edb17d3eb428 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Sat, 8 Aug 2020 23:05:27 +0200 Subject: [PATCH] fix macos and windows compilation issues --- .../src/jsMain/kotlin/debug/test/DebugTest.kt | 14 +++++----- .../jvmMain/kotlin/debug/test/DebugTest.kt | 14 +++++----- .../nativeMain/kotlin/debug/test/DebugTest.kt | 7 +++++ .../com/ionspin/kotlin/crypto/HelperTest.kt | 5 ++-- .../kotlin/bignum/crypto/util/testBlocking.kt | 27 ------------------- 5 files changed, 24 insertions(+), 43 deletions(-) delete mode 100644 multiplatform-crypto/src/mingwX64Test/kotlin/com/ionspin/kotlin/bignum/crypto/util/testBlocking.kt diff --git a/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/debug/test/DebugTest.kt b/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/debug/test/DebugTest.kt index b4be625..727d9c7 100644 --- a/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/debug/test/DebugTest.kt +++ b/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/debug/test/DebugTest.kt @@ -15,39 +15,39 @@ actual typealias GenericHashState = Any actual class Crypto internal actual constructor() { actual fun crypto_hash_sha256_init(): dynamic { - println("Debug") + println("Debug crypto_hash_sha256_init") val result = js("getSodium().crypto_hash_sha256_init()") return result } actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) { - println("Debug") + println("Debug crypto_hash_sha256_update") getSodium().crypto_hash_sha256_update(state, input.toUInt8Array(), ) } actual fun crypto_hash_sha256_final(state: Sha256State): UByteArray { - println("Debug") + println("Debug crypto_hash_sha256_final") return getSodium().crypto_hash_sha256_final(state).toUByteArray() } actual fun crypto_hash_sha512_init(): dynamic { - println("Debug") + println("Debug crypto_hash_sha512_init") val result = js("getSodium().crypto_hash_sha512_init()") return result } actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) { - println("Debug") + println("Debug crypto_hash_sha512_update") getSodium().crypto_hash_sha512_update(state, input.toUInt8Array(), ) } actual fun crypto_hash_sha512_final(state: Sha512State): UByteArray { - println("Debug") + println("Debug crypto_hash_sha512_final") return getSodium().crypto_hash_sha512_final(state).toUByteArray() } actual fun crypto_generichash_init(key: UByteArray, outlen: Int): dynamic { - println("Debug") + println("Debug crypto_generichash_init") return getSodium().crypto_generichash_init(key.toUInt8Array(), outlen) } } diff --git a/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/debug/test/DebugTest.kt b/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/debug/test/DebugTest.kt index f7d99eb..1213842 100644 --- a/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/debug/test/DebugTest.kt +++ b/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/debug/test/DebugTest.kt @@ -17,45 +17,45 @@ actual typealias GenericHashState = ByteArray actual class Crypto internal actual constructor() { actual fun crypto_hash_sha256_init(): Sha256State { val state = debug.test.Sha256State() - println("Debug") + println("Debug crypto_hash_sha256_init") sodium.crypto_hash_sha256_init(state) return state } actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) { - println("Debug") + println("Debug crypto_hash_sha256_update") sodium.crypto_hash_sha256_update(state, input.asByteArray(), input.size.toLong()) } actual fun crypto_hash_sha256_final(state: Sha256State): UByteArray { val out = UByteArray(32) - println("Debug") + println("Debug crypto_hash_sha256_final") sodium.crypto_hash_sha256_final(state, out.asByteArray()) return out } actual fun crypto_hash_sha512_init(): Sha512State { val state = debug.test.Sha512State() - println("Debug") + println("Debug crypto_hash_sha512_init") sodium.crypto_hash_sha512_init(state) return state } actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) { - println("Debug") + println("Debug crypto_hash_sha512_update") sodium.crypto_hash_sha512_update(state, input.asByteArray(), input.size.toLong()) } actual fun crypto_hash_sha512_final(state: Sha512State): UByteArray { val out = UByteArray(64) - println("Debug") + println("Debug crypto_hash_sha512_final") sodium.crypto_hash_sha512_final(state, out.asByteArray()) return out } actual fun crypto_generichash_init(key: UByteArray, outlen: Int): GenericHashState { val state = debug.test.GenericHashState(sodium.crypto_generichash_statebytes()) - println("Debug") + println("Debug crypto_generichash_init") sodium.crypto_generichash_init(state, key.asByteArray(), key.size, outlen) return state } diff --git a/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/debug/test/DebugTest.kt b/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/debug/test/DebugTest.kt index a199eab..5224235 100644 --- a/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/debug/test/DebugTest.kt +++ b/kotlin-multiplatform-libsodium-generator/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/debug/test/DebugTest.kt @@ -30,11 +30,13 @@ actual class Crypto internal actual constructor() { actual fun crypto_hash_sha256_init(): Sha256State { val allocated = sodium_malloc(debug.test.Sha256State.size.convert())!! val state = allocated.reinterpret().pointed + println("Debug crypto_hash_sha256_init") libsodium.crypto_hash_sha256_init(state.ptr) return state } actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) { + println("Debug crypto_hash_sha256_update") val pinnedInput = input.pin() libsodium.crypto_hash_sha256_update(state.ptr, pinnedInput.addressOf(0), input.size.convert()) pinnedInput.unpin() @@ -42,6 +44,7 @@ actual class Crypto internal actual constructor() { actual fun crypto_hash_sha256_final(state: Sha256State): UByteArray { val out = UByteArray(32) + println("Debug crypto_hash_sha256_final") val pinnedOut = out.pin() libsodium.crypto_hash_sha256_final(state.ptr, pinnedOut.addressOf(0)) pinnedOut.unpin() @@ -51,11 +54,13 @@ actual class Crypto internal actual constructor() { actual fun crypto_hash_sha512_init(): Sha512State { val allocated = sodium_malloc(debug.test.Sha512State.size.convert())!! val state = allocated.reinterpret().pointed + println("Debug crypto_hash_sha512_init") libsodium.crypto_hash_sha512_init(state.ptr) return state } actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) { + println("Debug crypto_hash_sha512_update") val pinnedInput = input.pin() libsodium.crypto_hash_sha512_update(state.ptr, pinnedInput.addressOf(0), input.size.convert()) pinnedInput.unpin() @@ -63,6 +68,7 @@ actual class Crypto internal actual constructor() { actual fun crypto_hash_sha512_final(state: Sha512State): UByteArray { val out = UByteArray(64) + println("Debug crypto_hash_sha512_final") val pinnedOut = out.pin() libsodium.crypto_hash_sha512_final(state.ptr, pinnedOut.addressOf(0)) pinnedOut.unpin() @@ -72,6 +78,7 @@ actual class Crypto internal actual constructor() { actual fun crypto_generichash_init(key: UByteArray, outlen: Int): GenericHashState { val allocated = sodium_malloc(debug.test.GenericHashState.size.convert())!! val state = allocated.reinterpret().pointed + println("Debug crypto_generichash_init") val pinnedKey = key.pin() libsodium.crypto_generichash_init(state.ptr, pinnedKey.addressOf(0), key.size.convert(), outlen.convert()) diff --git a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/HelperTest.kt b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/HelperTest.kt index c6cef5d..fd6827e 100644 --- a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/HelperTest.kt +++ b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/HelperTest.kt @@ -5,6 +5,7 @@ import com.ionspin.kotlin.crypto.util.toHexString import kotlinx.cinterop.* import libsodium.* import platform.posix.free +import platform.posix.malloc import kotlin.test.Ignore import kotlin.test.Test @@ -29,7 +30,7 @@ class HelperTest { fun generateForRounds256(target: Long) { val updateValue = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno".encodeToUByteArray().toCValues() - val state = platform.linux.malloc(crypto_hash_sha256_state.size.convert())!! + val state = malloc(crypto_hash_sha256_state.size.convert())!! .reinterpret() crypto_hash_sha256_init(state) @@ -59,7 +60,7 @@ class HelperTest { println("Wut") val updateValue = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno".encodeToUByteArray().toCValues() - val state = platform.linux.malloc(crypto_hash_sha512_state.size.convert())!! + val state = malloc(crypto_hash_sha512_state.size.convert())!! .reinterpret() crypto_hash_sha512_init(state) diff --git a/multiplatform-crypto/src/mingwX64Test/kotlin/com/ionspin/kotlin/bignum/crypto/util/testBlocking.kt b/multiplatform-crypto/src/mingwX64Test/kotlin/com/ionspin/kotlin/bignum/crypto/util/testBlocking.kt deleted file mode 100644 index 8fb509a..0000000 --- a/multiplatform-crypto/src/mingwX64Test/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