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 #include "net/quic/test_tools/crypto_test_utils.h" | 5 #include "net/quic/test_tools/crypto_test_utils.h" |
6 | 6 |
7 #include "net/quic/crypto/channel_id.h" | 7 #include "net/quic/crypto/channel_id.h" |
8 #include "net/quic/crypto/common_cert_set.h" | 8 #include "net/quic/crypto/common_cert_set.h" |
9 #include "net/quic/crypto/crypto_handshake.h" | 9 #include "net/quic/crypto/crypto_handshake.h" |
10 #include "net/quic/crypto/quic_crypto_server_config.h" | 10 #include "net/quic/crypto/quic_crypto_server_config.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 const char kServerHostname[] = "test.example.com"; | 34 const char kServerHostname[] = "test.example.com"; |
35 const uint16 kServerPort = 80; | 35 const uint16 kServerPort = 80; |
36 | 36 |
37 // CryptoFramerVisitor is a framer visitor that records handshake messages. | 37 // CryptoFramerVisitor is a framer visitor that records handshake messages. |
38 class CryptoFramerVisitor : public CryptoFramerVisitorInterface { | 38 class CryptoFramerVisitor : public CryptoFramerVisitorInterface { |
39 public: | 39 public: |
40 CryptoFramerVisitor() | 40 CryptoFramerVisitor() |
41 : error_(false) { | 41 : error_(false) { |
42 } | 42 } |
43 | 43 |
44 virtual void OnError(CryptoFramer* framer) OVERRIDE { error_ = true; } | 44 virtual void OnError(CryptoFramer* framer) override { error_ = true; } |
45 | 45 |
46 virtual void OnHandshakeMessage( | 46 virtual void OnHandshakeMessage( |
47 const CryptoHandshakeMessage& message) OVERRIDE { | 47 const CryptoHandshakeMessage& message) override { |
48 messages_.push_back(message); | 48 messages_.push_back(message); |
49 } | 49 } |
50 | 50 |
51 bool error() const { | 51 bool error() const { |
52 return error_; | 52 return error_; |
53 } | 53 } |
54 | 54 |
55 const vector<CryptoHandshakeMessage>& messages() const { | 55 const vector<CryptoHandshakeMessage>& messages() const { |
56 return messages_; | 56 return messages_; |
57 } | 57 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 public: | 136 public: |
137 // Takes ownership of |sync_source|, a synchronous ChannelIDSource. | 137 // Takes ownership of |sync_source|, a synchronous ChannelIDSource. |
138 explicit AsyncTestChannelIDSource(ChannelIDSource* sync_source) | 138 explicit AsyncTestChannelIDSource(ChannelIDSource* sync_source) |
139 : sync_source_(sync_source) {} | 139 : sync_source_(sync_source) {} |
140 virtual ~AsyncTestChannelIDSource() {} | 140 virtual ~AsyncTestChannelIDSource() {} |
141 | 141 |
142 // ChannelIDSource implementation. | 142 // ChannelIDSource implementation. |
143 virtual QuicAsyncStatus GetChannelIDKey( | 143 virtual QuicAsyncStatus GetChannelIDKey( |
144 const string& hostname, | 144 const string& hostname, |
145 scoped_ptr<ChannelIDKey>* channel_id_key, | 145 scoped_ptr<ChannelIDKey>* channel_id_key, |
146 ChannelIDSourceCallback* callback) OVERRIDE { | 146 ChannelIDSourceCallback* callback) override { |
147 // Synchronous mode. | 147 // Synchronous mode. |
148 if (!callback) { | 148 if (!callback) { |
149 return sync_source_->GetChannelIDKey(hostname, channel_id_key, nullptr); | 149 return sync_source_->GetChannelIDKey(hostname, channel_id_key, nullptr); |
150 } | 150 } |
151 | 151 |
152 // Asynchronous mode. | 152 // Asynchronous mode. |
153 QuicAsyncStatus status = | 153 QuicAsyncStatus status = |
154 sync_source_->GetChannelIDKey(hostname, &channel_id_key_, nullptr); | 154 sync_source_->GetChannelIDKey(hostname, &channel_id_key_, nullptr); |
155 if (status != QUIC_SUCCESS) { | 155 if (status != QUIC_SUCCESS) { |
156 return QUIC_FAILURE; | 156 return QUIC_FAILURE; |
157 } | 157 } |
158 callback_.reset(callback); | 158 callback_.reset(callback); |
159 return QUIC_PENDING; | 159 return QUIC_PENDING; |
160 } | 160 } |
161 | 161 |
162 // CallbackSource implementation. | 162 // CallbackSource implementation. |
163 virtual void RunPendingCallbacks() OVERRIDE { | 163 virtual void RunPendingCallbacks() override { |
164 if (callback_.get()) { | 164 if (callback_.get()) { |
165 callback_->Run(&channel_id_key_); | 165 callback_->Run(&channel_id_key_); |
166 callback_.reset(); | 166 callback_.reset(); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 private: | 170 private: |
171 scoped_ptr<ChannelIDSource> sync_source_; | 171 scoped_ptr<ChannelIDSource> sync_source_; |
172 scoped_ptr<ChannelIDSourceCallback> callback_; | 172 scoped_ptr<ChannelIDSourceCallback> callback_; |
173 scoped_ptr<ChannelIDKey> channel_id_key_; | 173 scoped_ptr<ChannelIDKey> channel_id_key_; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 349 } |
350 | 350 |
351 class MockCommonCertSets : public CommonCertSets { | 351 class MockCommonCertSets : public CommonCertSets { |
352 public: | 352 public: |
353 MockCommonCertSets(StringPiece cert, uint64 hash, uint32 index) | 353 MockCommonCertSets(StringPiece cert, uint64 hash, uint32 index) |
354 : cert_(cert.as_string()), | 354 : cert_(cert.as_string()), |
355 hash_(hash), | 355 hash_(hash), |
356 index_(index) { | 356 index_(index) { |
357 } | 357 } |
358 | 358 |
359 virtual StringPiece GetCommonHashes() const OVERRIDE { | 359 virtual StringPiece GetCommonHashes() const override { |
360 CHECK(false) << "not implemented"; | 360 CHECK(false) << "not implemented"; |
361 return StringPiece(); | 361 return StringPiece(); |
362 } | 362 } |
363 | 363 |
364 virtual StringPiece GetCert(uint64 hash, uint32 index) const OVERRIDE { | 364 virtual StringPiece GetCert(uint64 hash, uint32 index) const override { |
365 if (hash == hash_ && index == index_) { | 365 if (hash == hash_ && index == index_) { |
366 return cert_; | 366 return cert_; |
367 } | 367 } |
368 return StringPiece(); | 368 return StringPiece(); |
369 } | 369 } |
370 | 370 |
371 virtual bool MatchCert(StringPiece cert, | 371 virtual bool MatchCert(StringPiece cert, |
372 StringPiece common_set_hashes, | 372 StringPiece common_set_hashes, |
373 uint64* out_hash, | 373 uint64* out_hash, |
374 uint32* out_index) const OVERRIDE { | 374 uint32* out_index) const override { |
375 if (cert != cert_) { | 375 if (cert != cert_) { |
376 return false; | 376 return false; |
377 } | 377 } |
378 | 378 |
379 if (common_set_hashes.size() % sizeof(uint64) != 0) { | 379 if (common_set_hashes.size() % sizeof(uint64) != 0) { |
380 return false; | 380 return false; |
381 } | 381 } |
382 bool client_has_set = false; | 382 bool client_has_set = false; |
383 for (size_t i = 0; i < common_set_hashes.size(); i += sizeof(uint64)) { | 383 for (size_t i = 0; i < common_set_hashes.size(); i += sizeof(uint64)) { |
384 uint64 hash; | 384 uint64 hash; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); | 627 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); |
628 scoped_ptr<CryptoHandshakeMessage> parsed( | 628 scoped_ptr<CryptoHandshakeMessage> parsed( |
629 CryptoFramer::ParseMessage(bytes->AsStringPiece())); | 629 CryptoFramer::ParseMessage(bytes->AsStringPiece())); |
630 CHECK(parsed.get()); | 630 CHECK(parsed.get()); |
631 | 631 |
632 return *parsed; | 632 return *parsed; |
633 } | 633 } |
634 | 634 |
635 } // namespace test | 635 } // namespace test |
636 } // namespace net | 636 } // namespace net |
OLD | NEW |