1 // Copyright (c) 2010 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/base/cert_test_util.h"
7 #include "base/file_path.h"
8 #include "base/file_util.h"
9 #include "base/path_service.h"
10 #include "net/base/x509_certificate.h"
14 FilePath
GetTestCertsDirectory() {
16 PathService::Get(base::DIR_SOURCE_ROOT
, &certs_dir
);
17 certs_dir
= certs_dir
.AppendASCII("net");
18 certs_dir
= certs_dir
.AppendASCII("data");
19 certs_dir
= certs_dir
.AppendASCII("ssl");
20 certs_dir
= certs_dir
.AppendASCII("certificates");
24 scoped_refptr
<X509Certificate
> ImportCertFromFile(
25 const FilePath
& certs_dir
,
26 const std::string
& cert_file
) {
27 FilePath cert_path
= certs_dir
.AppendASCII(cert_file
);
28 std::string cert_data
;
29 if (!file_util::ReadFileToString(cert_path
, &cert_data
))
32 CertificateList certs_in_file
=
33 X509Certificate::CreateCertificateListFromBytes(
34 cert_data
.data(), cert_data
.size(), X509Certificate::FORMAT_AUTO
);
35 if (certs_in_file
.empty())
37 return certs_in_file
[0];