pax_global_header00006660000000000000000000000064150643563370014526gustar00rootroot0000000000000052 comment=e6638b8e757ce1f140fb0c38a3deb18f8bfc7018 hash-base-3.1.2/000077500000000000000000000000001506435633700133645ustar00rootroot00000000000000hash-base-3.1.2/.eslintrc000066400000000000000000000003651506435633700152140ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "globals": { "Uint8Array": "readonly", "Uint16Array": "readonly", }, "rules": { "array-bracket-newline": "off", "func-style": ["error", "declaration"], "no-underscore-dangle": "off", }, } hash-base-3.1.2/.github/000077500000000000000000000000001506435633700147245ustar00rootroot00000000000000hash-base-3.1.2/.github/FUNDING.yml000066400000000000000000000011041506435633700165350ustar00rootroot00000000000000# These are supported funding model platforms github: [ljharb] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: npm/hash-base community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] hash-base-3.1.2/.github/workflows/000077500000000000000000000000001506435633700167615ustar00rootroot00000000000000hash-base-3.1.2/.github/workflows/node-aught.yml000066400000000000000000000003251506435633700215370ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '0.8 - 9' type: minors command: npm run tests-only hash-base-3.1.2/.github/workflows/node-pretest.yml000066400000000000000000000002061506435633700221130ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main hash-base-3.1.2/.github/workflows/node-tens.yml000066400000000000000000000003241506435633700213770ustar00rootroot00000000000000name: 'Tests: node.js >= 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 10' type: minors command: npm run tests-only hash-base-3.1.2/.github/workflows/node-twenties.yml000066400000000000000000000003631506435633700222730ustar00rootroot00000000000000name: 'Tests: node.js >= 20' on: [pull_request, push] permissions: contents: read jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 20' type: minors command: npm run tests-only hash-base-3.1.2/.github/workflows/rebase.yml000066400000000000000000000007001506435633700207420ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] permissions: contents: read jobs: _: permissions: contents: write # for ljharb/rebase to push code to rebase pull-requests: read # for ljharb/rebase to get info about PR name: "Automatic Rebase" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ljharb/rebase@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} hash-base-3.1.2/.github/workflows/require-allow-edits.yml000066400000000000000000000003031506435633700233760ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main hash-base-3.1.2/.gitignore000066400000000000000000000002201506435633700153460ustar00rootroot00000000000000.nyc_output coverage node_modules npm-debug.log # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock .npmignore hash-base-3.1.2/.npmrc000066400000000000000000000000671506435633700145070ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s hash-base-3.1.2/.nycrc000066400000000000000000000002131506435633700144770ustar00rootroot00000000000000{ "all": true, "check-coverage": false, "reporter": ["text-summary", "text", "html", "json"], "exclude": [ "coverage", "test" ] } hash-base-3.1.2/CHANGELOG.md000066400000000000000000000262411506435633700152020ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [v3.1.2](https://github.com/browserify/hash-base/compare/v3.1.1...v3.1.2) - 2025-09-22 ### Commits - [fix] package already works in node 0.8 [`1c19201`](https://github.com/browserify/hash-base/commit/1c1920112ef4baa65085b08ada90b4d0a83b69f2) - [Dev Deps] add missing peer dep [`7ac34b6`](https://github.com/browserify/hash-base/commit/7ac34b6011fb02b7a8261ee35f01fe8828218dda) ## [v3.1.1](https://github.com/browserify/hash-base/compare/v3.1.0...v3.1.1) - 2025-09-22 ### Commits - [eslint] switch to eslint [`d63bf3b`](https://github.com/browserify/hash-base/commit/d63bf3b65c911e0de091918b7d331c6cf413567e) - [meta] add `auto-changelog` [`b2c7408`](https://github.com/browserify/hash-base/commit/b2c74084f744d090a1c59d2f8326a639409281f2) - [Tests] avoid tape-mutating beforeEach nonsense [`bb1f9b6`](https://github.com/browserify/hash-base/commit/bb1f9b6492acd97fd02acca575dcb334888b6fbb) - [Tests] avoid tape-mutating beforeEach nonsense [`ae228cd`](https://github.com/browserify/hash-base/commit/ae228cd0e9421fcca4c7e9e41b5451fa7ad74c73) - [readme] clean up formatting [`fd5cb3d`](https://github.com/browserify/hash-base/commit/fd5cb3d73a9be7617b6af647dd775ede7f5dab24) - [readme] clean up formatting [`a13ed61`](https://github.com/browserify/hash-base/commit/a13ed61331879e342435e71569a49061fdf1889c) - [Tests] migrate from travis to GHA [`9e2c04c`](https://github.com/browserify/hash-base/commit/9e2c04c435c25363fbe1f1fea8b32390f3f623b7) - [Tests] migrate from travis to GHA [`31766d4`](https://github.com/browserify/hash-base/commit/31766d413a21e534c96e6e562174f74b3d0368ca) - [Fix] return valid values on multi-byte-wide TypedArray input [`1af18ee`](https://github.com/browserify/hash-base/commit/1af18ee40d747bc177fba2cb89b4e937e3bd0724) - [Refactor] use `to-buffer` [`41d738b`](https://github.com/browserify/hash-base/commit/41d738bca2c5fa97c09bed9cdc7b2f3d8f1f9958) - [Dev Deps] update `tape`, downgrade `nyc`, clean up scripts [`13d373c`](https://github.com/browserify/hash-base/commit/13d373c1b06ed0a20db0fe158def49a7abf6a85b) - [Dev Deps] update `tape`, downgrade `nyc`, clean up scripts [`84f4fab`](https://github.com/browserify/hash-base/commit/84f4fab691c35591f44b1781311de10fc6f76b16) - [meta] use `npmignore` [`ecdd9a3`](https://github.com/browserify/hash-base/commit/ecdd9a312e26f81d6a84256d8bcdbf4427f84490) - Merge tag 'v3.0.5' [`d59c766`](https://github.com/browserify/hash-base/commit/d59c766986d962868457d05299fe111323dedd6f) - Only apps should have lockfiles [`de3ce83`](https://github.com/browserify/hash-base/commit/de3ce831c7f61a2ca3448f639d7b8ebe6b7b27ab) - Only apps should have lockfiles [`05b7504`](https://github.com/browserify/hash-base/commit/05b7504d4038fdf380e5c3227ee0719df12f5bda) - [Deps] update `inherits`, `safe-buffer` [`2b8687d`](https://github.com/browserify/hash-base/commit/2b8687d89f8e9de6c21bc277b147e76507ba74a6) - [Deps] update `safe-buffer`; downgrade `readable-stream` [`523da5d`](https://github.com/browserify/hash-base/commit/523da5dbfcef879a5c6967978cd4d39946f20c5a) - [Tests] clean up linting [`4274b7c`](https://github.com/browserify/hash-base/commit/4274b7cc9608712652e56091efcf5c66151be418) - [Tests] in node 0.10, Buffer `.fill` returns `undefined` [`0fdfd67`](https://github.com/browserify/hash-base/commit/0fdfd676fc51987e5d93f17858cc0f740b56b6af) - [Tests] in node 0.10, Buffer `.fill` returns `undefined` [`5d1f911`](https://github.com/browserify/hash-base/commit/5d1f91153a0c8365e970e0f9a4fde2fd901bb446) - [Fix] restore `engines.node` from 3.0.0 [`8cbfd12`](https://github.com/browserify/hash-base/commit/8cbfd123b307d51b6588718baa2c343dddf13fa4) - [Fix] restore `engines.node` from 3.0.0 [`b99d8a1`](https://github.com/browserify/hash-base/commit/b99d8a1ce428683c93ac005ea01e48f77ce005db) - [Tests] use `safe-buffer` in tests, too [`84bdfe9`](https://github.com/browserify/hash-base/commit/84bdfe944f46edbcaffed7b48567faf460f13bb8) - [Tests] use `safe-buffer` in tests, too [`9182f82`](https://github.com/browserify/hash-base/commit/9182f823b7f365189116a4582fa906f8fb008ab6) ## [v3.1.0](https://github.com/browserify/hash-base/compare/v3.0.5...v3.1.0) - 2020-05-01 ### Merged - Update deps, add readable-stream [`#14`](https://github.com/browserify/hash-base/pull/14) ## [v3.0.5](https://github.com/browserify/hash-base/compare/v3.0.4...v3.0.5) - 2024-11-23 ### Commits - [Tests] avoid tape-mutating beforeEach nonsense [`ae228cd`](https://github.com/browserify/hash-base/commit/ae228cd0e9421fcca4c7e9e41b5451fa7ad74c73) - [readme] clean up formatting [`a13ed61`](https://github.com/browserify/hash-base/commit/a13ed61331879e342435e71569a49061fdf1889c) - [Tests] migrate from travis to GHA [`31766d4`](https://github.com/browserify/hash-base/commit/31766d413a21e534c96e6e562174f74b3d0368ca) - [Fix] return valid values on multi-byte-wide TypedArray input [`1af18ee`](https://github.com/browserify/hash-base/commit/1af18ee40d747bc177fba2cb89b4e937e3bd0724) - [Dev Deps] update `tape`, downgrade `nyc`, clean up scripts [`13d373c`](https://github.com/browserify/hash-base/commit/13d373c1b06ed0a20db0fe158def49a7abf6a85b) - Only apps should have lockfiles [`de3ce83`](https://github.com/browserify/hash-base/commit/de3ce831c7f61a2ca3448f639d7b8ebe6b7b27ab) - [Deps] update `inherits`, `safe-buffer` [`2b8687d`](https://github.com/browserify/hash-base/commit/2b8687d89f8e9de6c21bc277b147e76507ba74a6) - [Tests] clean up linting [`4274b7c`](https://github.com/browserify/hash-base/commit/4274b7cc9608712652e56091efcf5c66151be418) - [Tests] in node 0.10, Buffer `.fill` returns `undefined` [`5d1f911`](https://github.com/browserify/hash-base/commit/5d1f91153a0c8365e970e0f9a4fde2fd901bb446) - [Fix] restore `engines.node` from 3.0.0 [`8cbfd12`](https://github.com/browserify/hash-base/commit/8cbfd123b307d51b6588718baa2c343dddf13fa4) - [Tests] use `safe-buffer` in tests, too [`9182f82`](https://github.com/browserify/hash-base/commit/9182f823b7f365189116a4582fa906f8fb008ab6) ## [v3.0.4](https://github.com/browserify/hash-base/compare/v3.0.3...v3.0.4) - 2017-05-24 ### Merged - use safe-buffer [`#12`](https://github.com/browserify/hash-base/pull/12) - Only Node v4 or greater [Buffer only] [`#11`](https://github.com/browserify/hash-base/pull/11) - Reset state after #_digest [`#10`](https://github.com/browserify/hash-base/pull/10) ### Commits - Improve tests [`b20d350`](https://github.com/browserify/hash-base/commit/b20d3509f1d3b79f68bd9cd330938ca6472b9aa5) - Only Node v4 or greater [`8e24ac9`](https://github.com/browserify/hash-base/commit/8e24ac9258a1c9294960ee24820eed7494c38e10) - Real example in README [`71fc5bb`](https://github.com/browserify/hash-base/commit/71fc5bb4ac98a837bc68a34b58aa668e88031a33) - Typecheck as function [`867095d`](https://github.com/browserify/hash-base/commit/867095d2d7d369d1c24a44d64bdf403ecb1dd653) - Reset state after HashBase#_digest [`1a4298c`](https://github.com/browserify/hash-base/commit/1a4298c9401597c5e632b29a653ca88d965ae2b2) - Update devdependencies [`3b46138`](https://github.com/browserify/hash-base/commit/3b46138ad6779cc7f50b4ab3a4a93c7c84cf9dda) - Add node7 to travis [`3d29655`](https://github.com/browserify/hash-base/commit/3d29655b7add9008e88f76f4acb5bfe77df7833e) - Fix example in README [`89cdcd8`](https://github.com/browserify/hash-base/commit/89cdcd885a0473b9b6109d6bf285baba8cbeea3f) ## [v3.0.3](https://github.com/browserify/hash-base/compare/v3.0.2...v3.0.3) - 2016-08-28 ### Commits - Add LICENSE file [`3d998aa`](https://github.com/browserify/hash-base/commit/3d998aaa4e6fbacc86b1b0f28b6fb7a4e4398998) ## [v3.0.2](https://github.com/browserify/hash-base/compare/v3.0.1...v3.0.2) - 2016-08-25 ### Commits - Remove extra check [`bd13db2`](https://github.com/browserify/hash-base/commit/bd13db2156ce1fa56ddfc7931ef034aebf693903) ## [v3.0.1](https://github.com/browserify/hash-base/compare/v3.0.0...v3.0.1) - 2016-08-09 ### Merged - Fix ._flush [`#7`](https://github.com/browserify/hash-base/pull/7) - Update nyc to version 7.0.0 🚀 [`#6`](https://github.com/browserify/hash-base/pull/6) ### Commits - Change ._digest to .digest in ._flush [`fdad9ad`](https://github.com/browserify/hash-base/commit/fdad9ad23f9a43f388123667e7ba917100e4fe3a) - Fix typo in README.md [`13264ec`](https://github.com/browserify/hash-base/commit/13264ec7adf25d68c3ff6a8a9a26f7e57282080f) - chore(package): update nyc to version 7.0.0 [`2a24e6a`](https://github.com/browserify/hash-base/commit/2a24e6a664bdd693dac080c81a903fb7548a89e4) ## [v3.0.0](https://github.com/browserify/hash-base/compare/v2.0.2...v3.0.0) - 2016-05-04 ### Merged - utf8 as default encoding [`#4`](https://github.com/browserify/hash-base/pull/4) - Update standard to version 7.0.0 🚀 [`#5`](https://github.com/browserify/hash-base/pull/5) ### Commits - chore(package): update standard to version 7.0.0 [`0720515`](https://github.com/browserify/hash-base/commit/0720515b0fa865bdbf772ea07a84c13e6f4db717) ## [v2.0.2](https://github.com/browserify/hash-base/compare/v2.0.1...v2.0.2) - 2016-04-17 ### Commits - Add type checking in .update [`96acf4a`](https://github.com/browserify/hash-base/commit/96acf4a5650fceb9dbaaba9873805a5c9d71eb88) - Normalize encoding in tests (utf-8 to utf8) [`0bb7c88`](https://github.com/browserify/hash-base/commit/0bb7c8871b177230c83ef27523812590a22ad6b4) ## [v2.0.1](https://github.com/browserify/hash-base/compare/v2.0.0...v2.0.1) - 2016-04-14 ### Commits - Use this._block as local variable [`aa8bab9`](https://github.com/browserify/hash-base/commit/aa8bab94e5d2a905c1abd913684fc00ae6db7a69) - Change Math.floor to |0 [`24f7bb5`](https://github.com/browserify/hash-base/commit/24f7bb573e4b9d2d3a8851fa72ed446a5df05960) ## [v2.0.0](https://github.com/browserify/hash-base/compare/v1.0.2...v2.0.0) - 2016-04-07 ### Fixed - (Closes #3) remove DEFAULT_ENCODING [`#3`](https://github.com/browserify/hash-base/issues/3) ### Commits - Add blocks handling [`0c8fb67`](https://github.com/browserify/hash-base/commit/0c8fb676e7d15af1fb7d441a7b9d783c17da5d08) - (#1) rename _initialized to _finalized [`ea3c00f`](https://github.com/browserify/hash-base/commit/ea3c00fdf768f68313e07f1d93652316f94d9de9) - Fix code style [`964daa5`](https://github.com/browserify/hash-base/commit/964daa56acf87439b229ee4582cc29f4b6f3a722) - Rename initialised_ to _initialised [`6e458c6`](https://github.com/browserify/hash-base/commit/6e458c69f9cf124758f68a01a8232fc7c3269945) ## [v1.0.2](https://github.com/browserify/hash-base/compare/v1.0.1...v1.0.2) - 2016-04-04 ### Commits - Update should return hash instance [`59fef2b`](https://github.com/browserify/hash-base/commit/59fef2bc3b417aac5563022bcc928d1ae8161ee9) ## [v1.0.1](https://github.com/browserify/hash-base/compare/v1.0.0...v1.0.1) - 2016-04-04 ### Commits - Throw error on second call digest [`f0b4caf`](https://github.com/browserify/hash-base/commit/f0b4cafb0a87e8bd3c22a6a3b31e323926dc4e63) - Update README.md [`6ca4555`](https://github.com/browserify/hash-base/commit/6ca4555d3be194f31725ebf21569d759e0bb9b74) ## v1.0.0 - 2016-04-03 ### Commits - Initial commit [`e315bd2`](https://github.com/browserify/hash-base/commit/e315bd2c5c9e98ecac9a45bb5af1c38d87c3bc47) hash-base-3.1.2/LICENSE000066400000000000000000000020721506435633700143720ustar00rootroot00000000000000The 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. hash-base-3.1.2/README.md000066400000000000000000000031111506435633700146370ustar00rootroot00000000000000# hash-base [![npm Package](https://img.shields.io/npm/v/hash-base.svg?style=flat-square)](https://www.npmjs.org/package/hash-base) [![Build Status](https://img.shields.io/travis/crypto-browserify/hash-base.svg?branch=master&style=flat-square)](https://travis-ci.org/crypto-browserify/hash-base) [![Dependency status](https://img.shields.io/david/crypto-browserify/hash-base.svg?style=flat-square)](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 hash-base-3.1.2/index.js000066400000000000000000000043521506435633700150350ustar00rootroot00000000000000'use strict'; var Buffer = require('safe-buffer').Buffer; var toBuffer = require('./to-buffer'); var Transform = require('readable-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); }; HashBase.prototype.update = function (data, encoding) { if (this._finalized) { throw new Error('Digest already called'); } var dataBuffer = toBuffer(data, encoding); // asserts correct input type // consume data var block = this._block; var offset = 0; while (this._blockOffset + dataBuffer.length - offset >= this._blockSize) { for (var i = this._blockOffset; i < this._blockSize;) { block[i] = dataBuffer[offset]; i += 1; offset += 1; } this._update(); this._blockOffset = 0; } while (offset < dataBuffer.length) { block[this._blockOffset] = dataBuffer[offset]; this._blockOffset += 1; offset += 1; } // update length for (var j = 0, carry = dataBuffer.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; hash-base-3.1.2/package.json000066400000000000000000000031711506435633700156540ustar00rootroot00000000000000{ "name": "hash-base", "version": "3.1.2", "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 (https://github.com/fanatid)", "main": "index.js", "repository": { "type": "git", "url": "https://github.com/crypto-browserify/hash-base.git" }, "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", "test": "npm run tests-only", "tests-only": "nyc tape \"test/**/*.js\"", "posttest": "npx npm@\">=10.2\" audit --production", "version": "auto-changelog && git add CHANGELOG.md", "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" }, "dependencies": { "inherits": "^2.0.4", "readable-stream": "^2.3.8", "safe-buffer": "^5.2.1", "to-buffer": "^1.2.1" }, "devDependencies": { "@ljharb/eslint-config": "^21.2.0", "auto-changelog": "^2.5.0", "encoding": "^0.1.13", "eslint": "=8.8.0", "npmignore": "^0.3.1", "nyc": "^10.3.2", "tape": "^5.9.0" }, "engines": { "node": ">= 0.8" }, "publishConfig": { "ignore": [ ".github/workflows", ".eslintrc", ".nycrc", "test" ] }, "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true } } hash-base-3.1.2/test/000077500000000000000000000000001506435633700143435ustar00rootroot00000000000000hash-base-3.1.2/test/index.js000066400000000000000000000116601506435633700160140ustar00rootroot00000000000000'use strict'; var test = require('tape'); var HashBase = require('../'); var Buffer = require('safe-buffer').Buffer; var utf8text = 'УТФ-8 text'; var utf8buf = Buffer.from(utf8text, 'utf8'); function noop() {} test('HashBase#_transform', function (t) { t.test('should use HashBase#update', function (st) { st.plan(3); var base = new HashBase(64); base.update = function () { st.same(arguments[0], utf8text); st.same(arguments[1], 'utf8'); }; base._transform(utf8text, 'utf8', function (err) { st.same(err, null); }); st.end(); }); t.test('should handle error in HashBase#update', function (st) { st.plan(1); var err = new Error('hey'); var base = new HashBase(64); base.update = function () { throw err; }; base._transform(Buffer.allocUnsafe(0), 'buffer', function (_err) { st['true'](_err === err); }); st.end(); }); t.end(); }); test('HashBase#_flush', function (t) { t.test('should use HashBase#digest', function (st) { st.plan(2); var buffer = Buffer.allocUnsafe(0); var base = new HashBase(64); base.push = function (data) { st['true'](data === buffer); }; base.digest = function () { return buffer; }; base._flush(function (err) { st.same(err, null); }); st.end(); }); t.test('should handle errors in HashBase#digest', function (st) { st.plan(1); var base = new HashBase(64); var err = new Error('hey'); base.digest = function () { throw err; }; base._flush(function (_err) { st['true'](_err === err); }); st.end(); }); t.end(); }); test('HashBase#update', function (t) { t.test('only string or buffer is allowed', function (st) { var base = new HashBase(64); st['throws'](function () { base.update(null); }, /^TypeError: The "data" argument must be a string, a Buffer, a Uint8Array, or a DataView$/); st.end(); }); t.test('should throw error after HashBase#digest', function (st) { var base = new HashBase(64); base._digest = noop; base.digest(); st['throws'](function () { base.update(''); }, /^Error: Digest already called$/); st.end(); }); t.test('should use HashBase#_update', function (st) { st.plan(1); var base = new HashBase(64); base._update = st.pass; base.update(Buffer.allocUnsafe(64)); st.end(); }); t.test('default encoding is utf8', function (st) { st.plan(1); var buffer = Buffer.allocUnsafe(64); buffer.fill(0); utf8buf.copy(buffer); var base = new HashBase(64); base._update = function () { st.same(this._block, buffer); }; base.update(buffer.toString('utf8')); st.end(); }); t.test('decode string with custom encoding', function (st) { st.plan(1); var buffer = Buffer.allocUnsafe(64); buffer.fill(0x42); var base = new HashBase(64); base._update = function () { st.same(this._block, buffer); }; base.update(buffer.toString('hex'), 'hex'); st.end(); }); t.test('data length is more than 2^32 bits', function (st) { var base = new HashBase(64); base._length = [Math.pow(2, 32) - 1, 0, 0, 0]; base.update(Buffer.allocUnsafe(1)); st.same(base._length, [7, 1, 0, 0]); st.end(); }); t.test('should return `this`', function (st) { var base = new HashBase(64); st.same(base.update(Buffer.allocUnsafe(0)), base); st.end(); }); t.test( 'handle UInt16Array', { skip: (ArrayBuffer.isView && (Buffer.prototype instanceof Uint8Array || Buffer.TYPED_ARRAY_SUPPORT)) || 'ArrayBuffer.isView and TypedArray fully supported' }, function (st) { var base = new HashBase(64); base._update = noop; base.update(new Uint16Array([1234, 512])); st.same(base._block.slice(0, base._blockOffset), Buffer.from('d2040002', 'hex')); st.end(); } ); t.end(); }); test('HashBase#_update', function (t) { t.test('is not implemented', function (st) { var base = new HashBase(64); st['throws'](function () { base._update(); }, /^Error: _update is not implemented$/); st.end(); }); t.end(); }); test('HashBase#digest', function (t) { t.test('should throw error on second call', function (st) { var base = new HashBase(64); base._digest = noop; base.digest(); st['throws'](function () { base.digest(); }, /^Error: Digest already called$/); st.end(); }); t.test('should use HashBase#_digest', function (st) { st.plan(1); var base = new HashBase(64); base._digest = st.pass; base.digest(); st.end(); }); t.test('should return buffer by default', function (st) { var base = new HashBase(64); base._digest = function () { return utf8buf; }; st.same(base.digest(), utf8buf); st.end(); }); t.test('should encode result with custom encoding', function (st) { var base = new HashBase(64); base._digest = function () { return utf8buf; }; st.same(base.digest('utf8'), utf8text); st.end(); }); t.end(); }); test('HashBase#_digest', function (t) { t.test('is not implemented', function (st) { var base = new HashBase(64); st['throws'](function () { base._digest(); }, /^Error: _digest is not implemented$/); st.end(); }); t.end(); }); hash-base-3.1.2/to-buffer.js000066400000000000000000000011571506435633700156170ustar00rootroot00000000000000'use strict'; var Buffer = require('safe-buffer').Buffer; var toBuffer = require('to-buffer'); var useUint8Array = typeof Uint8Array !== 'undefined'; var useArrayBuffer = useUint8Array && typeof ArrayBuffer !== 'undefined'; var isView = useArrayBuffer && ArrayBuffer.isView; module.exports = function (thing, encoding) { if ( typeof thing === 'string' || Buffer.isBuffer(thing) || (useUint8Array && thing instanceof Uint8Array) || (isView && isView(thing)) ) { return toBuffer(thing, encoding); } throw new TypeError('The "data" argument must be a string, a Buffer, a Uint8Array, or a DataView'); };