hash-instance.js 1015 B

1234567891011121314151617181920212223242526
  1. import native from './native.js';
  2. import { NodeHash } from '../node/hash-instance.js';
  3. import { NodeHashReader } from '../node/hash-reader.js';
  4. // A buffer we reuse for sending bigints. set_position is synchronous, so
  5. // this just saves creating garbage.
  6. const bigIntBuffer = Buffer.alloc(8);
  7. const readerFactory = (r) => new NodeHashReader({
  8. fill: target => r.fill(target),
  9. set_position: position => {
  10. bigIntBuffer.writeBigUInt64BE(position);
  11. r.set_position(bigIntBuffer);
  12. },
  13. });
  14. /**
  15. * A Node.js crypto-like createHash method.
  16. */
  17. export const createHash = () => new NodeHash(new native.Hasher(), readerFactory);
  18. /**
  19. * Construct a new Hasher for the keyed hash function.
  20. */
  21. export const createKeyed = (key) => new NodeHash(new native.Hasher(key), readerFactory);
  22. /**
  23. * Construct a new Hasher for the key derivation function.
  24. */
  25. export const createDeriveKey = (context) => new NodeHash(new native.Hasher(undefined, context), readerFactory);
  26. //# sourceMappingURL=hash-instance.js.map