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 |
156 TEST_F(CtSerializationTest, DecodesSignedCertificateTimestamp) { | 168 TEST_F(CtSerializationTest, DecodesSignedCertificateTimestamp) { |
157 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp()); | 169 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp()); |
158 base::StringPiece encoded_sct(encoded_test_sct); | 170 base::StringPiece encoded_sct(encoded_test_sct); |
159 | 171 |
160 scoped_refptr<ct::SignedCertificateTimestamp> sct; | 172 scoped_refptr<ct::SignedCertificateTimestamp> sct; |
161 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); | 173 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); |
162 EXPECT_EQ(0, sct->version); | 174 EXPECT_EQ(0, sct->version); |
163 EXPECT_EQ(ct::GetTestPublicKeyId(), sct->log_id); | 175 EXPECT_EQ(ct::GetTestPublicKeyId(), sct->log_id); |
164 base::Time expected_time = base::Time::UnixEpoch() + | 176 base::Time expected_time = base::Time::UnixEpoch() + |
165 base::TimeDelta::FromMilliseconds(1365181456089); | 177 base::TimeDelta::FromMilliseconds(1365181456089); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // Bytes 10-17 are tree size | 263 // Bytes 10-17 are tree size |
252 // Bytes 18-49 are sha256 root hash | 264 // Bytes 18-49 are sha256 root hash |
253 ASSERT_EQ(50u, encoded.length()); | 265 ASSERT_EQ(50u, encoded.length()); |
254 std::string expected_buffer( | 266 std::string expected_buffer( |
255 "\x0\x1\x0\x0\x1\x45\x3c\x5f\xb8\x35\x0\x0\x0\x0\x0\x0\x0\x15", 18); | 267 "\x0\x1\x0\x0\x1\x45\x3c\x5f\xb8\x35\x0\x0\x0\x0\x0\x0\x0\x15", 18); |
256 expected_buffer.append(ct::GetSampleSTHSHA256RootHash()); | 268 expected_buffer.append(ct::GetSampleSTHSHA256RootHash()); |
257 ASSERT_EQ(expected_buffer, encoded); | 269 ASSERT_EQ(expected_buffer, encoded); |
258 } | 270 } |
259 | 271 |
260 } // namespace net | 272 } // namespace net |
OLD | NEW |