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/crypto_utils.h" | 5 #include "net/quic/crypto/crypto_utils.h" |
6 | 6 |
| 7 #include <string> |
| 8 |
7 #include "net/quic/test_tools/quic_test_utils.h" | 9 #include "net/quic/test_tools/quic_test_utils.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
9 | 11 |
10 namespace net { | 12 namespace net { |
11 namespace test { | 13 namespace test { |
12 namespace { | 14 namespace { |
13 | 15 |
14 TEST(CryptoUtilsTest, IsValidSNI) { | 16 TEST(CryptoUtilsTest, IsValidSNI) { |
15 // IP as SNI. | 17 // IP as SNI. |
16 EXPECT_FALSE(CryptoUtils::IsValidSNI("192.168.0.1")); | 18 EXPECT_FALSE(CryptoUtils::IsValidSNI("192.168.0.1")); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 { "d0ec8a34f6cc9a8c96", | 90 { "d0ec8a34f6cc9a8c96", |
89 "49711798cc6251", | 91 "49711798cc6251", |
90 "933d4a2f30d22f089cfba842791116adc121e0", | 92 "933d4a2f30d22f089cfba842791116adc121e0", |
91 23, | 93 23, |
92 "c9a46ed0757bd1812f1f21b4d41e62125fec8364a21db7" | 94 "c9a46ed0757bd1812f1f21b4d41e62125fec8364a21db7" |
93 }, | 95 }, |
94 }; | 96 }; |
95 | 97 |
96 for (size_t i = 0; i < arraysize(test_vector); i++) { | 98 for (size_t i = 0; i < arraysize(test_vector); i++) { |
97 // Decode the test vector. | 99 // Decode the test vector. |
98 string subkey_secret; | 100 std::string subkey_secret; |
99 string label; | 101 std::string label; |
100 string context; | 102 std::string context; |
101 ASSERT_TRUE(DecodeHexString(test_vector[i].subkey_secret, &subkey_secret)); | 103 ASSERT_TRUE(DecodeHexString(test_vector[i].subkey_secret, &subkey_secret)); |
102 ASSERT_TRUE(DecodeHexString(test_vector[i].label, &label)); | 104 ASSERT_TRUE(DecodeHexString(test_vector[i].label, &label)); |
103 ASSERT_TRUE(DecodeHexString(test_vector[i].context, &context)); | 105 ASSERT_TRUE(DecodeHexString(test_vector[i].context, &context)); |
104 size_t result_len = test_vector[i].result_len; | 106 size_t result_len = test_vector[i].result_len; |
105 bool expect_ok = test_vector[i].expected != nullptr; | 107 bool expect_ok = test_vector[i].expected != nullptr; |
106 string expected; | 108 std::string expected; |
107 if (expect_ok) { | 109 if (expect_ok) { |
108 ASSERT_TRUE(DecodeHexString(test_vector[i].expected, &expected)); | 110 ASSERT_TRUE(DecodeHexString(test_vector[i].expected, &expected)); |
109 } | 111 } |
110 | 112 |
111 string result; | 113 std::string result; |
112 bool ok = CryptoUtils::ExportKeyingMaterial(subkey_secret, | 114 bool ok = CryptoUtils::ExportKeyingMaterial(subkey_secret, |
113 label, | 115 label, |
114 context, | 116 context, |
115 result_len, | 117 result_len, |
116 &result); | 118 &result); |
117 EXPECT_EQ(expect_ok, ok); | 119 EXPECT_EQ(expect_ok, ok); |
118 if (expect_ok) { | 120 if (expect_ok) { |
119 EXPECT_EQ(result_len, result.length()); | 121 EXPECT_EQ(result_len, result.length()); |
120 test::CompareCharArraysWithHexError("HKDF output", | 122 test::CompareCharArraysWithHexError("HKDF output", |
121 result.data(), | 123 result.data(), |
122 result.length(), | 124 result.length(), |
123 expected.data(), | 125 expected.data(), |
124 expected.length()); | 126 expected.length()); |
125 } | 127 } |
126 } | 128 } |
127 } | 129 } |
128 | 130 |
129 } // namespace | 131 } // namespace |
130 } // namespace test | 132 } // namespace test |
131 } // namespace net | 133 } // namespace net |
OLD | NEW |