1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_BASE_AUTH_H__
6 #define NET_BASE_AUTH_H__
10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string16.h"
12 #include "net/base/host_port_pair.h"
13 #include "net/base/net_export.h"
17 // Holds info about an authentication challenge that we may want to display
19 class NET_EXPORT AuthChallengeInfo
:
20 public base::RefCountedThreadSafe
<AuthChallengeInfo
> {
24 // Determines whether two AuthChallengeInfo's are equivalent.
25 bool Equals(const AuthChallengeInfo
& other
) const;
27 // Whether this came from a server or a proxy.
30 // The service issuing the challenge.
31 HostPortPair challenger
;
33 // The authentication scheme used, such as "basic" or "digest". If the
34 // |source| is FTP_SERVER, this is an empty string. The encoding is ASCII.
37 // The realm of the challenge. May be empty. The encoding is UTF-8.
41 friend class base::RefCountedThreadSafe
<AuthChallengeInfo
>;
45 // Authentication Credentials for an authentication credentials.
46 class NET_EXPORT AuthCredentials
{
49 AuthCredentials(const base::string16
& username
,
50 const base::string16
& password
);
53 // Set the |username| and |password|.
54 void Set(const base::string16
& username
, const base::string16
& password
);
56 // Determines if |this| is equivalent to |other|.
57 bool Equals(const AuthCredentials
& other
) const;
59 // Returns true if all credentials are empty.
62 // Overwrites the password memory to prevent it from being read if
63 // it's paged out to disk.
66 const base::string16
& username() const { return username_
; }
67 const base::string16
& password() const { return password_
; }
70 // The username to provide, possibly empty. This should be ASCII only to
71 // minimize compatibility problems, but arbitrary UTF-16 strings are allowed
72 // and will be attempted.
73 base::string16 username_
;
75 // The password to provide, possibly empty. This should be ASCII only to
76 // minimize compatibility problems, but arbitrary UTF-16 strings are allowed
77 // and will be attempted.
78 base::string16 password_
;
80 // Intentionally allowing the implicit copy constructor and assignment
84 // Authentication structures
86 AUTH_STATE_DONT_NEED_AUTH
,
92 class AuthData
: public base::RefCountedThreadSafe
<AuthData
> {
94 AuthState state
; // whether we need, have, or gave up on authentication.
95 AuthCredentials credentials
; // The credentials to use for auth.
97 // We wouldn't instantiate this class if we didn't need authentication.
101 friend class base::RefCountedThreadSafe
<AuthData
>;
107 #endif // NET_BASE_AUTH_H__