Skip to content

Commit 9374700

Browse files
authored
crypto: remove DEFAULT_ENCODING
Citing 76b0bdf from 2012, "only use this as a temporary measure." Getting or setting DEFAULT_ENCODING has emitted a warning ever since Node.js 10, so it seems appropriate to remove it in Node.js 20 five years later. The last Node.js version that did not emit a warning reached its end-of-life status at the end of 2019. This commit only removes the public API so that the change can land in time for Node.js 20. Refs: nodejs/node-v0.x-archive#4179 Refs: #18333 PR-URL: #47182 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: Erick Wendel <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent 106aa47 commit 9374700

File tree

7 files changed

+8
-785
lines changed

7 files changed

+8
-785
lines changed

doc/api/crypto.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,26 +2878,6 @@ An object containing commonly used constants for crypto and security related
28782878
operations. The specific constants currently defined are described in
28792879
[Crypto constants][].
28802880

2881-
### `crypto.DEFAULT_ENCODING`
2882-
2883-
<!-- YAML
2884-
added: v0.9.3
2885-
deprecated: v10.0.0
2886-
-->
2887-
2888-
> Stability: 0 - Deprecated
2889-
2890-
The default encoding to use for functions that can take either strings
2891-
or [buffers][`Buffer`]. The default value is `'buffer'`, which makes methods
2892-
default to [`Buffer`][] objects.
2893-
2894-
The `crypto.DEFAULT_ENCODING` mechanism is provided for backward compatibility
2895-
with legacy programs that expect `'latin1'` to be the default encoding.
2896-
2897-
New applications should expect the default to be `'buffer'`.
2898-
2899-
This property is deprecated.
2900-
29012881
### `crypto.fips`
29022882

29032883
<!-- YAML

doc/api/deprecations.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,14 +1864,18 @@ bits are allowed. Authentication tags of other lengths are invalid per
18641864

18651865
<!-- YAML
18661866
changes:
1867+
- version: REPLACEME
1868+
pr-url: https://github.com/nodejs/node/pull/47182
1869+
description: End-of-Life.
18671870
- version: v10.0.0
18681871
pr-url: https://github.com/nodejs/node/pull/18333
18691872
description: Runtime deprecation.
18701873
-->
18711874

1872-
Type: Runtime
1875+
Type: End-of-Life
18731876

1874-
The [`crypto.DEFAULT_ENCODING`][] property is deprecated.
1877+
The `crypto.DEFAULT_ENCODING` property only existed for compatibility with
1878+
Node.js releases prior to versions 0.9.3 and has been removed.
18751879

18761880
### DEP0092: Top-level `this` bound to `module.exports`
18771881

@@ -3388,7 +3392,6 @@ be added when a function is bound to an `AsyncResource`.
33883392
[`console.error()`]: console.md#consoleerrordata-args
33893393
[`console.log()`]: console.md#consolelogdata-args
33903394
[`crypto.Certificate()` constructor]: crypto.md#legacy-api
3391-
[`crypto.DEFAULT_ENCODING`]: crypto.md#cryptodefault_encoding
33923395
[`crypto.createCipher()`]: crypto.md#cryptocreatecipheralgorithm-password-options
33933396
[`crypto.createCipheriv()`]: crypto.md#cryptocreatecipherivalgorithm-key-iv-options
33943397
[`crypto.createDecipher()`]: crypto.md#cryptocreatedecipheralgorithm-password-options

lib/crypto.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ const {
114114
const {
115115
getCiphers,
116116
getCurves,
117-
getDefaultEncoding,
118117
getHashes,
119-
setDefaultEncoding,
120118
setEngine,
121119
secureHeapUsed,
122120
} = require('internal/crypto/util');
@@ -356,15 +354,6 @@ ObjectDefineProperties(module.exports, {
356354
get: getFips,
357355
set: setFips,
358356
},
359-
DEFAULT_ENCODING: {
360-
__proto__: null,
361-
enumerable: false,
362-
configurable: true,
363-
get: deprecate(getDefaultEncoding,
364-
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091'),
365-
set: deprecate(setDefaultEncoding,
366-
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091'),
367-
},
368357
constants: {
369358
__proto__: null,
370359
configurable: false,

lib/internal/crypto/util.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,9 @@ const {
7474
const kHandle = Symbol('kHandle');
7575
const kKeyObject = Symbol('kKeyObject');
7676

77-
let defaultEncoding = 'buffer';
78-
79-
function setDefaultEncoding(val) {
80-
defaultEncoding = val;
81-
}
82-
77+
// TODO(tniessen): remove all call sites and this function
8378
function getDefaultEncoding() {
84-
return defaultEncoding;
79+
return 'buffer';
8580
}
8681

8782
// This is here because many functions accepted binary strings without
@@ -561,7 +556,6 @@ module.exports = {
561556
getHashes,
562557
kHandle,
563558
kKeyObject,
564-
setDefaultEncoding,
565559
setEngine,
566560
toBuf,
567561

test/parallel/test-crypto-authenticated.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ const crypto = require('crypto');
2929
const { inspect } = require('util');
3030
const fixtures = require('../common/fixtures');
3131

32-
crypto.DEFAULT_ENCODING = 'buffer';
33-
3432
//
3533
// Test authenticated encryption modes.
3634
//
@@ -74,7 +72,6 @@ const expectedWarnings = common.hasFipsCrypto ?
7472
];
7573

7674
const expectedDeprecationWarnings = [
77-
['crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091'],
7875
['crypto.createCipher is deprecated.', 'DEP0106'],
7976
];
8077

0 commit comments

Comments
 (0)