chrome: Remove dependency on expat library.
[chromium-blink-merge.git] / net / ssl / ssl_client_auth_cache.h
blob53d5312a9ee04cba115803258b9619b5ce1f6f5a
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_SSL_SSL_CLIENT_AUTH_CACHE_H_
6 #define NET_SSL_SSL_CLIENT_AUTH_CACHE_H_
8 #include <map>
9 #include <string>
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "net/base/host_port_pair.h"
14 #include "net/base/net_export.h"
15 #include "net/cert/cert_database.h"
17 namespace net {
19 class X509Certificate;
21 // The SSLClientAuthCache class is a simple cache structure to store SSL
22 // client certificates. Provides lookup, insertion, and deletion of entries.
23 // The parameter for doing lookups, insertions, and deletions is the server's
24 // host and port.
26 // TODO(wtc): This class is based on FtpAuthCache. We can extract the common
27 // code to a template class.
28 class NET_EXPORT_PRIVATE SSLClientAuthCache : public CertDatabase::Observer {
29 public:
30 SSLClientAuthCache();
31 ~SSLClientAuthCache() override;
33 // Checks for a client certificate preference for SSL server at |server|.
34 // Returns true if a preference is found, and sets |*certificate| to the
35 // desired client certificate. The desired certificate may be NULL, which
36 // indicates a preference to not send any certificate to |server|.
37 // If a certificate preference is not found, returns false.
38 bool Lookup(const HostPortPair& server,
39 scoped_refptr<X509Certificate>* certificate);
41 // Add a client certificate for |server| to the cache. If there is already
42 // a client certificate for |server|, it will be overwritten. A NULL
43 // |client_cert| indicates a preference that no client certificate should
44 // be sent to |server|.
45 void Add(const HostPortPair& server, X509Certificate* client_cert);
47 // Remove the client certificate for |server| from the cache, if one exists.
48 void Remove(const HostPortPair& server);
50 // CertDatabase::Observer methods:
51 void OnCertAdded(const X509Certificate* cert) override;
53 private:
54 typedef HostPortPair AuthCacheKey;
55 typedef scoped_refptr<X509Certificate> AuthCacheValue;
56 typedef std::map<AuthCacheKey, AuthCacheValue> AuthCacheMap;
58 // internal representation of cache, an STL map.
59 AuthCacheMap cache_;
62 } // namespace net
64 #endif // NET_SSL_SSL_CLIENT_AUTH_CACHE_H_