Skip to content

Commit

Permalink
crypto: move _scrypt call out of handleError funct
Browse files Browse the repository at this point in the history
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: #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>
  • Loading branch information
danbev committed Jun 24, 2019
1 parent 7fad0af commit 882e8fe
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/internal/crypto/scrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,21 @@ 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) {
options = check(password, salt, keylen, options);
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;

Expand Down

0 comments on commit 882e8fe

Please sign in to comment.