Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion scrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
}

function ensureInteger(value, name) {
if (typeof(value) !== "number" || (value % 1)) { throw new Error('invalid ' + name); }
if (!Number.isInteger(value)) { throw new Error('invalid ' + name); }
return value;
}

Expand Down
14 changes: 14 additions & 0 deletions test/test-scrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ const scrypt = require('../scrypt.js');

const testVectors = require('./test-vectors.json');

for (const invalid of [NaN, Infinity, -Infinity, 0.5, null]) {
for (let i = 0; i < 4; i++) {
const password = Buffer.from('password');
const salt = Buffer.from('salt');
const argname = ['N', 'r', 'p', 'dkLen'][i];
const args = [16, 1, 1, 64];
args[i] = invalid;
it(`Test ${invalid} rejection ${i}`, () => assert.rejects(
() => scrypt.scrypt(password, salt, ...args, () => {}),
{ message: `invalid ${argname}` }
));
}
}

for (let i = 0; i < testVectors.length; i++) {
const test = testVectors[i];

Expand Down