hash-instance.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const index_1 = require("../base/index");
  4. const hash_fn_1 = require("./hash-fn");
  5. const encoding_1 = require("./encoding");
  6. const hash_reader_1 = require("./hash-reader");
  7. const hash_1 = require("./hash");
  8. const wasm_1 = require("./wasm");
  9. /**
  10. * @inheritdoc
  11. */
  12. class BrowserHasher extends index_1.BaseHash {
  13. /**
  14. * @inheritdoc
  15. * @override
  16. */
  17. update(data) {
  18. return super.update(hash_fn_1.normalizeInput(data));
  19. }
  20. digest(encoding, options) {
  21. let resolvedOpts;
  22. let resolvedEnc;
  23. if (encoding && typeof encoding === 'object') {
  24. resolvedOpts = encoding;
  25. resolvedEnc = undefined;
  26. }
  27. else {
  28. resolvedOpts = options;
  29. resolvedEnc = encoding;
  30. }
  31. const result = super.digest(resolvedOpts);
  32. return resolvedEnc ? encoding_1.mustGetEncoder(resolvedEnc)(result) : result;
  33. }
  34. }
  35. exports.BrowserHasher = BrowserHasher;
  36. /**
  37. * A Node.js crypto-like createHash method.
  38. */
  39. exports.createHash = () => new BrowserHasher(wasm_1.getWasm().create_hasher(), l => new hash_1.Hash(l), r => new hash_reader_1.BrowserHashReader(r));
  40. /**
  41. * A Node.js crypto-like createHash method.
  42. */
  43. exports.createKeyed = (key) => new BrowserHasher(wasm_1.getWasm().create_keyed(key), l => new hash_1.Hash(l), r => new hash_reader_1.BrowserHashReader(r));
  44. //# sourceMappingURL=hash-instance.js.map