Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: deprecate Decipher.finaltol #19353

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,15 @@ deprecated if the assigned value is not a string, boolean, or number. In the
future, such assignment may result in a thrown error. Please convert the
property to a string before assigning it to `process.env`.

<a id="DEP00XX"></a>
### DEP00XX: decipher.finaltol

Type: Runtime

`decipher.finaltol()` has never been documented and is currently an alias for
[`decipher.final()`][]. In the future, this API will likely be removed, and it
is recommended to use [`decipher.final()`][] instead.

[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
Expand All @@ -971,6 +980,7 @@ property to a string before assigning it to `process.env`.
[`crypto.DEFAULT_ENCODING`]: crypto.html#crypto_crypto_default_encoding
[`crypto.fips`]: crypto.html#crypto_crypto_fips
[`crypto.pbkdf2()`]: crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
[`decipher.final()`]: crypto.html#crypto_decipher_final_outputencoding
[`decipher.setAuthTag()`]: crypto.html#crypto_decipher_setauthtag_buffer
[`domain`]: domain.html
[`ecdh.setPublicKey()`]: crypto.html#crypto_ecdh_setpublickey_publickey_encoding
Expand Down
10 changes: 7 additions & 3 deletions lib/internal/crypto/cipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const LazyTransform = require('internal/streams/lazy_transform');
const { StringDecoder } = require('string_decoder');

const { inherits } = require('util');
const { normalizeEncoding } = require('internal/util');
const { deprecate, normalizeEncoding } = require('internal/util');

function rsaPublic(method, defaultPadding) {
return function(options, buffer) {
Expand Down Expand Up @@ -217,6 +217,10 @@ Cipheriv.prototype.setAuthTag = Cipher.prototype.setAuthTag;
Cipheriv.prototype.setAAD = Cipher.prototype.setAAD;


const finaltol = deprecate(Cipher.prototype.final,
'crypto.Decipher.finaltol is deprecated. Use ' +
'crypto.Decipher.final instead.', 'DEP00XX');

function Decipher(cipher, password, options) {
if (!(this instanceof Decipher))
return new Decipher(cipher, password, options);
Expand Down Expand Up @@ -245,7 +249,7 @@ Decipher.prototype._transform = Cipher.prototype._transform;
Decipher.prototype._flush = Cipher.prototype._flush;
Decipher.prototype.update = Cipher.prototype.update;
Decipher.prototype.final = Cipher.prototype.final;
Decipher.prototype.finaltol = Cipher.prototype.final;
Decipher.prototype.finaltol = finaltol;
Decipher.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
Decipher.prototype.getAuthTag = Cipher.prototype.getAuthTag;
Decipher.prototype.setAuthTag = Cipher.prototype.setAuthTag;
Expand Down Expand Up @@ -288,7 +292,7 @@ Decipheriv.prototype._transform = Cipher.prototype._transform;
Decipheriv.prototype._flush = Cipher.prototype._flush;
Decipheriv.prototype.update = Cipher.prototype.update;
Decipheriv.prototype.final = Cipher.prototype.final;
Decipheriv.prototype.finaltol = Cipher.prototype.final;
Decipheriv.prototype.finaltol = finaltol;
Decipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
Decipheriv.prototype.getAuthTag = Cipher.prototype.getAuthTag;
Decipheriv.prototype.setAuthTag = Cipher.prototype.setAuthTag;
Expand Down
16 changes: 15 additions & 1 deletion test/parallel/test-crypto-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const tls = require('tls');

common.expectWarning('DeprecationWarning', [
'crypto.Credentials is deprecated. Use tls.SecureContext instead.',
'crypto.createCredentials is deprecated. Use tls.createSecureContext instead.'
'crypto.createCredentials is deprecated. Use tls.createSecureContext ' +
'instead.',
'crypto.Decipher.finaltol is deprecated. Use crypto.Decipher.final instead.'
]);

// Accessing the deprecated function is enough to trigger the warning event.
Expand All @@ -18,3 +20,15 @@ common.expectWarning('DeprecationWarning', [
// mapped to the correct non-deprecated function.
assert.strictEqual(crypto.Credentials, tls.SecureContext);
assert.strictEqual(crypto.createCredentials, tls.createSecureContext);

{
const cipher = crypto.createCipheriv('aes-128-cbc', '0000000000000000',
'0000000000000000');
const ciphertext = cipher.update('Node.js', 'utf8', 'hex') +
cipher.final('hex');
const decipher = crypto.createDecipheriv('aes-128-cbc', '0000000000000000',
'0000000000000000');
const plaintext = decipher.update(ciphertext, 'hex', 'utf8') +
decipher.finaltol('utf8');
assert.strictEqual(plaintext, 'Node.js');
}