From e4de8c81caee2ed69b86335d65e79b4c24a8e861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 14 Mar 2018 18:15:41 +0100 Subject: [PATCH 1/2] crypto: deprecate Decipher.finaltol --- doc/api/deprecations.md | 10 ++++++++++ lib/internal/crypto/cipher.js | 10 +++++++--- test/parallel/test-crypto-deprecated.js | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 02822b5396ac22..21bf21e65b5f3c 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -950,11 +950,21 @@ 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`. + +### DEP00XX: crypto.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 [`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer [`Buffer.isBuffer()`]: buffer.html#buffer_class_method_buffer_isbuffer_obj +[`Decipher.final()`]: crypto.html#crypto_decipher_final_outputencoding [`assert`]: assert.html [`clearInterval()`]: timers.html#timers_clearinterval_timeout [`clearTimeout()`]: timers.html#timers_cleartimeout_timeout diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js index 0d468c3b1321ab..818f5b314b048f 100644 --- a/lib/internal/crypto/cipher.js +++ b/lib/internal/crypto/cipher.js @@ -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) { @@ -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); @@ -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; @@ -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; diff --git a/test/parallel/test-crypto-deprecated.js b/test/parallel/test-crypto-deprecated.js index acdd71301fbed0..d8f2be43693121 100644 --- a/test/parallel/test-crypto-deprecated.js +++ b/test/parallel/test-crypto-deprecated.js @@ -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. @@ -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'); +} From 161acdf55ad0bf79656a29aa3327731dac38f54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 14 Mar 2018 23:40:15 +0100 Subject: [PATCH 2/2] make Decipher lowercase --- doc/api/deprecations.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 21bf21e65b5f3c..9f1c65b99ac947 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -951,20 +951,19 @@ future, such assignment may result in a thrown error. Please convert the property to a string before assigning it to `process.env`. -### DEP00XX: crypto.Decipher.finaltol +### 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. +`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 [`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer [`Buffer.isBuffer()`]: buffer.html#buffer_class_method_buffer_isbuffer_obj -[`Decipher.final()`]: crypto.html#crypto_decipher_final_outputencoding [`assert`]: assert.html [`clearInterval()`]: timers.html#timers_clearinterval_timeout [`clearTimeout()`]: timers.html#timers_cleartimeout_timeout @@ -981,6 +980,7 @@ is recommended to use [`Decipher.final()`][] instead. [`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