mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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:
1 parent
924670f3af
commit
183bcc0699
3 files changed
+9
-7
No files matched your search
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user