Commit 61491fe3 authored by Calvin Metcalf's avatar Calvin Metcalf

fix error in 0.10

parent 8fbd9e76
......@@ -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 {
......
......@@ -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 () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment