Fixed native (i forgot to account for tag length. Added debug list of js functions, can be usefull when defining interface

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-08-27 22:07:03 +02:00
1 parent 9e10677165
commit 89e5ae62e4
9 files changed
+543 -97

No files matched your search

@@ -45,12 +45,12 @@ interface JsSodiumInterface {
//XChaCha20Poly1305
//encrypt
fun crypto_secretstream_xchacha20poly1305_init_push(header: Uint8Array) : dynamic
fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : dynamic
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, additionalData: Uint8Array, tag: UByte) : Uint8Array
//decrypt
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic
fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, additionalData: Uint8Array) : Uint8Array
fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, additionalData: Uint8Array) : dynamic
//util
fun memzero(array: Uint8Array)
@@ -1,10 +1,16 @@
package com.ionspin.kotlin.crypto.secretstream
import com.ionspin.kotlin.crypto.getSodium
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
import org.khronos.webgl.Uint8Array
actual typealias SecretStreamState = Any
actual object SecretStream {
actual fun xChaCha20Poly1305InitPush(key: UByteArray): SecretStreamStateAndHeader {
TODO("not implemented yet")
val state = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array())
return SecretStreamStateAndHeader(state.state, (state.header as Uint8Array).toUByteArray())
}
actual fun xChaCha20Poly1305Push(
@@ -13,14 +19,17 @@ actual object SecretStream {
additionalData: UByteArray,
tag: UByte
): UByteArray {
TODO("not implemented yet")
return getSodium().crypto_secretstream_xchacha20poly1305_push(
state, message.toUInt8Array(), additionalData.toUInt8Array(), tag
).toUByteArray()
}
actual fun xChaCha20Poly1305InitPull(
key: UByteArray,
header: UByteArray
): SecretStreamStateAndHeader {
TODO("not implemented yet")
val state = getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(), key.toUInt8Array())
return SecretStreamStateAndHeader(state, header)
}
actual fun xChaCha20Poly1305Pull(
@@ -28,7 +37,11 @@ actual object SecretStream {
ciphertext: UByteArray,
additionalData: UByteArray
): DecryptedDataAndTag {
TODO("not implemented yet")
val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull(
state, ciphertext.toUInt8Array(), additionalData.toUInt8Array()
)
return DecryptedDataAndTag((dataAndTag.message as Uint8Array).toUByteArray(), dataAndTag.tag)
}
}