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