Skip to content

Commit 2f97759

Browse files
tniessenjasnell
authored andcommitted
crypto: move Decipher.finaltol to End-of-Life
Refs: #19353 PR-URL: #19941 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
1 parent 72dc1ae commit 2f97759

File tree

4 files changed

+34
-59
lines changed

4 files changed

+34
-59
lines changed

doc/api/deprecations.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -959,11 +959,11 @@ property to a string before assigning it to `process.env`.
959959
<a id="DEP0105"></a>
960960
### DEP0105: decipher.finaltol
961961
962-
Type: Runtime
962+
Type: End-of-Life
963963
964-
`decipher.finaltol()` has never been documented and is currently an alias for
965-
[`decipher.final()`][]. In the future, this API will likely be removed, and it
966-
is recommended to use [`decipher.final()`][] instead.
964+
`decipher.finaltol()` has never been documented and was an alias for
965+
[`decipher.final()`][]. This API has been removed, and it is recommended to use
966+
[`decipher.final()`][] instead.
967967
968968
<a id="DEP0106"></a>
969969
### DEP0106: crypto.createCipher and crypto.createDecipher

lib/internal/crypto/cipher.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const LazyTransform = require('internal/streams/lazy_transform');
3131
const { StringDecoder } = require('string_decoder');
3232

3333
const { inherits } = require('util');
34-
const { deprecate, normalizeEncoding } = require('internal/util');
34+
const { normalizeEncoding } = require('internal/util');
3535

