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:
parent
895fe2f574
commit
f85d63609c
@ -247,12 +247,16 @@ Object.defineProperties(exports, {
|
|||||||
// The ecosystem needs those to exist for backwards compatibility.
|
// The ecosystem needs those to exist for backwards compatibility.
|
||||||
prng: {
|
prng: {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
|
configurable: true,
|
||||||
|
writable: true,
|
||||||
value: pendingDeprecation ?
|
value: pendingDeprecation ?
|
||||||
deprecate(randomBytes, 'crypto.prng is deprecated.', 'DEP0115') :
|
deprecate(randomBytes, 'crypto.prng is deprecated.', 'DEP0115') :
|
||||||
randomBytes
|
randomBytes
|
||||||
},
|
},
|
||||||
pseudoRandomBytes: {
|
pseudoRandomBytes: {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
|
configurable: true,
|
||||||
|
writable: true,
|
||||||
value: pendingDeprecation ?
|
value: pendingDeprecation ?
|
||||||
deprecate(randomBytes,
|
deprecate(randomBytes,
|
||||||
'crypto.pseudoRandomBytes is deprecated.', 'DEP0115') :
|
'crypto.pseudoRandomBytes is deprecated.', 'DEP0115') :
|
||||||
@ -260,6 +264,8 @@ Object.defineProperties(exports, {
|
|||||||
},
|
},
|
||||||
rng: {
|
rng: {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
|
configurable: true,
|
||||||
|
writable: true,
|
||||||
value: pendingDeprecation ?
|
value: pendingDeprecation ?
|
||||||
deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115') :
|
deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115') :
|
||||||
randomBytes
|
randomBytes
|
||||||
|
@ -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);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user