From 503844eb73c7924e859bf8284026f7c1f627a72d Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 20 Apr 2018 08:03:02 +0200 Subject: [PATCH] crypto: add addCipherPrototypeFunctions function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a function named addCipherPrototypeFunctions to avoid code duplication. Backport-PR-URL: https://github.com/nodejs/node/pull/20706 PR-URL: https://github.com/nodejs/node/pull/20164 Reviewed-By: James M Snell Reviewed-By: Tobias Nießen Reviewed-By: Trivikram Kamat Reviewed-By: Ruben Bridgewater --- lib/internal/crypto/cipher.js | 43 ++++++++++++----------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js index 76965a9c15b154..9a915c0c55ad27 100644 --- a/lib/internal/crypto/cipher.js +++ b/lib/internal/crypto/cipher.js @@ -236,17 +236,19 @@ function Cipheriv(cipher, key, iv, options) { createCipherWithIV.call(this, cipher, key, options, true, iv); } -inherits(Cipheriv, LazyTransform); - -Cipheriv.prototype._transform = Cipher.prototype._transform; -Cipheriv.prototype._flush = Cipher.prototype._flush; -Cipheriv.prototype.update = Cipher.prototype.update; -Cipheriv.prototype.final = Cipher.prototype.final; -Cipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding; -Cipheriv.prototype.getAuthTag = Cipher.prototype.getAuthTag; -Cipheriv.prototype.setAuthTag = Cipher.prototype.setAuthTag; -Cipheriv.prototype.setAAD = Cipher.prototype.setAAD; +function addCipherPrototypeFunctions(constructor) { + constructor.prototype._transform = Cipher.prototype._transform; + constructor.prototype._flush = Cipher.prototype._flush; + constructor.prototype.update = Cipher.prototype.update; + constructor.prototype.final = Cipher.prototype.final; + constructor.prototype.setAutoPadding = Cipher.prototype.setAutoPadding; + constructor.prototype.getAuthTag = Cipher.prototype.getAuthTag; + constructor.prototype.setAuthTag = Cipher.prototype.setAuthTag; + constructor.prototype.setAAD = Cipher.prototype.setAAD; +} +inherits(Cipheriv, LazyTransform); +addCipherPrototypeFunctions(Cipheriv); const finaltol = deprecate(Cipher.prototype.final, 'crypto.Decipher.finaltol is deprecated. Use ' + @@ -260,16 +262,8 @@ function Decipher(cipher, password, options) { } inherits(Decipher, LazyTransform); - -Decipher.prototype._transform = Cipher.prototype._transform; -Decipher.prototype._flush = Cipher.prototype._flush; -Decipher.prototype.update = Cipher.prototype.update; -Decipher.prototype.final = Cipher.prototype.final; +addCipherPrototypeFunctions(Decipher); Decipher.prototype.finaltol = finaltol; -Decipher.prototype.setAutoPadding = Cipher.prototype.setAutoPadding; -Decipher.prototype.getAuthTag = Cipher.prototype.getAuthTag; -Decipher.prototype.setAuthTag = Cipher.prototype.setAuthTag; -Decipher.prototype.setAAD = Cipher.prototype.setAAD; function Decipheriv(cipher, key, iv, options) { @@ -280,17 +274,8 @@ function Decipheriv(cipher, key, iv, options) { } inherits(Decipheriv, LazyTransform); - -Decipheriv.prototype._transform = Cipher.prototype._transform; -Decipheriv.prototype._flush = Cipher.prototype._flush; -Decipheriv.prototype.update = Cipher.prototype.update; -Decipheriv.prototype.final = Cipher.prototype.final; +addCipherPrototypeFunctions(Decipheriv); Decipheriv.prototype.finaltol = finaltol; -Decipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding; -Decipheriv.prototype.getAuthTag = Cipher.prototype.getAuthTag; -Decipheriv.prototype.setAuthTag = Cipher.prototype.setAuthTag; -Decipheriv.prototype.setAAD = Cipher.prototype.setAAD; - module.exports = { Cipher,