net: extract net/cert out of net/base
This introduces the following dependency of net/base on things outside:
net/base/openssl_client_key_store.cc:#include "net/cert/x509_certificate.h"
BUG=70818
Review URL: https://codereview.chromium.org/13006020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191450 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/test/cert_test_util.cc b/net/test/cert_test_util.cc
new file mode 100644
index 0000000..085a459
--- /dev/null
+++ b/net/test/cert_test_util.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2012 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/test/cert_test_util.h"
+
+#include "base/file_util.h"
+#include "base/files/file_path.h"
+#include "base/path_service.h"
+#include "net/cert/ev_root_ca_metadata.h"
+#include "net/cert/x509_certificate.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+CertificateList CreateCertificateListFromFile(
+ const base::FilePath& certs_dir,
+ const std::string& cert_file,
+ int format) {
+ base::FilePath cert_path = certs_dir.AppendASCII(cert_file);
+ std::string cert_data;
+ if (!file_util::ReadFileToString(cert_path, &cert_data))
+ return CertificateList();
+ return X509Certificate::CreateCertificateListFromBytes(cert_data.data(),
+ cert_data.size(),
+ format);
+}
+
+scoped_refptr<X509Certificate> ImportCertFromFile(
+ const base::FilePath& certs_dir,
+ const std::string& cert_file) {
+ base::FilePath cert_path = certs_dir.AppendASCII(cert_file);
+ std::string cert_data;
+ if (!file_util::ReadFileToString(cert_path, &cert_data))
+ return NULL;
+
+ CertificateList certs_in_file =
+ X509Certificate::CreateCertificateListFromBytes(
+ cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
+ if (certs_in_file.empty())
+ return NULL;
+ return certs_in_file[0];
+}
+
+ScopedTestEVPolicy::ScopedTestEVPolicy(EVRootCAMetadata* ev_root_ca_metadata,
+ const SHA1HashValue& fingerprint,
+ const char* policy)
+ : fingerprint_(fingerprint),
+ ev_root_ca_metadata_(ev_root_ca_metadata) {
+ EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy));
+}
+
+ScopedTestEVPolicy::~ScopedTestEVPolicy() {
+ EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_));
+}
+
+} // namespace net