Index: net/base/test_root_certs.cc |
diff --git a/net/base/test_root_certs.cc b/net/base/test_root_certs.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5c23e57adeeef8e5fd93e69cc3a4f82129cdf223 |
--- /dev/null |
+++ b/net/base/test_root_certs.cc |
@@ -0,0 +1,43 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/base/test_root_certs.h" |
+ |
+#include "base/file_path.h" |
+#include "base/file_util.h" |
+#include "base/logging.h" |
+#include "net/base/x509_certificate.h" |
+ |
+namespace net { |
+ |
+namespace { |
+ |
+CertificateList LoadCertificates(const FilePath& filename) { |
+ using ::operator<<; |
bulach
2010/11/17 17:17:30
is this needed?
Ryan Sleevi
2010/11/18 05:31:58
Until http://codereview.chromium.org/5162001/ land
|
+ std::string raw_cert; |
+ if (!file_util::ReadFileToString(filename, &raw_cert)) { |
+ LOG(ERROR) << "Can't load certificate " << filename.value(); |
+ return CertificateList(); |
+ } |
+ |
+ return X509Certificate::CreateCertificateListFromBytes( |
+ raw_cert.data(), raw_cert.length(), X509Certificate::FORMAT_AUTO); |
+} |
+ |
+} // namespace |
+ |
+// static |
+TestRootCerts* TestRootCerts::GetInstance() { |
+ return Singleton<TestRootCerts>::get(); |
+} |
+ |
+bool TestRootCerts::AddFromFile(const FilePath& file) { |
+ CertificateList root_certs = LoadCertificates(file); |
+ if (root_certs.empty() || root_certs.size() > 1) |
+ return false; |
+ |
+ return Add(root_certs.front()); |
+} |
+ |
+} // namespace net |