[Pkg-javascript-commits] [node-keygrip] 63/68: make it work with strings of arbitrary length

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 89c95a741879d5bdd7162eb63f84e9634fa47783
Author: Jonathan Ong <jonathanrichardong at gmail.com>
Date:   Wed Jun 18 19:14:55 2014 -0700

    make it work with strings of arbitrary length
---
 index.js | 5 ++---
 test.js  | 9 +++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index 14b04f8..a90b0d6 100644
--- a/index.js
+++ b/index.js
@@ -59,7 +59,7 @@ Keygrip.prototype.encrypt = function Keygrip$_encrypt(data, iv, key) {
   var cipher = iv
     ? crypto.createCipheriv(this.cipher, key, iv)
     : crypto.createCipher(this.cipher, key)
-  cipher.update(data)
+  return Buffer.concat([cipher.update(data), cipher.final()])
   return cipher.final()
 }
 
@@ -81,8 +81,7 @@ Keygrip.prototype.decrypt = function Keygrip$__decrypt(data, iv, key) {
     var cipher = iv
       ? crypto.createDecipheriv(this.cipher, key, iv)
       : crypto.createDecipher(this.cipher, key)
-    cipher.update(data)
-    return cipher.final()
+    return Buffer.concat([cipher.update(data), cipher.final()])
   } catch (err) {
     if (/bad decrypt/.test(err.message)) return false
     throw err
diff --git a/test.js b/test.js
index 34f5bb2..17d8e49 100644
--- a/test.js
+++ b/test.js
@@ -112,6 +112,15 @@ describe('Message encryption', function () {
       assert.equal(false, new Keygrip([crypto.randomBytes(32)])
         .decrypt(message))
     })
+
+    it('should work on really long strings', function () {
+      var string = ''
+      for (var i = 0; i < 10000; i++) {
+        string += 'a'
+      }
+      var msg = keygrip.encrypt(new Buffer(string))
+      assert.equal(string, keygrip.decrypt(msg)[0].toString('utf8'))
+    })
   })
 })
 

-- 
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