[Pkg-javascript-commits] [node-hash-base] 03/04: Throw error on second call digest

Bastien Roucariès rouca at moszumanska.debian.org
Thu May 4 10:21:22 UTC 2017


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

rouca pushed a commit to annotated tag v1.0.1
in repository node-hash-base.

commit f0b4cafb0a87e8bd3c22a6a3b31e323926dc4e63
Author: Kirill Fomichev <fanatid at ya.ru>
Date:   Mon Apr 4 13:14:35 2016 +0300

    Throw error on second call digest
---
 index.js      | 4 ++++
 test/index.js | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/index.js b/index.js
index 673cff3..5e9f15f 100644
--- a/index.js
+++ b/index.js
@@ -4,6 +4,7 @@ var inherits = require('inherits')
 
 function HashBase () {
   Transform.call(this)
+  this.initialised_ = true
 }
 
 inherits(HashBase, Transform)
@@ -21,6 +22,9 @@ HashBase.prototype.update = function (data, encoding) {
 }
 
 HashBase.prototype.digest = function (encoding) {
+  if (!this.initialised_) throw new Error('Not initialized')
+  this.initialised_ = false
+
   var digest = this._digest()
   if (encoding === undefined) encoding = HashBase.DEFAULT_ENCODING
   if (encoding !== 'buffer') digest = digest.toString(encoding)
diff --git a/test/index.js b/test/index.js
index 2d8c16d..b7177e3 100644
--- a/test/index.js
+++ b/test/index.js
@@ -81,6 +81,15 @@ test('decode', function (t) {
     t.end()
   })
 
+  t.test('second call digest throw error', function (t) {
+    t.base._digest = function () {}
+    t.base.digest()
+    t.throws(function () {
+      t.base.digest()
+    }, /^Error: Not initialized$/)
+    t.end()
+  })
+
   t.end()
 })
 

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



More information about the Pkg-javascript-commits mailing list