Chromium Code Reviews| 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 |