Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: net/quic/test_tools/fake_proof_source.cc

Issue 2429173004: Move FakeProofSource into its own library (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/test_tools/fake_proof_source.h ('k') | net/tools/quic/quic_dispatcher_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/quic/test_tools/fake_proof_source.h"
6 #include "net/quic/test_tools/crypto_test_utils.h"
7
8 using std::string;
9
10 namespace net {
11 namespace test {
12
13 FakeProofSource::FakeProofSource()
14 : delegate_(CryptoTestUtils::ProofSourceForTesting()) {}
15
16 FakeProofSource::~FakeProofSource() {}
17
18 FakeProofSource::Params::Params(const IPAddress& server_ip,
19 std::string hostname,
20 std::string server_config,
21 QuicVersion quic_version,
22 std::string chlo_hash,
23 std::unique_ptr<ProofSource::Callback> callback)
24 : server_ip(server_ip),
25 hostname(hostname),
26 server_config(server_config),
27 quic_version(quic_version),
28 chlo_hash(chlo_hash),
29 callback(std::move(callback)) {}
30
31 FakeProofSource::Params::~Params() {}
32
33 FakeProofSource::Params::Params(FakeProofSource::Params::Params&& other) =
34 default;
35
36 FakeProofSource::Params& FakeProofSource::Params::operator=(
37 FakeProofSource::Params&& other) = default;
38
39 void FakeProofSource::Activate() {
40 active_ = true;
41 }
42
43 bool FakeProofSource::GetProof(const IPAddress& server_ip,
44 const string& hostname,
45 const string& server_config,
46 QuicVersion quic_version,
47 StringPiece chlo_hash,
48 scoped_refptr<ProofSource::Chain>* out_chain,
49 string* out_signature,
50 string* out_leaf_cert_sct) {
51 LOG(WARNING) << "Synchronous GetProof called";
52 return delegate_->GetProof(server_ip, hostname, server_config, quic_version,
53 chlo_hash, out_chain, out_signature,
54 out_leaf_cert_sct);
55 }
56
57 void FakeProofSource::GetProof(
58 const IPAddress& server_ip,
59 const string& hostname,
60 const string& server_config,
61 QuicVersion quic_version,
62 StringPiece chlo_hash,
63 std::unique_ptr<ProofSource::Callback> callback) {
64 if (!active_) {
65 scoped_refptr<Chain> chain;
66 string signature;
67 string leaf_cert_sct;
68 const bool ok = GetProof(server_ip, hostname, server_config, quic_version,
69 chlo_hash, &chain, &signature, &leaf_cert_sct);
70 callback->Run(ok, chain, signature, leaf_cert_sct,
71 /* details = */ nullptr);
72 return;
73 }
74
75 LOG(WARNING) << "Asynchronous GetProof called";
76 params_.push_back(Params{server_ip, hostname, server_config, quic_version,
77 chlo_hash.as_string(), std::move(callback)});
78 }
79
80 int FakeProofSource::NumPendingCallbacks() const {
81 return params_.size();
82 }
83
84 void FakeProofSource::InvokePendingCallback(int n) {
85 CHECK(NumPendingCallbacks() > n);
86
87 const Params& params = params_[n];
88
89 scoped_refptr<ProofSource::Chain> chain;
90 string signature;
91 string leaf_cert_sct;
92 const bool ok =
93 delegate_->GetProof(params.server_ip, params.hostname,
94 params.server_config, params.quic_version,
95 params.chlo_hash, &chain, &signature, &leaf_cert_sct);
96
97 params.callback->Run(ok, chain, signature, leaf_cert_sct,
98 /* details = */ nullptr);
99 auto it = params_.begin() + n;
100 params_.erase(it);
101 }
102
103 } // namespace test
104 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/fake_proof_source.h ('k') | net/tools/quic/quic_dispatcher_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698