Skip to content

patch: do not reference arguments directly #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 17 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ var scryptNative = require("./build/Release/scrypt")
, Crypto = require("crypto")
, Os = require("os");

var argumentsToArgs = function() {
var len = arguments.length;
var args = new Array(len);
for (var i = 0; i < len; i++) {
args[i] = arguments[i];
}
return args;
}

var checkNumberOfArguments = function(args, message, numberOfArguments) {
if (message === undefined) message = "No arguments present";
if (numberOfArguments === undefined) numberOfArguments = 1;
Expand Down Expand Up @@ -251,12 +260,12 @@ var processHashArguments = function(args) {
//
var scrypt = {
paramsSync: function() {
var args = processParamsArguments(arguments);
var args = processParamsArguments(argumentsToArgs.apply(null, arguments));
return scryptNative.paramsSync(args[0], args[1], args[2], Os.totalmem());
},

params: function() {
var args = arguments
var args = argumentsToArgs.apply(null, arguments)
, callback_index = checkAsyncArguments(args, 1, "At least one argument is needed before the callback - the maxtime");

if (callback_index === undefined) {
Expand Down Expand Up @@ -287,12 +296,12 @@ var scrypt = {
},

kdfSync: function() {
var args = processKDFArguments(arguments);
var args = processKDFArguments(argumentsToArgs.apply(null, arguments));
return scryptNative.kdfSync(args[0], args[1], Crypto.randomBytes(256));
},

kdf: function() {
var args = arguments
var args = argumentsToArgs.apply(null, arguments)
, callback_index = checkAsyncArguments(args, 2, "At least two arguments are needed before the call back function - the key and the Scrypt parameters object")
, that = this;

Expand Down Expand Up @@ -327,12 +336,12 @@ var scrypt = {
},

verifyKdfSync: function() {
var args = processVerifyArguments(arguments);
var args = processVerifyArguments(argumentsToArgs.apply(null, arguments));
return scryptNative.verifySync(args[0], args[1]);
},

verifyKdf: function() {
var args = arguments
var args = argumentsToArgs.apply(null, arguments)
, callback_index = checkAsyncArguments(args, 2, "At least two arguments are needed before the callback function - the KDF and the key");

if (callback_index === undefined) {
Expand All @@ -355,12 +364,12 @@ var scrypt = {
},

hashSync: function() {
var args = processHashArguments(arguments);
var args = processHashArguments(argumentsToArgs.apply(null, arguments));
return scryptNative.hashSync(args[0], args[1], args[2], args[3]);
},

hash: function() {
var args = arguments
var args = argumentsToArgs.apply(null, arguments)
, callback_index = checkAsyncArguments(args, 4, "At least four arguments are needed before the callback - the key to hash, the scrypt params object, the output length of the hash and the salt");

args = processHashArguments(args);
Expand Down