create-hmac
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -8,8 +8,9 @@ 'use strict'; | ||
module.exports = Hmac | ||
module.exports = function createHmac(alg, key) { | ||
return new Hmac(alg, key) | ||
} | ||
inherits(Hmac, Transform) | ||
function Hmac (alg, key) { | ||
if(!(this instanceof Hmac)) return new Hmac(alg, key) | ||
Transform.call(this) | ||
Transform.call(this); | ||
this._opad = opad | ||
@@ -20,3 +21,3 @@ this._alg = alg | ||
key = this._key = !Buffer.isBuffer(key) ? new Buffer(key) : key | ||
key = this._key = (typeof key === 'string') ? new Buffer(key) : key | ||
@@ -41,7 +42,13 @@ if(key.length > blocksize) { | ||
Hmac.prototype.update = function (data, enc) { | ||
this.write(data, enc) | ||
if (typeof data === 'string') { | ||
data = new Buffer(data, enc) | ||
} | ||
this._hash.update(data) | ||
return this | ||
} | ||
Hmac.prototype._transform = function (data, _, next) { | ||
Hmac.prototype._transform = function (data, enc, next) { | ||
if (enc) { | ||
data = new Buffer(data, enc) | ||
} | ||
this._hash.update(data) | ||
@@ -52,4 +59,3 @@ next() | ||
Hmac.prototype._flush = function (next) { | ||
var h = this._hash.digest() | ||
this.push(createHash(this._alg).update(this._opad).update(h).digest()) | ||
this.push(this.digest()) | ||
next() | ||
@@ -59,8 +65,4 @@ } | ||
Hmac.prototype.digest = function (enc) { | ||
this.end() | ||
var outData = new Buffer('') | ||
var chunk | ||
while ((chunk = this.read())) { | ||
outData = Buffer.concat([outData, chunk]) | ||
} | ||
var h = this._hash.digest() | ||
var outData = createHash(this._alg).update(this._opad).update(h).digest(); | ||
if (enc) { | ||
@@ -67,0 +69,0 @@ outData = outData.toString(enc) |
{ | ||
"name": "create-hmac", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "node style hmacs in the browser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4074
80