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 BSSL_PKI_MOCK_SIGNATURE_VERIFY_CACHE_H_ 6 #define BSSL_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 <openssl/pki/signature_verify_cache.h> 15 16 namespace bssl { 17 18 // MockSignatureVerifyCache is an implementation of SignatureVerifyCache. It is 19 // intended only for testing of cache functionality. 20 21 class MockSignatureVerifyCache : public SignatureVerifyCache { 22 public: 23 MockSignatureVerifyCache(); 24 25 ~MockSignatureVerifyCache() override; 26 27 void Store(const std::string &key, 28 SignatureVerifyCache::Value value) override; 29 30 SignatureVerifyCache::Value Check(const std::string &key) override; 31 CacheHits()32 size_t CacheHits() { return hits_; } 33 CacheMisses()34 size_t CacheMisses() { return misses_; } 35 CacheStores()36 size_t CacheStores() { return stores_; } 37 38 private: 39 std::unordered_map<std::string, SignatureVerifyCache::Value> cache_; 40 size_t hits_ = 0; 41 size_t misses_ = 0; 42 size_t stores_ = 0; 43 }; 44 45 } // namespace bssl 46 47 #endif // BSSL_PKI_MOCK_PATH_BUILDER_DELEGATE_H_ 48