Comparing version 0.11.1 to 0.12.0
114
index.js
@@ -1,3 +0,3 @@ | ||
const crypto = require('crypto'); | ||
const bindings = require('bindings')('argon2'); | ||
const crypto = require('crypto') | ||
const bindings = require('bindings')('argon2') | ||
@@ -9,15 +9,15 @@ const defaults = Object.freeze({ | ||
argon2d: false | ||
}); | ||
}) | ||
const limits = Object.freeze(bindings.limits); | ||
const limits = Object.freeze(bindings.limits) | ||
const isValidHash = hash => { | ||
return /^\$argon2[di](\$v=\d+)?\$m=\d+,t=\d+,p=\d+(?:\$[a-zA-Z0-9+\/]+){2}$/.test(hash); | ||
}; | ||
return /^\$argon2[di](\$v=\d+)?\$m=\d+,t=\d+,p=\d+(?:\$[a-zA-Z0-9+\/]+){2}$/.test(hash) | ||
} | ||
const validate = (salt, options) => { | ||
'use strict'; | ||
'use strict' | ||
if (!Buffer.isBuffer(salt) || salt.length < 8) { | ||
throw new Error('Invalid salt, must be a buffer with 8 or more bytes.'); | ||
throw new Error('Invalid salt, must be a buffer with 8 or more bytes.') | ||
} | ||
@@ -27,107 +27,71 @@ | ||
/* istanbul ignore next */ | ||
options.parallelism = require('os').cpus().length; | ||
options.parallelism = require('os').cpus().length | ||
} | ||
for (const key of Object.keys(limits)) { | ||
const max = limits[key].max; | ||
const min = limits[key].min; | ||
const value = options[key]; | ||
const max = limits[key].max | ||
const min = limits[key].min | ||
const value = options[key] | ||
if (!Number.isInteger(value) || value > max || value < min) { | ||
throw new Error(`Invalid ${key}, must be an integer between ${min} and ${max}.`); | ||
throw new Error(`Invalid ${key}, must be an integer between ${min} and ${max}.`) | ||
} | ||
} | ||
}; | ||
} | ||
module.exports = { | ||
defaults, limits, | ||
defaults, | ||
limits, | ||
hash(plain, salt, options) { | ||
'use strict'; | ||
'use strict' | ||
options = Object.assign({}, defaults, options); | ||
options = Object.assign({}, defaults, options) | ||
if (!Buffer.isBuffer(plain)) { | ||
plain = new Buffer(plain); | ||
plain = new Buffer(plain) | ||
} | ||
try { | ||
validate(salt, options); | ||
return new Promise((resolve, reject) => { | ||
validate(salt, options) | ||
return new this.Promise((resolve, reject) => { | ||
return bindings.hash(plain, salt, options.timeCost, options.memoryCost, | ||
options.parallelism, options.argon2d, resolve, reject); | ||
}); | ||
options.parallelism, options.argon2d, resolve, reject) | ||
}) | ||
} catch (err) { | ||
return Promise.reject(err); | ||
return this.Promise.reject(err) | ||
} | ||
}, | ||
hashSync(plain, salt, options) { | ||
'use strict'; | ||
console.warn('The synchronous API is deprecated, use ES6 await instead.'); | ||
options = Object.assign({}, defaults, options); | ||
if (!Buffer.isBuffer(plain)) { | ||
plain = new Buffer(plain); | ||
} | ||
validate(salt, options); | ||
return bindings.hashSync(plain, salt, options.timeCost, options.memoryCost, | ||
options.parallelism, options.argon2d); | ||
}, | ||
generateSalt(length) { | ||
'use strict'; | ||
'use strict' | ||
length = typeof length === 'undefined' ? 16 : length; | ||
return new Promise((resolve, reject) => { | ||
length = typeof length === 'undefined' ? 16 : length | ||
return new this.Promise((resolve, reject) => { | ||
crypto.randomBytes(length, (err, salt) => { | ||
/* istanbul ignore if */ | ||
if (err) { | ||
return reject(err); | ||
return reject(err) | ||
} | ||
return resolve(salt); | ||
}); | ||
}); | ||
return resolve(salt) | ||
}) | ||
}) | ||
}, | ||
generateSaltSync(length) { | ||
'use strict'; | ||
console.warn('The synchronous API is deprecated, use ES6 await instead.'); | ||
length = typeof length === 'undefined' ? 16 : length; | ||
return crypto.randomBytes(length); | ||
}, | ||
verify(hash, plain) { | ||
'use strict'; | ||
'use strict' | ||
if (!isValidHash(hash)) { | ||
return Promise.reject(new Error('Invalid hash, must be generated by Argon2.')); | ||
return this.Promise.reject(new Error('Invalid hash, must be generated by Argon2.')) | ||
} | ||
if (!Buffer.isBuffer(plain)) { | ||
plain = new Buffer(plain); | ||
plain = new Buffer(plain) | ||
} | ||
return new Promise((resolve, reject) => { | ||
bindings.verify(hash, plain, hash[7] === 'd', resolve, reject); | ||
}); | ||
return new this.Promise((resolve, reject) => { | ||
bindings.verify(hash, plain, hash[7] === 'd', resolve, reject) | ||
}) | ||
}, | ||
verifySync(hash, plain) { | ||
'use strict'; | ||
console.warn('The synchronous API is deprecated, use ES6 await instead.'); | ||
if (!isValidHash(hash)) { | ||
throw new Error('Invalid hash, must be generated by Argon2.'); | ||
} | ||
if (!Buffer.isBuffer(plain)) { | ||
plain = new Buffer(plain); | ||
} | ||
return bindings.verifySync(new Buffer(hash), plain, hash[7] === 'd'); | ||
} | ||
}; | ||
Promise | ||
} |
{ | ||
"name": "argon2", | ||
"version": "0.11.1", | ||
"version": "0.12.0", | ||
"description": "An Argon2 library for Node", | ||
"main": "index.js", | ||
"scripts": { | ||
"benchmark": "node benchmark.js", | ||
"benchmark": "babel-node benchmark.js", | ||
"clean": "node-gyp clean", | ||
"test": "xo && babel-tap *.spec.js" | ||
"test": "xo && babel-tap test/*.spec.js" | ||
}, | ||
@@ -33,8 +33,10 @@ "repository": { | ||
"devDependencies": { | ||
"async": "^1.5.2", | ||
"async-benchmark": "^1.0.1", | ||
"babel-cli": "^6.9.0", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-stage-3": "^6.5.0", | ||
"babel-tap": "^5.0.0", | ||
"xo": "^0.14.0" | ||
"benchmark": "^2.1.0", | ||
"bluebird": "^3.4.0", | ||
"tap": "^5.7.2", | ||
"xo": "^0.16.0" | ||
}, | ||
@@ -45,7 +47,9 @@ "engines": { | ||
"xo": { | ||
"esnext": true, | ||
"rules": { | ||
"no-div-regex": "warn" | ||
"no-div-regex": "off" | ||
}, | ||
"semicolon": false, | ||
"space": 2 | ||
} | ||
} |
@@ -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] | ||
**Warning: synchronous API has been removed as of 0.12, either use async/await | ||
(recommended) or keep with 0.11.x if you need it.** | ||
**Want to use it on command line? Instead check | ||
@@ -7,0 +10,0 @@ [node-argon2-cli](https://github.com/ranisalt/node-argon2-cli).** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
30
232
163139
8
411
2