| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ct_serialization.h" | 5 #include "net/cert/ct_serialization.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 base::StringPiece encoded("\x0\xa\x0\x3\x61\x62\x63\x0\x5\x64\x65\x66", 12); | 128 base::StringPiece encoded("\x0\xa\x0\x3\x61\x62\x63\x0\x5\x64\x65\x66", 12); |
| 129 std::vector<base::StringPiece> decoded; | 129 std::vector<base::StringPiece> decoded; |
| 130 | 130 |
| 131 ASSERT_FALSE(ct::DecodeSCTList(&encoded, &decoded)); | 131 ASSERT_FALSE(ct::DecodeSCTList(&encoded, &decoded)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 TEST_F(CtSerializationTest, DecodesSignedCertificateTimestamp) { | 134 TEST_F(CtSerializationTest, DecodesSignedCertificateTimestamp) { |
| 135 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp()); | 135 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp()); |
| 136 base::StringPiece encoded_sct(encoded_test_sct); | 136 base::StringPiece encoded_sct(encoded_test_sct); |
| 137 | 137 |
| 138 ct::SignedCertificateTimestamp sct; | 138 scoped_refptr<ct::SignedCertificateTimestamp> sct; |
| 139 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); | 139 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); |
| 140 EXPECT_EQ(0, sct.version); | 140 EXPECT_EQ(0, sct->version); |
| 141 std::string expected_log_key( | 141 std::string expected_log_key( |
| 142 "\xdf\x1c\x2e\xc1\x15\x00\x94\x52\x47\xa9\x61\x68\x32\x5d\xdc\x5c\x79\x59" | 142 "\xdf\x1c\x2e\xc1\x15\x00\x94\x52\x47\xa9\x61\x68\x32\x5d\xdc\x5c\x79\x59" |
| 143 "\xe8\xf7\xc6\xd3\x88\xfc\x00\x2e\x0b\xbd\x3f\x74\xd7\x64", | 143 "\xe8\xf7\xc6\xd3\x88\xfc\x00\x2e\x0b\xbd\x3f\x74\xd7\x64", |
| 144 32); | 144 32); |
| 145 EXPECT_EQ(expected_log_key, sct.log_id); | 145 EXPECT_EQ(expected_log_key, sct->log_id); |
| 146 base::Time expected_time = base::Time::UnixEpoch() + | 146 base::Time expected_time = base::Time::UnixEpoch() + |
| 147 base::TimeDelta::FromMilliseconds(1365181456089); | 147 base::TimeDelta::FromMilliseconds(1365181456089); |
| 148 EXPECT_EQ(expected_time, sct.timestamp); | 148 EXPECT_EQ(expected_time, sct->timestamp); |
| 149 // Subtracting 4 bytes for signature data (hash & sig algs), | 149 // Subtracting 4 bytes for signature data (hash & sig algs), |
| 150 // actual signature data should be 71 bytes. | 150 // actual signature data should be 71 bytes. |
| 151 EXPECT_EQ((size_t) 71, sct.signature.signature_data.size()); | 151 EXPECT_EQ((size_t) 71, sct->signature.signature_data.size()); |
| 152 EXPECT_EQ(std::string(""), sct.extensions); | 152 EXPECT_EQ(std::string(""), sct->extensions); |
| 153 } | 153 } |
| 154 | 154 |
| 155 TEST_F(CtSerializationTest, FailsDecodingInvalidSignedCertificateTimestamp) { | 155 TEST_F(CtSerializationTest, FailsDecodingInvalidSignedCertificateTimestamp) { |
| 156 // Invalid version | 156 // Invalid version |
| 157 base::StringPiece invalid_version_sct("\x2\x0", 2); | 157 base::StringPiece invalid_version_sct("\x2\x0", 2); |
| 158 ct::SignedCertificateTimestamp sct; | 158 scoped_refptr<ct::SignedCertificateTimestamp> sct; |
| 159 | 159 |
| 160 ASSERT_FALSE( | 160 ASSERT_FALSE( |
| 161 ct::DecodeSignedCertificateTimestamp(&invalid_version_sct, &sct)); | 161 ct::DecodeSignedCertificateTimestamp(&invalid_version_sct, &sct)); |
| 162 | 162 |
| 163 // Valid version, invalid length (missing data) | 163 // Valid version, invalid length (missing data) |
| 164 base::StringPiece invalid_length_sct("\x0\xa\xb\xc", 4); | 164 base::StringPiece invalid_length_sct("\x0\xa\xb\xc", 4); |
| 165 ASSERT_FALSE( | 165 ASSERT_FALSE( |
| 166 ct::DecodeSignedCertificateTimestamp(&invalid_length_sct, &sct)); | 166 ct::DecodeSignedCertificateTimestamp(&invalid_length_sct, &sct)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace net | 169 } // namespace net |
| 170 | 170 |
| OLD | NEW |