crypto: allow monkey patching of pseudoRandomBytes

Make `pseudoRandomBytes` and it's aliases `prng` and `rng`
configurable to allow monkey patching.

PR-URL: https://github.com/nodejs/node/pull/24108
Refs: https://github.com/nodejs/node/pull/22519
Refs: https://github.com/nodejs/node/pull/23017
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Gerhard Stoebich 2018-11-05 17:07:48 +01:00 committed by Rich Trott
parent 895fe2f574
commit f85d63609c
2 changed files with 15 additions and 0 deletions

View File

@ -247,12 +247,16 @@ Object.defineProperties(exports, {
// The ecosystem needs those to exist for backwards compatibility.
prng: {
enumerable: false,
configurable: true,
writable: true,
value: pendingDeprecation ?
deprecate(randomBytes, 'crypto.prng is deprecated.', 'DEP0115') :
randomBytes
},
pseudoRandomBytes: {
enumerable: false,
configurable: true,
writable: true,
value: pendingDeprecation ?
deprecate(randomBytes,
'crypto.pseudoRandomBytes is deprecated.', 'DEP0115') :
@ -260,6 +264,8 @@ Object.defineProperties(exports, {
},
rng: {
enumerable: false,
configurable: true,
writable: true,
value: pendingDeprecation ?
deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115') :
randomBytes

View File

@ -306,3 +306,12 @@ assert.throws(
}
);
});
['pseudoRandomBytes', 'prng', 'rng'].forEach((f) => {
const desc = Object.getOwnPropertyDescriptor(crypto, f);
assert.ok(desc);
assert.strictEqual(desc.configurable, true);
assert.strictEqual(desc.writable, true);
assert.strictEqual(desc.enumerable, false);
});