![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@datkt/sodium
Advanced tools
libsodium bindings for Kotlin/Native.
The datkt.sodium
package an be installed with various package managers.
$ npm install @datkt/sodium
konanc
command line program.## Compile a program in 'main.kt' and link sodium.klib found in `node_modules/`
$ konanc -r node_modules/@datkt -l sodium/sodium main.kt
where main.kt
might be
import datkt.sodium.* // entire libsodium API
import kotlinx.cinterop.* // exposes types needed for interop
fun main(args: Array<String>) {
if (0 != sodium_init()) {
throw Error("Failed to initialize libsodium")
}
}
import kotlinx.cinterop.*
import datkt.sodium.sodium_init
import datkt.sodium.randombytes_buf
import datkt.sodium.randombytes_random
import datkt.sodium.randombytes_uniform
fun main(args: Array<String>) {
val rc = sodium_init()
if (0 != rc) {
throw Error("sodium_init() != 0")
}
println("${randombytes_random()} = randombytes_random()")
println("${randombytes_uniform(37)} = randombytes_uniform(37)")
var buffer = ByteArray(16)
buffer.usePinned { pinned ->
randombytes_buf(pinned.addressOf(0), buffer.size.convert())
}
println("${toHexString(buffer)} = randombytes_buf(ByteArray(16), 16)")
}
val table = "0123456789abcdef".toCharArray()
fun toHexString(bytes: ByteArray): String {
var output = CharArray(2 * bytes.size)
for (i in bytes.indices) {
val j = (bytes[i].toInt() and 0xff).toInt()
output[2 * i] = table[j ushr 4]
output[1 + 2 * i] = table[j and 0x0f]
}
return String(output)
}
This package binds libsodiums entire API and provides an
interop
API for Kotlin and can be imported from the sodium
package. For
example, the crypto_generichash()
with the following C function
signature:
int crypto_generichash(unsigned char *out,
size_t outlen,
const unsigned char *in,
unsigned long long inlen,
const unsigned char *key,
size_t keylen);
translates to the following Kotlin function signature:
fun crypto_generichash(out: CValuesRef<UByteVar>?,
outlen: size_t,
`in`: CValuesRef<UByteVar>?,
inlen: ULong,
key: CValuesRef<UByteVar>?,
keylen: size_t): Int;
and can be called in Kotlin like:
val buffer = ByteArray(crypto_generichash_BYTES.toInt())
val message = "hello"
buffer.usePinned { pinned ->
crypto_generichash(
pinned.addressOf(0) as CValuesRef<UByteVar>,
buffer.size.convert(),
message.cstr as CValuesRef<UByteVar>,
message.length.convert(),
null, // key
0 // key size
)
}
The sodium
package can be built from source into various targets.
sodium.klib
, a Kotlin library that can be linked with konanc
can be
built from source.
$ make klib
which will produce build/lib/sodium.klib
. The library can be installed
with klib
by running make install
libsodium.a
, a static library that can be linked with konanc
can be
built from source.
$ make static
which will produce build/lib/libsodium.a
and C header files in
build/include
. The library can be installed into your system by
running make install
. The path prefix can be set by defining the
PREFIX
environment or make
variable. It defaults to
PREFIX=/usr/local
MIT
FAQs
libsodium bindings for Kotlin
The npm package @datkt/sodium receives a total of 1 weekly downloads. As such, @datkt/sodium popularity was classified as not popular.
We found that @datkt/sodium demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.