Skip to content

Commit 19f3927

Browse files
committed
crypto: deprecate Decipher.finaltol
PR-URL: #19353 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6050add commit 19f3927

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

doc/api/deprecations.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,15 @@ deprecated if the assigned value is not a string, boolean, or number. In the
950950
future, such assignment may result in a thrown error. Please convert the
951951
property to a string before assigning it to `process.env`.
952952
953+
<a id="DEP0105"></a>
954+
### DEP0105: decipher.finaltol
955+
956+
Type: Runtime
957+
958+
`decipher.finaltol()` has never been documented and is currently an alias for
959+
[`decipher.final()`][]. In the future, this API will likely be removed, and it
960+
is recommended to use [`decipher.final()`][] instead.
961+
953962
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
954963
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
955964
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
@@ -971,6 +980,7 @@ property to a string before assigning it to `process.env`.
971980
[`crypto.DEFAULT_ENCODING`]: crypto.html#crypto_crypto_default_encoding
972981
[`crypto.fips`]: crypto.html#crypto_crypto_fips
973982
[`crypto.pbkdf2()`]: crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
983+
[`decipher.final()`]: crypto.html#crypto_decipher_final_outputencoding
974984
[`decipher.setAuthTag()`]: crypto.html#crypto_decipher_setauthtag_buffer
975985
[`domain`]: domain.html
976986
[`ecdh.setPublicKey()`]: crypto.html#crypto_ecdh_setpublickey_publickey_encoding

lib/internal/crypto/cipher.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const LazyTransform = require('internal/streams/lazy_transform');
3030
const { StringDecoder } = require('string_decoder');
3131

3232
const { inherits } = require('util');
33-
const { normalizeEncoding } = require('internal/util');
33+
const { deprecate, normalizeEncoding } = require('internal/util');
3434

3535
function rsaPublic(method, defaultPadding) {
3636
return function(options, buffer) {
@@ -217,6 +217,10 @@ Cipheriv.prototype.setAuthTag = Cipher.prototype.setAuthTag;
217217
Cipheriv.prototype.setAAD = Cipher.prototype.setAAD;
218218

219219

220+
const finaltol = deprecate(Cipher.prototype.final,
221+
'crypto.Decipher.finaltol is deprecated. Use ' +
222+
'crypto.Decipher.final instead.', 'DEP0105');
223+
220224
function Decipher(cipher, password, options) {
221225
if (!(this instanceof Decipher))
222226
return new Decipher(cipher, password, options);
@@ -245,7 +249,7 @@ Decipher.prototype._transform = Cipher.prototype._transform;
245249
Decipher.prototype._flush = Cipher.prototype._flush;
246250
Decipher.prototype.update = Cipher.prototype.update;
247251
Decipher.prototype.final = Cipher.prototype.final;
248-
Decipher.prototype.finaltol = Cipher.prototype.final;
252+
Decipher.prototype.finaltol = finaltol;
249253
Decipher.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
250254
Decipher.prototype.getAuthTag = Cipher.prototype.getAuthTag;
251255
Decipher.prototype.setAuthTag = Cipher.prototype.setAuthTag;
@@ -288,7 +292,7 @@ Decipheriv.prototype._transform = Cipher.prototype._transform;
288292
Decipheriv.prototype._flush = Cipher.prototype._flush;
289293
Decipheriv.prototype.update = Cipher.prototype.update;
290294
Decipheriv.prototype.final = Cipher.prototype.final;
291-
Decipheriv.prototype.finaltol = Cipher.prototype.final;
295+
Decipheriv.prototype.finaltol = finaltol;
292296
Decipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
293297
Decipheriv.prototype.getAuthTag = Cipher.prototype.getAuthTag;
294298
Decipheriv.prototype.setAuthTag = Cipher.prototype.setAuthTag;

test/parallel/test-crypto-deprecated.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const tls = require('tls');
99

1010
common.expectWarning('DeprecationWarning', [
1111
'crypto.Credentials is deprecated. Use tls.SecureContext instead.',
12-
'crypto.createCredentials is deprecated. Use tls.createSecureContext instead.'
12+
'crypto.createCredentials is deprecated. Use tls.createSecureContext ' +
13+
'instead.',
14+
'crypto.Decipher.finaltol is deprecated. Use crypto.Decipher.final instead.'
1315
]);
1416

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

0 commit comments

Comments
 (0)