Skip to content

Commit 6035bee

Browse files
committed
crypto: runtime deprecate DEFAULT_ENCODING
Runtime deprecate the crypto.DEFAULT_ENCODING property. This is specifically in preparation for eventual ESM support Refs: #18131 PR-URL: #18333 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent fd3a0cf commit 6035bee

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

doc/api/crypto.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ related operations. The specific constants currently defined are described in
12221222
### crypto.DEFAULT_ENCODING
12231223
<!-- YAML
12241224
added: v0.9.3
1225+
deprecated: REPLACEME
12251226
-->
12261227

12271228
The default encoding to use for functions that can take either strings
@@ -1231,8 +1232,9 @@ default to [`Buffer`][] objects.
12311232
The `crypto.DEFAULT_ENCODING` mechanism is provided for backwards compatibility
12321233
with legacy programs that expect `'latin1'` to be the default encoding.
12331234

1234-
New applications should expect the default to be `'buffer'`. This property may
1235-
become deprecated in a future Node.js release.
1235+
New applications should expect the default to be `'buffer'`.
1236+
1237+
This property is deprecated.
12361238

12371239
### crypto.fips
12381240
<!-- YAML
@@ -1643,8 +1645,9 @@ crypto.pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => {
16431645
});
16441646
```
16451647

1646-
The `crypto.DEFAULT_ENCODING` may be used to change the way the `derivedKey`
1647-
is passed to the callback:
1648+
The `crypto.DEFAULT_ENCODING` property can be used to change the way the
1649+
`derivedKey` is passed to the callback. This property, however, has been
1650+
deprecated and use should be avoided.
16481651

16491652
```js
16501653
const crypto = require('crypto');
@@ -1705,8 +1708,9 @@ const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
17051708
console.log(key.toString('hex')); // '3745e48...08d59ae'
17061709
```
17071710

1708-
The `crypto.DEFAULT_ENCODING` may be used to change the way the `derivedKey`
1709-
is returned:
1711+
The `crypto.DEFAULT_ENCODING` property may be used to change the way the
1712+
`derivedKey` is returned. This property, however, has been deprecated and use
1713+
should be avoided.
17101714

17111715
```js
17121716
const crypto = require('crypto');

doc/api/deprecations.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,13 @@ a future version at which point only authentication tag lengths of 128, 120,
824824
is not included in this list will be considered invalid in compliance with
825825
[NIST SP 800-38D][].
826826
827+
<a id="DEP00XX"></a>
828+
### DEP00XX: crypto.DEFAULT_ENCODING
829+
830+
Type: Runtime
831+
832+
The [`crypto.DEFAULT_ENCODING`][] property is deprecated.
833+
827834
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
828835
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
829836
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
@@ -838,6 +845,7 @@ is not included in this list will be considered invalid in compliance with
838845
[`console.error()`]: console.html#console_console_error_data_args
839846
[`console.log()`]: console.html#console_console_log_data_args
840847
[`crypto.createCredentials()`]: crypto.html#crypto_crypto_createcredentials_details
848+
[`crypto.DEFAULT_ENCODING`]: crypto.html#crypto_crypto_default_encoding
841849
[`crypto.pbkdf2()`]: crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
842850
[`decipher.setAuthTag()`]: crypto.html#crypto_decipher_setauthtag_buffer
843851
[`domain`]: domain.html

lib/crypto.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,10 @@ Object.defineProperties(exports, {
205205
DEFAULT_ENCODING: {
206206
enumerable: true,
207207
configurable: true,
208-
get: getDefaultEncoding,
209-
set: setDefaultEncoding
208+
get: deprecate(getDefaultEncoding,
209+
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP00XX'),
210+
set: deprecate(setDefaultEncoding,
211+
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP00XX')
210212
},
211213
constants: {
212214
configurable: false,

test/parallel/test-crypto-authenticated.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ const expectedDeprecationWarnings = [0, 1, 2, 6, 9, 10, 11, 17]
342342
.map((i) => `Permitting authentication tag lengths of ${i} bytes is ` +
343343
'deprecated. Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.');
344344

345+
expectedDeprecationWarnings.push('crypto.DEFAULT_ENCODING is deprecated.');
346+
345347
common.expectWarning({
346348
Warning: expectedWarnings,
347349
DeprecationWarning: expectedDeprecationWarnings

0 commit comments

Comments
 (0)