| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_QUIC_TEST_TOOLS_CRYPTO_TEST_UTILS_H_ | 5 #ifndef NET_QUIC_TEST_TOOLS_CRYPTO_TEST_UTILS_H_ |
| 6 #define NET_QUIC_TEST_TOOLS_CRYPTO_TEST_UTILS_H_ | 6 #define NET_QUIC_TEST_TOOLS_CRYPTO_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <stdarg.h> | 8 #include <stdarg.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 class QuicCryptoServerStream; | 31 class QuicCryptoServerStream; |
| 32 class QuicCryptoStream; | 32 class QuicCryptoStream; |
| 33 class QuicRandom; | 33 class QuicRandom; |
| 34 | 34 |
| 35 namespace test { | 35 namespace test { |
| 36 | 36 |
| 37 class PacketSavingConnection; | 37 class PacketSavingConnection; |
| 38 | 38 |
| 39 class CryptoTestUtils { | 39 class CryptoTestUtils { |
| 40 public: | 40 public: |
| 41 // An interface for a source of work. This may be use for invoking callbacks |
| 42 // asynchronously. |
| 43 // |
| 44 // Call the DoPendingWork method regularly to do the work from this source. |
| 45 class WorkSource { |
| 46 public: |
| 47 virtual ~WorkSource() {} |
| 48 |
| 49 // Does pending work in this source. If there is no pending work, does |
| 50 // nothing. |
| 51 virtual void DoPendingWork() = 0; |
| 52 }; |
| 53 |
| 41 // FakeClientOptions bundles together a number of options for configuring | 54 // FakeClientOptions bundles together a number of options for configuring |
| 42 // HandshakeWithFakeClient. | 55 // HandshakeWithFakeClient. |
| 43 struct FakeClientOptions { | 56 struct FakeClientOptions { |
| 44 FakeClientOptions(); | 57 FakeClientOptions(); |
| 45 | 58 |
| 46 // If dont_verify_certs is true then no ProofVerifier is set on the client. | 59 // If dont_verify_certs is true then no ProofVerifier is set on the client. |
| 47 // Thus no certificates will be requested or checked. | 60 // Thus no certificates will be requested or checked. |
| 48 bool dont_verify_certs; | 61 bool dont_verify_certs; |
| 49 | 62 |
| 50 // If channel_id_enabled is true then the client will attempt to send a | 63 // If channel_id_enabled is true then the client will attempt to send a |
| 51 // ChannelID. | 64 // ChannelID. |
| 52 bool channel_id_enabled; | 65 bool channel_id_enabled; |
| 66 |
| 67 // If channel_id_source_async is true then the client will use an async |
| 68 // ChannelIDSource for testing. Ignored if channel_id_enabled is false. |
| 69 bool channel_id_source_async; |
| 53 }; | 70 }; |
| 54 | 71 |
| 55 // returns: the number of client hellos that the client sent. | 72 // returns: the number of client hellos that the client sent. |
| 56 static int HandshakeWithFakeServer(PacketSavingConnection* client_conn, | 73 static int HandshakeWithFakeServer(PacketSavingConnection* client_conn, |
| 57 QuicCryptoClientStream* client); | 74 QuicCryptoClientStream* client); |
| 58 | 75 |
| 59 // returns: the number of client hellos that the client sent. | 76 // returns: the number of client hellos that the client sent. |
| 60 static int HandshakeWithFakeClient(PacketSavingConnection* server_conn, | 77 static int HandshakeWithFakeClient(PacketSavingConnection* server_conn, |
| 61 QuicCryptoServerStream* server, | 78 QuicCryptoServerStream* server, |
| 62 const FakeClientOptions& options); | 79 const FakeClientOptions& options); |
| 63 | 80 |
| 64 // SetupCryptoServerConfigForTest configures |config| and |crypto_config| | 81 // SetupCryptoServerConfigForTest configures |config| and |crypto_config| |
| 65 // with sensible defaults for testing. | 82 // with sensible defaults for testing. |
| 66 static void SetupCryptoServerConfigForTest( | 83 static void SetupCryptoServerConfigForTest( |
| 67 const QuicClock* clock, | 84 const QuicClock* clock, |
| 68 QuicRandom* rand, | 85 QuicRandom* rand, |
| 69 QuicConfig* config, | 86 QuicConfig* config, |
| 70 QuicCryptoServerConfig* crypto_config); | 87 QuicCryptoServerConfig* crypto_config); |
| 71 | 88 |
| 72 // CommunicateHandshakeMessages moves messages from |a| to |b| and back until | 89 // CommunicateHandshakeMessages moves messages from |a| to |b| and back until |
| 73 // |a|'s handshake has completed. | 90 // |a|'s handshake has completed. |
| 74 static void CommunicateHandshakeMessages(PacketSavingConnection* a_conn, | 91 static void CommunicateHandshakeMessages(PacketSavingConnection* a_conn, |
| 75 QuicCryptoStream* a, | 92 QuicCryptoStream* a, |
| 76 PacketSavingConnection* b_conn, | 93 PacketSavingConnection* b_conn, |
| 77 QuicCryptoStream* b); | 94 QuicCryptoStream* b); |
| 78 | 95 |
| 96 // CommunicateHandshakeMessagesAndDoWork moves messages from |a| to |b| and |
| 97 // back until |a|'s handshake has completed. If |work_source| is not NULL, |
| 98 // CommunicateHandshakeMessagesAndDoWork also does work from |work_source| |
| 99 // between processing messages. |
| 100 static void CommunicateHandshakeMessagesAndDoWork( |
| 101 PacketSavingConnection* a_conn, |
| 102 QuicCryptoStream* a, |
| 103 PacketSavingConnection* b_conn, |
| 104 QuicCryptoStream* b, |
| 105 WorkSource* work_source); |
| 106 |
| 79 // AdvanceHandshake attempts to moves messages from |a| to |b| and |b| to |a|. | 107 // AdvanceHandshake attempts to moves messages from |a| to |b| and |b| to |a|. |
| 80 // Returns the number of messages moved. | 108 // Returns the number of messages moved. |
| 81 static std::pair<size_t, size_t> AdvanceHandshake( | 109 static std::pair<size_t, size_t> AdvanceHandshake( |
| 82 PacketSavingConnection* a_conn, | 110 PacketSavingConnection* a_conn, |
| 83 QuicCryptoStream* a, | 111 QuicCryptoStream* a, |
| 84 size_t a_i, | 112 size_t a_i, |
| 85 PacketSavingConnection* b_conn, | 113 PacketSavingConnection* b_conn, |
| 86 QuicCryptoStream* b, | 114 QuicCryptoStream* b, |
| 87 size_t b_i); | 115 size_t b_i); |
| 88 | 116 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 QuicCryptoServerStream* server); | 180 QuicCryptoServerStream* server); |
| 153 | 181 |
| 154 DISALLOW_COPY_AND_ASSIGN(CryptoTestUtils); | 182 DISALLOW_COPY_AND_ASSIGN(CryptoTestUtils); |
| 155 }; | 183 }; |
| 156 | 184 |
| 157 } // namespace test | 185 } // namespace test |
| 158 | 186 |
| 159 } // namespace net | 187 } // namespace net |
| 160 | 188 |
| 161 #endif // NET_QUIC_TEST_TOOLS_CRYPTO_TEST_UTILS_H_ | 189 #endif // NET_QUIC_TEST_TOOLS_CRYPTO_TEST_UTILS_H_ |
| OLD | NEW |