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
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ var checkScryptParametersObject = function(params) {
var error = new TypeError("Scrypt params object 'N' property is not an integer");
}

if (!error && !((params.N > 0) && (params.N < 256))) {
var error = new RangeError("Scrypt params object 'N' property is out of range");
}

if (!error && !params.hasOwnProperty("r")) {
var error = new TypeError("Scrypt params object does not have 'r' property present");
}
Expand Down
8 changes: 7 additions & 1 deletion tests/scrypt-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,17 @@ describe("Scrypt Node Module Tests", function() {
.to.match(/^TypeError: Key type is incorrect: It can only be of type string or Buffer$/);
})

it("Will throw a TypeError if the Scrypt params object is incorrect", function() {
it("Will throw a TypeError if the Scrypt params object is missing 'r' property", function() {
expect(function(){scrypt.kdfSync("password", {N:1, p:1})})
.to.throw(TypeError)
.to.match(/^TypeError: Scrypt params object does not have 'r' property present$/);
})

it("Will throw a TypeError if the Scrypt params object has 'N' property out of range", function() {
expect(function(){scrypt.kdfSync("password", {N:65536, r:1, p:1})})
.to.throw(RangeError)
.to.match(/^RangeError: Scrypt params object 'N' property is out of range$/);
})
});

describe("Synchronous functionality with correct arguments", function() {
Expand Down