Skip to content

Commit 709b3b1

Browse files
committed
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: #23013 PR-URL: #23017 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent eccc659 commit 709b3b1

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

Diff for: doc/api/deprecations.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -2167,16 +2167,19 @@ of Node.js core and will be removed in the future.
21672167
<!-- YAML
21682168
changes:
21692169
- version: REPLACEME
2170-
pr-url: https://github.com/nodejs/node/pull/22519
2171-
description: Runtime deprecation.
2170+
pr-url:
2171+
- https://github.com/nodejs/node/pull/22519
2172+
- https://github.com/nodejs/node/pull/23017
2173+
description: Added documentation-only deprecation
2174+
with `--pending-deprecation` support.
21722175
-->
21732176
2174-
Type: Runtime
2177+
Type: Documentation-only (supports [`--pending-deprecation`][])
21752178
21762179
In recent versions of Node.js, there is no difference between
21772180
[`crypto.randomBytes()`][] and `crypto.pseudoRandomBytes()`. The latter is
21782181
deprecated along with the undocumented aliases `crypto.prng()` and
2179-
`crypto.rng()` in favor of [`crypto.randomBytes()`][] and will be removed in a
2182+
`crypto.rng()` in favor of [`crypto.randomBytes()`][] and may be removed in a
21802183
future release.
21812184
21822185
<a id="DEP0116"></a>

Diff for: lib/crypto.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const {
3636
ERR_CRYPTO_FIPS_UNAVAILABLE
3737
} = require('internal/errors').codes;
3838
const constants = process.binding('constants').crypto;
39+
const { pendingDeprecation } = process.binding('config');
3940
const {
4041
fipsMode,
4142
fipsForced
@@ -243,19 +244,24 @@ Object.defineProperties(exports, {
243244
},
244245

245246
// Aliases for randomBytes are deprecated.
246-
// The ecosystem needs those to exist for backwards compatibility with
247-
// ancient Node.js runtimes (0.10, 0.12).
247+
// The ecosystem needs those to exist for backwards compatibility.
248248
prng: {
249249
enumerable: false,
250-
value: deprecate(randomBytes, 'crypto.prng is deprecated.', 'DEP0115')
250+
value: pendingDeprecation ?
251+
deprecate(randomBytes, 'crypto.prng is deprecated.', 'DEP0115') :
252+
randomBytes
251253
},
252254
pseudoRandomBytes: {
253255
enumerable: false,
254-
value: deprecate(randomBytes,
255-
'crypto.pseudoRandomBytes is deprecated.', 'DEP0115')
256+
value: pendingDeprecation ?
257+
deprecate(randomBytes,
258+
'crypto.pseudoRandomBytes is deprecated.', 'DEP0115') :
259+
randomBytes
256260
},
257261
rng: {
258262
enumerable: false,
259-
value: deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115')
263+
value: pendingDeprecation ?
264+
deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115') :
265+
randomBytes
260266
}
261267
});

Diff for: test/parallel/test-crypto-random.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22+
// Flags: --pending-deprecation
2223
'use strict';
2324
const common = require('../common');
2425

0 commit comments

Comments
 (0)