crypto: clean up parameter validation in HKDF

PR-URL: https://github.com/nodejs/node/pull/42924
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
This commit is contained in:
Tobias Nießen authored and RafaelGSS committed 2022-05-10 09:13:15 -03:00
1 parent 924670f3af
commit 183bcc0699
3 files changed
+9 -7

No files matched your search

+3 -6
View File
@@ -53,13 +53,10 @@ const {
} = require('internal/errors');
const validateParameters = hideStackFrames((hash, key, salt, info, length) => {
key = prepareKey(key);
salt = toBuf(salt);
info = toBuf(info);
validateString(hash, 'digest');
validateByteSource(salt, 'salt');
validateByteSource(info, 'info');
key = prepareKey(key);
salt = validateByteSource(salt, 'salt');
info = validateByteSource(info, 'info');
validateInteger(length, 'length', 0, kMaxLength);
+1 -1
View File
@@ -271,7 +271,7 @@ const validateByteSource = hideStackFrames((val, name) => {
val = toBuf(val);
if (isAnyArrayBuffer(val) || isArrayBufferView(val))
return;
return val;
throw new ERR_INVALID_ARG_TYPE(
name,
+5
View File
@@ -15,6 +15,11 @@ const {
} = require('crypto');
{
assert.throws(() => hkdf(), {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "digest" argument must be of type string/
});
[1, {}, [], false, Infinity].forEach((i) => {
assert.throws(() => hkdf(i, 'a'), {
code: 'ERR_INVALID_ARG_TYPE',