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);