create-hash
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -7,6 +7,6 @@ 'use strict'; | ||
var Transform = require('stream').Transform | ||
var Base = require('cipher-base') | ||
function HashNoConstructor(hash) { | ||
Transform.call(this) | ||
Base.call(this, 'digest') | ||
@@ -17,25 +17,9 @@ this._hash = hash | ||
inherits(HashNoConstructor, Transform) | ||
inherits(HashNoConstructor, Base) | ||
HashNoConstructor.prototype._transform = function (data, _, next) { | ||
HashNoConstructor.prototype._update = function (data) { | ||
this.buffers.push(data) | ||
next() | ||
} | ||
HashNoConstructor.prototype._flush = function (next) { | ||
this.push(this.digest()) | ||
next() | ||
} | ||
HashNoConstructor.prototype.update = function (data, enc) { | ||
if (typeof data === 'string') { | ||
data = new Buffer(data, enc) | ||
} | ||
this.buffers.push(data) | ||
return this | ||
} | ||
HashNoConstructor.prototype.digest = function (enc) { | ||
HashNoConstructor.prototype._final = function () { | ||
var buf = Buffer.concat(this.buffers) | ||
@@ -45,7 +29,7 @@ var r = this._hash(buf) | ||
return enc ? r.toString(enc) : r | ||
return r | ||
} | ||
function Hash(hash) { | ||
Transform.call(this) | ||
Base.call(this, 'digest') | ||
@@ -55,39 +39,18 @@ this._hash = hash | ||
inherits(Hash, Transform) | ||
inherits(Hash, Base) | ||
Hash.prototype._transform = function (data, enc, next) { | ||
if (enc) data = new Buffer(data, enc) | ||
Hash.prototype._update = function (data) { | ||
this._hash.update(data) | ||
next() | ||
} | ||
Hash.prototype._flush = function (next) { | ||
this.push(this._hash.digest()) | ||
this._hash = null | ||
next() | ||
Hash.prototype._final = function () { | ||
return this._hash.digest() | ||
} | ||
Hash.prototype.update = function (data, enc) { | ||
if (typeof data === 'string') { | ||
data = new Buffer(data, enc) | ||
} | ||
this._hash.update(data) | ||
return this | ||
} | ||
Hash.prototype.digest = function (enc) { | ||
var outData = this._hash.digest() | ||
return enc ? outData.toString(enc) : outData | ||
} | ||
module.exports = function createHash (alg) { | ||
alg = alg.toLowerCase() | ||
if ('md5' === alg) return new HashNoConstructor(md5) | ||
if ('rmd160' === alg) return new HashNoConstructor(rmd160) | ||
if ('rmd160' === alg || 'ripemd160' === alg) return new HashNoConstructor(rmd160) | ||
return new Hash(sha(alg)) | ||
} |
{ | ||
"name": "create-hash", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "create hashes for browserify", | ||
@@ -29,2 +29,3 @@ "browser": "browser.js", | ||
"dependencies": { | ||
"cipher-base": "^1.0.1", | ||
"inherits": "^2.0.1", | ||
@@ -31,0 +32,0 @@ "ripemd160": "^1.0.0", |
var fs = require('fs') | ||
var test = require('tape') | ||
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'] | ||
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160', 'ripemd160'] | ||
var encodings = [/*'binary',*/ 'hex', 'base64']; | ||
var vectors = require('hash-test-vectors') | ||
vectors.forEach(function (vector) { | ||
vector.ripemd160 = vector.rmd160 | ||
}) | ||
var createHash = require('./browser') | ||
@@ -9,0 +11,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
10393
4
244
+ Addedcipher-base@^1.0.1
+ Addedcipher-base@1.0.6(transitive)