|
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 interface nsIInputStream; |
|
7 |
|
8 /** |
|
9 * nsICryptoHash |
|
10 * This interface provides crytographic hashing algorithms. |
|
11 */ |
|
12 |
|
13 [scriptable, uuid(1e5b7c43-4688-45ce-92e1-77ed931e3bbe)] |
|
14 interface nsICryptoHash : nsISupports |
|
15 { |
|
16 /** |
|
17 * Hashing Algorithms. These values are to be used by the |
|
18 * |init| method to indicate which hashing function to |
|
19 * use. These values map directly onto the values defined |
|
20 * in mozilla/security/nss/lib/cryptohi/hasht.h. |
|
21 */ |
|
22 const short MD2 = 1; /* String value: "md2" */ |
|
23 const short MD5 = 2; /* String value: "md5" */ |
|
24 const short SHA1 = 3; /* String value: "sha1" */ |
|
25 const short SHA256 = 4; /* String value: "sha256" */ |
|
26 const short SHA384 = 5; /* String value: "sha384" */ |
|
27 const short SHA512 = 6; /* String value: "sha512" */ |
|
28 |
|
29 /** |
|
30 * Initialize the hashing object. This method may be |
|
31 * called multiple times with different algorithm types. |
|
32 * |
|
33 * @param aAlgorithm the algorithm type to be used. |
|
34 * This value must be one of the above valid |
|
35 * algorithm types. |
|
36 * |
|
37 * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm |
|
38 * type is passed. |
|
39 * |
|
40 * NOTE: This method or initWithString must be called |
|
41 * before any other method on this interface is called. |
|
42 */ |
|
43 void init(in unsigned long aAlgorithm); |
|
44 |
|
45 /** |
|
46 * Initialize the hashing object. This method may be |
|
47 * called multiple times with different algorithm types. |
|
48 * |
|
49 * @param aAlgorithm the algorithm type to be used. |
|
50 * |
|
51 * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm |
|
52 * type is passed. |
|
53 * |
|
54 * NOTE: This method or init must be called before any |
|
55 * other method on this interface is called. |
|
56 */ |
|
57 void initWithString(in ACString aAlgorithm); |
|
58 |
|
59 /** |
|
60 * @param aData a buffer to calculate the hash over |
|
61 * |
|
62 * @param aLen the length of the buffer |aData| |
|
63 * |
|
64 * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been |
|
65 * called. |
|
66 */ |
|
67 void update([const, array, size_is(aLen)] in octet aData, in unsigned long aLen); |
|
68 |
|
69 /** |
|
70 * Calculates and updates a new hash based on a given data stream. |
|
71 * |
|
72 * @param aStream an input stream to read from. |
|
73 * |
|
74 * @param aLen how much to read from the given |aStream|. Passing |
|
75 * UINT32_MAX indicates that all data available will be used |
|
76 * to update the hash. |
|
77 * |
|
78 * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been |
|
79 * 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 void updateFromStream(in nsIInputStream aStream, in unsigned long aLen); |
|
86 |
|
87 /** |
|
88 * Completes this hash object and produces the actual hash data. |
|
89 * |
|
90 * @param aASCII if true then the returned value is a base-64 |
|
91 * encoded string. if false, then the returned value is |
|
92 * 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 |
|
98 * called. |
|
99 * |
|
100 * NOTE: This method may be called any time after |init| |
|
101 * is called. This call resets the object to its |
|
102 * pre-init state. |
|
103 */ |
|
104 ACString finish(in boolean aASCII); |
|
105 }; |