Path: blob/trunk/third_party/closure/goog/crypt/hash.js
2868 views
// Copyright 2011 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Abstract cryptographic hash interface.16*17* See goog.crypt.Sha1 and goog.crypt.Md5 for sample implementations.18*19*/2021goog.provide('goog.crypt.Hash');22232425/**26* Create a cryptographic hash instance.27*28* @constructor29* @struct30*/31goog.crypt.Hash = function() {32/**33* The block size for the hasher.34* @type {number}35*/36this.blockSize = -1;37};383940/**41* Resets the internal accumulator.42*/43goog.crypt.Hash.prototype.reset = goog.abstractMethod;444546/**47* Adds a byte array (array with values in [0-255] range) or a string (must48* only contain 8-bit, i.e., Latin1 characters) to the internal accumulator.49*50* Many hash functions operate on blocks of data and implement optimizations51* when a full chunk of data is readily available. Hence it is often preferable52* to provide large chunks of data (a kilobyte or more) than to repeatedly53* call the update method with few tens of bytes. If this is not possible, or54* not feasible, it might be good to provide data in multiplies of hash block55* size (often 64 bytes). Please see the implementation and performance tests56* of your favourite hash.57*58* @param {Array<number>|Uint8Array|string} bytes Data used for the update.59* @param {number=} opt_length Number of bytes to use.60*/61goog.crypt.Hash.prototype.update = goog.abstractMethod;626364/**65* @return {!Array<number>} The finalized hash computed66* from the internal accumulator.67*/68goog.crypt.Hash.prototype.digest = goog.abstractMethod;697071