1 // Copyright 2022 The Chromium Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BSSL_PKI_MOCK_SIGNATURE_VERIFY_CACHE_H_
16 #define BSSL_PKI_MOCK_SIGNATURE_VERIFY_CACHE_H_
17 
18 #include <stddef.h>
19 
20 #include <string>
21 #include <string_view>
22 #include <unordered_map>
23 
24 #include <openssl/pki/signature_verify_cache.h>
25 
26 BSSL_NAMESPACE_BEGIN
27 
28 // MockSignatureVerifyCache is an implementation of SignatureVerifyCache.  It is
29 // intended only for testing of cache functionality.
30 
31 class MockSignatureVerifyCache : public SignatureVerifyCache {
32  public:
33   MockSignatureVerifyCache();
34 
35   ~MockSignatureVerifyCache() override;
36 
37   void Store(const std::string &key,
38              SignatureVerifyCache::Value value) override;
39 
40   SignatureVerifyCache::Value Check(const std::string &key) override;
41 
CacheHits()42   size_t CacheHits() { return hits_; }
43 
CacheMisses()44   size_t CacheMisses() { return misses_; }
45 
CacheStores()46   size_t CacheStores() { return stores_; }
47 
48  private:
49   std::unordered_map<std::string, SignatureVerifyCache::Value> cache_;
50   size_t hits_ = 0;
51   size_t misses_ = 0;
52   size_t stores_ = 0;
53 };
54 
55 BSSL_NAMESPACE_END
56 
57 #endif  // BSSL_PKI_MOCK_PATH_BUILDER_DELEGATE_H_
58