From c662e87b73292507b21b37b276734be693ea7792 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 22 Sep 2018 11:45:42 +0200 Subject: [PATCH 1/3] crypto: downgrade DEP0115 to `--pending-deprecation` only 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 --- doc/api/deprecations.md | 4 ++-- lib/crypto.js | 18 ++++++++++++------ test/parallel/test-crypto-random.js | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index b14599f26b05e9..7eb558c68dba9a 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2168,12 +2168,12 @@ changes: description: Runtime deprecation. --> -Type: Runtime +Type: Runtime (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'); From c8b5d48a36495de72af948294be5f087476c5753 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 22 Sep 2018 11:57:23 +0200 Subject: [PATCH 2/3] fixup! crypto: downgrade DEP0115 to `--pending-deprecation` only --- doc/api/deprecations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 7eb558c68dba9a..c099bc5c2babb2 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2168,7 +2168,7 @@ changes: description: Runtime deprecation. --> -Type: Runtime (supports [`--pending-deprecation`][]) +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 From e16717584c7e838e3e71d885ef9e582609920748 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 22 Sep 2018 14:05:15 +0200 Subject: [PATCH 3/3] fixup! crypto: downgrade DEP0115 to `--pending-deprecation` only --- doc/api/deprecations.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index c099bc5c2babb2..83c820627311df 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2164,8 +2164,11 @@ of Node.js core and will be removed in the future. Type: Documentation-only (supports [`--pending-deprecation`][])