diff --git a/mailnews/base/util/nsMsgUtils.cpp b/mailnews/base/util/nsMsgUtils.cpp index ad23c8525efd..102168c46d7f 100644 --- a/mailnews/base/util/nsMsgUtils.cpp +++ b/mailnews/base/util/nsMsgUtils.cpp @@ -811,3 +811,29 @@ nsresult MSGCramMD5(const char *text, PRInt32 text_len, const char *key, PRInt32 } + +// digest needs to be a pointer to a DIGEST_LENGTH (16) byte buffer +nsresult MSGApopMD5(const char *text, PRInt32 text_len, const char *password, PRInt32 password_len, unsigned char *digest) +{ + nsresult rv; + unsigned char result[DIGEST_LENGTH]; + unsigned char *presult = result; + + nsCOMPtr verifier = do_GetService(SIGNATURE_VERIFIER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + + HASHContextStr *context; + PRUint32 resultLen; + + rv = verifier->HashBegin(nsISignatureVerifier::MD5, &context); + NS_ENSURE_SUCCESS(rv, rv); + rv = verifier->HashUpdate(context, text, text_len); + NS_ENSURE_SUCCESS(rv, rv); + rv = verifier->HashUpdate(context, password, password_len); + NS_ENSURE_SUCCESS(rv, rv); + rv = verifier->HashEnd(context, &presult, &resultLen, DIGEST_LENGTH); + NS_ENSURE_SUCCESS(rv, rv); + memcpy(digest, result, DIGEST_LENGTH); + return rv; +} diff --git a/mailnews/base/util/nsMsgUtils.h b/mailnews/base/util/nsMsgUtils.h index 31c3d79e6881..8c5b2dc4b341 100644 --- a/mailnews/base/util/nsMsgUtils.h +++ b/mailnews/base/util/nsMsgUtils.h @@ -97,5 +97,6 @@ NS_MSG_BASE nsresult GetOrCreateFolder(const nsACString & aURI, nsIUrlListener * #define DIGEST_LENGTH 16 NS_MSG_BASE nsresult MSGCramMD5(const char *text, PRInt32 text_len, const char *key, PRInt32 key_len, unsigned char *digest); +NS_MSG_BASE nsresult MSGApopMD5(const char *text, PRInt32 text_len, const char *password, PRInt32 password_len, unsigned char *digest); #endif