Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2022-02-22 19:51:50 +0300
committerGitHub <noreply@github.com>2022-02-22 19:51:50 +0300
commit470c2845cc65ac883794a1c35c962bff8d07dff2 (patch)
tree3fb5d05e04a86e698add93b112f402e5a6d0dc1a
parente8a972a3402e059c0c25ef23e3a7cafd4abba10e (diff)
crypto: clarify `require("crypto").getRandomValues` is Node.js specific
Refs: https://github.com/nodejs/node/pull/41779 Refs: https://github.com/nodejs/node/pull/41760 PR-URL: https://github.com/nodejs/node/pull/41782 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
-rw-r--r--doc/api/crypto.md4
-rw-r--r--lib/crypto.js6
2 files changed, 8 insertions, 2 deletions
diff --git a/doc/api/crypto.md b/doc/api/crypto.md
index e5b83eb4ff5..470c8f66418 100644
--- a/doc/api/crypto.md
+++ b/doc/api/crypto.md
@@ -4139,7 +4139,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)`
diff --git a/lib/crypto.js b/lib/crypto.js
index ac601a76646..a839f5fe27b 100644
--- a/lib/crypto.js
+++ b/lib/crypto.js
@@ -252,6 +252,10 @@ function getFipsForced() {
return 1;
}
+function getRandomValues(array) {
+ return lazyWebCrypto().crypto.getRandomValues(array);
+}
+
ObjectDefineProperty(constants, 'defaultCipherList', {
value: getOptionValue('--tls-cipher-list')
});
@@ -303,7 +307,7 @@ ObjectDefineProperties(module.exports, {
getRandomValues: {
configurable: false,
enumerable: true,
- get() { return lazyWebCrypto().crypto.getRandomValues; },
+ get: () => getRandomValues,
set: undefined,
},