initial commit
This commit is contained in:
21
node_modules/hash-base/LICENSE
generated
vendored
Normal file
21
node_modules/hash-base/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Kirill Fomichev
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
48
node_modules/hash-base/README.md
generated
vendored
Normal file
48
node_modules/hash-base/README.md
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
# hash-base
|
||||
|
||||
[](https://www.npmjs.org/package/hash-base)
|
||||
[](https://travis-ci.org/crypto-browserify/hash-base)
|
||||
[](https://david-dm.org/crypto-browserify/hash-base#info=dependencies)
|
||||
|
||||
Abstract base class to inherit from if you want to create streams implementing the same API as node crypto [Hash][1] (for [Cipher][2] / [Decipher][3] check [crypto-browserify/cipher-base][4]).
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
const HashBase = require('hash-base');
|
||||
const inherits = require('inherits');
|
||||
|
||||
// our hash function is XOR sum of all bytes
|
||||
function MyHash () {
|
||||
HashBase.call(this, 1); // in bytes
|
||||
|
||||
this._sum = 0x00;
|
||||
};
|
||||
|
||||
inherits(MyHash, HashBase)
|
||||
|
||||
MyHash.prototype._update = function () {
|
||||
for (let i = 0; i < this._block.length; ++i) {
|
||||
this._sum ^= this._block[i];
|
||||
}
|
||||
};
|
||||
|
||||
MyHash.prototype._digest = function () {
|
||||
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]
|
||||
|
||||
## LICENSE
|
||||
|
||||
MIT
|
||||
|
||||
[1]: https://nodejs.org/api/crypto.html#crypto_class_hash
|
||||
[2]: https://nodejs.org/api/crypto.html#crypto_class_cipher
|
||||
[3]: https://nodejs.org/api/crypto.html#crypto_class_decipher
|
||||
[4]: https://github.com/crypto-browserify/cipher-base
|
||||
[5]: https://github.com/crypto-browserify/md5.js
|
||||
138
node_modules/hash-base/index.js
generated
vendored
Normal file
138
node_modules/hash-base/index.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
'use strict'
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var Transform = require('stream').Transform
|
||||
var inherits = require('inherits')
|
||||
|
||||
function HashBase (blockSize) {
|
||||
Transform.call(this)
|
||||
|
||||
this._block = Buffer.allocUnsafe(blockSize)
|
||||
this._blockSize = blockSize
|
||||
this._blockOffset = 0
|
||||
this._length = [0, 0, 0, 0]
|
||||
|
||||
this._finalized = false
|
||||
}
|
||||
|
||||
inherits(HashBase, Transform)
|
||||
|
||||
HashBase.prototype._transform = function (chunk, encoding, callback) {
|
||||
var error = null
|
||||
try {
|
||||
this.update(chunk, encoding)
|
||||
} catch (err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
callback(error)
|
||||
}
|
||||
|
||||
HashBase.prototype._flush = function (callback) {
|
||||
var error = null
|
||||
try {
|
||||
this.push(this.digest())
|
||||
} catch (err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
callback(error)
|
||||
}
|
||||
|
||||
var useUint8Array = typeof Uint8Array !== 'undefined'
|
||||
var useArrayBuffer = typeof ArrayBuffer !== 'undefined' &&
|
||||
typeof Uint8Array !== 'undefined' &&
|
||||
ArrayBuffer.isView &&
|
||||
(Buffer.prototype instanceof Uint8Array || Buffer.TYPED_ARRAY_SUPPORT)
|
||||
|
||||
function toBuffer (data, encoding) {
|
||||
// No need to do anything for exact instance
|
||||
// This is only valid when safe-buffer.Buffer === buffer.Buffer, i.e. when Buffer.from/Buffer.alloc existed
|
||||
if (data instanceof Buffer) return data
|
||||
|
||||
// Convert strings to Buffer
|
||||
if (typeof data === 'string') return Buffer.from(data, encoding)
|
||||
|
||||
/*
|
||||
* Wrap any TypedArray instances and DataViews
|
||||
* Makes sense only on engines with full TypedArray support -- let Buffer detect that
|
||||
*/
|
||||
if (useArrayBuffer && ArrayBuffer.isView(data)) {
|
||||
if (data.byteLength === 0) return Buffer.alloc(0) // Bug in Node.js <6.3.1, which treats this as out-of-bounds
|
||||
var res = Buffer.from(data.buffer, data.byteOffset, data.byteLength)
|
||||
// Recheck result size, as offset/length doesn't work on Node.js <5.10
|
||||
// We just go to Uint8Array case if this fails
|
||||
if (res.byteLength === data.byteLength) return res
|
||||
}
|
||||
|
||||
/*
|
||||
* Uint8Array in engines where Buffer.from might not work with ArrayBuffer, just copy over
|
||||
* Doesn't make sense with other TypedArray instances
|
||||
*/
|
||||
if (useUint8Array && data instanceof Uint8Array) return Buffer.from(data)
|
||||
|
||||
/*
|
||||
* Old Buffer polyfill on an engine that doesn't have TypedArray support
|
||||
* Also, this is from a different Buffer polyfill implementation then we have, as instanceof check failed
|
||||
* Convert to our current Buffer implementation
|
||||
*/
|
||||
if (
|
||||
Buffer.isBuffer(data) &&
|
||||
data.constructor &&
|
||||
typeof data.constructor.isBuffer === 'function' &&
|
||||
data.constructor.isBuffer(data)
|
||||
) {
|
||||
return Buffer.from(data)
|
||||
}
|
||||
|
||||
throw new TypeError('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.')
|
||||
}
|
||||
|
||||
HashBase.prototype.update = function (data, encoding) {
|
||||
if (this._finalized) throw new Error('Digest already called')
|
||||
|
||||
data = toBuffer(data, encoding) // asserts correct input type
|
||||
|
||||
// consume data
|
||||
var block = this._block
|
||||
var offset = 0
|
||||
while (this._blockOffset + data.length - offset >= this._blockSize) {
|
||||
for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]
|
||||
this._update()
|
||||
this._blockOffset = 0
|
||||
}
|
||||
while (offset < data.length) block[this._blockOffset++] = data[offset++]
|
||||
|
||||
// update length
|
||||
for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
|
||||
this._length[j] += carry
|
||||
carry = (this._length[j] / 0x0100000000) | 0
|
||||
if (carry > 0) this._length[j] -= 0x0100000000 * carry
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
HashBase.prototype._update = function () {
|
||||
throw new Error('_update is not implemented')
|
||||
}
|
||||
|
||||
HashBase.prototype.digest = function (encoding) {
|
||||
if (this._finalized) throw new Error('Digest already called')
|
||||
this._finalized = true
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
HashBase.prototype._digest = function () {
|
||||
throw new Error('_digest is not implemented')
|
||||
}
|
||||
|
||||
module.exports = HashBase
|
||||
42
node_modules/hash-base/package.json
generated
vendored
Normal file
42
node_modules/hash-base/package.json
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "hash-base",
|
||||
"version": "3.0.5",
|
||||
"description": "abstract base class for hash-streams",
|
||||
"keywords": [
|
||||
"hash",
|
||||
"stream"
|
||||
],
|
||||
"homepage": "https://github.com/crypto-browserify/hash-base",
|
||||
"bugs": {
|
||||
"url": "https://github.com/crypto-browserify/hash-base/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "Kirill Fomichev <fanatid@ya.ru> (https://github.com/fanatid)",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/crypto-browserify/hash-base.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "standard",
|
||||
"pretest": "npm run lint",
|
||||
"test": "npm run tests-only",
|
||||
"tests-only": "nyc tape 'test/**/*.js'",
|
||||
"posttest": "npx npm@'>=10.2' audit --production"
|
||||
},
|
||||
"dependencies": {
|
||||
"inherits": "^2.0.4",
|
||||
"safe-buffer": "^5.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nyc": "^10.3.2",
|
||||
"standard": "^14.3.3",
|
||||
"tape": "^5.9.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user