Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef NET_TEST_CERT_TEST_UTIL_H_ | 5 #ifndef NET_TEST_CERT_TEST_UTIL_H_ | 
| 6 #define NET_TEST_CERT_TEST_UTIL_H_ | 6 #define NET_TEST_CERT_TEST_UTIL_H_ | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" | 
| 11 #include "net/cert/x509_cert_types.h" | 11 #include "net/cert/x509_cert_types.h" | 
| 12 #include "net/cert/x509_certificate.h" | 12 #include "net/cert/x509_certificate.h" | 
| 13 #include "net/test/test_data_directory.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | 15 | 
| 14 #if defined(USE_NSS_CERTS) | 16 #if defined(USE_NSS_CERTS) | 
| 15 // From <pk11pub.h> | 17 // From <pk11pub.h> | 
| 16 typedef struct PK11SlotInfoStr PK11SlotInfo; | 18 typedef struct PK11SlotInfoStr PK11SlotInfo; | 
| 17 #endif | 19 #endif | 
| 18 | 20 | 
| 19 namespace base { | 21 namespace base { | 
| 20 class FilePath; | 22 class FilePath; | 
| 21 } | 23 } | 
| 22 | 24 | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 41 const std::string& key_filename, | 43 const std::string& key_filename, | 
| 42 PK11SlotInfo* slot); | 44 PK11SlotInfo* slot); | 
| 43 #endif | 45 #endif | 
| 44 | 46 | 
| 45 // Imports all of the certificates in |cert_file|, a file in |certs_dir|, into a | 47 // Imports all of the certificates in |cert_file|, a file in |certs_dir|, into a | 
| 46 // CertificateList. | 48 // CertificateList. | 
| 47 CertificateList CreateCertificateListFromFile(const base::FilePath& certs_dir, | 49 CertificateList CreateCertificateListFromFile(const base::FilePath& certs_dir, | 
| 48 const std::string& cert_file, | 50 const std::string& cert_file, | 
| 49 int format); | 51 int format); | 
| 50 | 52 | 
| 53 // Template helper to load a series of certificate files into a CertificateList. | |
| 54 // Like CreateCertificateListFromFile, except it can load a | |
| 55 // series of individual certificates (to make the tests clearer). | |
| 56 template <size_t N> | |
| 57 void LoadCertificateFiles(const char* const (&cert_files)[N], | |
| 58 CertificateList* certs) { | |
| 
 
Ryan Sleevi
2017/02/02 22:20:12
A thought: It might be worth refactoring this a li
 
eroman
2017/02/02 23:27:17
PTAL, I have removed the template parameter all-to
 
 | |
| 59 certs->clear(); | |
| 60 for (size_t i = 0; i < N; ++i) { | |
| 61 SCOPED_TRACE(cert_files[i]); | |
| 62 scoped_refptr<X509Certificate> cert = CreateCertificateChainFromFile( | |
| 63 GetTestCertsDirectory(), cert_files[i], X509Certificate::FORMAT_AUTO); | |
| 64 ASSERT_TRUE(cert); | |
| 65 certs->push_back(cert); | |
| 66 } | |
| 67 } | |
| 68 | |
| 51 // Imports all of the certificates in |cert_file|, a file in |certs_dir|, into | 69 // Imports all of the certificates in |cert_file|, a file in |certs_dir|, into | 
| 52 // a new X509Certificate. The first certificate in the chain will be used for | 70 // a new X509Certificate. The first certificate in the chain will be used for | 
| 53 // the returned cert, with any additional certificates configured as | 71 // the returned cert, with any additional certificates configured as | 
| 54 // intermediate certificates. | 72 // intermediate certificates. | 
| 55 scoped_refptr<X509Certificate> CreateCertificateChainFromFile( | 73 scoped_refptr<X509Certificate> CreateCertificateChainFromFile( | 
| 56 const base::FilePath& certs_dir, | 74 const base::FilePath& certs_dir, | 
| 57 const std::string& cert_file, | 75 const std::string& cert_file, | 
| 58 int format); | 76 int format); | 
| 59 | 77 | 
| 60 // Imports a single certificate from |cert_file|. | 78 // Imports a single certificate from |cert_file|. | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 77 ~ScopedTestEVPolicy(); | 95 ~ScopedTestEVPolicy(); | 
| 78 | 96 | 
| 79 private: | 97 private: | 
| 80 SHA1HashValue fingerprint_; | 98 SHA1HashValue fingerprint_; | 
| 81 EVRootCAMetadata* const ev_root_ca_metadata_; | 99 EVRootCAMetadata* const ev_root_ca_metadata_; | 
| 82 }; | 100 }; | 
| 83 | 101 | 
| 84 } // namespace net | 102 } // namespace net | 
| 85 | 103 | 
| 86 #endif // NET_TEST_CERT_TEST_UTIL_H_ | 104 #endif // NET_TEST_CERT_TEST_UTIL_H_ | 
| OLD | NEW |