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
Refs: #41779
Refs: #41760
PR-URL: #41782
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
aduh95 authored and sxa committed Mar 7, 2022
1 parent 0ce00ca commit 288f627
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
Original file line number Diff line number Diff line change
Expand Up @@ -4104,7 +4104,9 @@ 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.webcrypto.getRandomValues()`][]. This
implementation is not compliant with the Web Crypto spec, to write
web-compatible code use [`crypto.webcrypto.getRandomValues()`][] instead.

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

Expand Down
6 changes: 5 additions & 1 deletion lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ function getFipsForced() {
return 1;
}

function getRandomValues(array) {
return lazyWebCrypto().crypto.getRandomValues(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 288f627

Please sign in to comment.