1 // Copyright 2017 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/test_root_certs.h"
6 
7 #include "base/location.h"
8 #include "base/logging.h"
9 #include "net/cert/internal/cert_errors.h"
10 #include "net/cert/internal/parsed_certificate.h"
11 #include "net/cert/x509_certificate.h"
12 #include "net/cert/x509_util.h"
13 #include "third_party/boringssl/src/include/openssl/pool.h"
14 
15 namespace net {
16 
Add(X509Certificate * certificate)17 bool TestRootCerts::Add(X509Certificate* certificate) {
18   CertErrors errors;
19   auto parsed =
20       ParsedCertificate::Create(bssl::UpRef(certificate->cert_buffer()),
21                                 ParseCertificateOptions(), &errors);
22   if (!parsed) {
23     LOG(ERROR) << "Failed to parse DER certificate: " << errors.ToDebugString();
24     return false;
25   }
26   test_trust_store_.AddTrustAnchor(parsed);
27   empty_ = false;
28   return true;
29 }
30 
Clear()31 void TestRootCerts::Clear() {
32   test_trust_store_.Clear();
33   empty_ = true;
34 }
35 
IsEmpty() const36 bool TestRootCerts::IsEmpty() const {
37   return empty_;
38 }
39 
~TestRootCerts()40 TestRootCerts::~TestRootCerts() {}
41 
Init()42 void TestRootCerts::Init() {
43   empty_ = true;
44 }
45 
46 }  // namespace net
47