summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmit Zur <sendwithchibo@gmail.com>2019-01-16 13:04:14 +0200
committerAnna Henningsen <anna@addaleax.net>2019-02-09 17:21:41 +0100
commite0a3d741352001d3254adc290763b1bdcbad3ad3 (patch)
tree0c72fe8e4c767eda67c08b6332abb3dd9837eeaa
parentea2350bb00faee684319ce462037a3f0906e54f0 (diff)
downloadandroid-node-v8-e0a3d741352001d3254adc290763b1bdcbad3ad3.tar.gz
android-node-v8-e0a3d741352001d3254adc290763b1bdcbad3ad3.tar.bz2
android-node-v8-e0a3d741352001d3254adc290763b1bdcbad3ad3.zip
crypto: include 'Buffer' in error output of Hash.update method
Fixes: https://github.com/nodejs/node/issues/25487 PR-URL: https://github.com/nodejs/node/pull/25533 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
-rw-r--r--lib/internal/crypto/hash.js6
-rw-r--r--test/parallel/test-crypto-hash.js11
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js
index d486d83e91..5e67efe6c5 100644
--- a/lib/internal/crypto/hash.js
+++ b/lib/internal/crypto/hash.js
@@ -62,7 +62,11 @@ Hash.prototype.update = function update(data, encoding) {
if (typeof data !== 'string' && !isArrayBufferView(data)) {
throw new ERR_INVALID_ARG_TYPE('data',
- ['string', 'TypedArray', 'DataView'], data);
+ ['string',
+ 'Buffer',
+ 'TypedArray',
+ 'DataView'],
+ data);
}
if (!this[kHandle].update(data, encoding || getDefaultEncoding()))
diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js
index 5cc622b48c..60904cf08f 100644
--- a/test/parallel/test-crypto-hash.js
+++ b/test/parallel/test-crypto-hash.js
@@ -122,6 +122,17 @@ common.expectsError(
message: 'boom'
});
+// Issue https://github.com/nodejs/node/issues/25487: error message for invalid
+// arg type to update method should include all possible types
+common.expectsError(
+ () => crypto.createHash('sha256').update(),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "data" argument must be one of type string, Buffer, ' +
+ 'TypedArray, or DataView. Received type undefined'
+ });
+
// Default UTF-8 encoding
const hutf8 = crypto.createHash('sha512').update('УТФ-8 text').digest('hex');
assert.strictEqual(