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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: net/base/temporary_root_certs.cc
diff --git a/net/base/temporary_root_certs.cc b/net/base/temporary_root_certs.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d80be8ab512a0988068fbcd5462edb6de6d07ad7
--- /dev/null
+++ b/net/base/temporary_root_certs.cc
@@ -0,0 +1,53 @@
+// 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/temporary_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 {
wtc 2010/11/16 23:24:01 Nit: add a blank line after the beginning and befo
+CertificateList LoadCertificates(const FilePath& filename) {
+ std::string raw_cert;
+ if (!file_util::ReadFileToString(filename, &raw_cert)) {
+ LOG(ERROR) << "Can't load certificate " << filename.value().c_str();
bulach 2010/11/09 16:21:09 s/c_str()//
+ return CertificateList();
+ }
+
+ return X509Certificate::CreateCertificateListFromBytes(
+ raw_cert.c_str(), raw_cert.length(), X509Certificate::FORMAT_AUTO);
bulach 2010/11/09 16:21:09 s/c_str()/data()/
+}
+} // namespace
+
+// static
+TemporaryRootCerts* TemporaryRootCerts::GetInstance() {
+ return Singleton<TemporaryRootCerts>::get();
+}
+
+bool TemporaryRootCerts::AddFromFile(const FilePath& file) {
+ CertificateList root_certs = LoadCertificates(file);
+ if (root_certs.empty())
+ return false;
+
+ for (CertificateList::const_iterator it = root_certs.begin();
+ it != root_certs.end(); ++it) {
+ if (!Add(*it))
+ return false;
bulach 2010/11/09 16:21:09 if there's an error with N-th, should we remove 0.
+ }
+
+ return true;
+}
+
+void TemporaryRootCerts::RemoveFromFile(const FilePath& file) {
+ CertificateList root_certs = LoadCertificates(file);
+ for (CertificateList::const_iterator it = root_certs.begin();
+ it != root_certs.end(); ++it)
+ Remove(*it);
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698