From 7edd5f3bdd2faaf9072a6456dfed6207c41cce6a Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 20 Jun 2019 08:09:17 +0200 Subject: [PATCH] crypto: move _pbkdf2 call out of handleError funct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. PR-URL: https://github.com/nodejs/node/pull/28318 Reviewed-By: Yongsheng Zhang Reviewed-By: Benjamin Gruenbaum Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Tobias Nießen Reviewed-By: James M Snell --- lib/internal/crypto/pbkdf2.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/internal/crypto/pbkdf2.js b/lib/internal/crypto/pbkdf2.js index fc6341b83f4110..d8c4bc9b518dc1 100644 --- a/lib/internal/crypto/pbkdf2.js +++ b/lib/internal/crypto/pbkdf2.js @@ -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); @@ -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);