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 08a7e7b

Browse filesBrowse files
fanatidaddaleax
authored andcommitted
crypto: return this in setAuthTag/setAAD
Allow method chaining as with setAutoPadding and other methods. PR-URL: #9398 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sam Roberts <sam@strongloop.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b070df8 commit 08a7e7b
Copy full SHA for 08a7e7b

File tree

Expand file treeCollapse file tree

3 files changed

+23
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/crypto.md‎

Copy file name to clipboardExpand all lines: doc/api/crypto.md
+10Lines changed: 10 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ When using an authenticated encryption mode (only `GCM` is currently
194194
supported), the `cipher.setAAD()` method sets the value used for the
195195
_additional authenticated data_ (AAD) input parameter.
196196

197+
Returns `this` for method chaining.
198+
197199
### cipher.getAuthTag()
198200
<!-- YAML
199201
added: v1.0.0
@@ -222,6 +224,8 @@ using `0x0` instead of PKCS padding.
222224

223225
The `cipher.setAutoPadding()` method must be called before [`cipher.final()`][].
224226

227+
Returns `this` for method chaining.
228+
225229
### cipher.update(data[, input_encoding][, output_encoding])
226230
<!-- YAML
227231
added: v0.1.94
@@ -329,6 +333,8 @@ When using an authenticated encryption mode (only `GCM` is currently
329333
supported), the `cipher.setAAD()` method sets the value used for the
330334
_additional authenticated data_ (AAD) input parameter.
331335

336+
Returns `this` for method chaining.
337+
332338
### decipher.setAuthTag(buffer)
333339
<!-- YAML
334340
added: v1.0.0
@@ -340,6 +346,8 @@ received _authentication tag_. If no tag is provided, or if the cipher text
340346
has been tampered with, [`decipher.final()`][] with throw, indicating that the
341347
cipher text should be discarded due to failed authentication.
342348

349+
Returns `this` for method chaining.
350+
343351
### decipher.setAutoPadding(auto_padding=true)
344352
<!-- YAML
345353
added: v0.7.1
@@ -355,6 +363,8 @@ multiple of the ciphers block size.
355363
The `decipher.setAutoPadding()` method must be called before
356364
[`decipher.update()`][].
357365

366+
Returns `this` for method chaining.
367+
358368
### decipher.update(data[, input_encoding][, output_encoding])
359369
<!-- YAML
360370
added: v0.1.94
Collapse file

‎lib/crypto.js‎

Copy file name to clipboardExpand all lines: lib/crypto.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,12 @@ Cipher.prototype.getAuthTag = function getAuthTag() {
177177

178178
Cipher.prototype.setAuthTag = function setAuthTag(tagbuf) {
179179
this._handle.setAuthTag(tagbuf);
180+
return this;
180181
};
181182

182183
Cipher.prototype.setAAD = function setAAD(aadbuf) {
183184
this._handle.setAAD(aadbuf);
185+
return this;
184186
};
185187

186188
exports.createCipheriv = exports.Cipheriv = Cipheriv;
Collapse file

‎test/parallel/test-crypto-cipher-decipher.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-cipher-decipher.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,14 @@ testCipher2(Buffer.from('0123456789abcdef'));
139139
assert.doesNotThrow(() => txt += decipher.final('utf-16le'));
140140
assert.strictEqual(txt, plaintext, 'decrypted result in utf-16le');
141141
}
142+
143+
// setAutoPadding/setAuthTag/setAAD should return `this`
144+
{
145+
const key = '0123456789';
146+
const tagbuf = Buffer.from('tagbuf');
147+
const aadbuf = Buffer.from('aadbuf');
148+
const decipher = crypto.createDecipher('aes-256-gcm', key);
149+
assert.strictEqual(decipher.setAutoPadding(), decipher);
150+
assert.strictEqual(decipher.setAuthTag(tagbuf), decipher);
151+
assert.strictEqual(decipher.setAAD(aadbuf), decipher);
152+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.