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

Side by Side Diff: net/test/cert_test_util.cc

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months 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
« no previous file with comments | « net/test/cert_test_util.h ('k') | net/test/cert_test_util_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/test/cert_test_util.h"
6
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "net/cert/ev_root_ca_metadata.h"
10 #include "net/cert/x509_certificate.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace net {
14
15 CertificateList CreateCertificateListFromFile(
16 const base::FilePath& certs_dir,
17 const std::string& cert_file,
18 int format) {
19 base::FilePath cert_path = certs_dir.AppendASCII(cert_file);
20 std::string cert_data;
21 if (!base::ReadFileToString(cert_path, &cert_data))
22 return CertificateList();
23 return X509Certificate::CreateCertificateListFromBytes(cert_data.data(),
24 cert_data.size(),
25 format);
26 }
27
28 scoped_refptr<X509Certificate> CreateCertificateChainFromFile(
29 const base::FilePath& certs_dir,
30 const std::string& cert_file,
31 int format) {
32 CertificateList certs = CreateCertificateListFromFile(
33 certs_dir, cert_file, format);
34 if (certs.empty())
35 return NULL;
36
37 X509Certificate::OSCertHandles intermediates;
38 for (size_t i = 1; i < certs.size(); ++i)
39 intermediates.push_back(certs[i]->os_cert_handle());
40
41 scoped_refptr<X509Certificate> result(X509Certificate::CreateFromHandle(
42 certs[0]->os_cert_handle(), intermediates));
43 return result;
44 }
45
46 scoped_refptr<X509Certificate> ImportCertFromFile(
47 const base::FilePath& certs_dir,
48 const std::string& cert_file) {
49 base::FilePath cert_path = certs_dir.AppendASCII(cert_file);
50 std::string cert_data;
51 if (!base::ReadFileToString(cert_path, &cert_data))
52 return NULL;
53
54 CertificateList certs_in_file =
55 X509Certificate::CreateCertificateListFromBytes(
56 cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
57 if (certs_in_file.empty())
58 return NULL;
59 return certs_in_file[0];
60 }
61
62 ScopedTestEVPolicy::ScopedTestEVPolicy(EVRootCAMetadata* ev_root_ca_metadata,
63 const SHA1HashValue& fingerprint,
64 const char* policy)
65 : fingerprint_(fingerprint),
66 ev_root_ca_metadata_(ev_root_ca_metadata) {
67 EXPECT_TRUE(ev_root_ca_metadata->AddEVCA(fingerprint, policy));
68 }
69
70 ScopedTestEVPolicy::~ScopedTestEVPolicy() {
71 EXPECT_TRUE(ev_root_ca_metadata_->RemoveEVCA(fingerprint_));
72 }
73
74 } // namespace net
OLDNEW
« no previous file with comments | « net/test/cert_test_util.h ('k') | net/test/cert_test_util_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698