crypto: Streaming interface for Sign and Verify

This commit is contained in:
isaacs 2012-10-30 10:18:55 -07:00
parent e336134658
commit dd3ebb8cf6

View File

@ -340,17 +340,24 @@ Decipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
exports.createSign = exports.Sign = Sign;
function Sign(algorithm) {
function Sign(algorithm, options) {
if (!(this instanceof Sign))
return new Sign(algorithm);
this._binding = new binding.Sign();
this._binding.init(algorithm);
stream.Writable.call(this, options);
}
util.inherits(Sign, stream.Writable);
Sign.prototype._write = function(chunk, callback) {
this._binding.update(chunk);
callback();
};
Sign.prototype.update = Hash.prototype.update;
Sign.prototype.sign = function(key, encoding) {
encoding = encoding || exports.DEFAULT_ENCODING;
var ret = this._binding.sign(toBuf(key));
@ -364,17 +371,20 @@ Sign.prototype.sign = function(key, encoding) {
exports.createVerify = exports.Verify = Verify;
function Verify(algorithm) {
function Verify(algorithm, options) {
if (!(this instanceof Verify))
return new Verify(algorithm);
this._binding = new binding.Verify;
this._binding.init(algorithm);
stream.Writable.call(this, options);
}
util.inherits(Verify, stream.Writable);
Verify.prototype.update = Hash.prototype.update;
Verify.prototype._write = Sign.prototype._write;
Verify.prototype.update = Sign.prototype.update;
Verify.prototype.verify = function(object, signature, sigEncoding) {
sigEncoding = sigEncoding || exports.DEFAULT_ENCODING;