Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80542 views
1
var Transform = require('stream').Transform
2
var inherits = require('inherits')
3
4
module.exports = CipherBase
5
inherits(CipherBase, Transform)
6
function CipherBase () {
7
Transform.call(this)
8
}
9
CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
10
if (typeof data === 'string') {
11
data = new Buffer(data, inputEnc)
12
}
13
var outData = this._update(data)
14
if (outputEnc) {
15
outData = outData.toString(outputEnc)
16
}
17
return outData
18
}
19
CipherBase.prototype._transform = function (data, _, next) {
20
this.push(this._update(data))
21
next()
22
}
23
CipherBase.prototype._flush = function (next) {
24
try {
25
this.push(this._final())
26
} catch(e) {
27
return next(e)
28
}
29
next()
30
}
31
CipherBase.prototype.final = function (outputEnc) {
32
var outData = this._final() || new Buffer('')
33
if (outputEnc) {
34
outData = outData.toString(outputEnc)
35
}
36
return outData
37
}
38
39