Merge remote-tracking branch 'origin/master'
# Conflicts: # build.gradle.kts
This commit is contained in:
commit
65ddd11101
8
.idea/artifacts/crypto2_wasm_js_0_1_1_SNAPSHOT.xml
generated
Normal file
8
.idea/artifacts/crypto2_wasm_js_0_1_1_SNAPSHOT.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="crypto2-wasm-js-0.1.1-SNAPSHOT">
|
||||
<output-path>$PROJECT_DIR$/build/libs</output-path>
|
||||
<root id="archive" name="crypto2-wasm-js-0.1.1-SNAPSHOT.jar">
|
||||
<element id="module-output" name="crypto2.wasmJsMain" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
|
@ -1,3 +1,5 @@
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform") version "2.0.0"
|
||||
id("org.jetbrains.kotlin.plugin.serialization") version "2.0.0"
|
||||
@ -15,23 +17,26 @@ repositories {
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
// {
|
||||
// jvmToolchain(8)
|
||||
// withJava()
|
||||
// testRuns.named("test") {
|
||||
// executionTask.configure {
|
||||
// useJUnitPlatform()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
js(IR) {
|
||||
browser()
|
||||
nodejs()
|
||||
jvm {
|
||||
jvmToolchain(8)
|
||||
withJava()
|
||||
testRuns.named("test") {
|
||||
executionTask.configure {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
}
|
||||
}
|
||||
linuxX64("native")
|
||||
|
||||
val ktor_version = "2.3.6"
|
||||
macosX64()
|
||||
macosArm64()
|
||||
iosX64()
|
||||
iosArm64()
|
||||
iosSimulatorArm64()
|
||||
linuxX64()
|
||||
mingwX64()
|
||||
// wasmJs() no libsodimu bindings yet (strangely)
|
||||
// val ktor_version = "2.3.6"
|
||||
|
||||
sourceSets {
|
||||
all {
|
||||
@ -46,7 +51,7 @@ kotlin {
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0")
|
||||
|
||||
implementation("com.ionspin.kotlin:multiplatform-crypto-libsodium-bindings:0.9.0")
|
||||
api("com.ionspin.kotlin:bignum:0.3.8")
|
||||
api("com.ionspin.kotlin:bignum:0.3.9")
|
||||
|
||||
api("net.sergeych:mp_bintools:0.1.5-SNAPSHOT")
|
||||
api("net.sergeych:mp_stools:1.4.1")
|
||||
@ -69,11 +74,11 @@ kotlin {
|
||||
}
|
||||
}
|
||||
val jsTest by getting
|
||||
// val nativeMain by getting {
|
||||
// dependencies {
|
||||
// }
|
||||
// }
|
||||
// val nativeTest by getting
|
||||
val nativeMain by getting {
|
||||
dependencies {
|
||||
}
|
||||
}
|
||||
val nativeTest by getting
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@ package net.sergeych.crypto2
|
||||
|
||||
import net.sergeych.bintools.CRC
|
||||
|
||||
fun isValidContrail(data: UByteArray): Boolean = CRC.crc8(data.copyOfRange(1, data.size)) == data[0]
|
||||
fun isValidContrail(data: UByteArray): Boolean = CRC.crc8(
|
||||
data.copyOfRange(1, data.size).toByteArray()
|
||||
) == data[0]
|
||||
|
||||
fun createContrail(data: UByteArray): UByteArray = ubyteArrayOf(CRC.crc8(data)) + data
|
||||
fun createContrail(data: UByteArray): UByteArray = ubyteArrayOf(CRC.crc8(data.toByteArray())) + data
|
@ -1,5 +1,8 @@
|
||||
package net.sergeych.tools
|
||||
|
||||
import net.sergeych.synctools.ProtectedOp
|
||||
import net.sergeych.synctools.invoke
|
||||
|
||||
/**
|
||||
* Multiplatform (JS and battery included) atomically mutable value.
|
||||
* Actual value can be either changed in a block of [mutuate] when
|
||||
@ -18,7 +21,7 @@ open class AtomicValue<T>(initialValue: T) {
|
||||
* @return result of the mutation. Note that immediate call to property [value]
|
||||
* could already return modified bu some other thread value!
|
||||
*/
|
||||
fun mutate(mutator: (T) -> T): T = op {
|
||||
fun mutate(mutator: (T) -> T): T = op.invoke {
|
||||
actualValue = mutator(actualValue)
|
||||
actualValue
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package net.sergeych.tools
|
||||
|
||||
/**
|
||||
* Multiplatform interface to perform a regular (not suspend) operation
|
||||
* protected by a platform mutex (where necessary). Get real implementation
|
||||
* with [ProtectedOp]
|
||||
*/
|
||||
interface ProtectedOpImplementation {
|
||||
/**
|
||||
* Call [f] iin mutually exclusive mode, it means that only one invocation
|
||||
* can be active at a time, all the rest are waiting until the current operation
|
||||
* will finish.
|
||||
*/
|
||||
operator fun <T>invoke(f: ()->T): T
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the platform-depended implementation of a mutex-protected operation.
|
||||
*/
|
||||
expect fun ProtectedOp(): ProtectedOpImplementation
|
@ -11,6 +11,10 @@ fun ByteArray.digestKeccak(parameter: KeccakParameter): ByteArray {
|
||||
return Keccak.digest(this, parameter)
|
||||
}
|
||||
|
||||
fun UByteArray.digestKeccak(parameter: KeccakParameter): UByteArray {
|
||||
return Keccak.digest(this.toByteArray(), parameter).toUByteArray()
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the proper Keccak digest of [this] string based on the given [parameter]
|
||||
*/
|
||||
|
@ -1,6 +0,0 @@
|
||||
package net.sergeych.tools
|
||||
|
||||
actual fun ProtectedOp(): ProtectedOpImplementation = object : ProtectedOpImplementation {
|
||||
// JS targets are inherently single-threaded, so we do noting:
|
||||
override fun <T> invoke(f: () -> T): T = f()
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package net.sergeych.tools
|
||||
|
||||
actual fun ProtectedOp(): ProtectedOpImplementation = object : ProtectedOpImplementation {
|
||||
private val lock = Object()
|
||||
override fun <T> invoke(f: () -> T): T {
|
||||
synchronized(lock) { return f() }
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package net.sergeych.tools
|
||||
|
||||
import kotlinx.atomicfu.locks.SynchronizedObject
|
||||
import kotlinx.atomicfu.locks.synchronized
|
||||
|
||||
actual fun ProtectedOp(): ProtectedOpImplementation = object : ProtectedOpImplementation {
|
||||
private val lock = SynchronizedObject()
|
||||
override fun <T> invoke(f: () -> T): T {
|
||||
synchronized(lock) {
|
||||
return f()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user