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/cert_compressor.h" | 5 #include "net/quic/crypto/cert_compressor.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "net/quic/quic_utils.h" | 8 #include "net/quic/quic_utils.h" |
9 #include "net/quic/test_tools/crypto_test_utils.h" | 9 #include "net/quic/test_tools/crypto_test_utils.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 ASSERT_TRUE( | 40 ASSERT_TRUE( |
41 CertCompressor::DecompressChain(compressed, cached_certs, NULL, &chain2)); | 41 CertCompressor::DecompressChain(compressed, cached_certs, NULL, &chain2)); |
42 EXPECT_EQ(chain.size(), chain2.size()); | 42 EXPECT_EQ(chain.size(), chain2.size()); |
43 EXPECT_EQ(chain[0], chain2[0]); | 43 EXPECT_EQ(chain[0], chain2[0]); |
44 } | 44 } |
45 | 45 |
46 TEST(CertCompressor, Common) { | 46 TEST(CertCompressor, Common) { |
47 vector<string> chain; | 47 vector<string> chain; |
48 chain.push_back("testcert"); | 48 chain.push_back("testcert"); |
49 static const uint64 set_hash = 42; | 49 static const uint64 set_hash = 42; |
50 scoped_ptr<CommonCertSets> common_set( | 50 scoped_ptr<CommonCertSets> common_sets( |
51 CryptoTestUtils::MockCommonCertSets(chain[0], set_hash, 1)); | 51 CryptoTestUtils::MockCommonCertSets(chain[0], set_hash, 1)); |
52 const string compressed = CertCompressor::CompressChain( | 52 const string compressed = CertCompressor::CompressChain( |
53 chain, | 53 chain, |
54 StringPiece(reinterpret_cast<const char*>(&set_hash), sizeof(set_hash)), | 54 StringPiece(reinterpret_cast<const char*>(&set_hash), sizeof(set_hash)), |
55 StringPiece(), common_set.get()); | 55 StringPiece(), common_sets.get()); |
56 const string common("03" /* common */ | 56 const string common("03" /* common */ |
57 "2A00000000000000" /* set hash 42 */ | 57 "2A00000000000000" /* set hash 42 */ |
58 "01000000" /* index 1 */ | 58 "01000000" /* index 1 */ |
59 "00" /* end of list */); | 59 "00" /* end of list */); |
60 EXPECT_EQ(common.data(), | 60 EXPECT_EQ(common.data(), |
61 base::HexEncode(compressed.data(), compressed.size())); | 61 base::HexEncode(compressed.data(), compressed.size())); |
62 | 62 |
63 vector<string> chain2, cached_certs; | 63 vector<string> chain2, cached_certs; |
64 ASSERT_TRUE(CertCompressor::DecompressChain(compressed, cached_certs, | 64 ASSERT_TRUE(CertCompressor::DecompressChain(compressed, cached_certs, |
65 common_set.get(), &chain2)); | 65 common_sets.get(), &chain2)); |
66 EXPECT_EQ(chain.size(), chain2.size()); | 66 EXPECT_EQ(chain.size(), chain2.size()); |
67 EXPECT_EQ(chain[0], chain2[0]); | 67 EXPECT_EQ(chain[0], chain2[0]); |
68 } | 68 } |
69 | 69 |
70 TEST(CertCompressor, Cached) { | 70 TEST(CertCompressor, Cached) { |
71 vector<string> chain; | 71 vector<string> chain; |
72 chain.push_back("testcert"); | 72 chain.push_back("testcert"); |
73 uint64 hash = QuicUtils::FNV1a_64_Hash(chain[0].data(), chain[0].size()); | 73 uint64 hash = QuicUtils::FNV1a_64_Hash(chain[0].data(), chain[0].size()); |
74 StringPiece hash_bytes(reinterpret_cast<char*>(&hash), sizeof(hash)); | 74 StringPiece hash_bytes(reinterpret_cast<char*>(&hash), sizeof(hash)); |
75 const string compressed = | 75 const string compressed = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 cached_certs, NULL, &chain)); | 117 cached_certs, NULL, &chain)); |
118 | 118 |
119 /* without a CommonCertSets */ | 119 /* without a CommonCertSets */ |
120 const string without_a_common_cert_set( | 120 const string without_a_common_cert_set( |
121 "03" "0000000000000000" "00000000"); | 121 "03" "0000000000000000" "00000000"); |
122 EXPECT_FALSE(CertCompressor::DecompressChain( | 122 EXPECT_FALSE(CertCompressor::DecompressChain( |
123 base::HexEncode(without_a_common_cert_set.data(), | 123 base::HexEncode(without_a_common_cert_set.data(), |
124 without_a_common_cert_set.size()), | 124 without_a_common_cert_set.size()), |
125 cached_certs, NULL, &chain)); | 125 cached_certs, NULL, &chain)); |
126 | 126 |
127 scoped_ptr<CommonCertSets> common_set( | 127 scoped_ptr<CommonCertSets> common_sets( |
128 CryptoTestUtils::MockCommonCertSets("foo", 42, 1)); | 128 CryptoTestUtils::MockCommonCertSets("foo", 42, 1)); |
129 | 129 |
130 /* incorrect hash and index */ | 130 /* incorrect hash and index */ |
131 const string incorrect_hash_and_index( | 131 const string incorrect_hash_and_index( |
132 "03" "a200000000000000" "00000000"); | 132 "03" "a200000000000000" "00000000"); |
133 EXPECT_FALSE(CertCompressor::DecompressChain( | 133 EXPECT_FALSE(CertCompressor::DecompressChain( |
134 base::HexEncode(incorrect_hash_and_index.data(), | 134 base::HexEncode(incorrect_hash_and_index.data(), |
135 incorrect_hash_and_index.size()), | 135 incorrect_hash_and_index.size()), |
136 cached_certs, NULL, &chain)); | 136 cached_certs, NULL, &chain)); |
137 } | 137 } |
138 | 138 |
139 } // namespace test | 139 } // namespace test |
140 } // namespace net | 140 } // namespace net |
OLD | NEW |