Skip to content

Commit

Permalink
crypto: remove DEFAULT_ENCODING
Browse files Browse the repository at this point in the history
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 <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Beth Griggs <bethanyngriggs@gmail.com>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
  • Loading branch information
tniessen authored Mar 26, 2023
1 parent 106aa47 commit 9374700
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 785 deletions.
20 changes: 0 additions & 20 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -2878,26 +2878,6 @@ An object containing commonly used constants for crypto and security related
operations. The specific constants currently defined are described in
[Crypto constants][].

### `crypto.DEFAULT_ENCODING`

<!-- YAML
added: v0.9.3
deprecated: v10.0.0
-->

> Stability: 0 - Deprecated
The default encoding to use for functions that can take either strings
or [buffers][`Buffer`]. The default value is `'buffer'`, which makes methods
default to [`Buffer`][] objects.

The `crypto.DEFAULT_ENCODING` mechanism is provided for backward compatibility
with legacy programs that expect `'latin1'` to be the default encoding.

New applications should expect the default to be `'buffer'`.

This property is deprecated.

### `crypto.fips`

<!-- YAML
Expand Down
9 changes: 6 additions & 3 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1864,14 +1864,18 @@ bits are allowed. Authentication tags of other lengths are invalid per

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/47182
description: End-of-Life.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18333
description: Runtime deprecation.
-->

Type: Runtime
Type: End-of-Life

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

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

Expand Down Expand Up @@ -3388,7 +3392,6 @@ be added when a function is bound to an `AsyncResource`.
[`console.error()`]: console.md#consoleerrordata-args
[`console.log()`]: console.md#consolelogdata-args
[`crypto.Certificate()` constructor]: crypto.md#legacy-api
[`crypto.DEFAULT_ENCODING`]: crypto.md#cryptodefault_encoding
[`crypto.createCipher()`]: crypto.md#cryptocreatecipheralgorithm-password-options
[`crypto.createCipheriv()`]: crypto.md#cryptocreatecipherivalgorithm-key-iv-options
[`crypto.createDecipher()`]: crypto.md#cryptocreatedecipheralgorithm-password-options
Expand Down
11 changes: 0 additions & 11 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ const {
const {
getCiphers,
getCurves,
getDefaultEncoding,
getHashes,
setDefaultEncoding,
setEngine,
secureHeapUsed,
} = require('internal/crypto/util');
Expand Down Expand Up @@ -356,15 +354,6 @@ ObjectDefineProperties(module.exports, {
get: getFips,
set: setFips,
},
DEFAULT_ENCODING: {
__proto__: null,
enumerable: false,
configurable: true,
get: deprecate(getDefaultEncoding,
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091'),
set: deprecate(setDefaultEncoding,
'crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091'),
},
constants: {
__proto__: null,
configurable: false,
Expand Down
10 changes: 2 additions & 8 deletions lib/internal/crypto/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,9 @@ const {
const kHandle = Symbol('kHandle');
const kKeyObject = Symbol('kKeyObject');

let defaultEncoding = 'buffer';

function setDefaultEncoding(val) {
defaultEncoding = val;
}

// TODO(tniessen): remove all call sites and this function
function getDefaultEncoding() {
return defaultEncoding;
return 'buffer';
}

// This is here because many functions accepted binary strings without
Expand Down Expand Up @@ -561,7 +556,6 @@ module.exports = {
getHashes,
kHandle,
kKeyObject,
setDefaultEncoding,
setEngine,
toBuf,

Expand Down
3 changes: 0 additions & 3 deletions test/parallel/test-crypto-authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const crypto = require('crypto');
const { inspect } = require('util');
const fixtures = require('../common/fixtures');

crypto.DEFAULT_ENCODING = 'buffer';

//
// Test authenticated encryption modes.
//
Expand Down Expand Up @@ -74,7 +72,6 @@ const expectedWarnings = common.hasFipsCrypto ?
];

const expectedDeprecationWarnings = [
['crypto.DEFAULT_ENCODING is deprecated.', 'DEP0091'],
['crypto.createCipher is deprecated.', 'DEP0106'],
];

Expand Down
Loading

0 comments on commit 9374700

Please sign in to comment.