Skip to content

Commit

Permalink
crypto: include 'Buffer' in error output of Hash.update method
Browse files Browse the repository at this point in the history
Fixes: #25487

PR-URL: #25533
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
amitzur authored and targos committed Feb 10, 2019
1 parent 85d5f67 commit 8c9800c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/internal/crypto/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-crypto-hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8c9800c

Please sign in to comment.