Adding data classes

This commit is contained in:
Ugljesa Jovanovic committed 2020-08-14 12:39:27 +02:00
1 parent fcc4d87610
commit a5b20daf5a
17 files changed
+263 -375

No files matched your search

@@ -9,7 +9,13 @@ expect class Sha512State
expect class GenericHashState
expect class SecretStreamState
expect class Crypto internal constructor() {
/**
* Initialize the SHA256 hash
* returns sha 256 state
*/
fun crypto_hash_sha256_init(): Sha256State
fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray)
@@ -23,4 +29,11 @@ expect class Crypto internal constructor() {
fun crypto_hash_sha512_final(state: Sha512State): UByteArray
fun crypto_generichash_init(key: UByteArray, outlen: Int): GenericHashState
fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): UByteArray
data class SecretStreamStateAndHeader(
val state: SecretStreamState,
val header: UByteArray
)
}
@@ -13,7 +13,13 @@ actual typealias Sha512State = Any
actual typealias GenericHashState = Any
actual typealias SecretStreamState = Any
actual class Crypto internal actual constructor() {
/**
* Initialize the SHA256 hash
* returns sha 256 state
*/
actual fun crypto_hash_sha256_init(): dynamic {
println("Debug crypto_hash_sha256_init")
val result = js("getSodium().crypto_hash_sha256_init()")
@@ -50,4 +56,9 @@ actual class Crypto internal actual constructor() {
println("Debug crypto_generichash_init")
return getSodium().crypto_generichash_init(key.toUInt8Array(), outlen)
}
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): dynamic {
println("Debug crypto_secretstream_xchacha20poly1305_init_push")
}
}
@@ -2,6 +2,7 @@ package debug.test
import com.goterl.lazycode.lazysodium.SodiumJava
import com.goterl.lazycode.lazysodium.interfaces.Hash
import com.goterl.lazycode.lazysodium.interfaces.SecretStream
import kotlin.ByteArray
import kotlin.Int
import kotlin.UByteArray
@@ -14,7 +15,13 @@ actual typealias Sha512State = Hash.State512
actual typealias GenericHashState = ByteArray
actual typealias SecretStreamState = SecretStream.State
actual class Crypto internal actual constructor() {
/**
* Initialize the SHA256 hash
* returns sha 256 state
*/
actual fun crypto_hash_sha256_init(): Sha256State {
val state = debug.test.Sha256State()
println("Debug crypto_hash_sha256_init")
@@ -59,4 +66,10 @@ actual class Crypto internal actual constructor() {
sodium.crypto_generichash_init(state, key.asByteArray(), key.size, outlen)
return state
}
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): UByteArray {
println("Debug crypto_secretstream_xchacha20poly1305_init_push")
sodium.crypto_secretstream_xchacha20poly1305_init_push(key.asByteArray())
return state
}
}
@@ -22,11 +22,17 @@ actual typealias Sha512State = crypto_hash_sha512_state
actual typealias GenericHashState = crypto_generichash_blake2b_state
actual typealias SecretStreamState = crypto_hash_sha256_state
actual class Crypto internal actual constructor() {
val _emitByte: Byte = 0
val _emitByteArray: ByteArray = ByteArray(0)
/**
* Initialize the SHA256 hash
* returns sha 256 state
*/
actual fun crypto_hash_sha256_init(): Sha256State {
val allocated = sodium_malloc(debug.test.Sha256State.size.convert())!!
val state = allocated.reinterpret<debug.test.Sha256State>().pointed
@@ -85,4 +91,12 @@ actual class Crypto internal actual constructor() {
pinnedKey.unpin()
return state
}
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): UByteArray {
println("Debug crypto_secretstream_xchacha20poly1305_init_push")
val pinnedKey = key.pin()
libsodium.crypto_secretstream_xchacha20poly1305_init_push(pinnedKey.addressOf(0))
pinnedKey.unpin()
return state
}
}