[Pkg-javascript-commits] [node-cipher-base] 02/18: fix error in 0.10

Bastien Roucariès rouca at moszumanska.debian.org
Thu Apr 20 19:25:24 UTC 2017


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

rouca pushed a commit to branch master
in repository node-cipher-base.

commit 61491fe31fcc9bee0901f93b26cee6eaaca07575
Author: Calvin Metcalf <calvin.metcalf at gmail.com>
Date:   Sat Sep 26 18:00:41 2015 -0400

    fix error in 0.10
---
 index.js |  8 ++++++--
 test.js  | 25 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/index.js b/index.js
index 095a6c3..901791f 100644
--- a/index.js
+++ b/index.js
@@ -5,7 +5,7 @@ module.exports = CipherBase
 inherits(CipherBase, Transform)
 function CipherBase (hashMode) {
   Transform.call(this)
-  this.hashMode = typeof hashMode === 'string';
+  this.hashMode = typeof hashMode === 'string'
   if (this.hashMode) {
     this[hashMode] = this._finalOrDigest
   } else {
@@ -30,7 +30,11 @@ CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
 CipherBase.prototype._transform = function (data, _, next) {
   var err
   try {
-    this.push(this._update(data))
+    if (this.hashMode) {
+      this._update(data)
+    } else {
+      this.push(this._update(data))
+    }
   } catch (e) {
     err = e
   } finally {
diff --git a/test.js b/test.js
index 952a920..57d144a 100644
--- a/test.js
+++ b/test.js
@@ -42,6 +42,31 @@ test('hash mode', function (t) {
   t.equals(utf8, string)
   t.end()
 })
+test('hash mode as stream', function (t) {
+  inherits(Cipher, CipherBase)
+  function Cipher () {
+    CipherBase.call(this, 'finalName')
+    this._cache = []
+  }
+  Cipher.prototype._update = function (input) {
+    t.ok(Buffer.isBuffer(input))
+    this._cache.push(input)
+  }
+  Cipher.prototype._final = function () {
+    return Buffer.concat(this._cache)
+  }
+  var cipher = new Cipher()
+  cipher.on('error', function (e) {
+    t.notOk(e)
+  })
+  var utf8 = 'abc123abcd'
+  cipher.end(utf8, 'utf8')
+  var update = cipher.read().toString('base64')
+  var string = (new Buffer(update, 'base64')).toString()
+
+  t.equals(utf8, string)
+  t.end()
+})
 test('encodings', function (t) {
   inherits(Cipher, CipherBase)
   function Cipher () {

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



More information about the Pkg-javascript-commits mailing list