crypto_hash.h (1144B)
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 "nsICryptoHash.h" 6 7 extern "C" { 8 nsresult crypto_hash_constructor(REFNSIID iid, void** result); 9 }; 10 11 nsresult NS_NewCryptoHash(uint32_t aHashType, nsICryptoHash** aOutHasher) { 12 MOZ_ASSERT(aOutHasher); 13 14 nsCOMPtr<nsICryptoHash> hasher; 15 nsresult rv = 16 crypto_hash_constructor(NS_ICRYPTOHASH_IID, getter_AddRefs(hasher)); 17 if (NS_FAILED(rv)) { 18 return rv; 19 } 20 rv = hasher->Init(aHashType); 21 if (NS_FAILED(rv)) { 22 return rv; 23 } 24 hasher.forget(aOutHasher); 25 26 return NS_OK; 27 } 28 29 nsresult NS_NewCryptoHash(const nsACString& aHashType, 30 nsICryptoHash** aOutHasher) { 31 MOZ_ASSERT(aOutHasher); 32 33 nsCOMPtr<nsICryptoHash> hasher; 34 nsresult rv = 35 crypto_hash_constructor(NS_ICRYPTOHASH_IID, getter_AddRefs(hasher)); 36 if (NS_FAILED(rv)) { 37 return rv; 38 } 39 rv = hasher->InitWithString(aHashType); 40 if (NS_FAILED(rv)) { 41 return rv; 42 } 43 hasher.forget(aOutHasher); 44 45 return NS_OK; 46 }