mirror of https://github.com/nodejs/node.git
crypto: move _scrypt call out of handleError funct
This commit moves the _scrypt function call out of the handleError function, which now only takes in an error object as its parameter. The motivation for this is to hopefully improve readability as it was not clear to me the first time I stepped through the code where the actual call to _scrypt was. PR-URL: https://github.com/nodejs/node/pull/28318 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
7fad0afd2c
commit
882e8fea66
|
@ -44,7 +44,7 @@ function scrypt(password, salt, keylen, options, callback = defaults) {
|
|||
callback.call(wrap, null, keybuf.toString(encoding));
|
||||
};
|
||||
|
||||
handleError(keybuf, password, salt, N, r, p, maxmem, wrap);
|
||||
handleError(_scrypt(keybuf, password, salt, N, r, p, maxmem, wrap));
|
||||
}
|
||||
|
||||
function scryptSync(password, salt, keylen, options = defaults) {
|
||||
|
@ -52,15 +52,13 @@ function scryptSync(password, salt, keylen, options = defaults) {
|
|||
const { N, r, p, maxmem } = options;
|
||||
({ password, salt, keylen } = options);
|
||||
const keybuf = Buffer.alloc(keylen);
|
||||
handleError(keybuf, password, salt, N, r, p, maxmem);
|
||||
handleError(_scrypt(keybuf, password, salt, N, r, p, maxmem));
|
||||
const encoding = getDefaultEncoding();
|
||||
if (encoding === 'buffer') return keybuf;
|
||||
return keybuf.toString(encoding);
|
||||
}
|
||||
|
||||
function handleError(keybuf, password, salt, N, r, p, maxmem, wrap) {
|
||||
const ex = _scrypt(keybuf, password, salt, N, r, p, maxmem, wrap);
|
||||
|
||||
function handleError(ex) {
|
||||
if (ex === undefined)
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue