1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/public/nsICryptoHash.idl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "nsISupports.idl" 1.9 +interface nsIInputStream; 1.10 + 1.11 +/** 1.12 + * nsICryptoHash 1.13 + * This interface provides crytographic hashing algorithms. 1.14 + */ 1.15 + 1.16 +[scriptable, uuid(1e5b7c43-4688-45ce-92e1-77ed931e3bbe)] 1.17 +interface nsICryptoHash : nsISupports 1.18 +{ 1.19 + /** 1.20 + * Hashing Algorithms. These values are to be used by the 1.21 + * |init| method to indicate which hashing function to 1.22 + * use. These values map directly onto the values defined 1.23 + * in mozilla/security/nss/lib/cryptohi/hasht.h. 1.24 + */ 1.25 + const short MD2 = 1; /* String value: "md2" */ 1.26 + const short MD5 = 2; /* String value: "md5" */ 1.27 + const short SHA1 = 3; /* String value: "sha1" */ 1.28 + const short SHA256 = 4; /* String value: "sha256" */ 1.29 + const short SHA384 = 5; /* String value: "sha384" */ 1.30 + const short SHA512 = 6; /* String value: "sha512" */ 1.31 + 1.32 + /** 1.33 + * Initialize the hashing object. This method may be 1.34 + * called multiple times with different algorithm types. 1.35 + * 1.36 + * @param aAlgorithm the algorithm type to be used. 1.37 + * This value must be one of the above valid 1.38 + * algorithm types. 1.39 + * 1.40 + * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm 1.41 + * type is passed. 1.42 + * 1.43 + * NOTE: This method or initWithString must be called 1.44 + * before any other method on this interface is called. 1.45 + */ 1.46 + void init(in unsigned long aAlgorithm); 1.47 + 1.48 + /** 1.49 + * Initialize the hashing object. This method may be 1.50 + * called multiple times with different algorithm types. 1.51 + * 1.52 + * @param aAlgorithm the algorithm type to be used. 1.53 + * 1.54 + * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm 1.55 + * type is passed. 1.56 + * 1.57 + * NOTE: This method or init must be called before any 1.58 + * other method on this interface is called. 1.59 + */ 1.60 + void initWithString(in ACString aAlgorithm); 1.61 + 1.62 + /** 1.63 + * @param aData a buffer to calculate the hash over 1.64 + * 1.65 + * @param aLen the length of the buffer |aData| 1.66 + * 1.67 + * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been 1.68 + * called. 1.69 + */ 1.70 + void update([const, array, size_is(aLen)] in octet aData, in unsigned long aLen); 1.71 + 1.72 + /** 1.73 + * Calculates and updates a new hash based on a given data stream. 1.74 + * 1.75 + * @param aStream an input stream to read from. 1.76 + * 1.77 + * @param aLen how much to read from the given |aStream|. Passing 1.78 + * UINT32_MAX indicates that all data available will be used 1.79 + * to update the hash. 1.80 + * 1.81 + * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been 1.82 + * called. 1.83 + * 1.84 + * @throws NS_ERROR_NOT_AVAILABLE if the requested amount of 1.85 + * data to be calculated into the hash is not available. 1.86 + * 1.87 + */ 1.88 + void updateFromStream(in nsIInputStream aStream, in unsigned long aLen); 1.89 + 1.90 + /** 1.91 + * Completes this hash object and produces the actual hash data. 1.92 + * 1.93 + * @param aASCII if true then the returned value is a base-64 1.94 + * encoded string. if false, then the returned value is 1.95 + * binary data. 1.96 + * 1.97 + * @return a hash of the data that was read by this object. This can 1.98 + * be either binary data or base 64 encoded. 1.99 + * 1.100 + * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been 1.101 + * called. 1.102 + * 1.103 + * NOTE: This method may be called any time after |init| 1.104 + * is called. This call resets the object to its 1.105 + * pre-init state. 1.106 + */ 1.107 + ACString finish(in boolean aASCII); 1.108 +};