OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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/base/test_root_certs.h" |
| 6 |
| 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" |
| 10 #include "net/base/x509_certificate.h" |
| 11 |
| 12 namespace net { |
| 13 |
| 14 namespace { |
| 15 |
| 16 CertificateList LoadCertificates(const FilePath& filename) { |
| 17 using ::operator<<; |
| 18 std::string raw_cert; |
| 19 if (!file_util::ReadFileToString(filename, &raw_cert)) { |
| 20 LOG(ERROR) << "Can't load certificate " << filename.value(); |
| 21 return CertificateList(); |
| 22 } |
| 23 |
| 24 return X509Certificate::CreateCertificateListFromBytes( |
| 25 raw_cert.data(), raw_cert.length(), X509Certificate::FORMAT_AUTO); |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 // static |
| 31 TestRootCerts* TestRootCerts::GetInstance() { |
| 32 return Singleton<TestRootCerts>::get(); |
| 33 } |
| 34 |
| 35 bool TestRootCerts::AddFromFile(const FilePath& file) { |
| 36 CertificateList root_certs = LoadCertificates(file); |
| 37 if (root_certs.empty() || root_certs.size() > 1) |
| 38 return false; |
| 39 |
| 40 return Add(root_certs.front()); |
| 41 } |
| 42 |
| 43 } // namespace net |
OLD | NEW |