| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "net/cert/internal/parse_certificate.h" | 5 #include "net/cert/internal/parse_certificate.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "net/cert/internal/test_helpers.h" | 8 #include "net/cert/internal/test_helpers.h" |
| 9 #include "net/der/input.h" | 9 #include "net/der/input.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 {"SUBJECT", &expected_subject}, | 149 {"SUBJECT", &expected_subject}, |
| 150 {"SPKI", &expected_spki}, | 150 {"SPKI", &expected_spki}, |
| 151 {"ISSUER UNIQUE ID", &expected_issuer_unique_id, true}, | 151 {"ISSUER UNIQUE ID", &expected_issuer_unique_id, true}, |
| 152 {"SUBJECT UNIQUE ID", &expected_subject_unique_id, true}, | 152 {"SUBJECT UNIQUE ID", &expected_subject_unique_id, true}, |
| 153 {"EXTENSIONS", &expected_extensions, true}, | 153 {"EXTENSIONS", &expected_extensions, true}, |
| 154 }; | 154 }; |
| 155 ASSERT_TRUE(ReadTestDataFromPemFile(GetFilePath(file_name), mappings)); | 155 ASSERT_TRUE(ReadTestDataFromPemFile(GetFilePath(file_name), mappings)); |
| 156 | 156 |
| 157 // Parsing the TBSCertificate should succeed. | 157 // Parsing the TBSCertificate should succeed. |
| 158 ParsedTbsCertificate parsed; | 158 ParsedTbsCertificate parsed; |
| 159 ASSERT_TRUE(ParseTbsCertificate(der::Input(&data), &parsed)); | 159 ASSERT_TRUE(ParseTbsCertificate(der::Input(&data), {}, &parsed)); |
| 160 | 160 |
| 161 // Ensure that the ParsedTbsCertificate matches expectations. | 161 // Ensure that the ParsedTbsCertificate matches expectations. |
| 162 EXPECT_EQ(expected_version, parsed.version); | 162 EXPECT_EQ(expected_version, parsed.version); |
| 163 | 163 |
| 164 EXPECT_EQ(der::Input(&expected_serial_number), parsed.serial_number); | 164 EXPECT_EQ(der::Input(&expected_serial_number), parsed.serial_number); |
| 165 EXPECT_EQ(der::Input(&expected_signature_algorithm), | 165 EXPECT_EQ(der::Input(&expected_signature_algorithm), |
| 166 parsed.signature_algorithm_tlv); | 166 parsed.signature_algorithm_tlv); |
| 167 | 167 |
| 168 EXPECT_EQ(der::Input(&expected_issuer), parsed.issuer_tlv); | 168 EXPECT_EQ(der::Input(&expected_issuer), parsed.issuer_tlv); |
| 169 | 169 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 192 std::string data; | 192 std::string data; |
| 193 | 193 |
| 194 const PemBlockMapping mappings[] = { | 194 const PemBlockMapping mappings[] = { |
| 195 {"TBS CERTIFICATE", &data}, | 195 {"TBS CERTIFICATE", &data}, |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 ASSERT_TRUE(ReadTestDataFromPemFile(GetFilePath(file_name), mappings)); | 198 ASSERT_TRUE(ReadTestDataFromPemFile(GetFilePath(file_name), mappings)); |
| 199 | 199 |
| 200 // Parsing the TBSCertificate should fail. | 200 // Parsing the TBSCertificate should fail. |
| 201 ParsedTbsCertificate parsed; | 201 ParsedTbsCertificate parsed; |
| 202 ASSERT_FALSE(ParseTbsCertificate(der::Input(&data), &parsed)); | 202 ASSERT_FALSE(ParseTbsCertificate(der::Input(&data), {}, &parsed)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Tests parsing a TBSCertificate for v3 that contains no optional fields. | 205 // Tests parsing a TBSCertificate for v3 that contains no optional fields. |
| 206 TEST(ParseTbsCertificateTest, Version3NoOptionals) { | 206 TEST(ParseTbsCertificateTest, Version3NoOptionals) { |
| 207 EnsureParsingTbsSucceeds("tbs_v3_no_optionals.pem", CertificateVersion::V3); | 207 EnsureParsingTbsSucceeds("tbs_v3_no_optionals.pem", CertificateVersion::V3); |
| 208 } | 208 } |
| 209 | 209 |
| 210 // Tests parsing a TBSCertificate for v3 that contains extensions. | 210 // Tests parsing a TBSCertificate for v3 that contains extensions. |
| 211 TEST(ParseTbsCertificateTest, Version3WithExtensions) { | 211 TEST(ParseTbsCertificateTest, Version3WithExtensions) { |
| 212 EnsureParsingTbsSucceeds("tbs_v3_extensions.pem", CertificateVersion::V3); | 212 EnsureParsingTbsSucceeds("tbs_v3_extensions.pem", CertificateVersion::V3); |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 0x00, // Number of unused bits | 786 0x00, // Number of unused bits |
| 787 }; | 787 }; |
| 788 | 788 |
| 789 der::BitString key_usage; | 789 der::BitString key_usage; |
| 790 ASSERT_FALSE(ParseKeyUsage(der::Input(der), &key_usage)); | 790 ASSERT_FALSE(ParseKeyUsage(der::Input(der), &key_usage)); |
| 791 } | 791 } |
| 792 | 792 |
| 793 } // namespace | 793 } // namespace |
| 794 | 794 |
| 795 } // namespace net | 795 } // namespace net |
| OLD | NEW |