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 #include "cert_issuer_source_static.h"
16 
17 BSSL_NAMESPACE_BEGIN
18 
19 CertIssuerSourceStatic::CertIssuerSourceStatic() = default;
20 CertIssuerSourceStatic::~CertIssuerSourceStatic() = default;
21 
AddCert(std::shared_ptr<const ParsedCertificate> cert)22 void CertIssuerSourceStatic::AddCert(
23     std::shared_ptr<const ParsedCertificate> cert) {
24   intermediates_.insert(std::make_pair(
25       BytesAsStringView(cert->normalized_subject()), std::move(cert)));
26 }
27 
Clear()28 void CertIssuerSourceStatic::Clear() { intermediates_.clear(); }
29 
30 std::vector<std::shared_ptr<const ParsedCertificate>>
Certs() const31 CertIssuerSourceStatic::Certs() const {
32   std::vector<std::shared_ptr<const ParsedCertificate>> result;
33   result.reserve(intermediates_.size());
34   for (const auto& [key, cert] : intermediates_) {
35     result.push_back(cert);
36   }
37   return result;
38 }
39 
SyncGetIssuersOf(const ParsedCertificate * cert,ParsedCertificateList * issuers)40 void CertIssuerSourceStatic::SyncGetIssuersOf(const ParsedCertificate *cert,
41                                               ParsedCertificateList *issuers) {
42   auto range =
43       intermediates_.equal_range(BytesAsStringView(cert->normalized_issuer()));
44   for (auto it = range.first; it != range.second; ++it) {
45     issuers->push_back(it->second);
46   }
47 }
48 
AsyncGetIssuersOf(const ParsedCertificate * cert,std::unique_ptr<Request> * out_req)49 void CertIssuerSourceStatic::AsyncGetIssuersOf(
50     const ParsedCertificate *cert, std::unique_ptr<Request> *out_req) {
51   // CertIssuerSourceStatic never returns asynchronous results.
52   out_req->reset();
53 }
54 
55 BSSL_NAMESPACE_END
56