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

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

Issue 72333007: Add an SignedCertificateTimetampStore, making SignedCertificateTimestamp be refcounted to aid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@piecewise
Patch Set: Fixes for wtc. Created 7 years 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/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
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 EXPECT_EQ(ct::GetTestPublicKeyId(), sct.log_id); 141 EXPECT_EQ(ct::GetTestPublicKeyId(), sct->log_id);
142 base::Time expected_time = base::Time::UnixEpoch() + 142 base::Time expected_time = base::Time::UnixEpoch() +
143 base::TimeDelta::FromMilliseconds(1365181456089); 143 base::TimeDelta::FromMilliseconds(1365181456089);
144 EXPECT_EQ(expected_time, sct.timestamp); 144 EXPECT_EQ(expected_time, sct->timestamp);
145 // Subtracting 4 bytes for signature data (hash & sig algs), 145 // Subtracting 4 bytes for signature data (hash & sig algs),
146 // actual signature data should be 71 bytes. 146 // actual signature data should be 71 bytes.
147 EXPECT_EQ((size_t) 71, sct.signature.signature_data.size()); 147 EXPECT_EQ((size_t) 71, sct->signature.signature_data.size());
148 EXPECT_EQ(std::string(""), sct.extensions); 148 EXPECT_EQ(std::string(""), sct->extensions);
149 } 149 }
150 150
151 TEST_F(CtSerializationTest, FailsDecodingInvalidSignedCertificateTimestamp) { 151 TEST_F(CtSerializationTest, FailsDecodingInvalidSignedCertificateTimestamp) {
152 // Invalid version 152 // Invalid version
153 base::StringPiece invalid_version_sct("\x2\x0", 2); 153 base::StringPiece invalid_version_sct("\x2\x0", 2);
154 ct::SignedCertificateTimestamp sct; 154 scoped_refptr<ct::SignedCertificateTimestamp> sct;
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 } // namespace net 165 } // namespace net
166 166
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698