Update readme and changelog, as this is going into master so snapshots are available for experimenting
This commit is contained in:
1 parent
e997c18d1d
commit
e6e7a7664c
13 files changed
+265
-28
No files matched your search
+26
@@ -0,0 +1,26 @@
|
||||
package debug.test
|
||||
|
||||
import kotlin.Int
|
||||
import kotlin.UByteArray
|
||||
|
||||
expect class Sha256State
|
||||
|
||||
expect class Sha512State
|
||||
|
||||
expect class GenericHashState
|
||||
|
||||
expect class Crypto internal constructor() {
|
||||
fun crypto_hash_sha256_init(): Sha256State
|
||||
|
||||
fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray)
|
||||
|
||||
fun crypto_hash_sha256_final(state: Sha256State): UByteArray
|
||||
|
||||
fun crypto_hash_sha512_init(): Sha512State
|
||||
|
||||
fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray)
|
||||
|
||||
fun crypto_hash_sha512_final(state: Sha512State): UByteArray
|
||||
|
||||
fun crypto_generichash_init(key: UByteArray, outlen: Int): GenericHashState
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
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
|
||||
import kotlin.UByteArray
|
||||
|
||||
actual typealias Sha256State = Any
|
||||
|
||||
actual typealias Sha512State = Any
|
||||
|
||||
actual typealias GenericHashState = Any
|
||||
|
||||
actual class Crypto internal actual constructor() {
|
||||
actual fun crypto_hash_sha256_init(): dynamic {
|
||||
println("Debug")
|
||||
val result = js("getSodium().crypto_hash_sha256_init()")
|
||||
return result
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) {
|
||||
println("Debug")
|
||||
getSodium().crypto_hash_sha256_update(state, input.toUInt8Array(), )
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_final(state: Sha256State): UByteArray {
|
||||
println("Debug")
|
||||
return getSodium().crypto_hash_sha256_final(state).toUByteArray()
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_init(): dynamic {
|
||||
println("Debug")
|
||||
val result = js("getSodium().crypto_hash_sha512_init()")
|
||||
return result
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) {
|
||||
println("Debug")
|
||||
getSodium().crypto_hash_sha512_update(state, input.toUInt8Array(), )
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_final(state: Sha512State): UByteArray {
|
||||
println("Debug")
|
||||
return getSodium().crypto_hash_sha512_final(state).toUByteArray()
|
||||
}
|
||||
|
||||
actual fun crypto_generichash_init(key: UByteArray, outlen: Int): dynamic {
|
||||
println("Debug")
|
||||
return getSodium().crypto_generichash_init(key.toUInt8Array(), outlen)
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package debug.test
|
||||
|
||||
import com.goterl.lazycode.lazysodium.SodiumJava
|
||||
import com.goterl.lazycode.lazysodium.interfaces.Hash
|
||||
import kotlin.ByteArray
|
||||
import kotlin.Int
|
||||
import kotlin.UByteArray
|
||||
|
||||
val sodium: SodiumJava = SodiumJava()
|
||||
|
||||
actual typealias Sha256State = Hash.State256
|
||||
|
||||
actual typealias Sha512State = Hash.State512
|
||||
|
||||
actual typealias GenericHashState = ByteArray
|
||||
|
||||
actual class Crypto internal actual constructor() {
|
||||
actual fun crypto_hash_sha256_init(): Sha256State {
|
||||
val state = debug.test.Sha256State()
|
||||
println("Debug")
|
||||
sodium.crypto_hash_sha256_init(state)
|
||||
return state
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) {
|
||||
println("Debug")
|
||||
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")
|
||||
sodium.crypto_hash_sha256_final(state, out.asByteArray())
|
||||
return out
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_init(): Sha512State {
|
||||
val state = debug.test.Sha512State()
|
||||
println("Debug")
|
||||
sodium.crypto_hash_sha512_init(state)
|
||||
return state
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) {
|
||||
println("Debug")
|
||||
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")
|
||||
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")
|
||||
sodium.crypto_generichash_init(state, key.asByteArray(), key.size, outlen)
|
||||
return state
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
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
|
||||
|
||||
actual typealias Sha512State = crypto_hash_sha512_state
|
||||
|
||||
actual typealias GenericHashState = crypto_generichash_blake2b_state
|
||||
|
||||
actual class Crypto internal actual constructor() {
|
||||
val _emitByte: Byte = 0
|
||||
|
||||
val _emitByteArray: ByteArray = ByteArray(0)
|
||||
|
||||
actual fun crypto_hash_sha256_init(): Sha256State {
|
||||
val allocated = sodium_malloc(debug.test.Sha256State.size.convert())!!
|
||||
val state = allocated.reinterpret<debug.test.Sha256State>().pointed
|
||||
libsodium.crypto_hash_sha256_init(state.ptr)
|
||||
return state
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) {
|
||||
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): UByteArray {
|
||||
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(): Sha512State {
|
||||
val allocated = sodium_malloc(debug.test.Sha512State.size.convert())!!
|
||||
val state = allocated.reinterpret<debug.test.Sha512State>().pointed
|
||||
libsodium.crypto_hash_sha512_init(state.ptr)
|
||||
return state
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) {
|
||||
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): UByteArray {
|
||||
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(key: UByteArray, outlen: Int): GenericHashState {
|
||||
val allocated = sodium_malloc(debug.test.GenericHashState.size.convert())!!
|
||||
val state = allocated.reinterpret<debug.test.GenericHashState>().pointed
|
||||
val pinnedKey = key.pin()
|
||||
libsodium.crypto_generichash_init(state.ptr, pinnedKey.addressOf(0), key.size.convert(),
|
||||
outlen.convert())
|
||||
pinnedKey.unpin()
|
||||
return state
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -69,7 +69,7 @@ object JsLibsodiumGenerator {
|
||||
actualReturnType = paramDefinition.parameterType.typeName
|
||||
}
|
||||
}
|
||||
methodBuilder.addStatement("println(\"Debug\")")
|
||||
methodBuilder.addStatement("println(\"Debug ${methodDefinition.name}\")")
|
||||
val constructJsCall = StringBuilder()
|
||||
when (methodDefinition.returnType) {
|
||||
TypeDefinition.ARRAY_OF_UBYTES -> {
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ object JvmLibsodiumGenerator {
|
||||
)
|
||||
}
|
||||
}
|
||||
methodBuilder.addStatement("println(\"Debug\")")
|
||||
methodBuilder.addStatement("println(\"Debug ${methodDefinition.name}\")")
|
||||
val constructJvmCall = StringBuilder()
|
||||
if (methodDefinition.isStateCreationFunction) {
|
||||
constructJvmCall.append("sodium.${methodDefinition.nativeName}")
|
||||
|
||||
+1
@@ -108,6 +108,7 @@ object NativeLibsodiumGenerator {
|
||||
createOutputParam(actualReturnParameterDefinition, methodDefinition.outputLengthWhenArray.toString(), methodBuilder)
|
||||
}
|
||||
}
|
||||
methodBuilder.addStatement("println(\"Debug ${methodDefinition.name}\")")
|
||||
pinParams(methodDefinition, methodBuilder)
|
||||
val constructNativeCall = StringBuilder()
|
||||
if (methodDefinition.isStateCreationFunction) {
|
||||
|
||||
Reference in new issue
Block a user