hash-instance.js 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const native_1 = __importDefault(require("./native"));
  7. const hash_instance_1 = require("../node/hash-instance");
  8. const hash_reader_1 = require("../node/hash-reader");
  9. // A buffer we reuse for sending bigints. set_position is synchronous, so
  10. // this just saves creating garbage.
  11. const bigIntBuffer = Buffer.alloc(8);
  12. const readerFactory = (r) => new hash_reader_1.NodeHashReader({
  13. fill: target => r.fill(target),
  14. set_position: position => {
  15. bigIntBuffer.writeBigUInt64BE(position);
  16. r.set_position(bigIntBuffer);
  17. },
  18. });
  19. /**
  20. * A Node.js crypto-like createHash method.
  21. */
  22. exports.createHash = () => new hash_instance_1.NodeHash(new native_1.default.Hasher(), readerFactory);
  23. /**
  24. * Construct a new Hasher for the keyed hash function.
  25. */
  26. exports.createKeyed = (key) => new hash_instance_1.NodeHash(new native_1.default.Hasher(key), readerFactory);
  27. /**
  28. * Construct a new Hasher for the key derivation function.
  29. */
  30. exports.createDeriveKey = (context) => new hash_instance_1.NodeHash(new native_1.default.Hasher(undefined, context), readerFactory);
  31. //# sourceMappingURL=hash-instance.js.map