michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: interface nsIInputStream; michael@0: michael@0: /** michael@0: * nsICryptoHash michael@0: * This interface provides crytographic hashing algorithms. michael@0: */ michael@0: michael@0: [scriptable, uuid(1e5b7c43-4688-45ce-92e1-77ed931e3bbe)] michael@0: interface nsICryptoHash : nsISupports michael@0: { michael@0: /** michael@0: * Hashing Algorithms. These values are to be used by the michael@0: * |init| method to indicate which hashing function to michael@0: * use. These values map directly onto the values defined michael@0: * in mozilla/security/nss/lib/cryptohi/hasht.h. michael@0: */ michael@0: const short MD2 = 1; /* String value: "md2" */ michael@0: const short MD5 = 2; /* String value: "md5" */ michael@0: const short SHA1 = 3; /* String value: "sha1" */ michael@0: const short SHA256 = 4; /* String value: "sha256" */ michael@0: const short SHA384 = 5; /* String value: "sha384" */ michael@0: const short SHA512 = 6; /* String value: "sha512" */ michael@0: michael@0: /** michael@0: * Initialize the hashing object. This method may be michael@0: * called multiple times with different algorithm types. michael@0: * michael@0: * @param aAlgorithm the algorithm type to be used. michael@0: * This value must be one of the above valid michael@0: * algorithm types. michael@0: * michael@0: * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm michael@0: * type is passed. michael@0: * michael@0: * NOTE: This method or initWithString must be called michael@0: * before any other method on this interface is called. michael@0: */ michael@0: void init(in unsigned long aAlgorithm); michael@0: michael@0: /** michael@0: * Initialize the hashing object. This method may be michael@0: * called multiple times with different algorithm types. michael@0: * michael@0: * @param aAlgorithm the algorithm type to be used. michael@0: * michael@0: * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm michael@0: * type is passed. michael@0: * michael@0: * NOTE: This method or init must be called before any michael@0: * other method on this interface is called. michael@0: */ michael@0: void initWithString(in ACString aAlgorithm); michael@0: michael@0: /** michael@0: * @param aData a buffer to calculate the hash over michael@0: * michael@0: * @param aLen the length of the buffer |aData| michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been michael@0: * called. michael@0: */ michael@0: void update([const, array, size_is(aLen)] in octet aData, in unsigned long aLen); michael@0: michael@0: /** michael@0: * Calculates and updates a new hash based on a given data stream. michael@0: * michael@0: * @param aStream an input stream to read from. michael@0: * michael@0: * @param aLen how much to read from the given |aStream|. Passing michael@0: * UINT32_MAX indicates that all data available will be used michael@0: * to update the hash. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been michael@0: * called. michael@0: * michael@0: * @throws NS_ERROR_NOT_AVAILABLE if the requested amount of michael@0: * data to be calculated into the hash is not available. michael@0: * michael@0: */ michael@0: void updateFromStream(in nsIInputStream aStream, in unsigned long aLen); michael@0: michael@0: /** michael@0: * Completes this hash object and produces the actual hash data. michael@0: * michael@0: * @param aASCII if true then the returned value is a base-64 michael@0: * encoded string. if false, then the returned value is michael@0: * binary data. michael@0: * michael@0: * @return a hash of the data that was read by this object. This can michael@0: * be either binary data or base 64 encoded. michael@0: * michael@0: * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been michael@0: * called. michael@0: * michael@0: * NOTE: This method may be called any time after |init| michael@0: * is called. This call resets the object to its michael@0: * pre-init state. michael@0: */ michael@0: ACString finish(in boolean aASCII); michael@0: };