Bug 1935611 - Fix libyuv/libpng link failed for loongarch64. r=glandium,tnikkel,ng
[gecko.git] / security / manager / ssl / nsICryptoHash.idl
blob2aa0ebb242b454856c0070a7285e721b0500906d
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/. */
5 #include "nsISupports.idl"
7 interface nsIInputStream;
9 /**
10 * nsICryptoHash
11 * This interface provides crytographic hashing algorithms.
14 [builtinclass, scriptable, uuid(1e5b7c43-4688-45ce-92e1-77ed931e3bbe)]
15 interface nsICryptoHash : nsISupports
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.
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" */
31 /**
32 * Initialize the hashing object. This method may be
33 * called multiple times with different algorithm types.
35 * @param aAlgorithm the algorithm type to be used.
36 * This value must be one of the above valid
37 * algorithm types.
39 * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm
40 * type is passed.
42 * NOTE: This method or initWithString must be called
43 * before any other method on this interface is called.
45 void init(in unsigned long aAlgorithm);
47 /**
48 * Initialize the hashing object. This method may be
49 * called multiple times with different algorithm types.
51 * @param aAlgorithm the algorithm type to be used.
53 * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm
54 * type is passed.
56 * NOTE: This method or init must be called before any
57 * other method on this interface is called.
59 [must_use]
60 void initWithString(in ACString aAlgorithm);
62 /**
63 * @param aData a buffer to calculate the hash over
65 * @param aLen the length of the buffer |aData|
67 * @throws NS_ERROR_NOT_INITIALIZED If |init| has not been called.
69 void update([const, array, size_is(aLen)] in octet aData, in unsigned long aLen);
71 /**
72 * Calculates and updates a new hash based on a given data stream.
74 * @param aStream an input stream to read from.
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.
79 * @throws NS_ERROR_NOT_INITIALIZED If |init| has not been called.
81 * @throws NS_ERROR_NOT_AVAILABLE If the requested amount of
82 * data to be calculated into the hash is not available.
85 [must_use]
86 void updateFromStream(in nsIInputStream aStream, in unsigned long aLen);
88 /**
89 * Completes this hash object and produces the actual hash data.
91 * @param aASCII If true then the returned value is a base64 encoded string.
92 * If false, then the returned value is binary data.
94 * @return a hash of the data that was read by this object. This can
95 * be either binary data or base 64 encoded.
97 * @throws NS_ERROR_NOT_INITIALIZED If |init| has not been called.
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.
103 ACString finish(in boolean aASCII);
106 %{C++
107 nsresult NS_NewCryptoHash(uint32_t aHashType, nsICryptoHash** aOutHasher);
108 nsresult NS_NewCryptoHash(const nsACString& aHashType, nsICryptoHash** aOutHasher);