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/core/crypto/crypto_utils.h" | 5 #include "net/quic/core/crypto/crypto_utils.h" |
6 | 6 |
7 #include "net/quic/core/quic_utils.h" | 7 #include "net/quic/core/quic_utils.h" |
| 8 #include "net/quic/platform/api/quic_test.h" |
8 #include "net/quic/platform/api/quic_text_utils.h" | 9 #include "net/quic/platform/api/quic_text_utils.h" |
9 #include "net/quic/test_tools/quic_test_utils.h" | 10 #include "net/quic/test_tools/quic_test_utils.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | 11 |
12 using std::string; | 12 using std::string; |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 namespace test { | 15 namespace test { |
16 namespace { | 16 namespace { |
17 | 17 |
18 TEST(CryptoUtilsTest, TestExportKeyingMaterial) { | 18 class CryptoUtilsTest : public QuicTest {}; |
| 19 |
| 20 TEST_F(CryptoUtilsTest, TestExportKeyingMaterial) { |
19 const struct TestVector { | 21 const struct TestVector { |
20 // Input (strings of hexadecimal digits): | 22 // Input (strings of hexadecimal digits): |
21 const char* subkey_secret; | 23 const char* subkey_secret; |
22 const char* label; | 24 const char* label; |
23 const char* context; | 25 const char* context; |
24 size_t result_len; | 26 size_t result_len; |
25 | 27 |
26 // Expected output (string of hexadecimal digits): | 28 // Expected output (string of hexadecimal digits): |
27 const char* expected; // Null if it should fail. | 29 const char* expected; // Null if it should fail. |
28 } test_vector[] = { | 30 } test_vector[] = { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 EXPECT_EQ(expect_ok, ok); | 67 EXPECT_EQ(expect_ok, ok); |
66 if (expect_ok) { | 68 if (expect_ok) { |
67 EXPECT_EQ(result_len, result.length()); | 69 EXPECT_EQ(result_len, result.length()); |
68 test::CompareCharArraysWithHexError("HKDF output", result.data(), | 70 test::CompareCharArraysWithHexError("HKDF output", result.data(), |
69 result.length(), expected.data(), | 71 result.length(), expected.data(), |
70 expected.length()); | 72 expected.length()); |
71 } | 73 } |
72 } | 74 } |
73 } | 75 } |
74 | 76 |
75 TEST(CryptoUtilsTest, HandshakeFailureReasonToString) { | 77 TEST_F(CryptoUtilsTest, HandshakeFailureReasonToString) { |
76 EXPECT_STREQ("HANDSHAKE_OK", | 78 EXPECT_STREQ("HANDSHAKE_OK", |
77 CryptoUtils::HandshakeFailureReasonToString(HANDSHAKE_OK)); | 79 CryptoUtils::HandshakeFailureReasonToString(HANDSHAKE_OK)); |
78 EXPECT_STREQ("CLIENT_NONCE_UNKNOWN_FAILURE", | 80 EXPECT_STREQ("CLIENT_NONCE_UNKNOWN_FAILURE", |
79 CryptoUtils::HandshakeFailureReasonToString( | 81 CryptoUtils::HandshakeFailureReasonToString( |
80 CLIENT_NONCE_UNKNOWN_FAILURE)); | 82 CLIENT_NONCE_UNKNOWN_FAILURE)); |
81 EXPECT_STREQ("CLIENT_NONCE_INVALID_FAILURE", | 83 EXPECT_STREQ("CLIENT_NONCE_INVALID_FAILURE", |
82 CryptoUtils::HandshakeFailureReasonToString( | 84 CryptoUtils::HandshakeFailureReasonToString( |
83 CLIENT_NONCE_INVALID_FAILURE)); | 85 CLIENT_NONCE_INVALID_FAILURE)); |
84 EXPECT_STREQ("CLIENT_NONCE_NOT_UNIQUE_FAILURE", | 86 EXPECT_STREQ("CLIENT_NONCE_NOT_UNIQUE_FAILURE", |
85 CryptoUtils::HandshakeFailureReasonToString( | 87 CryptoUtils::HandshakeFailureReasonToString( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 CryptoUtils::HandshakeFailureReasonToString(MAX_FAILURE_REASON)); | 144 CryptoUtils::HandshakeFailureReasonToString(MAX_FAILURE_REASON)); |
143 EXPECT_STREQ( | 145 EXPECT_STREQ( |
144 "INVALID_HANDSHAKE_FAILURE_REASON", | 146 "INVALID_HANDSHAKE_FAILURE_REASON", |
145 CryptoUtils::HandshakeFailureReasonToString( | 147 CryptoUtils::HandshakeFailureReasonToString( |
146 static_cast<HandshakeFailureReason>(MAX_FAILURE_REASON + 1))); | 148 static_cast<HandshakeFailureReason>(MAX_FAILURE_REASON + 1))); |
147 } | 149 } |
148 | 150 |
149 } // namespace | 151 } // namespace |
150 } // namespace test | 152 } // namespace test |
151 } // namespace net | 153 } // namespace net |
OLD | NEW |