Skip to content

Commit 61491fe

Browse files
committed
fix error in 0.10
1 parent 8fbd9e7 commit 61491fe

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = CipherBase
55
inherits(CipherBase, Transform)
66
function CipherBase (hashMode) {
77
Transform.call(this)
8-
this.hashMode = typeof hashMode === 'string';
8+
this.hashMode = typeof hashMode === 'string'
99
if (this.hashMode) {
1010
this[hashMode] = this._finalOrDigest
1111
} else {
@@ -30,7 +30,11 @@ CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
3030
CipherBase.prototype._transform = function (data, _, next) {
3131
var err
3232
try {
33-
this.push(this._update(data))
33+
if (this.hashMode) {
34+
this._update(data)
35+
} else {
36+
this.push(this._update(data))
37+
}
3438
} catch (e) {
3539
err = e
3640
} finally {

test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@ test('hash mode', function (t) {
4242
t.equals(utf8, string)
4343
t.end()
4444
})
45+
test('hash mode as stream', function (t) {
46+
inherits(Cipher, CipherBase)
47+
function Cipher () {
48+
CipherBase.call(this, 'finalName')
49+
this._cache = []
50+
}
51+
Cipher.prototype._update = function (input) {
52+
t.ok(Buffer.isBuffer(input))
53+
this._cache.push(input)
54+
}
55+
Cipher.prototype._final = function () {
56+
return Buffer.concat(this._cache)
57+
}
58+
var cipher = new Cipher()
59+
cipher.on('error', function (e) {
60+
t.notOk(e)
61+
})
62+
var utf8 = 'abc123abcd'
63+
cipher.end(utf8, 'utf8')
64+
var update = cipher.read().toString('base64')
65+
var string = (new Buffer(update, 'base64')).toString()
66+
67+
t.equals(utf8, string)
68+
t.end()
69+
})
4570
test('encodings', function (t) {
4671
inherits(Cipher, CipherBase)
4772
function Cipher () {

0 commit comments

Comments
 (0)