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/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 146 } |
147 | 147 |
148 TEST_F(CtSerializationTest, FailsDecodingInvalidSCTList) { | 148 TEST_F(CtSerializationTest, FailsDecodingInvalidSCTList) { |
149 // A list with one item that's too short | 149 // A list with one item that's too short |
150 base::StringPiece encoded("\x0\xa\x0\x3\x61\x62\x63\x0\x5\x64\x65\x66", 12); | 150 base::StringPiece encoded("\x0\xa\x0\x3\x61\x62\x63\x0\x5\x64\x65\x66", 12); |
151 std::vector<base::StringPiece> decoded; | 151 std::vector<base::StringPiece> decoded; |
152 | 152 |
153 ASSERT_FALSE(ct::DecodeSCTList(encoded, &decoded)); | 153 ASSERT_FALSE(ct::DecodeSCTList(encoded, &decoded)); |
154 } | 154 } |
155 | 155 |
156 TEST_F(CtSerializationTest, EncodeSignedCertificateTimestamp) { | |
157 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp()); | |
158 base::StringPiece encoded_sct(encoded_test_sct); | |
159 | |
160 scoped_refptr<ct::SignedCertificateTimestamp> sct; | |
161 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); | |
162 | |
163 std::string serialized; | |
164 ct::EncodeSignedCertificateTimestamp(sct, &serialized); | |
165 EXPECT_EQ(serialized, encoded_test_sct); | |
166 } | |
167 | |
168 TEST_F(CtSerializationTest, DecodesSignedCertificateTimestamp) { | 156 TEST_F(CtSerializationTest, DecodesSignedCertificateTimestamp) { |
169 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp()); | 157 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp()); |
170 base::StringPiece encoded_sct(encoded_test_sct); | 158 base::StringPiece encoded_sct(encoded_test_sct); |
171 | 159 |
172 scoped_refptr<ct::SignedCertificateTimestamp> sct; | 160 scoped_refptr<ct::SignedCertificateTimestamp> sct; |
173 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); | 161 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); |
174 EXPECT_EQ(0, sct->version); | 162 EXPECT_EQ(0, sct->version); |
175 EXPECT_EQ(ct::GetTestPublicKeyId(), sct->log_id); | 163 EXPECT_EQ(ct::GetTestPublicKeyId(), sct->log_id); |
176 base::Time expected_time = base::Time::UnixEpoch() + | 164 base::Time expected_time = base::Time::UnixEpoch() + |
177 base::TimeDelta::FromMilliseconds(1365181456089); | 165 base::TimeDelta::FromMilliseconds(1365181456089); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // Bytes 10-17 are tree size | 251 // Bytes 10-17 are tree size |
264 // Bytes 18-49 are sha256 root hash | 252 // Bytes 18-49 are sha256 root hash |
265 ASSERT_EQ(50u, encoded.length()); | 253 ASSERT_EQ(50u, encoded.length()); |
266 std::string expected_buffer( | 254 std::string expected_buffer( |
267 "\x0\x1\x0\x0\x1\x45\x3c\x5f\xb8\x35\x0\x0\x0\x0\x0\x0\x0\x15", 18); | 255 "\x0\x1\x0\x0\x1\x45\x3c\x5f\xb8\x35\x0\x0\x0\x0\x0\x0\x0\x15", 18); |
268 expected_buffer.append(ct::GetSampleSTHSHA256RootHash()); | 256 expected_buffer.append(ct::GetSampleSTHSHA256RootHash()); |
269 ASSERT_EQ(expected_buffer, encoded); | 257 ASSERT_EQ(expected_buffer, encoded); |
270 } | 258 } |
271 | 259 |
272 } // namespace net | 260 } // namespace net |
OLD | NEW |