OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/quic/crypto/common_cert_set.h" | 5 #include "net/quic/crypto/common_cert_set.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 0xbb, 0x8d, 0xd7, 0xad, 0x52, 0x64, 0x16, 0x57, 0x96, 0xd9, 0x5e, 0x34, | 187 0xbb, 0x8d, 0xd7, 0xad, 0x52, 0x64, 0x16, 0x57, 0x96, 0xd9, 0x5e, 0x34, |
188 0x7e, 0xc8, 0x35, 0xd8, | 188 0x7e, 0xc8, 0x35, 0xd8, |
189 }; | 189 }; |
190 | 190 |
191 TEST(CommonCertSets, FindGIA_1) { | 191 TEST(CommonCertSets, FindGIA_1) { |
192 StringPiece gia(reinterpret_cast<const char*>(kGIACertificate1), | 192 StringPiece gia(reinterpret_cast<const char*>(kGIACertificate1), |
193 sizeof(kGIACertificate1)); | 193 sizeof(kGIACertificate1)); |
194 | 194 |
195 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); | 195 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); |
196 // Common Cert Set 1's hash. | 196 // Common Cert Set 1's hash. |
197 const uint64 in_hash = UINT64_C(0xff715ce4e7e9267b); | 197 const uint64_t in_hash = UINT64_C(0xff715ce4e7e9267b); |
198 uint64 hash; | 198 uint64_t hash; |
199 uint32 index; | 199 uint32_t index; |
200 ASSERT_TRUE(sets->MatchCert( | 200 ASSERT_TRUE(sets->MatchCert( |
201 gia, | 201 gia, |
202 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 202 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
203 &hash, &index)); | 203 &hash, &index)); |
204 EXPECT_EQ(in_hash, hash); | 204 EXPECT_EQ(in_hash, hash); |
205 | 205 |
206 StringPiece gia_copy = sets->GetCert(hash, index); | 206 StringPiece gia_copy = sets->GetCert(hash, index); |
207 EXPECT_FALSE(gia_copy.empty()); | 207 EXPECT_FALSE(gia_copy.empty()); |
208 ASSERT_EQ(gia.size(), gia_copy.size()); | 208 ASSERT_EQ(gia.size(), gia_copy.size()); |
209 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); | 209 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); |
210 } | 210 } |
211 | 211 |
212 TEST(CommonCertSets, FindGIA_2) { | 212 TEST(CommonCertSets, FindGIA_2) { |
213 StringPiece gia(reinterpret_cast<const char*>(kGIACertificate2), | 213 StringPiece gia(reinterpret_cast<const char*>(kGIACertificate2), |
214 sizeof(kGIACertificate2)); | 214 sizeof(kGIACertificate2)); |
215 | 215 |
216 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); | 216 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); |
217 // Common Cert Set 2's hash. | 217 // Common Cert Set 2's hash. |
218 const uint64 in_hash = UINT64_C(0xe81a92926081e801); | 218 const uint64_t in_hash = UINT64_C(0xe81a92926081e801); |
219 uint64 hash; | 219 uint64_t hash; |
220 uint32 index; | 220 uint32_t index; |
221 ASSERT_TRUE(sets->MatchCert( | 221 ASSERT_TRUE(sets->MatchCert( |
222 gia, | 222 gia, |
223 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 223 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
224 &hash, &index)); | 224 &hash, &index)); |
225 EXPECT_EQ(in_hash, hash); | 225 EXPECT_EQ(in_hash, hash); |
226 | 226 |
227 StringPiece gia_copy = sets->GetCert(hash, index); | 227 StringPiece gia_copy = sets->GetCert(hash, index); |
228 EXPECT_FALSE(gia_copy.empty()); | 228 EXPECT_FALSE(gia_copy.empty()); |
229 ASSERT_EQ(gia.size(), gia_copy.size()); | 229 ASSERT_EQ(gia.size(), gia_copy.size()); |
230 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); | 230 EXPECT_EQ(0, memcmp(gia.data(), gia_copy.data(), gia.size())); |
231 } | 231 } |
232 | 232 |
233 TEST(CommonCertSets, NonMatch) { | 233 TEST(CommonCertSets, NonMatch) { |
234 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); | 234 const CommonCertSets* sets(CommonCertSets::GetInstanceQUIC()); |
235 StringPiece not_a_cert("hello"); | 235 StringPiece not_a_cert("hello"); |
236 const uint64 in_hash = UINT64_C(0xc9fef74053f99f39); | 236 const uint64_t in_hash = UINT64_C(0xc9fef74053f99f39); |
237 uint64 hash; | 237 uint64_t hash; |
238 uint32 index; | 238 uint32_t index; |
239 EXPECT_FALSE(sets->MatchCert( | 239 EXPECT_FALSE(sets->MatchCert( |
240 not_a_cert, | 240 not_a_cert, |
241 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), | 241 StringPiece(reinterpret_cast<const char*>(&in_hash), sizeof(in_hash)), |
242 &hash, &index)); | 242 &hash, &index)); |
243 } | 243 } |
244 | 244 |
245 } // namespace test | 245 } // namespace test |
246 } // namespace net | 246 } // namespace net |
OLD | NEW |