• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/ssl/ssl_client_auth_cache.h"
6 
7 #include "base/check.h"
8 #include "net/cert/x509_certificate.h"
9 #include "net/ssl/ssl_private_key.h"
10 
11 namespace net {
12 
13 SSLClientAuthCache::SSLClientAuthCache() = default;
14 
15 SSLClientAuthCache::~SSLClientAuthCache() = default;
16 
Lookup(const HostPortPair & server,scoped_refptr<X509Certificate> * certificate,scoped_refptr<SSLPrivateKey> * private_key)17 bool SSLClientAuthCache::Lookup(const HostPortPair& server,
18                                 scoped_refptr<X509Certificate>* certificate,
19                                 scoped_refptr<SSLPrivateKey>* private_key) {
20   DCHECK(certificate);
21 
22   auto iter = cache_.find(server);
23   if (iter == cache_.end())
24     return false;
25 
26   *certificate = iter->second.first;
27   *private_key = iter->second.second;
28   return true;
29 }
30 
Add(const HostPortPair & server,scoped_refptr<X509Certificate> certificate,scoped_refptr<SSLPrivateKey> private_key)31 void SSLClientAuthCache::Add(const HostPortPair& server,
32                              scoped_refptr<X509Certificate> certificate,
33                              scoped_refptr<SSLPrivateKey> private_key) {
34   cache_[server] =
35       std::make_pair(std::move(certificate), std::move(private_key));
36 
37   // TODO(wtc): enforce a maximum number of entries.
38 }
39 
Remove(const HostPortPair & server)40 bool SSLClientAuthCache::Remove(const HostPortPair& server) {
41   return cache_.erase(server);
42 }
43 
Clear()44 void SSLClientAuthCache::Clear() {
45   cache_.clear();
46 }
47 
48 }  // namespace net
49