crypto: Streaming interface for cipher/decipher/iv
This commit is contained in:
parent
175f78c6ba
commit
e336134658
@ -213,15 +213,28 @@ function getDecoder(decoder, encoding) {
|
|||||||
|
|
||||||
|
|
||||||
exports.createCipher = exports.Cipher = Cipher;
|
exports.createCipher = exports.Cipher = Cipher;
|
||||||
function Cipher(cipher, password) {
|
function Cipher(cipher, password, options) {
|
||||||
if (!(this instanceof Cipher))
|
if (!(this instanceof Cipher))
|
||||||
return new Cipher(cipher, password);
|
return new Cipher(cipher, password);
|
||||||
this._binding = new binding.Cipher;
|
this._binding = new binding.Cipher;
|
||||||
|
|
||||||
this._binding.init(cipher, toBuf(password));
|
this._binding.init(cipher, toBuf(password));
|
||||||
this._decoder = null;
|
this._decoder = null;
|
||||||
|
|
||||||
|
stream.Transform.call(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util.inherits(Cipher, stream.Transform);
|
||||||
|
|
||||||
|
Cipher.prototype._transform = function(chunk, output, callback) {
|
||||||
|
output(this._binding.update(chunk));
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
|
Cipher.prototype._flush = function(output, callback) {
|
||||||
|
output(this._binding.final());
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
Cipher.prototype.update = function(data, inputEncoding, outputEncoding) {
|
Cipher.prototype.update = function(data, inputEncoding, outputEncoding) {
|
||||||
inputEncoding = inputEncoding || exports.DEFAULT_ENCODING;
|
inputEncoding = inputEncoding || exports.DEFAULT_ENCODING;
|
||||||
@ -260,15 +273,20 @@ Cipher.prototype.setAutoPadding = function(ap) {
|
|||||||
|
|
||||||
|
|
||||||
exports.createCipheriv = exports.Cipheriv = Cipheriv;
|
exports.createCipheriv = exports.Cipheriv = Cipheriv;
|
||||||
function Cipheriv(cipher, key, iv) {
|
function Cipheriv(cipher, key, iv, options) {
|
||||||
if (!(this instanceof Cipheriv))
|
if (!(this instanceof Cipheriv))
|
||||||
return new Cipheriv(cipher, key, iv);
|
return new Cipheriv(cipher, key, iv);
|
||||||
this._binding = new binding.Cipher();
|
this._binding = new binding.Cipher();
|
||||||
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
|
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
|
||||||
this._decoder = null;
|
this._decoder = null;
|
||||||
|
|
||||||
|
stream.Transform.call(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util.inherits(Cipheriv, stream.Transform);
|
||||||
|
|
||||||
|
Cipheriv.prototype._transform = Cipher.prototype._transform;
|
||||||
|
Cipheriv.prototype._flush = Cipher.prototype._flush;
|
||||||
Cipheriv.prototype.update = Cipher.prototype.update;
|
Cipheriv.prototype.update = Cipher.prototype.update;
|
||||||
Cipheriv.prototype.final = Cipher.prototype.final;
|
Cipheriv.prototype.final = Cipher.prototype.final;
|
||||||
Cipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
|
Cipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
|
||||||
@ -276,16 +294,21 @@ Cipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
|
|||||||
|
|
||||||
|
|
||||||
exports.createDecipher = exports.Decipher = Decipher;
|
exports.createDecipher = exports.Decipher = Decipher;
|
||||||
function Decipher(cipher, password) {
|
function Decipher(cipher, password, options) {
|
||||||
if (!(this instanceof Decipher))
|
if (!(this instanceof Decipher))
|
||||||
return new Decipher(cipher, password);
|
return new Decipher(cipher, password);
|
||||||
|
|
||||||
this._binding = new binding.Decipher;
|
this._binding = new binding.Decipher;
|
||||||
this._binding.init(cipher, toBuf(password));
|
this._binding.init(cipher, toBuf(password));
|
||||||
this._decoder = null;
|
this._decoder = null;
|
||||||
|
|
||||||
|
stream.Transform.call(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util.inherits(Decipher, stream.Transform);
|
||||||
|
|
||||||
|
Decipher.prototype._transform = Cipher.prototype._transform;
|
||||||
|
Decipher.prototype._flush = Cipher.prototype._flush;
|
||||||
Decipher.prototype.update = Cipher.prototype.update;
|
Decipher.prototype.update = Cipher.prototype.update;
|
||||||
Decipher.prototype.final = Cipher.prototype.final;
|
Decipher.prototype.final = Cipher.prototype.final;
|
||||||
Decipher.prototype.finaltol = Cipher.prototype.final;
|
Decipher.prototype.finaltol = Cipher.prototype.final;
|
||||||
@ -294,16 +317,21 @@ Decipher.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
|
|||||||
|
|
||||||
|
|
||||||
exports.createDecipheriv = exports.Decipheriv = Decipheriv;
|
exports.createDecipheriv = exports.Decipheriv = Decipheriv;
|
||||||
function Decipheriv(cipher, key, iv) {
|
function Decipheriv(cipher, key, iv, options) {
|
||||||
if (!(this instanceof Decipheriv))
|
if (!(this instanceof Decipheriv))
|
||||||
return new Decipheriv(cipher, key, iv);
|
return new Decipheriv(cipher, key, iv);
|
||||||
|
|
||||||
this._binding = new binding.Decipher;
|
this._binding = new binding.Decipher;
|
||||||
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
|
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
|
||||||
this._decoder = null;
|
this._decoder = null;
|
||||||
|
|
||||||
|
stream.Transform.call(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util.inherits(Decipheriv, stream.Transform);
|
||||||
|
|
||||||
|
Decipheriv.prototype._transform = Cipher.prototype._transform;
|
||||||
|
Decipheriv.prototype._flush = Cipher.prototype._flush;
|
||||||
Decipheriv.prototype.update = Cipher.prototype.update;
|
Decipheriv.prototype.update = Cipher.prototype.update;
|
||||||
Decipheriv.prototype.final = Cipher.prototype.final;
|
Decipheriv.prototype.final = Cipher.prototype.final;
|
||||||
Decipheriv.prototype.finaltol = Cipher.prototype.final;
|
Decipheriv.prototype.finaltol = Cipher.prototype.final;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user