◐ Shell
clean mode source ↗

lib: replace checkUint() with validateInt32() · nodejs/node@f3570f2

@@ -2,15 +2,15 @@

2233

const { AsyncWrap, Providers } = process.binding('async_wrap');

44

const { Buffer } = require('buffer');

5-

const { scrypt: _scrypt } = process.binding('crypto');

5+

const { INT_MAX, scrypt: _scrypt } = process.binding('crypto');

6+

const { validateInt32 } = require('internal/validators');

67

const {

78

ERR_CRYPTO_SCRYPT_INVALID_PARAMETER,

89

ERR_CRYPTO_SCRYPT_NOT_SUPPORTED,

910

ERR_INVALID_CALLBACK,

1011

} = require('internal/errors').codes;

1112

const {

1213

checkIsArrayBufferView,

13-

checkIsUint,

1414

getDefaultEncoding,

1515

} = require('internal/crypto/util');

1616

@@ -75,16 +75,19 @@ function check(password, salt, keylen, options, callback) {

7575

throw new ERR_CRYPTO_SCRYPT_NOT_SUPPORTED();

76767777

password = checkIsArrayBufferView('password', password);

78-

salt = checkIsArrayBufferView('salt', salt);

79-

keylen = checkIsUint('keylen', keylen);

78+

salt = checkIsArrayBufferView(salt, 'salt');

79+

keylen = validateInt32(keylen, 'keylen', 0, INT_MAX);

80808181

let { N, r, p, maxmem } = defaults;

8282

if (options && options !== defaults) {

83-

if (options.hasOwnProperty('N')) N = checkIsUint('N', options.N);

84-

if (options.hasOwnProperty('r')) r = checkIsUint('r', options.r);

85-

if (options.hasOwnProperty('p')) p = checkIsUint('p', options.p);

83+

if (options.hasOwnProperty('N'))

84+

N = validateInt32(options.N, 'N', 0, INT_MAX);

85+

if (options.hasOwnProperty('r'))

86+

r = validateInt32(options.r, 'r', 0, INT_MAX);

87+

if (options.hasOwnProperty('p'))

88+

p = validateInt32(options.p, 'p', 0, INT_MAX);

8689

if (options.hasOwnProperty('maxmem'))

87-

maxmem = checkIsUint('maxmem', options.maxmem);

90+

maxmem = validateInt32(options.maxmem, 'maxmem', 0, INT_MAX);

8891

if (N === 0) N = defaults.N;

8992

if (r === 0) r = defaults.r;

9093

if (p === 0) p = defaults.p;