Skip to content

Commit 503844e

Browse files
danbevaddaleax
authored andcommitted
crypto: add addCipherPrototypeFunctions function
This commit adds a function named addCipherPrototypeFunctions to avoid code duplication. Backport-PR-URL: #20706 PR-URL: #20164 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 72029b8 commit 503844e

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

lib/internal/crypto/cipher.js

+14-29
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,19 @@ function Cipheriv(cipher, key, iv, options) {
236236
createCipherWithIV.call(this, cipher, key, options, true, iv);
237237
}
238238

239-
inherits(Cipheriv, LazyTransform);
240-
241-
Cipheriv.prototype._transform = Cipher.prototype._transform;
242-
Cipheriv.prototype._flush = Cipher.prototype._flush;
243-
Cipheriv.prototype.update = Cipher.prototype.update;
244-
Cipheriv.prototype.final = Cipher.prototype.final;
245-
Cipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
246-
Cipheriv.prototype.getAuthTag = Cipher.prototype.getAuthTag;
247-
Cipheriv.prototype.setAuthTag = Cipher.prototype.setAuthTag;
248-
Cipheriv.prototype.setAAD = Cipher.prototype.setAAD;
239+
function addCipherPrototypeFunctions(constructor) {
240+
constructor.prototype._transform = Cipher.prototype._transform;
241+
constructor.prototype._flush = Cipher.prototype._flush;
242+
constructor.prototype.update = Cipher.prototype.update;
243+
constructor.prototype.final = Cipher.prototype.final;
244+
constructor.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
245+
constructor.prototype.getAuthTag = Cipher.prototype.getAuthTag;
246+
constructor.prototype.setAuthTag = Cipher.prototype.setAuthTag;
247+
constructor.prototype.setAAD = Cipher.prototype.setAAD;
248+
}
249249

250+
inherits(Cipheriv, LazyTransform);
251+
addCipherPrototypeFunctions(Cipheriv);
250252

251253
const finaltol = deprecate(Cipher.prototype.final,
252254
'crypto.Decipher.finaltol is deprecated. Use ' +
@@ -260,16 +262,8 @@ function Decipher(cipher, password, options) {
260262
}
261263

262264
inherits(Decipher, LazyTransform);
263-
264-
Decipher.prototype._transform = Cipher.prototype._transform;
265-
Decipher.prototype._flush = Cipher.prototype._flush;
266-
Decipher.prototype.update = Cipher.prototype.update;
267-
Decipher.prototype.final = Cipher.prototype.final;
265+
addCipherPrototypeFunctions(Decipher);
268266
Decipher.prototype.finaltol = finaltol;
269-
Decipher.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
270-
Decipher.prototype.getAuthTag = Cipher.prototype.getAuthTag;
271-
Decipher.prototype.setAuthTag = Cipher.prototype.setAuthTag;
272-
Decipher.prototype.setAAD = Cipher.prototype.setAAD;
273267

274268

275269
function Decipheriv(cipher, key, iv, options) {
@@ -280,17 +274,8 @@ function Decipheriv(cipher, key, iv, options) {
280274
}
281275

282276
inherits(Decipheriv, LazyTransform);
283-
284-
Decipheriv.prototype._transform = Cipher.prototype._transform;
285-
Decipheriv.prototype._flush = Cipher.prototype._flush;
286-
Decipheriv.prototype.update = Cipher.prototype.update;
287-
Decipheriv.prototype.final = Cipher.prototype.final;
277+
addCipherPrototypeFunctions(Decipheriv);
288278
Decipheriv.prototype.finaltol = finaltol;
289-
Decipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
290-
Decipheriv.prototype.getAuthTag = Cipher.prototype.getAuthTag;
291-
Decipheriv.prototype.setAuthTag = Cipher.prototype.setAuthTag;
292-
Decipheriv.prototype.setAAD = Cipher.prototype.setAAD;
293-
294279

295280
module.exports = {
296281
Cipher,

0 commit comments

Comments
 (0)