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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 ASSERT_FALSE( | 156 ASSERT_FALSE( |
157 ct::DecodeSignedCertificateTimestamp(&invalid_version_sct, &sct)); | 157 ct::DecodeSignedCertificateTimestamp(&invalid_version_sct, &sct)); |
158 | 158 |
159 // Valid version, invalid length (missing data) | 159 // Valid version, invalid length (missing data) |
160 base::StringPiece invalid_length_sct("\x0\xa\xb\xc", 4); | 160 base::StringPiece invalid_length_sct("\x0\xa\xb\xc", 4); |
161 ASSERT_FALSE( | 161 ASSERT_FALSE( |
162 ct::DecodeSignedCertificateTimestamp(&invalid_length_sct, &sct)); | 162 ct::DecodeSignedCertificateTimestamp(&invalid_length_sct, &sct)); |
163 } | 163 } |
164 | 164 |
| 165 TEST_F(CtSerializationTest, EncodesValidSignedTreeHead) { |
| 166 ct::SignedTreeHead signed_tree_head; |
| 167 GetSignedTreeHead(&signed_tree_head); |
| 168 |
| 169 std::string encoded; |
| 170 ct::EncodeTreeHeadSignature(signed_tree_head, &encoded); |
| 171 // Expected size is 50 bytes: |
| 172 // Byte 0 is version, byte 1 is signature type |
| 173 // Bytes 2-9 are timestamp |
| 174 // Bytes 10-17 are tree size |
| 175 // Bytes 18-49 are sha256 root hash |
| 176 ASSERT_EQ(50u, encoded.length()); |
| 177 std::string expected_buffer( |
| 178 "\x0\x1\x0\x0\x1\x45\x3c\x5f\xb8\x35\x0\x0\x0\x0\x0\x0\x0\x15", 18); |
| 179 expected_buffer.append(ct::GetSampleSTHSHA256RootHash()); |
| 180 ASSERT_EQ(expected_buffer, encoded); |
| 181 } |
| 182 |
165 } // namespace net | 183 } // namespace net |
166 | 184 |
OLD | NEW |