Chromium Code Reviews| Index: ios/web/net/cert_verification_cache.h |
| diff --git a/ios/web/net/cert_verification_cache.h b/ios/web/net/cert_verification_cache.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e992b35df7e758484ac9d8237741f3dfd0be9084 |
| --- /dev/null |
| +++ b/ios/web/net/cert_verification_cache.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef IOS_WEB_NET_CERT_VERIFICATION_CACHE_H_ |
| +#define IOS_WEB_NET_CERT_VERIFICATION_CACHE_H_ |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "net/cert/x509_certificate.h" |
| + |
| +namespace web { |
| + |
| +// Allows caching cert verification data. Key is cert-host pair, value is |
| +// a template param. |
| +template <typename ValueType> |
|
stuartmorgan
2015/09/23 17:36:09
Why templated? The actual code only stores one val
Eugene But (OOO till 7-30)
2015/09/23 20:40:47
Because ValueType (CertStatus, is_recoverable flag
|
| +class CertVerificationCache { |
| + public: |
| + CertVerificationCache() {} |
| + ~CertVerificationCache() {} |
| + |
| + // Retrieves |value| for the given cert-host pair. |cert| cannot be null. |
| + // Returns true on success. |
| + bool get(const scoped_refptr<net::X509Certificate>& cert, |
| + const std::string& host, |
| + ValueType* value) const { |
| + auto it = map_.find(KeyType(cert, host)); |
| + if (it == map_.end()) |
| + return false; |
| + |
| + *value = it->second; |
| + return true; |
| + } |
| + |
| + // Adds |value| for the given cert-host pair. |cert| cannot be null. |
| + void set(const scoped_refptr<net::X509Certificate>& cert, |
| + const std::string& host, |
| + const ValueType& value) { |
| + DCHECK(cert); |
| + map_[KeyType(cert, host)] = value; |
| + } |
| + |
| + // Clears the cache. |
| + void reset() { map_.clear(); } |
| + |
| + private: |
| + // Holds cert-host pair and provides less-than comparator. |
| + struct KeyType { |
| + KeyType(const scoped_refptr<net::X509Certificate>& cert, |
| + const std::string& host) |
| + : cert(cert), host(host) {} |
| + |
| + bool operator<(const KeyType& other) const { |
| + if (host == other.host) |
| + return cert_comparator(cert, other.cert); |
| + return host < other.host; |
| + } |
| + |
| + scoped_refptr<net::X509Certificate> cert; |
| + std::string host; |
| + |
| + private: |
| + net::X509Certificate::LessThan cert_comparator; |
| + }; |
| + |
| + std::map<KeyType, ValueType> map_; |
| +}; |
| + |
| +} // namespace web |
| + |
| +#endif // IOS_WEB_NET_CERT_VERIFICATION_CACHE_H_ |