Bug 458256. Use LoadLibraryW instead of LoadLibrary (patch by DougT). r+sr=vlad
[wine-gecko.git] / netwerk / protocol / http / src / nsHttpDigestAuth.h
blob044236afc9c522d2adb516069f7b05d674cc0f29
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Justin Bradford <jab@atdot.org> (original author of nsDigestAuth.h)
25 * An-Cheng Huang <pach@cs.cmu.edu>
26 * Darin Fisher <darin@netscape.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #ifndef nsDigestAuth_h__
43 #define nsDigestAuth_h__
45 #include "nsIHttpAuthenticator.h"
46 #include "nsICryptoHash.h"
47 #include "nsString.h"
48 #include "nsCOMPtr.h"
50 #define ALGO_SPECIFIED 0x01
51 #define ALGO_MD5 0x02
52 #define ALGO_MD5_SESS 0x04
53 #define QOP_AUTH 0x01
54 #define QOP_AUTH_INT 0x02
56 #define DIGEST_LENGTH 16
57 #define EXPANDED_DIGEST_LENGTH 32
58 #define NONCE_COUNT_LENGTH 8
60 //-----------------------------------------------------------------------------
61 // nsHttpDigestAuth
62 //-----------------------------------------------------------------------------
64 class nsHttpDigestAuth : public nsIHttpAuthenticator
66 public:
67 NS_DECL_ISUPPORTS
68 NS_DECL_NSIHTTPAUTHENTICATOR
70 nsHttpDigestAuth();
71 ~nsHttpDigestAuth();
73 protected:
74 nsresult ExpandToHex(const char * digest, char * result);
76 nsresult CalculateResponse(const char * ha1_digest,
77 const char * ha2_digest,
78 const nsAFlatCString & nonce,
79 PRUint16 qop,
80 const char * nonce_count,
81 const nsAFlatCString & cnonce,
82 char * result);
84 nsresult CalculateHA1(const nsAFlatCString & username,
85 const nsAFlatCString & password,
86 const nsAFlatCString & realm,
87 PRUint16 algorithm,
88 const nsAFlatCString & nonce,
89 const nsAFlatCString & cnonce,
90 char * result);
92 nsresult CalculateHA2(const nsAFlatCString & http_method,
93 const nsAFlatCString & http_uri_path,
94 PRUint16 qop,
95 const char * body_digest,
96 char * result);
98 nsresult ParseChallenge(const char * challenge,
99 nsACString & realm,
100 nsACString & domain,
101 nsACString & nonce,
102 nsACString & opaque,
103 PRBool * stale,
104 PRUint16 * algorithm,
105 PRUint16 * qop);
107 // result is in mHashBuf
108 nsresult MD5Hash(const char *buf, PRUint32 len);
110 nsresult GetMethodAndPath(nsIHttpChannel *, PRBool, nsCString &, nsCString &);
112 // append the quoted version of value to aHeaderLine
113 nsresult AppendQuotedString(const nsACString & value,
114 nsACString & aHeaderLine);
116 protected:
117 nsCOMPtr<nsICryptoHash> mVerifier;
118 char mHashBuf[DIGEST_LENGTH];
121 #endif // nsHttpDigestAuth_h__