Updating trunk VERSION from 1014.0 to 1015.0
[chromium-blink-merge.git] / net / base / cert_test_util.cc
blobfb0c0f8355b604ed3056cac71e09deb27beee4da
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"
12 namespace net {
14 FilePath GetTestCertsDirectory() {
15 FilePath certs_dir;
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");
21 return certs_dir;
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))
30 return NULL;
32 CertificateList certs_in_file =
33 X509Certificate::CreateCertificateListFromBytes(
34 cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
35 if (certs_in_file.empty())
36 return NULL;
37 return certs_in_file[0];
40 } // namespace net