Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
**/
package org.kotlincrypto.random.internal.js

import kotlin.math.min
import kotlin.js.unsafeCast

internal actual val IS_NODE_JS: Boolean by lazy { isNodeJs() }

Expand All @@ -25,13 +25,13 @@ internal actual fun jsCryptoNode(): JsCrypto = js(CODE_JS_CRYPTO_NODE)
private fun isNodeJs(): Boolean = js(CODE_IS_NODE_JS)

internal actual fun ByteArray.cryptoRandFill(procure: (JsUint8Array) -> Unit) {
val a = asJsInt8Array().asJsUint8Array()
val a = JsUint8Array.new(unsafeCast<JsTypedArrayLike>().buffer)
if (a.length < JS_CRYPTO_MAX_FILL) return procure(a)

var remainder = size
var offset = 0
while (remainder > 0) {
val len = min(JS_CRYPTO_MAX_FILL, remainder)
val len = minOf(JS_CRYPTO_MAX_FILL, remainder)
val s = a.subarray(start = offset, end = offset + len)
procure(s)
offset += len
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ internal inline fun JsUint8Array.Companion.new(buffer: JsArrayBufferLike): JsUin
internal inline operator fun JsUint8Array.get(index: Int): Byte = jsUint8ArrayGet(this, index).toByte()
internal inline operator fun JsUint8Array.set(index: Int, value: UByte) { jsUint8ArraySet(this, index, value.toByte()) }

internal inline fun JsUint8Array.asJsInt8Array(): JsInt8Array = JsInt8Array.new(buffer)

internal const val CODE_JS_NEW_UINT8_LENGTH = "new Uint8Array(length)"
internal const val CODE_JS_NEW_UINT8_BUFFER = "new Uint8Array(buffer)"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.kotlincrypto.random.internal.js

import kotlin.math.min

internal actual val IS_NODE_JS: Boolean by lazy { isNodeJs() }

internal actual fun jsCryptoBrowser(): JsCrypto = js(CODE_JS_CRYPTO_BROWSER)
Expand All @@ -32,7 +30,7 @@ internal actual fun ByteArray.cryptoRandFill(procure: (JsUint8Array) -> Unit) {
// Kotlin/WasmJs does not provide access to ByteArray.storage
// (i.e. the WasmByteArray), so we must always use a buffer and
// copy back and forth.
val buf = JsUint8Array.new(length = min(size, BUFFER_SIZE))
val buf = JsUint8Array.new(length = minOf(size, BUFFER_SIZE))

try {
var remainder = size
Expand Down

This file was deleted.