1 // Copyright 2022 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 #ifndef NET_CERT_PKI_MOCK_SIGNATURE_VERIFY_CACHE_H_ 6 #define NET_CERT_PKI_MOCK_SIGNATURE_VERIFY_CACHE_H_ 7 8 #include <stddef.h> 9 10 #include <string> 11 #include <string_view> 12 #include <unordered_map> 13 14 #include "net/base/net_export.h" 15 #include "net/cert/pki/signature_verify_cache.h" 16 17 namespace net { 18 19 // MockSignatureVerifyCache is an implementation of SignatureVerifyCache. It is 20 // intended only for testing of cache functionality. 21 22 class MockSignatureVerifyCache : public SignatureVerifyCache { 23 public: 24 MockSignatureVerifyCache(); 25 26 ~MockSignatureVerifyCache() override; 27 28 void Store(const std::string& key, 29 SignatureVerifyCache::Value value) override; 30 31 SignatureVerifyCache::Value Check(const std::string& key) override; 32 CacheHits()33 size_t CacheHits() { return hits_; } 34 CacheMisses()35 size_t CacheMisses() { return misses_; } 36 CacheStores()37 size_t CacheStores() { return stores_; } 38 39 private: 40 std::unordered_map<std::string, SignatureVerifyCache::Value> cache_; 41 size_t hits_ = 0; 42 size_t misses_ = 0; 43 size_t stores_ = 0; 44 }; 45 46 } // namespace net 47 48 #endif // NET_CERT_PKI_MOCK_PATH_BUILDER_DELEGATE_H_ 49