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 | var chunk = this._final();
|
25 | if (chunk) {
|
26 | this.push(chunk);
|
27 | }
|
28 | next();
|
29 | };
|
30 | CipherBase.prototype.final = function (outputEnc) {
|
31 | var outData = this._final() || new Buffer('');
|
32 | if (outputEnc) {
|
33 | outData = outData.toString(outputEnc);
|
34 | }
|
35 | return outData;
|
36 | }; |
\ | No newline at end of file |