From 882e8fea669911a008ccdddd889b92414ca68949 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 20 Jun 2019 08:09:17 +0200 Subject: [PATCH] crypto: move _scrypt call out of handleError funct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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/scrypt.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/internal/crypto/scrypt.js b/lib/internal/crypto/scrypt.js index 0ed4140c9c5df5..50a2bbc1536026 100644 --- a/lib/internal/crypto/scrypt.js +++ b/lib/internal/crypto/scrypt.js @@ -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;