Skip to content

Commit e17280e

Browse files
danbevMylesBorins
authored andcommitted
crypto: make pbkdf2 use checkIsArrayBufferView
This commit updates pbkdf2 to use checkIsArrayBufferView from internal/crypto/util. PR-URL: #20251 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
1 parent 61e9396 commit e17280e

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

lib/internal/crypto/pbkdf2.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const {
77
ERR_OUT_OF_RANGE
88
} = require('internal/errors').codes;
99
const {
10+
checkIsArrayBufferView,
1011
getDefaultEncoding,
1112
toBuf
1213
} = require('internal/crypto/util');
13-
const { isArrayBufferView } = require('internal/util/types');
1414
const {
1515
PBKDF2
1616
} = process.binding('crypto');
@@ -39,19 +39,8 @@ function _pbkdf2(password, salt, iterations, keylen, digest, callback) {
3939
if (digest !== null && typeof digest !== 'string')
4040
throw new ERR_INVALID_ARG_TYPE('digest', ['string', 'null'], digest);
4141

42-
password = toBuf(password);
43-
salt = toBuf(salt);
44-
45-
if (!isArrayBufferView(password)) {
46-
throw new ERR_INVALID_ARG_TYPE('password',
47-
['string', 'Buffer', 'TypedArray'],
48-
password);
49-
}
50-
51-
if (!isArrayBufferView(salt)) {
52-
throw new ERR_INVALID_ARG_TYPE('salt',
53-
['string', 'Buffer', 'TypedArray'], salt);
54-
}
42+
password = checkIsArrayBufferView('password', toBuf(password));
43+
salt = checkIsArrayBufferView('salt', toBuf(salt));
5544

5645
if (typeof iterations !== 'number')
5746
throw new ERR_INVALID_ARG_TYPE('iterations', 'number', iterations);

test/parallel/test-crypto-pbkdf2.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ assert.throws(
123123
});
124124

125125
[1, {}, [], true, undefined, null].forEach((input) => {
126-
const msgPart2 = `Buffer, or TypedArray. Received type ${typeof input}`;
126+
const msgPart2 = 'Buffer, TypedArray, or DataView.' +
127+
` Received type ${typeof input}`;
127128
assert.throws(
128129
() => crypto.pbkdf2(input, 'salt', 8, 8, 'sha256', common.mustNotCall()),
129130
{

0 commit comments

Comments
 (0)