Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: runtime deprecate DEFAULT_ENCODING #18333

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,7 @@ related operations. The specific constants currently defined are described in
### crypto.DEFAULT_ENCODING
<!-- YAML
added: v0.9.3
deprecated: REPLACEME
-->

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

New applications should expect the default to be `'buffer'`. This property may
become deprecated in a future Node.js release.
New applications should expect the default to be `'buffer'`.

This property is deprecated.

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

The `crypto.DEFAULT_ENCODING` may be used to change the way the `derivedKey`
is passed to the callback:
The `crypto.DEFAULT_ENCODING` property can be used to change the way the
`derivedKey` is passed to the callback. This property, however, has been
deprecated and use should be avoided.

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

The `crypto.DEFAULT_ENCODING` may be used to change the way the `derivedKey`
is returned:
The `crypto.DEFAULT_ENCODING` property may be used to change the way the
`derivedKey` is returned. This property, however, has been deprecated and use
should be avoided.

```js
const crypto = require('crypto');
Expand Down
8 changes: 8 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,13 @@ a future version at which point only authentication tag lengths of 128, 120,
is not included in this list will be considered invalid in compliance with
[NIST SP 800-38D][].

<a id="DEP00XX"></a>
### DEP00XX: crypto.DEFAULT_ENCODING

Type: Runtime

The [`crypto.DEFAULT_ENCODING`][] property is deprecated.

[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
Expand All @@ -838,6 +845,7 @@ is not included in this list will be considered invalid in compliance with
[`console.error()`]: console.html#console_console_error_data_args
[`console.log()`]: console.html#console_console_log_data_args
[`crypto.createCredentials()`]: crypto.html#crypto_crypto_createcredentials_details
[`crypto.DEFAULT_ENCODING`]: crypto.html#crypto_crypto_default_encoding
[`crypto.pbkdf2()`]: crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
[`decipher.setAuthTag()`]: crypto.html#crypto_decipher_setauthtag_buffer
[`domain`]: domain.html
Expand Down
6 changes: 4 additions & 2 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ Object.defineProperties(exports, {
DEFAULT_ENCODING: {
enumerable: true,
configurable: true,
get: getDefaultEncoding,
set: setDefaultEncoding
get: deprecate(getDefaultEncoding,
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP00XX'),
set: deprecate(setDefaultEncoding,
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP00XX')
},
constants: {
configurable: false,
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-crypto-authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ const expectedDeprecationWarnings = [0, 1, 2, 6, 9, 10, 11, 17]
.map((i) => `Permitting authentication tag lengths of ${i} bytes is ` +
'deprecated. Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.');

expectedDeprecationWarnings.push('crypto.DEFAULT_ENCODING is deprecated.');

common.expectWarning({
Warning: expectedWarnings,
DeprecationWarning: expectedDeprecationWarnings
Expand Down