summaryrefslogtreecommitdiff
path: root/test/parallel/test-crypto-update-encoding.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2020-02-13 12:05:18 +0100
committerTobias Nießen <tniessen@tnie.de>2020-03-05 15:24:17 -0400
commit9ec87815027ddf6782ab930975b86333a61ed554 (patch)
tree89f7ed845da8e6f30d649a0844460af7c8bf7aae /test/parallel/test-crypto-update-encoding.js
parentb1d4c13430c92e94920f0c8c9ba1295c075c9e89 (diff)
downloadnode-new-9ec87815027ddf6782ab930975b86333a61ed554.tar.gz
crypto: make update(buf, enc) ignore encoding
Make the cipher/decipher/hash/hmac update() methods ignore the input encoding when the input is a buffer. This is the documented behavior but some inputs were rejected, notably when the specified encoding is 'hex' and the buffer has an odd length (because a _string_ with an odd length is never a valid hex string.) The sign/verify update() methods work okay because they use different validation logic. Fixes: https://github.com/nodejs/node/issues/31751 PR-URL: https://github.com/nodejs/node/pull/31766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'test/parallel/test-crypto-update-encoding.js')
-rw-r--r--test/parallel/test-crypto-update-encoding.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/parallel/test-crypto-update-encoding.js b/test/parallel/test-crypto-update-encoding.js
new file mode 100644
index 0000000000..e1e6d029aa
--- /dev/null
+++ b/test/parallel/test-crypto-update-encoding.js
@@ -0,0 +1,22 @@
+'use strict';
+const common = require('../common');
+
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+
+const crypto = require('crypto');
+
+const zeros = Buffer.alloc;
+const key = zeros(16);
+const iv = zeros(16);
+
+const cipher = () => crypto.createCipheriv('aes-128-cbc', key, iv);
+const decipher = () => crypto.createDecipheriv('aes-128-cbc', key, iv);
+const hash = () => crypto.createSign('sha256');
+const hmac = () => crypto.createHmac('sha256', key);
+const sign = () => crypto.createSign('sha256');
+const verify = () => crypto.createVerify('sha256');
+
+for (const f of [cipher, decipher, hash, hmac, sign, verify])
+ for (const n of [15, 16])
+ f().update(zeros(n), 'hex'); // Should ignore inputEncoding.