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.
5 #include "net/test/cert_test_util.h"
7 #include "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "base/path_service.h"
10 #include "net/cert/ev_root_ca_metadata.h"
11 #include "net/cert/x509_certificate.h"
12 #include "testing/gtest/include/gtest/gtest.h"
16 CertificateList
CreateCertificateListFromFile(
17 const base::FilePath
& certs_dir
,
18 const std::string
& cert_file
,
20 base::FilePath cert_path
= certs_dir
.AppendASCII(cert_file
);
21 std::string cert_data
;
22 if (!file_util::ReadFileToString(cert_path
, &cert_data
))
23 return CertificateList();
24 return X509Certificate::CreateCertificateListFromBytes(cert_data
.data(),
29 scoped_refptr
<X509Certificate
> ImportCertFromFile(
30 const base::FilePath
& certs_dir
,
31 const std::string
& cert_file
) {
32 base::FilePath cert_path
= certs_dir
.AppendASCII(cert_file
);
33 std::string cert_data
;
34 if (!file_util::ReadFileToString(cert_path
, &cert_data
))
37 CertificateList certs_in_file
=
38 X509Certificate::CreateCertificateListFromBytes(
39 cert_data
.data(), cert_data
.size(), X509Certificate::FORMAT_AUTO
);
40 if (certs_in_file
.empty())
42 return certs_in_file
[0];
45 ScopedTestEVPolicy::ScopedTestEVPolicy(EVRootCAMetadata
* ev_root_ca_metadata
,
46 const SHA1HashValue
& fingerprint
,
48 : fingerprint_(fingerprint
),
49 ev_root_ca_metadata_(ev_root_ca_metadata
) {
50 EXPECT_TRUE(ev_root_ca_metadata
->AddEVCA(fingerprint
, policy
));
53 ScopedTestEVPolicy::~ScopedTestEVPolicy() {
54 EXPECT_TRUE(ev_root_ca_metadata_
->RemoveEVCA(fingerprint_
));