Update kotlin version, need to fix secretstream pull, at least in js if not everywhere

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-08-18 23:32:50 +02:00
1 parent 0c098e57db
commit cd90f964ab
9 files changed
+74 -57

No files matched your search

@@ -50,7 +50,7 @@ interface JsSodiumInterface {
//decrypt
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic
fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, additionalData: Uint8Array) : dynamic
fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, additionalData: Uint8Array) : Uint8Array
//util
fun memzero(array: Uint8Array)
@@ -15,6 +15,9 @@ fun UByteArray.toUInt8Array() : Uint8Array {
fun Uint8Array.toUByteArray() : UByteArray {
if (length.asDynamic() == undefined) {
println("Error")
}
val result = UByteArray(length)
for (i in 0 until length) {
result[i] = get(i).toUByte()
@@ -63,23 +63,24 @@ actual class Crypto internal actual constructor() {
* Initialize a state and generate a random header. Both are returned inside
* `SecretStreamStateAndHeader` object.
*/
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): dynamic {
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray):
SecretStreamStateAndHeader {
println("Debug crypto_secretstream_xchacha20poly1305_init_push")
val stateAndHeader =
getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array())
val state = stateAndHeader.state
val header = (stateAndHeader.header as Uint8Array).toUByteArray()
return SecretStreamStateAndHeader(state, header)
return SecretStreamStateAndHeader(state, header)
}
/**
* Initialize state from header and key. The state can then be used for decryption.
*/
actual fun crypto_secretstream_xchacha20poly1305_init_pull(header: UByteArray, key: UByteArray):
dynamic {
SecretStreamState {
println("Debug crypto_secretstream_xchacha20poly1305_init_pull")
return getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(),
key.toUInt8Array())
key.toUInt8Array()) as SecretStreamState
}
/**