Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 503844e

Browse filesBrowse 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 <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 72029b8 commit 503844e
Copy full SHA for 503844e

File tree

Expand file treeCollapse file tree

1 file changed

+14
-29
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-29
lines changed
Open diff view settings
Collapse file

‎lib/internal/crypto/cipher.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/cipher.js
+14-29Lines changed: 14 additions & 29 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.