[Pkg-javascript-commits] [node-browserify-aes] 46/92: catch errors in _flush

Bastien Roucariès rouca at moszumanska.debian.org
Sun Jun 4 09:35:18 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-browserify-aes.

commit 9ed83cfddeb4a73d12270b895f5874dbd969deb2
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date:   Tue Dec 23 11:02:19 2014 -0500

    catch errors in _flush
---
 cipherBase.js |  7 ++++---
 test/index.js | 26 +++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/cipherBase.js b/cipherBase.js
index 8dfbb5b..0983a72 100644
--- a/cipherBase.js
+++ b/cipherBase.js
@@ -21,9 +21,10 @@ CipherBase.prototype._transform = function (data, _, next) {
   next();
 };
 CipherBase.prototype._flush = function (next) {
-  var chunk = this._final();
-  if (chunk) {
-    this.push(chunk);
+  try {
+    this.push(this._final());
+  } catch(e) {
+    return next(e);
   }
   next();
 };
diff --git a/test/index.js b/test/index.js
index d31831e..647777d 100644
--- a/test/index.js
+++ b/test/index.js
@@ -438,20 +438,44 @@ function incorectPaddingthrows(padding) {
     }, 'node');
   });
 }
+function incorectPaddingDoesNotThrow(padding) {
+  test('stream incorrect padding ' + padding.toString('hex'), function (t) {
+    t.plan(2);
+    var block1 = new Buffer(16);
+    block1.fill(4);
+    var cipher = crypto.createCipher('aes128', new Buffer('password'));
+    cipher.setAutoPadding(false);
+    var decipher = crypto.createDecipher('aes128', new Buffer('password'));
+    var decipher2 = _crypto.createDecipher('aes128', new Buffer('password'));
+    cipher.pipe(decipher);
+    cipher.pipe(decipher2);
+    cipher.write(block1);
+    cipher.write(padding);
+    decipher.on('error', function (e) {
+      t.ok(e, 'mine');
+    });
+    decipher2.on('error', function (e) {
+      t.ok(e, 'node');
+    });
+    cipher.end();
+  });
+}
 var sixteens2 = new Buffer(16);
 sixteens2.fill(16);
 sixteens2[3] = 5;
 incorectPaddingthrows(sixteens2);
+incorectPaddingDoesNotThrow(sixteens2);
 var fifteens2 = new Buffer(16);
 fifteens2.fill(15);
 fifteens2[0] = 5;
 fifteens2[1] = 6;
 incorectPaddingthrows(fifteens2);
-
+incorectPaddingDoesNotThrow(fifteens2);
 var two = _crypto.randomBytes(16);
 two[15] = 2;
 two[14] = 1;
 incorectPaddingthrows(two);
+incorectPaddingDoesNotThrow(two);
 test('autopadding false decipher', function (t) {
   t.plan(2);
   var mycipher = crypto.createCipher('aes-128-ecb', new Buffer('password'));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-browserify-aes.git



More information about the Pkg-javascript-commits mailing list