Skip to content
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
14 changes: 6 additions & 8 deletions lib/internal/crypto/scrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,28 @@ 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);

if (ex === undefined)
function handleError(error) {
if (error === undefined)
return;

if (ex === null)
if (error === null)
throw new ERR_CRYPTO_SCRYPT_INVALID_PARAMETER(); // Bad N, r, p, or maxmem.

throw ex; // Scrypt operation failed, exception object contains details.
throw error; // Scrypt operation failed, exception object contains details.
}

function check(password, salt, keylen, options) {
Expand Down