crypto: Streaming interface for Sign and Verify
authorisaacs <i@izs.me>
Tue, 30 Oct 2012 17:18:55 +0000 (10:18 -0700)
committerisaacs <i@izs.me>
Fri, 14 Dec 2012 18:52:27 +0000 (10:52 -0800)
lib/crypto.js

index e6b0396..0033267 100644 (file)
@@ -340,16 +340,23 @@ 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.update = Hash.prototype.update;
+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;
@@ -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);
+}
 
-Verify.prototype.update = Hash.prototype.update;
+util.inherits(Verify, stream.Writable);
 
+Verify.prototype._write = Sign.prototype._write;
+Verify.prototype.update = Sign.prototype.update;
 
 Verify.prototype.verify = function(object, signature, sigEncoding) {
   sigEncoding = sigEncoding || exports.DEFAULT_ENCODING;