aboutsummaryrefslogtreecommitdiff
path: root/node_modules/cipher-base/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/cipher-base/index.js')
-rw-r--r--node_modules/cipher-base/index.js39
1 files changed, 24 insertions, 15 deletions
diff --git a/node_modules/cipher-base/index.js b/node_modules/cipher-base/index.js
index 1a661d626..6728005e9 100644
--- a/node_modules/cipher-base/index.js
+++ b/node_modules/cipher-base/index.js
@@ -1,8 +1,8 @@
+var Buffer = require('safe-buffer').Buffer
var Transform = require('stream').Transform
-var inherits = require('inherits')
var StringDecoder = require('string_decoder').StringDecoder
-module.exports = CipherBase
-inherits(CipherBase, Transform)
+var inherits = require('inherits')
+
function CipherBase (hashMode) {
Transform.call(this)
this.hashMode = typeof hashMode === 'string'
@@ -11,25 +11,31 @@ function CipherBase (hashMode) {
} else {
this.final = this._finalOrDigest
}
+ if (this._final) {
+ this.__final = this._final
+ this._final = null
+ }
this._decoder = null
this._encoding = null
}
+inherits(CipherBase, Transform)
+
CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
if (typeof data === 'string') {
- data = new Buffer(data, inputEnc)
+ data = Buffer.from(data, inputEnc)
}
+
var outData = this._update(data)
- if (this.hashMode) {
- return this
- }
+ if (this.hashMode) return this
+
if (outputEnc) {
outData = this._toString(outData, outputEnc)
}
+
return outData
}
CipherBase.prototype.setAutoPadding = function () {}
-
CipherBase.prototype.getAuthTag = function () {
throw new Error('trying to get auth tag in unsupported state')
}
@@ -59,15 +65,15 @@ CipherBase.prototype._transform = function (data, _, next) {
CipherBase.prototype._flush = function (done) {
var err
try {
- this.push(this._final())
+ this.push(this.__final())
} catch (e) {
err = e
- } finally {
- done(err)
}
+
+ done(err)
}
CipherBase.prototype._finalOrDigest = function (outputEnc) {
- var outData = this._final() || new Buffer('')
+ var outData = this.__final() || Buffer.alloc(0)
if (outputEnc) {
outData = this._toString(outData, outputEnc, true)
}
@@ -79,12 +85,15 @@ CipherBase.prototype._toString = function (value, enc, fin) {
this._decoder = new StringDecoder(enc)
this._encoding = enc
}
- if (this._encoding !== enc) {
- throw new Error('can\'t switch encodings')
- }
+
+ if (this._encoding !== enc) throw new Error('can\'t switch encodings')
+
var out = this._decoder.write(value)
if (fin) {
out += this._decoder.end()
}
+
return out
}
+
+module.exports = CipherBase