Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: move _scrypt call out of handleError funct #28318

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
crypto: move _pbkdf2 call out of handleError funct
This commit moves the _pbkdf2 function call out of the handleError
function, which now only takes in an error and a digest object as
its parameters.
  • Loading branch information
danbev committed Jun 20, 2019
commit d96eff6dc32a14de516dd5642e92aa7a99456a5a
9 changes: 4 additions & 5 deletions lib/internal/crypto/pbkdf2.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) {
callback.call(wrap, null, keybuf.toString(encoding));
};

handleError(keybuf, password, salt, iterations, digest, wrap);
handleError(_pbkdf2(keybuf, password, salt, iterations, digest, wrap),
digest);
}

function pbkdf2Sync(password, salt, iterations, keylen, digest) {
({ password, salt, iterations, keylen, digest } =
check(password, salt, iterations, keylen, digest));
const keybuf = Buffer.alloc(keylen);
handleError(keybuf, password, salt, iterations, digest);
handleError(_pbkdf2(keybuf, password, salt, iterations, digest), digest);
const encoding = getDefaultEncoding();
if (encoding === 'buffer') return keybuf;
return keybuf.toString(encoding);
Expand All @@ -71,9 +72,7 @@ function check(password, salt, iterations, keylen, digest) {
return { password, salt, iterations, keylen, digest };
}

function handleError(keybuf, password, salt, iterations, digest, wrap) {
const rc = _pbkdf2(keybuf, password, salt, iterations, digest, wrap);

function handleError(rc, digest) {
if (rc === -1)
throw new ERR_CRYPTO_INVALID_DIGEST(digest);

Expand Down