From bbff7403fbf46f9ad92240ac213df8d30ef31b64 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Sep 2018 02:56:13 +0200 Subject: update packages --- node_modules/hash-base/README.md | 18 ++++++++++++++---- node_modules/hash-base/index.js | 26 +++++++++++++++++++------- node_modules/hash-base/package.json | 12 ++++++++---- 3 files changed, 41 insertions(+), 15 deletions(-) (limited to 'node_modules/hash-base') diff --git a/node_modules/hash-base/README.md b/node_modules/hash-base/README.md index 2fa8f1d23..83ae2edcc 100644 --- a/node_modules/hash-base/README.md +++ b/node_modules/hash-base/README.md @@ -11,19 +11,29 @@ Abstract base class to inherit from if you want to create streams implementing t ## Example ```js +const HashBase = require('hash-base') +const inherits = require('inherits') + +// our hash function is XOR sum of all bytes function MyHash () { - HashBase.call(64) // in bytes + HashBase.call(this, 1) // in bytes + + this._sum = 0x00 } -inherti(MyHash, HashBase) +inherits(MyHash, HashBase) MyHash.prototype._update = function () { - // hashing one block with buffer this._block + for (let i = 0; i < this._block.length; ++i) this._sum ^= this._block[i] } MyHash.prototype._digest = function () { - // create padding and produce result + return this._sum } + +const data = Buffer.from([ 0x00, 0x42, 0x01 ]) +const hash = new MyHash().update(data).digest() +console.log(hash) // => 67 ``` You also can check [source code](index.js) or [crypto-browserify/md5.js][5] diff --git a/node_modules/hash-base/index.js b/node_modules/hash-base/index.js index 9cd6a7005..bf788daa4 100644 --- a/node_modules/hash-base/index.js +++ b/node_modules/hash-base/index.js @@ -1,11 +1,18 @@ 'use strict' +var Buffer = require('safe-buffer').Buffer var Transform = require('stream').Transform var inherits = require('inherits') +function throwIfNotStringOrBuffer (val, prefix) { + if (!Buffer.isBuffer(val) && typeof val !== 'string') { + throw new TypeError(prefix + ' must be a string or a buffer') + } +} + function HashBase (blockSize) { Transform.call(this) - this._block = new Buffer(blockSize) + this._block = Buffer.allocUnsafe(blockSize) this._blockSize = blockSize this._blockOffset = 0 this._length = [0, 0, 0, 0] @@ -18,8 +25,7 @@ inherits(HashBase, Transform) HashBase.prototype._transform = function (chunk, encoding, callback) { var error = null try { - if (encoding !== 'buffer') chunk = new Buffer(chunk, encoding) - this.update(chunk) + this.update(chunk, encoding) } catch (err) { error = err } @@ -30,7 +36,7 @@ HashBase.prototype._transform = function (chunk, encoding, callback) { HashBase.prototype._flush = function (callback) { var error = null try { - this.push(this._digest()) + this.push(this.digest()) } catch (err) { error = err } @@ -39,9 +45,9 @@ HashBase.prototype._flush = function (callback) { } HashBase.prototype.update = function (data, encoding) { - if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer') + throwIfNotStringOrBuffer(data, 'Data') if (this._finalized) throw new Error('Digest already called') - if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding || 'binary') + if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding) // consume data var block = this._block @@ -63,7 +69,7 @@ HashBase.prototype.update = function (data, encoding) { return this } -HashBase.prototype._update = function (data) { +HashBase.prototype._update = function () { throw new Error('_update is not implemented') } @@ -73,6 +79,12 @@ HashBase.prototype.digest = function (encoding) { var digest = this._digest() if (encoding !== undefined) digest = digest.toString(encoding) + + // reset state + this._block.fill(0) + this._blockOffset = 0 + for (var i = 0; i < 4; ++i) this._length[i] = 0 + return digest } diff --git a/node_modules/hash-base/package.json b/node_modules/hash-base/package.json index 3f009c6c2..0edf37d02 100644 --- a/node_modules/hash-base/package.json +++ b/node_modules/hash-base/package.json @@ -1,6 +1,6 @@ { "name": "hash-base", - "version": "2.0.2", + "version": "3.0.4", "description": "abstract base class for hash-streams", "keywords": [ "hash", @@ -27,11 +27,15 @@ "unit": "node test/*.js" }, "dependencies": { - "inherits": "^2.0.1" + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" }, "devDependencies": { - "nyc": "^6.1.1", - "standard": "^6.0.8", + "nyc": "^8.3.2", + "standard": "*", "tape": "^4.2.0" + }, + "engines": { + "node": ">=4" } } -- cgit v1.2.3