signature_verify_cache.h (2030B)
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 #if !defined(BSSL_PKI_SIGNATURE_VERIFY_CACHE_H_) && defined(__cplusplus) 16 #define BSSL_PKI_SIGNATURE_VERIFY_CACHE_H_ 17 18 #include <openssl/base.h> // IWYU pragma: export 19 #include <string> 20 21 BSSL_NAMESPACE_BEGIN 22 23 class OPENSSL_EXPORT SignatureVerifyCache { 24 public: 25 enum class Value { 26 kValid, // Cached as a valid signature result. 27 kInvalid, // Cached as an invalid signature result. 28 kUnknown, // Cache has no information. 29 }; 30 31 virtual ~SignatureVerifyCache() = default; 32 33 // This interface uses a const std::string reference instead of 34 // std::string_view because any implementation that may reasonably want to use 35 // std::unordered_map or similar can run into problems with std::hash before 36 // C++20. (https://en.cppreference.com/w/cpp/container/unordered_map/find) 37 38 // |Store| is called to store the result of a verification for |key| as kValid 39 // or kInvalid after a signature check. 40 virtual void Store(const std::string &key, Value value) = 0; 41 42 // |Check| is called to fetch a cached value for a verification for |key|. If 43 // the result is kValid, or kInvalid, signature checking is skipped and the 44 // corresponding cached result is used. If the result is kUnknown signature 45 // checking is performed and the corresponding result saved using |Store|. 46 virtual Value Check(const std::string &key) = 0; 47 }; 48 49 BSSL_NAMESPACE_END 50 51 #endif // BSSL_PKI_SIGNATURE_VERIFY_CACHE_H_ && __cplusplus