| 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 |
/** |
| 16 |
* @fileoverview Abstract cryptographic hash interface. |
| 17 |
* |
| 18 |
* See goog.crypt.Sha1 and goog.crypt.Md5 for sample implementations. |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
goog.provide('goog.crypt.Hash'); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* Create a cryptographic hash instance. |
| 28 |
* |
| 29 |
* @constructor |
| 30 |
* @struct |
| 31 |
*/ |
| 32 |
goog.crypt.Hash = function() { |
| 33 |
/** |
| 34 |
* The block size for the hasher. |
| 35 |
* @type {number} |
| 36 |
*/ |
| 37 |
this.blockSize = -1; |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
/** |
| 42 |
* Resets the internal accumulator. |
| 43 |
*/ |
| 44 |
goog.crypt.Hash.prototype.reset = goog.abstractMethod; |
| 45 |
|
| 46 |
|
| 47 |
/** |
| 48 |
* Adds a byte array (array with values in [0-255] range) or a string (must |
| 49 |
* only contain 8-bit, i.e., Latin1 characters) to the internal accumulator. |
| 50 |
* |
| 51 |
* Many hash functions operate on blocks of data and implement optimizations |
| 52 |
* when a full chunk of data is readily available. Hence it is often preferable |
| 53 |
* to provide large chunks of data (a kilobyte or more) than to repeatedly |
| 54 |
* call the update method with few tens of bytes. If this is not possible, or |
| 55 |
* not feasible, it might be good to provide data in multiplies of hash block |
| 56 |
* size (often 64 bytes). Please see the implementation and performance tests |
| 57 |
* of your favourite hash. |
| 58 |
* |
| 59 |
* @param {Array<number>|Uint8Array|string} bytes Data used for the update. |
| 60 |
* @param {number=} opt_length Number of bytes to use. |
| 61 |
*/ |
| 62 |
goog.crypt.Hash.prototype.update = goog.abstractMethod; |
| 63 |
|
| 64 |
|
| 65 |
/** |
| 66 |
* @return {!Array<number>} The finalized hash computed |
| 67 |
* from the internal accumulator. |
| 68 |
*/ |
| 69 |
goog.crypt.Hash.prototype.digest = goog.abstractMethod; |