From 709b3b1e1c75afe6b5dd9d7859d0142dd4d20e5c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 22 Sep 2018 11:45:42 +0200 Subject: [PATCH] crypto: downgrade DEP0115 to `--pending-deprecation` only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Aliases are very cheap to maintain, so an unconditional runtime deprecation that affects existing ecosystem code is not a good idea. This commit turns the runtime deprecation into a `--pending-deprecation` one. Fixes: https://github.com/nodejs/node/issues/23013 PR-URL: https://github.com/nodejs/node/pull/23017 Reviewed-By: Michaël Zasso Reviewed-By: Luigi Pinca Reviewed-By: Tobias Nießen Reviewed-By: Colin Ihrig Reviewed-By: Refael Ackermann Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat --- doc/api/deprecations.md | 11 +++++++---- lib/crypto.js | 18 ++++++++++++------ test/parallel/test-crypto-random.js | 1 + 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 9f1b3c0b700491..dc12efb9069f12 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2167,16 +2167,19 @@ of Node.js core and will be removed in the future. -Type: Runtime +Type: Documentation-only (supports [`--pending-deprecation`][]) In recent versions of Node.js, there is no difference between [`crypto.randomBytes()`][] and `crypto.pseudoRandomBytes()`. The latter is deprecated along with the undocumented aliases `crypto.prng()` and -`crypto.rng()` in favor of [`crypto.randomBytes()`][] and will be removed in a +`crypto.rng()` in favor of [`crypto.randomBytes()`][] and may be removed in a future release. diff --git a/lib/crypto.js b/lib/crypto.js index 12f5bd4bd94539..ed902272de4b4d 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -36,6 +36,7 @@ const { ERR_CRYPTO_FIPS_UNAVAILABLE } = require('internal/errors').codes; const constants = process.binding('constants').crypto; +const { pendingDeprecation } = process.binding('config'); const { fipsMode, fipsForced @@ -243,19 +244,24 @@ Object.defineProperties(exports, { }, // Aliases for randomBytes are deprecated. - // The ecosystem needs those to exist for backwards compatibility with - // ancient Node.js runtimes (0.10, 0.12). + // The ecosystem needs those to exist for backwards compatibility. prng: { enumerable: false, - value: deprecate(randomBytes, 'crypto.prng is deprecated.', 'DEP0115') + value: pendingDeprecation ? + deprecate(randomBytes, 'crypto.prng is deprecated.', 'DEP0115') : + randomBytes }, pseudoRandomBytes: { enumerable: false, - value: deprecate(randomBytes, - 'crypto.pseudoRandomBytes is deprecated.', 'DEP0115') + value: pendingDeprecation ? + deprecate(randomBytes, + 'crypto.pseudoRandomBytes is deprecated.', 'DEP0115') : + randomBytes }, rng: { enumerable: false, - value: deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115') + value: pendingDeprecation ? + deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115') : + randomBytes } }); diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index fe7b24b4854144..df06134e4326f9 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -19,6 +19,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. +// Flags: --pending-deprecation 'use strict'; const common = require('../common');