|
|
@ -37,6 +37,9 @@ try { |
|
|
|
var crypto = false; |
|
|
|
} |
|
|
|
|
|
|
|
var stream = require('stream'); |
|
|
|
var util = require('util'); |
|
|
|
|
|
|
|
// This is here because many functions accepted binary strings without
|
|
|
|
// any explicit encoding in older versions of node, and we don't want
|
|
|
|
// to break them unnecessarily.
|
|
|
@ -148,12 +151,24 @@ exports.createCredentials = function(options, context) { |
|
|
|
|
|
|
|
|
|
|
|
exports.createHash = exports.Hash = Hash; |
|
|
|
function Hash(algorithm) { |
|
|
|
function Hash(algorithm, options) { |
|
|
|
if (!(this instanceof Hash)) |
|
|
|
return new Hash(algorithm); |
|
|
|
this._binding = new binding.Hash(algorithm); |
|
|
|
stream.Transform.call(this, options); |
|
|
|
} |
|
|
|
|
|
|
|
util.inherits(Hash, stream.Transform); |
|
|
|
|
|
|
|
Hash.prototype._transform = function(chunk, output, callback) { |
|
|
|
this._binding.update(chunk); |
|
|
|
callback(); |
|
|
|
}; |
|
|
|
|
|
|
|
Hash.prototype._flush = function(output, callback) { |
|
|
|
output(this._binding.digest()); |
|
|
|
callback(); |
|
|
|
}; |
|
|
|
|
|
|
|
Hash.prototype.update = function(data, encoding) { |
|
|
|
encoding = encoding || exports.DEFAULT_ENCODING; |
|
|
|