Comparing version 0.10.0 to 0.10.1
43
index.js
@@ -13,20 +13,7 @@ const bindings = require('bindings')('argon2'); | ||
const fail = (message, reject) => { | ||
const validate = (salt, options) => { | ||
'use strict'; | ||
const error = new Error(message); | ||
if (typeof reject === 'function') { | ||
process.nextTick(reject.bind(null, error)); | ||
} else { | ||
throw error; | ||
} | ||
}; | ||
const validate = (salt, options, resolve, reject) => { | ||
'use strict'; | ||
if (!Buffer.isBuffer(salt) || salt.length < 8) { | ||
fail('Invalid salt, must be a buffer with 8 or more bytes.', reject); | ||
return false; | ||
throw new Error('Invalid salt, must be a buffer with 8 or more bytes.'); | ||
} | ||
@@ -43,12 +30,5 @@ | ||
if (!Number.isInteger(value) || value > max || value < min) { | ||
fail(`Invalid ${key}, must be an integer between ${min} and ${max}.`, reject); | ||
return false; | ||
throw new Error(`Invalid ${key}, must be an integer between ${min} and ${max}.`); | ||
} | ||
} | ||
if (typeof resolve === 'function') { | ||
resolve(); | ||
} | ||
return true; | ||
}; | ||
@@ -68,5 +48,9 @@ | ||
return new Promise(validate.bind(null, salt, options)) | ||
.then(bindings.hash.bind(null, plain, salt, options.timeCost, | ||
options.memoryCost, options.parallelism, options.argon2d)); | ||
try { | ||
validate(salt, options); | ||
return bindings.hash(plain, salt, options.timeCost, options.memoryCost, | ||
options.parallelism, options.argon2d); | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
}, | ||
@@ -84,6 +68,5 @@ | ||
if (validate(salt, options)) { | ||
return bindings.hashSync(plain, salt, options.timeCost, | ||
options.memoryCost, options.parallelism, options.argon2d); | ||
} | ||
validate(salt, options); | ||
return bindings.hashSync(plain, salt, options.timeCost, options.memoryCost, | ||
options.parallelism, options.argon2d); | ||
}, | ||
@@ -90,0 +73,0 @@ |
{ | ||
"name": "argon2", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"description": "An Argon2 library for Node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,2 +5,5 @@ # node-argon2 [![NPM package][npm-image]][npm-url] [![Build status][travis-image]][travis-url] [![Coverage status][coverage-image]][coverage-url] [![Code Quality][codequality-image]][codequality-url] [![Dependencies][david-dm-image]][david-dm-url] | ||
**Want to use it on command line? Instead check | ||
[node-argon2-cli](https://github.com/ranisalt/node-argon2-cli).** | ||
### Before installing | ||
@@ -7,0 +10,0 @@ You **MUST** have a **node-gyp** global install before proceeding with install, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
210
170035
806