1 // Copyright 2016 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_CERT_ISSUER_SOURCE_STATIC_H_ 16 #define BSSL_PKI_CERT_ISSUER_SOURCE_STATIC_H_ 17 18 #include <unordered_map> 19 #include <vector> 20 21 #include <openssl/base.h> 22 23 #include "cert_issuer_source.h" 24 25 BSSL_NAMESPACE_BEGIN 26 27 // Synchronously returns issuers from a pre-supplied set. 28 class OPENSSL_EXPORT CertIssuerSourceStatic : public CertIssuerSource { 29 public: 30 CertIssuerSourceStatic(); 31 32 CertIssuerSourceStatic(const CertIssuerSourceStatic &) = delete; 33 CertIssuerSourceStatic &operator=(const CertIssuerSourceStatic &) = delete; 34 35 ~CertIssuerSourceStatic() override; 36 37 // Adds |cert| to the set of certificates that this CertIssuerSource will 38 // provide. 39 void AddCert(std::shared_ptr<const ParsedCertificate> cert); 40 41 // Clears the set of certificates. 42 void Clear(); 43 44 // Returns a vector containing all the certificates added to this source. 45 std::vector<std::shared_ptr<const ParsedCertificate>> Certs() const; 46 size()47 size_t size() const { return intermediates_.size(); } 48 49 // CertIssuerSource implementation: 50 void SyncGetIssuersOf(const ParsedCertificate *cert, 51 ParsedCertificateList *issuers) override; 52 void AsyncGetIssuersOf(const ParsedCertificate *cert, 53 std::unique_ptr<Request> *out_req) override; 54 55 private: 56 // The certificates that the CertIssuerSourceStatic can return, keyed on the 57 // normalized subject value. 58 std::unordered_multimap<std::string_view, 59 std::shared_ptr<const ParsedCertificate>> 60 intermediates_; 61 }; 62 63 BSSL_NAMESPACE_END 64 65 #endif // BSSL_PKI_CERT_ISSUER_SOURCE_STATIC_H_ 66