3636
function rsaPublic(method, defaultPadding) {
3737
return function(options, buffer) {
@@ -240,10 +240,6 @@ Cipheriv.prototype.setAuthTag = Cipher.prototype.setAuthTag;
240240
Cipheriv.prototype.setAAD = Cipher.prototype.setAAD;
241241

242242

243-
const finaltol = deprecate(Cipher.prototype.final,
244-
'crypto.Decipher.finaltol is deprecated. Use ' +
245-
'crypto.Decipher.final instead.', 'DEP0105');
246-
247243
function Decipher(cipher, password, options) {
248244
if (!(this instanceof Decipher))
249245
return new Decipher(cipher, password, options);
@@ -275,7 +271,6 @@ Decipher.prototype._transform = Cipher.prototype._transform;
275271
Decipher.prototype._flush = Cipher.prototype._flush;
276272
Decipher.prototype.update = Cipher.prototype.update;
277273
Decipher.prototype.final = Cipher.prototype.final;
278-
Decipher.prototype.finaltol = finaltol;
279274
Decipher.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
280275
Decipher.prototype.getAuthTag = Cipher.prototype.getAuthTag;
281276
Decipher.prototype.setAuthTag = Cipher.prototype.setAuthTag;
@@ -322,7 +317,6 @@ Decipheriv.prototype._transform = Cipher.prototype._transform;
322317
Decipheriv.prototype._flush = Cipher.prototype._flush;
323318
Decipheriv.prototype.update = Cipher.prototype.update;
324319
Decipheriv.prototype.final = Cipher.prototype.final;
325-
Decipheriv.prototype.finaltol = finaltol;
326320
Decipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
327321
Decipheriv.prototype.getAuthTag = Cipher.prototype.getAuthTag;
328322
Decipheriv.prototype.setAuthTag = Cipher.prototype.setAuthTag;

test/parallel/test-crypto-deprecated.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ common.expectWarning('DeprecationWarning', [
1111
['crypto.Credentials is deprecated. Use tls.SecureContext instead.',
1212
'DEP0011'],
1313
['crypto.createCredentials is deprecated. Use tls.createSecureContext ' +
14-
'instead.', 'DEP0010'],
15-
['crypto.Decipher.finaltol is deprecated. Use crypto.Decipher.final instead.',
16-
'DEP0105']
14+
'instead.', 'DEP0010']
1715
]);
1816

1917
// Accessing the deprecated function is enough to trigger the warning event.
@@ -22,15 +20,3 @@ common.expectWarning('DeprecationWarning', [
2220
// mapped to the correct non-deprecated function.
2321
assert.strictEqual(crypto.Credentials, tls.SecureContext);
2422
assert.strictEqual(crypto.createCredentials, tls.createSecureContext);
25-
26-
{
27-
const cipher = crypto.createCipheriv('aes-128-cbc', '0000000000000000',
28-
'0000000000000000');
29-
const ciphertext = cipher.update('Node.js', 'utf8', 'hex') +
30-
cipher.final('hex');
31-
const decipher = crypto.createDecipheriv('aes-128-cbc', '0000000000000000',
32-
'0000000000000000');
33-
const plaintext = decipher.update(ciphertext, 'hex', 'utf8') +
34-
decipher.finaltol('utf8');
35-
assert.strictEqual(plaintext, 'Node.js');
36-
}

test/parallel/test-crypto-padding-aes256.js

+28-33
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,34 @@ const crypto = require('crypto');
2929

3030
crypto.DEFAULT_ENCODING = 'buffer';
3131

32-
function aes256(decipherFinal) {
33-
const iv = Buffer.from('00000000000000000000000000000000', 'hex');
34-
const key = Buffer.from('0123456789abcdef0123456789abcdef' +
35-
'0123456789abcdef0123456789abcdef', 'hex');
36-
37-
function encrypt(val, pad) {
38-
const c = crypto.createCipheriv('aes256', key, iv);
39-
c.setAutoPadding(pad);
40-
return c.update(val, 'utf8', 'latin1') + c.final('latin1');
41-
}
42-
43-
function decrypt(val, pad) {
44-
const c = crypto.createDecipheriv('aes256', key, iv);
45-
c.setAutoPadding(pad);
46-
return c.update(val, 'latin1', 'utf8') + c[decipherFinal]('utf8');
47-
}
48-
49-
// echo 0123456789abcdef0123456789abcdef \
50-
// | openssl enc -e -aes256 -nopad -K <key> -iv <iv> \
51-
// | openssl enc -d -aes256 -nopad -K <key> -iv <iv>
52-
let plaintext = '0123456789abcdef0123456789abcdef'; // multiple of block size
53-
let encrypted = encrypt(plaintext, false);
54-
let decrypted = decrypt(encrypted, false);
55-
assert.strictEqual(decrypted, plaintext);
32+
const iv = Buffer.from('00000000000000000000000000000000', 'hex');
33+
const key = Buffer.from('0123456789abcdef0123456789abcdef' +
34+
'0123456789abcdef0123456789abcdef', 'hex');
35+
36+
function encrypt(val, pad) {
37+
const c = crypto.createCipheriv('aes256', key, iv);
38+
c.setAutoPadding(pad);
39+
return c.update(val, 'utf8', 'latin1') + c.final('latin1');
40+
}
5641

57-
// echo 0123456789abcdef0123456789abcde \
58-
// | openssl enc -e -aes256 -K <key> -iv <iv> \
59-
// | openssl enc -d -aes256 -K <key> -iv <iv>
60-
plaintext = '0123456789abcdef0123456789abcde'; // not a multiple
61-
encrypted = encrypt(plaintext, true);
62-
decrypted = decrypt(encrypted, true);
63-
assert.strictEqual(decrypted, plaintext);
42+
function decrypt(val, pad) {
43+
const c = crypto.createDecipheriv('aes256', key, iv);
44+
c.setAutoPadding(pad);
45+
return c.update(val, 'latin1', 'utf8') + c.final('utf8');
6446
}
6547

66-
aes256('final');
67-
aes256('finaltol');
48+
// echo 0123456789abcdef0123456789abcdef \
49+
// | openssl enc -e -aes256 -nopad -K <key> -iv <iv> \
50+
// | openssl enc -d -aes256 -nopad -K <key> -iv <iv>
51+
let plaintext = '0123456789abcdef0123456789abcdef'; // multiple of block size
52+
let encrypted = encrypt(plaintext, false);
53+
let decrypted = decrypt(encrypted, false);
54+
assert.strictEqual(decrypted, plaintext);
55+
56+
// echo 0123456789abcdef0123456789abcde \
57+
// | openssl enc -e -aes256 -K <key> -iv <iv> \
58+
// | openssl enc -d -aes256 -K <key> -iv <iv>
59+
plaintext = '0123456789abcdef0123456789abcde'; // not a multiple
60+
encrypted = encrypt(plaintext, true);
61+
decrypted = decrypt(encrypted, true);
62+
assert.strictEqual(decrypted, plaintext);

0 commit comments

Comments
 (0)