OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/cert/internal/trust_store.h" |
| 6 |
| 7 #include "net/cert/internal/parsed_certificate.h" |
| 8 |
| 9 namespace net { |
| 10 |
| 11 TrustStore::TrustStore() {} |
| 12 TrustStore::~TrustStore() {} |
| 13 |
| 14 void TrustStore::Clear() { |
| 15 anchors_.clear(); |
| 16 } |
| 17 |
| 18 void TrustStore::AddTrustedCertificate( |
| 19 scoped_refptr<ParsedCertificate> anchor) { |
| 20 // TODO(mattm): should this check for duplicate certs? |
| 21 anchors_.insert(std::make_pair(anchor->normalized_subject().AsStringPiece(), |
| 22 std::move(anchor))); |
| 23 } |
| 24 |
| 25 void TrustStore::FindTrustAnchorsByNormalizedName( |
| 26 const der::Input& normalized_name, |
| 27 std::vector<scoped_refptr<ParsedCertificate>>* matches) const { |
| 28 auto range = anchors_.equal_range(normalized_name.AsStringPiece()); |
| 29 for (auto it = range.first; it != range.second; ++it) |
| 30 matches->push_back(it->second); |
| 31 } |
| 32 |
| 33 bool TrustStore::IsTrustedCertificate(const ParsedCertificate* cert) const { |
| 34 auto range = anchors_.equal_range(cert->normalized_subject().AsStringPiece()); |
| 35 for (auto it = range.first; it != range.second; ++it) { |
| 36 // First compare the ParsedCertificate pointers as an optimization, fall |
| 37 // back to comparing full DER encoding. |
| 38 if (it->second == cert || it->second->der_cert() == cert->der_cert()) |
| 39 return true; |
| 40 } |
| 41 return false; |
| 42 } |
| 43 |
| 44 } // namespace net |
OLD | NEW |