[Pkg-javascript-commits] [node-keygrip] 59/68: additional encrypt() and decrypt() tests

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Fri Jun 27 22:13:28 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 b3f849460ca968194f8393d647f83a863ef16053
Author: Jonathan Ong <jonathanrichardong at gmail.com>
Date:   Tue Jun 3 22:52:31 2014 -0700

    additional encrypt() and decrypt() tests
---
 index.js |  2 +-
 test.js  | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index b9bc1c7..100f59e 100644
--- a/index.js
+++ b/index.js
@@ -47,7 +47,7 @@ Keygrip.prototype = {
 
   // defaults
   _hash: 'sha256',
-  _cipher: 'aes256',
+  _cipher: 'aes-256-cbc',
 }
 
 // encrypt a message
diff --git a/test.js b/test.js
index c0ad4f6..768fb0d 100644
--- a/test.js
+++ b/test.js
@@ -1,6 +1,7 @@
 "use strict";
 
 // ./test.js
+var crypto = require('crypto')
 var assert = require("assert")
   , Keygrip = require("./")
   , keylist, keys, hash, index
@@ -73,6 +74,47 @@ describe('keygrip([keys...])', function () {
   })
 })
 
+describe('Message encryption', function () {
+  var length = 16
+  var key = crypto.randomBytes(32)
+  var keygrip = new Keygrip([key])
+
+  describe('with iv', function () {
+    var iv = crypto.randomBytes(length)
+    var message = keygrip.encrypt('lol', iv)
+
+    it('should encrypt and decrypt', function () {
+      assert.equal('lol', keygrip.decrypt(message, iv).toString('utf8'))
+    })
+
+    it('should return false on invalid key', function () {
+      assert.equal(false, new Keygrip([crypto.randomBytes(32)])
+        .decrypt(message, iv))
+    })
+
+    it('should return false on missing iv', function () {
+      assert.equal(false, keygrip.decrypt(message))
+    })
+
+    it('should return false on invalid iv', function () {
+      assert.equal(false, keygrip.decrypt(message, crypto.randomBytes(length)))
+    })
+  })
+
+  describe('without iv', function () {
+    var message = keygrip.encrypt('lol')
+
+    it('should encrypt and decrypt', function () {
+      assert.equal('lol', keygrip.decrypt(message).toString('utf8'))
+    })
+
+    it('should return false on invalid key', function () {
+      assert.equal(false, new Keygrip([crypto.randomBytes(32)])
+        .decrypt(message))
+    })
+  })
+})
+
 function testKeygripInstance(keys) {
 	hash = keys.sign("bieberschnitzel")
 

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