diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/hash-base/README.md | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
Diffstat (limited to 'node_modules/hash-base/README.md')
-rw-r--r-- | node_modules/hash-base/README.md | 18 |
1 files changed, 14 insertions, 4 deletions
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] |