Update kotlin version, need to fix secretstream pull, at least in js if not everywhere
This commit is contained in:
parent
0c098e57db
commit
cd90f964ab
@ -15,12 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
object Versions {
|
object Versions {
|
||||||
val kotlinCoroutines = "1.3.8-1.4.0-rc"
|
val kotlinCoroutines = "1.3.9"
|
||||||
val kotlin = "1.4.0-rc"
|
val kotlin = "1.4.0"
|
||||||
val kotlinSerialization = "1.0-M1-1.4.0-rc"
|
val kotlinSerialization = "1.0.0-RC"
|
||||||
val atomicfu = "0.14.3-M2-2-SNAPSHOT" //NOTE: my linux arm32 and arm64 build
|
val atomicfu = "0.14.3-M2-2-SNAPSHOT" //NOTE: my linux arm32 and arm64 build
|
||||||
val nodePlugin = "1.3.0"
|
val nodePlugin = "1.3.0"
|
||||||
val dokkaPlugin = "1.4.0-M3-dev-92"
|
val dokkaPlugin = "1.4.0-rc"
|
||||||
val taskTreePlugin = "1.5"
|
val taskTreePlugin = "1.5"
|
||||||
|
|
||||||
val kotlinBigNumVersion = "0.1.6-1.4.0-rc-SNAPSHOT"
|
val kotlinBigNumVersion = "0.1.6-1.4.0-rc-SNAPSHOT"
|
||||||
|
@ -69,7 +69,7 @@ fun ClassDefinition.defineSecretStreamFunctions() {
|
|||||||
Initialize a state and generate a random header. Both are returned inside `SecretStreamStateAndHeader` object.
|
Initialize a state and generate a random header. Both are returned inside `SecretStreamStateAndHeader` object.
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
returnType = CustomTypeDefinition(withPackageName("SecretStreamStateAndHeader")),
|
returnType = CustomTypeDefinition(withPackageName("SecretStreamStateAndHeader")),
|
||||||
dynamicJsReturn = true,
|
dynamicJsReturn = false,
|
||||||
isStateCreationFunction = true,
|
isStateCreationFunction = true,
|
||||||
customCodeBlockReplacesFunctionBody = listOf(jsSecretStreamInit, jvmSecretStreamInit, nativeSecretStreamInit)
|
customCodeBlockReplacesFunctionBody = listOf(jsSecretStreamInit, jvmSecretStreamInit, nativeSecretStreamInit)
|
||||||
) {
|
) {
|
||||||
|
@ -45,6 +45,10 @@ fun generateDataClass(fileBuilder: FileSpec.Builder, dataClassDefinition: DataCl
|
|||||||
val dataClassConstructor = FunSpec.constructorBuilder()
|
val dataClassConstructor = FunSpec.constructorBuilder()
|
||||||
for (parameter in dataClassDefinition.parameters) {
|
for (parameter in dataClassDefinition.parameters) {
|
||||||
val parameterBuilder = ParameterSpec.builder(parameter.parameterName, parameter.parameterType.typeName)
|
val parameterBuilder = ParameterSpec.builder(parameter.parameterName, parameter.parameterType.typeName)
|
||||||
|
val annotationBuilder =
|
||||||
|
AnnotationSpec.builder(ClassName("kotlin.js", "JsName"))
|
||||||
|
.addMember("\"${parameter.parameterName}\"")
|
||||||
|
parameterBuilder.addAnnotation(annotationBuilder.build())
|
||||||
dataClassConstructor.addParameter(parameterBuilder.build())
|
dataClassConstructor.addParameter(parameterBuilder.build())
|
||||||
}
|
}
|
||||||
dataClassBuilder.primaryConstructor(dataClassConstructor.build())
|
dataClassBuilder.primaryConstructor(dataClassConstructor.build())
|
||||||
|
@ -50,7 +50,7 @@ interface JsSodiumInterface {
|
|||||||
|
|
||||||
//decrypt
|
//decrypt
|
||||||
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic
|
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
|
//util
|
||||||
fun memzero(array: Uint8Array)
|
fun memzero(array: Uint8Array)
|
||||||
|
@ -3,6 +3,7 @@ package debug.test
|
|||||||
import kotlin.Int
|
import kotlin.Int
|
||||||
import kotlin.UByte
|
import kotlin.UByte
|
||||||
import kotlin.UByteArray
|
import kotlin.UByteArray
|
||||||
|
import kotlin.js.JsName
|
||||||
|
|
||||||
expect class Sha256State
|
expect class Sha256State
|
||||||
|
|
||||||
@ -13,7 +14,9 @@ expect class GenericHashState
|
|||||||
expect class SecretStreamState
|
expect class SecretStreamState
|
||||||
|
|
||||||
data class SecretStreamStateAndHeader(
|
data class SecretStreamStateAndHeader(
|
||||||
|
@JsName("state")
|
||||||
val state: SecretStreamState,
|
val state: SecretStreamState,
|
||||||
|
@JsName("header")
|
||||||
val header: UByteArray
|
val header: UByteArray
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.ionspin.kotlin.crypto.secretstream
|
package com.ionspin.kotlin.crypto.secretstream
|
||||||
|
|
||||||
import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint
|
import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint
|
||||||
|
import com.ionspin.kotlin.crypto.Initializer
|
||||||
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
||||||
|
import com.ionspin.kotlin.crypto.util.testBlocking
|
||||||
import debug.test.Crypto
|
import debug.test.Crypto
|
||||||
import kotlin.math.exp
|
import kotlin.math.exp
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
@ -14,7 +16,8 @@ import kotlin.test.assertTrue
|
|||||||
*/
|
*/
|
||||||
class SecretStreamTest {
|
class SecretStreamTest {
|
||||||
@Test
|
@Test
|
||||||
fun testSecretStream() {
|
fun testSecretStream() = testBlocking {
|
||||||
|
Initializer.initializeWithCallback {
|
||||||
assertTrue {
|
assertTrue {
|
||||||
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " +
|
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " +
|
||||||
"only one tip for the future, sunscreen would be it.").encodeToUByteArray()
|
"only one tip for the future, sunscreen would be it.").encodeToUByteArray()
|
||||||
@ -57,14 +60,17 @@ class SecretStreamTest {
|
|||||||
message.hexColumsPrint()
|
message.hexColumsPrint()
|
||||||
val crypto = Crypto()
|
val crypto = Crypto()
|
||||||
val stateAndHeader = crypto.crypto_secretstream_xchacha20poly1305_init_push(key)
|
val stateAndHeader = crypto.crypto_secretstream_xchacha20poly1305_init_push(key)
|
||||||
val encrypted = crypto.crypto_secretstream_xchacha20poly1305_push(stateAndHeader.state, message, ubyteArrayOf(), 0U)
|
val encrypted =
|
||||||
|
crypto.crypto_secretstream_xchacha20poly1305_push(stateAndHeader.state, message, ubyteArrayOf(), 0U)
|
||||||
encrypted.hexColumsPrint()
|
encrypted.hexColumsPrint()
|
||||||
val decryptState = crypto.crypto_secretstream_xchacha20poly1305_init_pull(stateAndHeader.header, key)
|
val decryptState = crypto.crypto_secretstream_xchacha20poly1305_init_pull(stateAndHeader.header, key)
|
||||||
val decrypted = crypto.crypto_secretstream_xchacha20poly1305_pull(decryptState, encrypted, ubyteArrayOf())
|
val decrypted =
|
||||||
|
crypto.crypto_secretstream_xchacha20poly1305_pull(decryptState, encrypted, ubyteArrayOf()) //TODO JS pull returns a tag and a message!!!
|
||||||
decrypted.hexColumsPrint()
|
decrypted.hexColumsPrint()
|
||||||
decrypted.contentEquals(message)
|
decrypted.contentEquals(message)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ interface JsSodiumInterface {
|
|||||||
|
|
||||||
//decrypt
|
//decrypt
|
||||||
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic
|
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
|
//util
|
||||||
fun memzero(array: Uint8Array)
|
fun memzero(array: Uint8Array)
|
||||||
|
@ -15,6 +15,9 @@ fun UByteArray.toUInt8Array() : Uint8Array {
|
|||||||
|
|
||||||
|
|
||||||
fun Uint8Array.toUByteArray() : UByteArray {
|
fun Uint8Array.toUByteArray() : UByteArray {
|
||||||
|
if (length.asDynamic() == undefined) {
|
||||||
|
println("Error")
|
||||||
|
}
|
||||||
val result = UByteArray(length)
|
val result = UByteArray(length)
|
||||||
for (i in 0 until length) {
|
for (i in 0 until length) {
|
||||||
result[i] = get(i).toUByte()
|
result[i] = get(i).toUByte()
|
||||||
|
@ -63,7 +63,8 @@ actual class Crypto internal actual constructor() {
|
|||||||
* Initialize a state and generate a random header. Both are returned inside
|
* Initialize a state and generate a random header. Both are returned inside
|
||||||
* `SecretStreamStateAndHeader` object.
|
* `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")
|
println("Debug crypto_secretstream_xchacha20poly1305_init_push")
|
||||||
val stateAndHeader =
|
val stateAndHeader =
|
||||||
getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array())
|
getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array())
|
||||||
@ -76,10 +77,10 @@ actual class Crypto internal actual constructor() {
|
|||||||
* Initialize state from header and key. The state can then be used for decryption.
|
* 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):
|
actual fun crypto_secretstream_xchacha20poly1305_init_pull(header: UByteArray, key: UByteArray):
|
||||||
dynamic {
|
SecretStreamState {
|
||||||
println("Debug crypto_secretstream_xchacha20poly1305_init_pull")
|
println("Debug crypto_secretstream_xchacha20poly1305_init_pull")
|
||||||
return getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(),
|
return getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(),
|
||||||
key.toUInt8Array())
|
key.toUInt8Array()) as SecretStreamState
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user