Comparing version 0.1.1 to 0.1.2-1
19
index.js
@@ -16,2 +16,12 @@ var bindings = require("bindings")("argon2_lib"); | ||
exports.encryptSync = function (plain, salt) { | ||
"use strict"; | ||
if (salt.length > 16) { | ||
throw new Error("Salt too long, maximum 16 characters."); | ||
} | ||
return bindings.encryptSync(plain, salt); | ||
}; | ||
exports.verify = function (encrypted, plain, callback) { | ||
@@ -21,2 +31,9 @@ "use strict"; | ||
return bindings.verify(encrypted, plain, callback); | ||
} | ||
}; | ||
exports.verifySync = function (encrypted, plain) { | ||
"use strict"; | ||
return bindings.verifySync(encrypted, plain); | ||
}; | ||
{ | ||
"name": "argon2", | ||
"version": "0.1.1", | ||
"version": "0.1.2-1", | ||
"description": "An Argon2 library for Node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,6 +0,7 @@ | ||
# node-argon2 [![Build status][travis-image]][travis-url] | ||
Bindings to the [reference Argon2 implementation](https://github.com/P-H-C/phc-winner-argon2). | ||
# node-argon2 [![NPM package][npm-image]][npm-url] [![Build status][travis-image]][travis-url] [![Code Climate][codeclimate-image]][codeclimate-url] [![Dependencies][david-dm-image]][david-dm-url] | ||
Bindings to the reference [Argon2](https://github.com/P-H-C/phc-winner-argon2). | ||
implementation. | ||
### Usage | ||
Currently, only the encrypt and verify methods are implemented for Argon2i, asynchronously. | ||
Currently, only the encrypt and verify methods are implemented for Argon2i. | ||
@@ -11,3 +12,3 @@ To hash a password: | ||
argon2.encrypt('password', 'somesalt', function(err, hash) { | ||
argon2.encrypt('password', 'somesalt', function (err, hash) { | ||
if (err) // encryption failure | ||
@@ -18,2 +19,10 @@ throw err; | ||
}); | ||
// OR | ||
try { | ||
var hash = argon2.encryptSync('password', 'somesalt'); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
``` | ||
@@ -26,3 +35,3 @@ Resultant hashes will be 90 characters long. | ||
argon2.verify('<big long hash>', 'password', function(err) { | ||
argon2.verify('<big long hash>', 'password', function (err) { | ||
if (err) // password did not match | ||
@@ -33,10 +42,26 @@ throw err; | ||
}); | ||
// OR | ||
if (argon2.verifySync('<big long hash>', 'password')) { | ||
authenticate(); | ||
} else { | ||
fail(); | ||
} | ||
``` | ||
First parameter must have been generated by an Argon2 encoded hashing method, not raw. | ||
First parameter must have been generated by an Argon2 encoded hashing method, | ||
not raw. | ||
# License | ||
Work licensed under the [MIT License](LICENSE). Please check [P-H-C/phc-winner-argon2] | ||
(https://github.com/P-H-C/phc-winner-argon2) for license over Argon2 and the reference implementation. | ||
Work licensed under the [MIT License](LICENSE). Please check | ||
[P-H-C/phc-winner-argon2] (https://github.com/P-H-C/phc-winner-argon2) for | ||
license over Argon2 and the reference implementation. | ||
[travis-image]: https://travis-ci.org/ranisalt/node-argon2.svg?branch=master | ||
[npm-image]: https://img.shields.io/npm/v/argon2.svg | ||
[npm-url]: https://www.npmjs.com/package/argon2 | ||
[travis-image]: https://img.shields.io/travis/ranisalt/node-argon2.svg | ||
[travis-url]: https://travis-ci.org/ranisalt/node-argon2 | ||
[codeclimate-image]: https://img.shields.io/codeclimate/github/ranisalt/node-argon2.svg | ||
[codeclimate-url]: https://codeclimate.com/github/ranisalt/node-argon2 | ||
[david-dm-image]: https://img.shields.io/david/ranisalt/node-argon2.svg | ||
[david-dm-url]: https://david-dm.org/ranisalt/node-argon2 |
@@ -7,2 +7,4 @@ var argon2 = require('.'); | ||
assert.expect(3); | ||
argon2.encrypt("password", "somesalt", function (err, hash) { | ||
@@ -20,2 +22,4 @@ assert.ok(hash, "Hash should be defined."); | ||
assert.expect(3); | ||
argon2.encrypt("password", "somesaltwaytoobig", function (err, hash) { | ||
@@ -29,5 +33,29 @@ assert.ok(err, "Error should be defined."); | ||
test_hash_sync: function (assert) { | ||
"use strict"; | ||
assert.expect(1); | ||
var hash = argon2.encryptSync("password", "somesalt"); | ||
assert.equal(hash, "$argon2i$m=4096,t=3,p=1$c29tZXNhbHQAAAAAAAAAAA$FHF/OZ0GJpMRAlBmPTqXxw36Ftp87JllALZPcP9w9gs", | ||
"Hash should be equal to expected."); | ||
assert.done(); | ||
}, | ||
test_hash_sync_long_salt: function (assert) { | ||
"use strict"; | ||
assert.expect(1); | ||
assert.throws(function() { | ||
argon2.encryptSync("password", "somesaltwaytoobig") | ||
}, Error, "Error should be thrown."); | ||
assert.done(); | ||
}, | ||
test_verify_ok: function (assert) { | ||
"use strict"; | ||
assert.expect(1); | ||
argon2.verify( | ||
@@ -44,2 +72,4 @@ "$argon2i$m=4096,t=3,p=1$c29tZXNhbHQAAAAAAAAAAA$FHF/OZ0GJpMRAlBmPTqXxw36Ftp87JllALZPcP9w9gs", | ||
assert.expect(1); | ||
argon2.verify( | ||
@@ -51,3 +81,25 @@ "$argon2i$m=4096,t=3,p=1$c29tZXNhbHQAAAAAAAAAAA$FHF/OZ0GJpMRAlBmPTqXxw36Ftp87JllALZPcP9w9gs", | ||
}); | ||
}, | ||
test_verify_sync_ok: function (assert) { | ||
"use strict"; | ||
assert.expect(1); | ||
assert.equal(true, argon2.verifySync( | ||
"$argon2i$m=4096,t=3,p=1$c29tZXNhbHQAAAAAAAAAAA$FHF/OZ0GJpMRAlBmPTqXxw36Ftp87JllALZPcP9w9gs", | ||
"password")); | ||
assert.done(); | ||
}, | ||
test_verify_sync_fail: function (assert) { | ||
"use strict"; | ||
assert.expect(1); | ||
assert.equal(false, argon2.verifySync( | ||
"$argon2i$m=4096,t=3,p=1$c29tZXNhbHQAAAAAAAAAAA$FHF/OZ0GJpMRAlBmPTqXxw36Ftp87JllALZPcP9w9gs", | ||
"passwolrd")); | ||
assert.done(); | ||
} | ||
}; |
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
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
1716076
102
64