hash.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2011 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Abstract cryptographic hash interface.
  16. *
  17. * See goog.crypt.Sha1 and goog.crypt.Md5 for sample implementations.
  18. *
  19. */
  20. goog.provide('goog.crypt.Hash');
  21. /**
  22. * Create a cryptographic hash instance.
  23. *
  24. * @constructor
  25. * @struct
  26. */
  27. goog.crypt.Hash = function() {
  28. /**
  29. * The block size for the hasher.
  30. * @type {number}
  31. */
  32. this.blockSize = -1;
  33. };
  34. /**
  35. * Resets the internal accumulator.
  36. */
  37. goog.crypt.Hash.prototype.reset = goog.abstractMethod;
  38. /**
  39. * Adds a byte array (array with values in [0-255] range) or a string (must
  40. * only contain 8-bit, i.e., Latin1 characters) to the internal accumulator.
  41. *
  42. * Many hash functions operate on blocks of data and implement optimizations
  43. * when a full chunk of data is readily available. Hence it is often preferable
  44. * to provide large chunks of data (a kilobyte or more) than to repeatedly
  45. * call the update method with few tens of bytes. If this is not possible, or
  46. * not feasible, it might be good to provide data in multiplies of hash block
  47. * size (often 64 bytes). Please see the implementation and performance tests
  48. * of your favourite hash.
  49. *
  50. * @param {Array<number>|Uint8Array|string} bytes Data used for the update.
  51. * @param {number=} opt_length Number of bytes to use.
  52. */
  53. goog.crypt.Hash.prototype.update = goog.abstractMethod;
  54. /**
  55. * @return {!Array<number>} The finalized hash computed
  56. * from the internal accumulator.
  57. */
  58. goog.crypt.Hash.prototype.digest = goog.abstractMethod;