diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-06-25 17:40:59 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-07-18 14:18:01 +0200 |
commit | e9b22e9569008de8485ece22bcbb2ce8b143d4b2 (patch) | |
tree | e331e384c7875b9a4d01c152e995af2aabb8547b /lib | |
parent | 07c514ce29ffb1875b62ad5cbf056b33b7fdc9e5 (diff) | |
download | android-node-v8-e9b22e9569008de8485ece22bcbb2ce8b143d4b2.tar.gz android-node-v8-e9b22e9569008de8485ece22bcbb2ce8b143d4b2.tar.bz2 android-node-v8-e9b22e9569008de8485ece22bcbb2ce8b143d4b2.zip |
crypto: add better scrypt option aliases
Make parameter names available in a human-readable way, for
more accessible/self-documenting usage of the `scrypt` functions.
This implements a review comment from the original PR that has
not been addressed.
Refs: https://github.com/nodejs/node/pull/20816#discussion_r189220776
PR-URL: https://github.com/nodejs/node/pull/21525
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/crypto/scrypt.js | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/internal/crypto/scrypt.js b/lib/internal/crypto/scrypt.js index fedf7f5b10..edfe522be4 100644 --- a/lib/internal/crypto/scrypt.js +++ b/lib/internal/crypto/scrypt.js @@ -80,13 +80,26 @@ function check(password, salt, keylen, options, callback) { let { N, r, p, maxmem } = defaults; if (options && options !== defaults) { - if (options.hasOwnProperty('N')) + let has_N, has_r, has_p; + if (has_N = (options.N !== undefined)) N = validateInt32(options.N, 'N', 0, INT_MAX); - if (options.hasOwnProperty('r')) + if (options.cost !== undefined) { + if (has_N) throw new ERR_CRYPTO_SCRYPT_INVALID_PARAMETER(); + N = validateInt32(options.cost, 'cost', 0, INT_MAX); + } + if (has_r = (options.r !== undefined)) r = validateInt32(options.r, 'r', 0, INT_MAX); - if (options.hasOwnProperty('p')) + if (options.blockSize !== undefined) { + if (has_r) throw new ERR_CRYPTO_SCRYPT_INVALID_PARAMETER(); + r = validateInt32(options.blockSize, 'blockSize', 0, INT_MAX); + } + if (has_p = (options.p !== undefined)) p = validateInt32(options.p, 'p', 0, INT_MAX); - if (options.hasOwnProperty('maxmem')) + if (options.parallelization !== undefined) { + if (has_p) throw new ERR_CRYPTO_SCRYPT_INVALID_PARAMETER(); + p = validateInt32(options.parallelization, 'parallelization', 0, INT_MAX); + } + if (options.maxmem !== undefined) maxmem = validateInt32(options.maxmem, 'maxmem', 0, INT_MAX); if (N === 0) N = defaults.N; if (r === 0) r = defaults.r; |