diff options
author | Tobias Nießen <tniessen@tnie.de> | 2022-05-02 20:46:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 20:46:04 +0300 |
commit | 75dbb86c58d6abb1a0b1202381be019d8e8c5792 (patch) | |
tree | 6a2fbaace869b93ac59878edd9e15a3c8524f469 | |
parent | 73a8a0ee3ceb3ea5d972375fb554b276e28777e1 (diff) |
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>
-rw-r--r-- | lib/internal/crypto/hkdf.js | 9 | ||||
-rw-r--r-- | lib/internal/crypto/util.js | 2 | ||||
-rw-r--r-- | test/parallel/test-crypto-hkdf.js | 5 |
3 files changed, 9 insertions, 7 deletions
diff --git a/lib/internal/crypto/hkdf.js b/lib/internal/crypto/hkdf.js index fd274caf0b8..724217c08eb 100644 --- a/lib/internal/crypto/hkdf.js +++ b/lib/internal/crypto/hkdf.js @@ -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); diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js index 854994277e5..4c1590ed9da 100644 --- a/lib/internal/crypto/util.js +++ b/lib/internal/crypto/util.js @@ -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, diff --git a/test/parallel/test-crypto-hkdf.js b/test/parallel/test-crypto-hkdf.js index 16744201a93..2d6689a486d 100644 --- a/test/parallel/test-crypto-hkdf.js +++ b/test/parallel/test-crypto-hkdf.js @@ -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', |