Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: net/cert/ct_serialization_unittest.cc

Issue 1576513002: Serialisation code for Certificate Transparency data (Closed) Base URL: ssh://caladan.lon.corp.google.com/usr/local/google/eranm/opensource_clients/chrome/src@sth_consistency_validation_2
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) { 165 TEST_F(CtSerializationTest, EncodesSignedCertificateTimestamp) {
166 scoped_refptr<ct::SignedCertificateTimestamp> sct;
167 ct::GetX509CertSCT(&sct);
168
169 std::string output;
170 EXPECT_TRUE(ct::EncodeSignedCertificateTimestamp(*sct, &output));
171 EXPECT_EQ(ct::GetTestSignedCertificateTimestamp(), output);
172 }
173
174 TEST_F(CtSerializationTest, EncodesValidTreeHeadForSignature) {
166 ct::SignedTreeHead signed_tree_head; 175 ct::SignedTreeHead signed_tree_head;
167 GetSampleSignedTreeHead(&signed_tree_head); 176 GetSampleSignedTreeHead(&signed_tree_head);
168 177
169 std::string encoded; 178 std::string encoded;
170 ct::EncodeTreeHeadSignature(signed_tree_head, &encoded); 179 ct::EncodeTreeHeadSignature(signed_tree_head, &encoded);
171 // Expected size is 50 bytes: 180 // Expected size is 50 bytes:
172 // Byte 0 is version, byte 1 is signature type 181 // Byte 0 is version, byte 1 is signature type
173 // Bytes 2-9 are timestamp 182 // Bytes 2-9 are timestamp
174 // Bytes 10-17 are tree size 183 // Bytes 10-17 are tree size
175 // Bytes 18-49 are sha256 root hash 184 // Bytes 18-49 are sha256 root hash
176 ASSERT_EQ(50u, encoded.length()); 185 ASSERT_EQ(50u, encoded.length());
177 std::string expected_buffer( 186 std::string expected_buffer(
178 "\x0\x1\x0\x0\x1\x45\x3c\x5f\xb8\x35\x0\x0\x0\x0\x0\x0\x0\x15", 18); 187 "\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()); 188 expected_buffer.append(ct::GetSampleSTHSHA256RootHash());
180 ASSERT_EQ(expected_buffer, encoded); 189 ASSERT_EQ(expected_buffer, encoded);
181 } 190 }
182 191
192 TEST_F(CtSerializationTest, EncodesSignedTreeHead) {
193 ct::SignedTreeHead sth;
194 GetSampleSignedTreeHead(&sth);
195
196 std::string output;
197 EXPECT_TRUE(ct::EncodeSignedTreeHead(sth, &output));
198
199 EXPECT_EQ(ct::GetSampleSTH(), output);
200 }
201
202 TEST_F(CtSerializationTest, DecodesSignedTreeHead) {
203 ct::SignedTreeHead expected_sth;
204 GetSampleSignedTreeHead(&expected_sth);
205
206 std::string encoded_sth = ct::GetSampleSTH();
207 base::StringPiece encoded_sth_ptr(encoded_sth);
208 ct::SignedTreeHead sth;
209
210 EXPECT_TRUE(ct::DecodeSignedTreeHead(&encoded_sth_ptr, &sth));
211 EXPECT_EQ(expected_sth, sth);
212 }
213
183 } // namespace net 214 } // namespace net
184 215
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698