|
2 | 2 |
|
3 | 3 | const { AsyncWrap, Providers } = process.binding('async_wrap');
|
4 | 4 | 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'); |
6 | 7 | const {
|
7 | 8 | ERR_CRYPTO_SCRYPT_INVALID_PARAMETER,
|
8 | 9 | ERR_CRYPTO_SCRYPT_NOT_SUPPORTED,
|
9 | 10 | ERR_INVALID_CALLBACK,
|
10 | 11 | } = require('internal/errors').codes;
|
11 | 12 | const {
|
12 | 13 | checkIsArrayBufferView,
|
13 |
| - checkIsUint, |
14 | 14 | getDefaultEncoding,
|
15 | 15 | } = require('internal/crypto/util');
|
16 | 16 |
|
@@ -75,16 +75,19 @@ function check(password, salt, keylen, options, callback) {
|
75 | 75 | throw new ERR_CRYPTO_SCRYPT_NOT_SUPPORTED();
|
76 | 76 |
|
77 | 77 | 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); |
80 | 80 |
|
81 | 81 | let { N, r, p, maxmem } = defaults;
|
82 | 82 | 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); |
86 | 89 | if (options.hasOwnProperty('maxmem'))
|
87 |
| - maxmem = checkIsUint('maxmem', options.maxmem); |
| 90 | + maxmem = validateInt32(options.maxmem, 'maxmem', 0, INT_MAX); |
88 | 91 | if (N === 0) N = defaults.N;
|
89 | 92 | if (r === 0) r = defaults.r;
|
90 | 93 | if (p === 0) p = defaults.p;
|
|
0 commit comments