crypto: fix input
validation in crypto.hash
PR-URL: https://github.com/nodejs/node/pull/52070 Refs: https://github.com/nodejs/node/pull/51044/files#r1522362983 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
0a252c23d9
commit
6dd1c75f4a
@ -52,7 +52,6 @@ const {
|
|||||||
validateEncoding,
|
validateEncoding,
|
||||||
validateString,
|
validateString,
|
||||||
validateUint32,
|
validateUint32,
|
||||||
validateBuffer,
|
|
||||||
} = require('internal/validators');
|
} = require('internal/validators');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -196,8 +195,8 @@ async function asyncDigest(algorithm, data) {
|
|||||||
|
|
||||||
function hash(algorithm, input, outputEncoding = 'hex') {
|
function hash(algorithm, input, outputEncoding = 'hex') {
|
||||||
validateString(algorithm, 'algorithm');
|
validateString(algorithm, 'algorithm');
|
||||||
if (typeof input !== 'string') {
|
if (typeof input !== 'string' && !isArrayBufferView(input)) {
|
||||||
validateBuffer(input, 'input');
|
throw new ERR_INVALID_ARG_TYPE('input', ['Buffer', 'TypedArray', 'DataView', 'string'], input);
|
||||||
}
|
}
|
||||||
let normalized = outputEncoding;
|
let normalized = outputEncoding;
|
||||||
// Fast case: if it's 'hex', we don't need to validate it further.
|
// Fast case: if it's 'hex', we don't need to validate it further.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user