crypto: make pbkdf2 use checkIsArrayBufferView
This commit updates pbkdf2 to use checkIsArrayBufferView from internal/crypto/util. PR-URL: https://github.com/nodejs/node/pull/20251 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
This commit is contained in:
parent
fe70af9072
commit
20612486d9
@ -7,10 +7,10 @@ const {
|
||||
ERR_OUT_OF_RANGE
|
||||
} = require('internal/errors').codes;
|
||||
const {
|
||||
checkIsArrayBufferView,
|
||||
getDefaultEncoding,
|
||||
toBuf
|
||||
} = require('internal/crypto/util');
|
||||
const { isArrayBufferView } = require('internal/util/types');
|
||||
const {
|
||||
PBKDF2
|
||||
} = process.binding('crypto');
|
||||
@ -39,19 +39,8 @@ function _pbkdf2(password, salt, iterations, keylen, digest, callback) {
|
||||
if (digest !== null && typeof digest !== 'string')
|
||||
throw new ERR_INVALID_ARG_TYPE('digest', ['string', 'null'], digest);
|
||||
|
||||
password = toBuf(password);
|
||||
salt = toBuf(salt);
|
||||
|
||||
if (!isArrayBufferView(password)) {
|
||||
throw new ERR_INVALID_ARG_TYPE('password',
|
||||
['string', 'Buffer', 'TypedArray'],
|
||||
password);
|
||||
}
|
||||
|
||||
if (!isArrayBufferView(salt)) {
|
||||
throw new ERR_INVALID_ARG_TYPE('salt',
|
||||
['string', 'Buffer', 'TypedArray'], salt);
|
||||
}
|
||||
password = checkIsArrayBufferView('password', toBuf(password));
|
||||
salt = checkIsArrayBufferView('salt', toBuf(salt));
|
||||
|
||||
if (typeof iterations !== 'number')
|
||||
throw new ERR_INVALID_ARG_TYPE('iterations', 'number', iterations);
|
||||
|
@ -123,7 +123,8 @@ assert.throws(
|
||||
});
|
||||
|
||||
[1, {}, [], true, undefined, null].forEach((input) => {
|
||||
const msgPart2 = `Buffer, or TypedArray. Received type ${typeof input}`;
|
||||
const msgPart2 = 'Buffer, TypedArray, or DataView.' +
|
||||
` Received type ${typeof input}`;
|
||||
assert.throws(
|
||||
() => crypto.pbkdf2(input, 'salt', 8, 8, 'sha256', common.mustNotCall()),
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user