Merge remote-tracking branch 'origin/master'

# Conflicts:
#	build.gradle.kts
This commit is contained in:
sergeych committed 2024-06-08 16:22:15 +07:00
commit 65ddd11101
10 files changed
+45 -72

No files matched your search

@@ -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]
*/