Skip to content

Commit

Permalink
crypto: clarify require("crypto').getRandomValues is Node.js specific
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jan 31, 2022
1 parent 4fbe9e5 commit dd02e9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion doc/api/crypto.md
Expand Up @@ -4112,7 +4112,8 @@ added: v17.4.0
* `typedArray` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Buffer|TypedArray|DataView|ArrayBuffer} Returns `typedArray`.

A convenient alias for [`crypto.webcrypto.getRandomValues()`][].
A convenient alias for [`crypto.randomFillSync()`][] that has the same signature as
[`crypto.webcrypto.getRandomValues()`][].

### `crypto.hkdf(digest, ikm, salt, info, keylen, callback)`

Expand Down Expand Up @@ -6005,6 +6006,7 @@ See the [list of SSL OP Flags][] for details.
[`crypto.publicEncrypt()`]: #cryptopublicencryptkey-buffer
[`crypto.randomBytes()`]: #cryptorandombytessize-callback
[`crypto.randomFill()`]: #cryptorandomfillbuffer-offset-size-callback
[`crypto.randomFillSync()`]: #cryptorandomfillsyncbuffer-offset-size
[`crypto.scrypt()`]: #cryptoscryptpassword-salt-keylen-options-callback
[`crypto.webcrypto.getRandomValues()`]: webcrypto.md#cryptogetrandomvaluestypedarray
[`crypto.webcrypto.subtle`]: webcrypto.md#class-subtlecrypto
Expand Down
6 changes: 5 additions & 1 deletion lib/crypto.js
Expand Up @@ -252,6 +252,10 @@ function getFipsForced() {
return 1;
}

function getRandomValues(array) {
return randomFillSync(array);
}

ObjectDefineProperty(constants, 'defaultCipherList', {
value: getOptionValue('--tls-cipher-list')
});
Expand Down Expand Up @@ -303,7 +307,7 @@ ObjectDefineProperties(module.exports, {
getRandomValues: {
configurable: false,
enumerable: true,
get() { return lazyWebCrypto().crypto.getRandomValues; },
get: () => getRandomValues,
set: undefined,
},

Expand Down

0 comments on commit dd02e9e

Please sign in to comment.