Call sodium init in js and jvm
This commit is contained in:
parent
010ee5bd11
commit
e000d13b79
@ -2,6 +2,7 @@
|
|||||||
(All dates are DD.MM.YYYY)
|
(All dates are DD.MM.YYYY)
|
||||||
|
|
||||||
#### 0.8.3-SNAPSHOT
|
#### 0.8.3-SNAPSHOT
|
||||||
|
- Fixed loading but not initializing libsodium on js and jvm
|
||||||
- Changed subkey id to UInt from Int, limited by JS api
|
- Changed subkey id to UInt from Int, limited by JS api
|
||||||
- Updated libsodium to latest master 710b2d3963347017ba (potentially will be switched to stable branch)
|
- Updated libsodium to latest master 710b2d3963347017ba (potentially will be switched to stable branch)
|
||||||
- Experimentig with sodium_malloc usage instead of pinned UByteArrays
|
- Experimentig with sodium_malloc usage instead of pinned UByteArrays
|
||||||
|
@ -31,7 +31,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30")
|
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32")
|
||||||
implementation("com.android.tools.build:gradle:4.0.2")
|
implementation("com.android.tools.build:gradle:4.0.2")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ import org.khronos.webgl.Uint8Array
|
|||||||
*/
|
*/
|
||||||
interface JsSodiumInterface {
|
interface JsSodiumInterface {
|
||||||
|
|
||||||
|
fun sodium_init() : Int
|
||||||
|
|
||||||
fun randombytes_buf(numberOfBytes: Int): Uint8Array
|
fun randombytes_buf(numberOfBytes: Int): Uint8Array
|
||||||
|
|
||||||
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
|
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
|
||||||
|
@ -3,6 +3,7 @@ package ext.libsodium.com.ionspin.kotlin.crypto
|
|||||||
import com.ionspin.kotlin.crypto.getSodiumLoaded
|
import com.ionspin.kotlin.crypto.getSodiumLoaded
|
||||||
import com.ionspin.kotlin.crypto.setSodiumPointer
|
import com.ionspin.kotlin.crypto.setSodiumPointer
|
||||||
import com.ionspin.kotlin.crypto.sodiumLoaded
|
import com.ionspin.kotlin.crypto.sodiumLoaded
|
||||||
|
import com.ionspin.kotlin.crypto.sodiumPointer
|
||||||
import ext.libsodium.*
|
import ext.libsodium.*
|
||||||
import kotlin.coroutines.Continuation
|
import kotlin.coroutines.Continuation
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
@ -28,13 +29,16 @@ object JsSodiumLoader {
|
|||||||
setSodiumPointer(promisedSodium)
|
setSodiumPointer(promisedSodium)
|
||||||
sodiumLoaded = true
|
sodiumLoaded = true
|
||||||
continuation.resumeWith(Result.success(Unit))
|
continuation.resumeWith(Result.success(Unit))
|
||||||
|
sodiumPointer.sodium_init()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun load() = suspendCoroutine<Unit> { continuation ->
|
suspend fun load() = suspendCoroutine<Unit> { continuation ->
|
||||||
console.log(getSodiumLoaded())
|
console.log(getSodiumLoaded())
|
||||||
if (!getSodiumLoaded()) {
|
if (!getSodiumLoaded()) {
|
||||||
val libsodiumModule = js("\$module\$libsodium_wrappers_sumo")
|
val libsodiumModule = js("\$module\$libsodium_wrappers_sumo")
|
||||||
_libsodiumPromise.then<dynamic> { storeSodium(libsodiumModule, continuation) }
|
_libsodiumPromise.then<dynamic> {
|
||||||
|
storeSodium(libsodiumModule, continuation)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
continuation.resumeWith(Result.success(Unit))
|
continuation.resumeWith(Result.success(Unit))
|
||||||
}
|
}
|
||||||
@ -46,6 +50,7 @@ object JsSodiumLoader {
|
|||||||
val libsodiumModule = js("\$module\$libsodium_wrappers_sumo")
|
val libsodiumModule = js("\$module\$libsodium_wrappers_sumo")
|
||||||
_libsodiumPromise.then<dynamic> {
|
_libsodiumPromise.then<dynamic> {
|
||||||
setSodiumPointer(libsodiumModule)
|
setSodiumPointer(libsodiumModule)
|
||||||
|
sodiumPointer.sodium_init()
|
||||||
sodiumLoaded = true
|
sodiumLoaded = true
|
||||||
doneCallback.invoke()
|
doneCallback.invoke()
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,12 @@ class SecretStreamXChaCha20Poly1305State : Structure() {
|
|||||||
|
|
||||||
interface JnaLibsodiumInterface : Library {
|
interface JnaLibsodiumInterface : Library {
|
||||||
|
|
||||||
|
// ---- Initialization ---
|
||||||
|
|
||||||
|
fun sodium_init() : Int
|
||||||
|
|
||||||
|
// ---- Initialization end ---
|
||||||
|
|
||||||
// ---- Utils ----
|
// ---- Utils ----
|
||||||
fun sodium_version_string(): String
|
fun sodium_version_string(): String
|
||||||
|
|
||||||
|
@ -55,11 +55,13 @@ actual object LibsodiumInitializer {
|
|||||||
lateinit var sodiumJna : JnaLibsodiumInterface
|
lateinit var sodiumJna : JnaLibsodiumInterface
|
||||||
actual suspend fun initialize() {
|
actual suspend fun initialize() {
|
||||||
sodiumJna = loadLibrary()
|
sodiumJna = loadLibrary()
|
||||||
|
sodiumJna.sodium_init()
|
||||||
isPlatformInitialized = true
|
isPlatformInitialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun initializeWithCallback(done: () -> Unit) {
|
actual fun initializeWithCallback(done: () -> Unit) {
|
||||||
sodiumJna = loadLibrary()
|
sodiumJna = loadLibrary()
|
||||||
|
sodiumJna.sodium_init()
|
||||||
isPlatformInitialized = true
|
isPlatformInitialized = true
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user