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