nsICryptoHash.idl (3966B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "nsISupports.idl" 6 7 interface nsIInputStream; 8 9 /** 10 * nsICryptoHash 11 * This interface provides crytographic hashing algorithms. 12 */ 13 14 [builtinclass, scriptable, uuid(1e5b7c43-4688-45ce-92e1-77ed931e3bbe)] 15 interface nsICryptoHash : nsISupports 16 { 17 /** 18 * Hashing Algorithms. These values are to be used by the 19 * |init| method to indicate which hashing function to 20 * use. These values must be identical to the values defined 21 * in security/nss/lib/util/hasht.h in type HASH_HashType. 22 * This allows us to use NSS mapping functions like 23 * HASH_GetHashOidTagByHashType with these values. 24 */ 25 const unsigned long MD5 = 2; /* String value: "md5" */ 26 const unsigned long SHA1 = 3; /* String value: "sha1" */ 27 const unsigned long SHA256 = 4; /* String value: "sha256" */ 28 const unsigned long SHA384 = 5; /* String value: "sha384" */ 29 const unsigned long SHA512 = 6; /* String value: "sha512" */ 30 31 /** 32 * Initialize the hashing object. This method may be 33 * called multiple times with different algorithm types. 34 * 35 * @param aAlgorithm the algorithm type to be used. 36 * This value must be one of the above valid 37 * algorithm types. 38 * 39 * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm 40 * type is passed. 41 * 42 * NOTE: This method or initWithString must be called 43 * before any other method on this interface is called. 44 */ 45 void init(in unsigned long aAlgorithm); 46 47 /** 48 * Initialize the hashing object. This method may be 49 * called multiple times with different algorithm types. 50 * 51 * @param aAlgorithm the algorithm type to be used. 52 * 53 * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm 54 * type is passed. 55 * 56 * NOTE: This method or init must be called before any 57 * other method on this interface is called. 58 */ 59 [must_use] 60 void initWithString(in ACString aAlgorithm); 61 62 /** 63 * @param aData a buffer to calculate the hash over 64 * 65 * @param aLen the length of the buffer |aData| 66 * 67 * @throws NS_ERROR_NOT_INITIALIZED If |init| has not been called. 68 */ 69 void update([const, array, size_is(aLen)] in octet aData, in unsigned long aLen); 70 71 /** 72 * Calculates and updates a new hash based on a given data stream. 73 * 74 * @param aStream an input stream to read from. 75 * 76 * @param aLen How much to read from the given |aStream|. Passing UINT32_MAX 77 * indicates that all data available will be used to update the hash. 78 * 79 * @throws NS_ERROR_NOT_INITIALIZED If |init| has not been called. 80 * 81 * @throws NS_ERROR_NOT_AVAILABLE If the requested amount of 82 * data to be calculated into the hash is not available. 83 * 84 */ 85 [must_use] 86 void updateFromStream(in nsIInputStream aStream, in unsigned long aLen); 87 88 /** 89 * Completes this hash object and produces the actual hash data. 90 * 91 * @param aASCII If true then the returned value is a base64 encoded string. 92 * If false, then the returned value is binary data. 93 * 94 * @return a hash of the data that was read by this object. This can 95 * be either binary data or base 64 encoded. 96 * 97 * @throws NS_ERROR_NOT_INITIALIZED If |init| has not been called. 98 * 99 * NOTE: This method may be called any time after |init| 100 * is called. This call resets the object to its 101 * pre-init state. 102 */ 103 ACString finish(in boolean aASCII); 104 }; 105 106 %{C++ 107 nsresult NS_NewCryptoHash(uint32_t aHashType, nsICryptoHash** aOutHasher); 108 nsresult NS_NewCryptoHash(const nsACString& aHashType, nsICryptoHash** aOutHasher); 109 %}