Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: net/base/temporary_root_certs.cc

Issue 4646001: Implement LoadTemporaryRoot for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/net/base
Patch Set: Feedback from phajdan.jr and bulach Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/temporary_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 {
wtc 2010/11/16 23:24:01 Nit: add a blank line after the beginning and befo
15 CertificateList LoadCertificates(const FilePath& filename) {
16 std::string raw_cert;
17 if (!file_util::ReadFileToString(filename, &raw_cert)) {
18 LOG(ERROR) << "Can't load certificate " << filename.value().c_str();
bulach 2010/11/09 16:21:09 s/c_str()//
19 return CertificateList();
20 }
21
22 return X509Certificate::CreateCertificateListFromBytes(
23 raw_cert.c_str(), raw_cert.length(), X509Certificate::FORMAT_AUTO);
bulach 2010/11/09 16:21:09 s/c_str()/data()/
24 }
25 } // namespace
26
27 // static
28 TemporaryRootCerts* TemporaryRootCerts::GetInstance() {
29 return Singleton<TemporaryRootCerts>::get();
30 }
31
32 bool TemporaryRootCerts::AddFromFile(const FilePath& file) {
33 CertificateList root_certs = LoadCertificates(file);
34 if (root_certs.empty())
35 return false;
36
37 for (CertificateList::const_iterator it = root_certs.begin();
38 it != root_certs.end(); ++it) {
39 if (!Add(*it))
40 return false;
bulach 2010/11/09 16:21:09 if there's an error with N-th, should we remove 0.
41 }
42
43 return true;
44 }
45
46 void TemporaryRootCerts::RemoveFromFile(const FilePath& file) {
47 CertificateList root_certs = LoadCertificates(file);
48 for (CertificateList::const_iterator it = root_certs.begin();
49 it != root_certs.end(); ++it)
50 Remove(*it);
51 }
52
53 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698