[Pkg-javascript-commits] [node-keygrip] 61/68: decrypt returns i for the index of the key
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Fri Jun 27 22:13:29 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to branch master
in repository node-keygrip.
commit fd611fd45beb46cf3725a11724323902c9d17ce7
Author: Jonathan Ong <jonathanrichardong at gmail.com>
Date: Wed Jun 18 00:27:02 2014 -0700
decrypt returns i for the index of the key
---
README.md | 6 ++++--
index.js | 2 +-
test.js | 6 +++---
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index a9d9e6f..5a509ab 100644
--- a/README.md
+++ b/README.md
@@ -51,10 +51,12 @@ Creates an encrypted message as a buffer based on the _first_ key in the keylist
Uses `.cipher=` as the underlying algorithm.
Note that `iv` length is important.
-### var buf = keys.decrypt(message, [iv])
+### var [buf, i] = keys.decrypt(message, [iv])
Decrypts a message, optionally with an initialization vector.
-Returns a buffer.
+Returns a buffer as `buf`.
+Also returns `i`, the index of the `key` used.
+If `i !== 0`, you may want to re-encrypt the message to use the latest key.
### keys.hash=
diff --git a/index.js b/index.js
index c5947c4..6c429de 100644
--- a/index.js
+++ b/index.js
@@ -69,7 +69,7 @@ Keygrip.prototype.decrypt = function Keygrip$__decrypt(data, iv, key) {
var keys = this.keys
for (var i = 0, l = keys.length; i < l; i++) {
var message = this.decrypt(data, iv, keys[i])
- if (message !== false) return message
+ if (message !== false) return [message, i]
}
return false
diff --git a/test.js b/test.js
index d4e9608..34f5bb2 100644
--- a/test.js
+++ b/test.js
@@ -42,7 +42,7 @@ describe('keygrip([key])', function () {
it('should encrypt a message', function () {
hash = keys.encrypt('lol')
- assert.equal('lol', keys.decrypt(hash).toString('utf8'))
+ assert.equal('lol', keys.decrypt(hash)[0].toString('utf8'))
})
it('should return false on bad decryptions', function () {
@@ -84,7 +84,7 @@ describe('Message encryption', function () {
var message = keygrip.encrypt('lol', iv)
it('should encrypt and decrypt', function () {
- assert.equal('lol', keygrip.decrypt(message, iv).toString('utf8'))
+ assert.equal('lol', keygrip.decrypt(message, iv)[0].toString('utf8'))
})
it('should return false on invalid key', function () {
@@ -105,7 +105,7 @@ describe('Message encryption', function () {
var message = keygrip.encrypt('lol')
it('should encrypt and decrypt', function () {
- assert.equal('lol', keygrip.decrypt(message).toString('utf8'))
+ assert.equal('lol', keygrip.decrypt(message)[0].toString('utf8'))
})
it('should return false on invalid key', function () {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-keygrip.git
More information about the Pkg-javascript-commits
mailing list