cipher-base
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -8,3 +8,3 @@ var Transform = require('stream').Transform | ||
Transform.call(this) | ||
this.hashMode = typeof hashMode === 'string'; | ||
this.hashMode = typeof hashMode === 'string' | ||
if (this.hashMode) { | ||
@@ -34,3 +34,7 @@ this[hashMode] = this._finalOrDigest | ||
try { | ||
this.push(this._update(data)) | ||
if (this.hashMode) { | ||
this._update(data) | ||
} else { | ||
this.push(this._update(data)) | ||
} | ||
} catch (e) { | ||
@@ -37,0 +41,0 @@ err = e |
{ | ||
"name": "cipher-base", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "abstract base class for crypto-streams", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
25
test.js
@@ -45,2 +45,27 @@ var test = require('tape') | ||
}) | ||
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) { | ||
@@ -47,0 +72,0 @@ inherits(Cipher, CipherBase) |
6048
176