crypto: Pass encodings for Hmac digest

This commit is contained in:
isaacs 2013-05-02 18:38:04 -07:00
parent c1e8c8de1c
commit a241deb19a
2 changed files with 9 additions and 6 deletions

View File

@ -213,10 +213,7 @@ Hash.prototype.update = function(data, encoding) {
Hash.prototype.digest = function(outputEncoding) {
outputEncoding = outputEncoding || exports.DEFAULT_ENCODING;
var ret = this._binding.digest(outputEncoding);
if (outputEncoding !== 'buffer' && Buffer.isBuffer(ret))
ret = ret.toString(outputEncoding);
return ret;
return this._binding.digest(outputEncoding);
};

View File

@ -2761,6 +2761,11 @@ class Hmac : public ObjectWrap {
HandleScope scope;
enum encoding encoding = BUFFER;
if (args.Length() >= 1) {
encoding = ParseEncoding(args[0]->ToString(), BUFFER);
}
unsigned char* md_value = NULL;
unsigned int md_len = 0;
Local<Value> outString;
@ -2771,9 +2776,10 @@ class Hmac : public ObjectWrap {
md_len = 0;
}
outString = Encode(md_value, md_len, BUFFER);
outString = StringBytes::Encode(
reinterpret_cast<const char*>(md_value), md_len, encoding);
delete [] md_value;
delete[] md_value;
return scope.Close(outString);
}