Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -3520,7 +3520,7 @@ added:
> Stability: 1.2 - Release candidate

* `algorithm` {string|undefined}
* `data` {string|ArrayBuffer|Buffer|TypedArray|DataView} When `data` is a
* `data` {string|Buffer|TypedArray|DataView} When `data` is a
string, it will be encoded as UTF-8 before being hashed. If a different
input encoding is desired for a string input, user could encode the string
into a `TypedArray` using either `TextEncoder` or `Buffer.from()` and passing
Expand Down
5 changes: 2 additions & 3 deletions lib/internal/crypto/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const {
validateEncoding,
validateString,
validateUint32,
validateBuffer,
} = require('internal/validators');

const {
Expand Down Expand Up @@ -196,8 +195,8 @@ async function asyncDigest(algorithm, data) {

function hash(algorithm, input, outputEncoding = 'hex') {
validateString(algorithm, 'algorithm');
if (typeof input !== 'string') {
validateBuffer(input, 'input');
if (typeof input !== 'string' && !isArrayBufferView(input)) {
throw new ERR_INVALID_ARG_TYPE('input', ['Buffer', 'TypedArray', 'DataView', 'string'], input);
}
let normalized = outputEncoding;
// Fast case: if it's 'hex', we don't need to validate it further.
Expand Down