crypto: runtime deprecate DEFAULT_ENCODING

Runtime deprecate the crypto.DEFAULT_ENCODING property.

This is specifically in preparation for eventual ESM support
Refs: https://github.com/nodejs/node/pull/18131

PR-URL: https://github.com/nodejs/node/pull/18333
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
James M Snell 2018-01-23 15:58:14 -08:00
parent fd3a0cfb7c
commit 6035beea93
4 changed files with 24 additions and 8 deletions

View file

@ -1222,6 +1222,7 @@ related operations. The specific constants currently defined are described in
### crypto.DEFAULT_ENCODING ### crypto.DEFAULT_ENCODING
<!-- YAML <!-- YAML
added: v0.9.3 added: v0.9.3
deprecated: REPLACEME
--> -->
The default encoding to use for functions that can take either strings The default encoding to use for functions that can take either strings
@ -1231,8 +1232,9 @@ default to [`Buffer`][] objects.
The `crypto.DEFAULT_ENCODING` mechanism is provided for backwards compatibility The `crypto.DEFAULT_ENCODING` mechanism is provided for backwards compatibility
with legacy programs that expect `'latin1'` to be the default encoding. with legacy programs that expect `'latin1'` to be the default encoding.
New applications should expect the default to be `'buffer'`. This property may New applications should expect the default to be `'buffer'`.
become deprecated in a future Node.js release.
This property is deprecated.
### crypto.fips ### crypto.fips
<!-- YAML <!-- YAML
@ -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` The `crypto.DEFAULT_ENCODING` property can be used to change the way the
is passed to the callback: `derivedKey` is passed to the callback. This property, however, has been
deprecated and use should be avoided.
```js ```js
const crypto = require('crypto'); const crypto = require('crypto');
@ -1705,8 +1708,9 @@ const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
console.log(key.toString('hex')); // '3745e48...08d59ae' console.log(key.toString('hex')); // '3745e48...08d59ae'
``` ```
The `crypto.DEFAULT_ENCODING` may be used to change the way the `derivedKey` The `crypto.DEFAULT_ENCODING` property may be used to change the way the
is returned: `derivedKey` is returned. This property, however, has been deprecated and use
should be avoided.
```js ```js
const crypto = require('crypto'); const crypto = require('crypto');

View file

@ -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 is not included in this list will be considered invalid in compliance with
[NIST SP 800-38D][]. [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 [`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array [`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
[`console.error()`]: console.html#console_console_error_data_args [`console.error()`]: console.html#console_console_error_data_args
[`console.log()`]: console.html#console_console_log_data_args [`console.log()`]: console.html#console_console_log_data_args
[`crypto.createCredentials()`]: crypto.html#crypto_crypto_createcredentials_details [`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 [`crypto.pbkdf2()`]: crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
[`decipher.setAuthTag()`]: crypto.html#crypto_decipher_setauthtag_buffer [`decipher.setAuthTag()`]: crypto.html#crypto_decipher_setauthtag_buffer
[`domain`]: domain.html [`domain`]: domain.html

View file

@ -205,8 +205,10 @@ Object.defineProperties(exports, {
DEFAULT_ENCODING: { DEFAULT_ENCODING: {
enumerable: true, enumerable: true,
configurable: true, configurable: true,
get: getDefaultEncoding, get: deprecate(getDefaultEncoding,
set: setDefaultEncoding 'crypto.DEFAULT_ENCODING is deprecated.', 'DEP00XX'),
set: deprecate(setDefaultEncoding,
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP00XX')
}, },
constants: { constants: {
configurable: false, configurable: false,

View file

@ -342,6 +342,8 @@ const expectedDeprecationWarnings = [0, 1, 2, 6, 9, 10, 11, 17]
.map((i) => `Permitting authentication tag lengths of ${i} bytes is ` + .map((i) => `Permitting authentication tag lengths of ${i} bytes is ` +
'deprecated. Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.'); 'deprecated. Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.');
expectedDeprecationWarnings.push('crypto.DEFAULT_ENCODING is deprecated.');
common.expectWarning({ common.expectWarning({
Warning: expectedWarnings, Warning: expectedWarnings,
DeprecationWarning: expectedDeprecationWarnings DeprecationWarning: expectedDeprecationWarnings