Pivot to a handled API, update common js and native generators
This commit is contained in:
1 parent
d8b92a6970
commit
1f0eaf59ca
12 files changed
+419
-258
No files matched your search
+5
-9
@@ -10,21 +10,17 @@ expect class Sha512State
|
||||
expect class GenericHashState
|
||||
|
||||
expect class Crypto {
|
||||
fun crypto_hash_sha256_init(state: Sha256State): Int
|
||||
fun crypto_hash_sha256_init(): Sha256State
|
||||
|
||||
fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray)
|
||||
|
||||
fun crypto_hash_sha256_final(state: Sha256State, out: UByteArray)
|
||||
fun crypto_hash_sha256_final(state: Sha256State): UByteArray
|
||||
|
||||
fun crypto_hash_sha512_init(state: Sha512State): Int
|
||||
fun crypto_hash_sha512_init(): Sha512State
|
||||
|
||||
fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray)
|
||||
|
||||
fun crypto_hash_sha512_final(state: Sha512State, out: UByteArray)
|
||||
fun crypto_hash_sha512_final(state: Sha512State): UByteArray
|
||||
|
||||
fun crypto_generichash_init(
|
||||
state: GenericHashState,
|
||||
key: UByteArray,
|
||||
outlen: Int
|
||||
): Int
|
||||
fun crypto_generichash_init(key: UByteArray, outlen: Int): GenericHashState
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package debug.test
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
import kotlin.Any
|
||||
import kotlin.Int
|
||||
@@ -13,42 +14,38 @@ actual typealias Sha512State = Any
|
||||
actual typealias GenericHashState = Any
|
||||
|
||||
actual class Crypto {
|
||||
actual fun crypto_hash_sha256_init(state: Sha256State): Int {
|
||||
actual fun crypto_hash_sha256_init(): dynamic {
|
||||
println("Debug")
|
||||
return getSodium().crypto_hash_sha256_init(state)
|
||||
return getSodium().crypto_hash_sha256_init()
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) {
|
||||
println("Debug")
|
||||
getSodium().crypto_hash_sha256_update(state, input.toUInt8Array(), input.size.toLong())
|
||||
getSodium().crypto_hash_sha256_update(state, input.toUInt8Array(), )
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_final(state: Sha256State, out: UByteArray) {
|
||||
actual fun crypto_hash_sha256_final(state: Sha256State): UByteArray {
|
||||
println("Debug")
|
||||
getSodium().crypto_hash_sha256_final(state, out.toUInt8Array())
|
||||
return getSodium().crypto_hash_sha256_final(state).toUByteArray()
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_init(state: Sha512State): Int {
|
||||
actual fun crypto_hash_sha512_init(): dynamic {
|
||||
println("Debug")
|
||||
return getSodium().crypto_hash_sha512_init(state)
|
||||
return getSodium().crypto_hash_sha512_init()
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) {
|
||||
println("Debug")
|
||||
getSodium().crypto_hash_sha512_update(state, input.toUInt8Array(), input.size.toLong())
|
||||
getSodium().crypto_hash_sha512_update(state, input.toUInt8Array(), )
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_final(state: Sha512State, out: UByteArray) {
|
||||
actual fun crypto_hash_sha512_final(state: Sha512State): UByteArray {
|
||||
println("Debug")
|
||||
getSodium().crypto_hash_sha512_final(state, out.toUInt8Array())
|
||||
return getSodium().crypto_hash_sha512_final(state).toUByteArray()
|
||||
}
|
||||
|
||||
actual fun crypto_generichash_init(
|
||||
state: GenericHashState,
|
||||
key: UByteArray,
|
||||
outlen: Int
|
||||
): Int {
|
||||
actual fun crypto_generichash_init(key: UByteArray, outlen: Int): dynamic {
|
||||
println("Debug")
|
||||
return getSodium().crypto_generichash_init(state, key.toUInt8Array(), key.size, outlen)
|
||||
return getSodium().crypto_generichash_init(key.toUInt8Array(), outlen)
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ actual typealias Sha512State = Hash.State512
|
||||
actual typealias GenericHashState = ByteArray
|
||||
|
||||
actual class Crypto {
|
||||
actual fun crypto_hash_sha256_init(state: Sha256State): Int {
|
||||
actual fun crypto_hash_sha256_init(state: Sha256State): Sha256State {
|
||||
println("Debug")
|
||||
return sodium.crypto_hash_sha256_init(state)
|
||||
}
|
||||
@@ -25,12 +25,12 @@ actual class Crypto {
|
||||
sodium.crypto_hash_sha256_update(state, input.asByteArray(), input.size.toLong())
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_final(state: Sha256State, out: UByteArray) {
|
||||
actual fun crypto_hash_sha256_final(state: Sha256State, out: UByteArray): UByteArray {
|
||||
println("Debug")
|
||||
sodium.crypto_hash_sha256_final(state, out.asByteArray())
|
||||
return sodium.crypto_hash_sha256_final(state, out.asByteArray())
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_init(state: Sha512State): Int {
|
||||
actual fun crypto_hash_sha512_init(state: Sha512State): Sha512State {
|
||||
println("Debug")
|
||||
return sodium.crypto_hash_sha512_init(state)
|
||||
}
|
||||
@@ -40,16 +40,16 @@ actual class Crypto {
|
||||
sodium.crypto_hash_sha512_update(state, input.asByteArray(), input.size.toLong())
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_final(state: Sha512State, out: UByteArray) {
|
||||
actual fun crypto_hash_sha512_final(state: Sha512State, out: UByteArray): UByteArray {
|
||||
println("Debug")
|
||||
sodium.crypto_hash_sha512_final(state, out.asByteArray())
|
||||
return sodium.crypto_hash_sha512_final(state, out.asByteArray())
|
||||
}
|
||||
|
||||
actual fun crypto_generichash_init(
|
||||
state: GenericHashState,
|
||||
key: UByteArray,
|
||||
outlen: Int
|
||||
): Int {
|
||||
): GenericHashState {
|
||||
println("Debug")
|
||||
return sodium.crypto_generichash_init(state, key.asByteArray(), key.size, outlen)
|
||||
}
|
||||
|
||||
+31
-14
@@ -1,16 +1,20 @@
|
||||
package debug.test
|
||||
|
||||
import kotlin.Byte
|
||||
import kotlin.ByteArray
|
||||
import kotlin.Int
|
||||
import kotlin.UByteArray
|
||||
import kotlinx.cinterop.addressOf
|
||||
import kotlinx.cinterop.convert
|
||||
import kotlinx.cinterop.pin
|
||||
import kotlinx.cinterop.pointed
|
||||
import kotlinx.cinterop.ptr
|
||||
import kotlinx.cinterop.reinterpret
|
||||
import kotlinx.cinterop.toCValues
|
||||
import libsodium.crypto_generichash_blake2b_state
|
||||
import libsodium.crypto_hash_sha256_state
|
||||
import libsodium.crypto_hash_sha512_state
|
||||
import libsodium.sodium_malloc
|
||||
|
||||
actual typealias Sha256State = crypto_hash_sha256_state
|
||||
|
||||
@@ -21,51 +25,64 @@ actual typealias GenericHashState = crypto_generichash_blake2b_state
|
||||
actual class Crypto {
|
||||
val _emitByte: Byte = 0
|
||||
|
||||
val _emitByteArray: Byte = ByteArray(0) {}
|
||||
val _emitByteArray: ByteArray = ByteArray(0) {}
|
||||
|
||||
actual fun crypto_hash_sha256_init(state: Sha256State): Int {
|
||||
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")
|
||||
return libsodium.crypto_hash_sha256_init(state.ptr)
|
||||
libsodium.crypto_hash_sha256_init(state.ptr)
|
||||
return state
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) {
|
||||
println("Debug")
|
||||
val pinnedInput = input.pin()
|
||||
libsodium.crypto_hash_sha256_update(state.ptr, pinnedInput.addressOf(0), input.size.convert())
|
||||
pinnedInput.unpin()
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_final(state: Sha256State, out: UByteArray) {
|
||||
actual fun crypto_hash_sha256_final(state: Sha256State): UByteArray {
|
||||
println("Debug")
|
||||
val out = UByteArray(32)
|
||||
val pinnedOut = out.pin()
|
||||
libsodium.crypto_hash_sha256_final(state.ptr, pinnedOut.addressOf(0))
|
||||
pinnedOut.unpin()
|
||||
return out
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_init(state: Sha512State): Int {
|
||||
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")
|
||||
return libsodium.crypto_hash_sha512_init(state.ptr)
|
||||
libsodium.crypto_hash_sha512_init(state.ptr)
|
||||
return state
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) {
|
||||
println("Debug")
|
||||
val pinnedInput = input.pin()
|
||||
libsodium.crypto_hash_sha512_update(state.ptr, pinnedInput.addressOf(0), input.size.convert())
|
||||
pinnedInput.unpin()
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_final(state: Sha512State, out: UByteArray) {
|
||||
actual fun crypto_hash_sha512_final(state: Sha512State): UByteArray {
|
||||
println("Debug")
|
||||
val out = UByteArray(64)
|
||||
val pinnedOut = out.pin()
|
||||
libsodium.crypto_hash_sha512_final(state.ptr, pinnedOut.addressOf(0))
|
||||
pinnedOut.unpin()
|
||||
return out
|
||||
}
|
||||
|
||||
actual fun crypto_generichash_init(
|
||||
state: GenericHashState,
|
||||
key: UByteArray,
|
||||
outlen: Int
|
||||
): Int {
|
||||
val pinnedKey = key.pin()
|
||||
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")
|
||||
return libsodium.crypto_generichash_init(state.ptr, pinnedKey.addressOf(0), key.size.convert(),
|
||||
val pinnedKey = key.pin()
|
||||
libsodium.crypto_generichash_init(state.ptr, pinnedKey.addressOf(0), key.size.convert(),
|
||||
outlen.convert())
|
||||
pinnedKey.unpin()
|
||||
return state
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user