fix macos and windows compilation issues
This commit is contained in:
parent
e6e7a7664c
commit
d1a910b965
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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<debug.test.Sha256State>().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<debug.test.Sha512State>().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<debug.test.GenericHashState>().pointed
|
||||
println("Debug crypto_generichash_init")
|
||||
val pinnedKey = key.pin()
|
||||
libsodium.crypto_generichash_init(state.ptr, pinnedKey.addressOf(0), key.size.convert(),
|
||||
outlen.convert())
|
||||
|
@ -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_state>()
|
||||
|
||||
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_state>()
|
||||
|
||||
crypto_hash_sha512_init(state)
|
||||
|
@ -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() }
|
Loading…
x
Reference in New Issue
Block a user