Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

[crypto] Add crypto.randomInt #317

Merged
merged 1 commit into from
Sep 9, 2020
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
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14.7.0
v14.10.0
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jdk:

env:
matrix:
- TRAVIS_NODE_VERSION="14.7.0"
- TRAVIS_NODE_VERSION="14.10.0"
- TRAVIS_NODE_VERSION="12.18.3"
- TRAVIS_NODE_VERSION="10.22.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ trait Crypto extends js.Object {
js.native
def randomFill[T <: scala.scalajs.js.typedarray.TypedArray[_, T]](buffer: T, callback: Callback1[T]): T = js.native

@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
def randomInt(max: Int): Int = js.native
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
def randomInt(max: Int, callback: Callback1[Int]): Unit = js.native
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
def randomInt(min: Int, max: Int): Int = js.native
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
def randomInt(min: Int, max: Int, callback: Callback1[Int]): Unit = js.native

def scrypt(password: String, salt: String, keylen: Int, options: ScryptOptions, callback: Callback1[Buffer]): Unit =
js.native
def scrypt(password: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.scalajs.nodejs.crypto

import org.scalatest.funsuite.AnyFunSuite

class CryptoNodeJS14Test extends AnyFunSuite {
test("randomInt") {
val i1 = Crypto.randomInt(10)
assert(0 <= i1 && i1 <= 10)

val i2 = Crypto.randomInt(10, 100)
assert(10 <= i2 && i2 <= 100)

Crypto.randomInt(
10,
(_, i3) => {
assert(0 <= i3 && i3 <= 10)
}
)

Crypto.randomInt(
10,
100,
(_, i4) => {
assert(10 <= i4 && i4 <= 100)
}
)
}
}
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ lazy val core = (project in file("./core"))
libraryDependencies ++= Dependencies.core.value
)

lazy val nodejs_v14 = createNodeVersionSpecificProject("14.7.0")
lazy val nodejs_v14 = createNodeVersionSpecificProject("14.10.0")
lazy val nodejs_v12 = createNodeVersionSpecificProject("12.18.3")
lazy val nodejs_v10 = createNodeVersionSpecificProject("10.22.0")

Expand Down