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..bb2489cf94204e54b312eba18db7162f7e4f0b7e |
--- /dev/null |
+++ b/net/base/test_root_certs.cc |
@@ -0,0 +1,52 @@ |
+// 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 <string> |
+ |
+#include "base/file_path.h" |
+#include "base/file_util.h" |
+#include "base/logging.h" |
+#include "net/base/x509_certificate.h" |
+ |
+namespace net { |
+ |
+namespace { |
+ |
+bool g_has_instance = false; |
+ |
+CertificateList LoadCertificates(const FilePath& filename) { |
+ using ::operator<<; |
+ 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() { |
+ g_has_instance = true; |
+ return Singleton<TestRootCerts>::get(); |
+} |
+ |
+bool TestRootCerts::HasInstance() { |
+ return g_has_instance; |
joth
2010/11/22 13:05:40
this might give some valgrind warnings as g_has_in
bulach
2010/11/22 14:36:50
I like this idea, just some minor suggestions on t
Ryan Sleevi
2010/12/03 03:28:06
joth: I pushed the platform-specific implementatio
Ryan Sleevi
2010/12/03 03:28:06
bulach: Could you explain the reasoning behind thi
joth
2010/12/03 10:40:59
My thinking was to put the "g_has_instance = true;
bulach
2010/12/03 10:58:27
sorry, I wasn't clear :) let me try to explain my
|
+} |
+ |
+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 |