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

Side by Side Diff: net/quic/core/crypto/quic_server_info.cc

Issue 2566783002: Various formatting cleanups to net/quic/crypto and net/quic/congestion_control (Closed)
Patch Set: Rebase Created 4 years 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/core/crypto/quic_server_info.h ('k') | net/quic/core/crypto/strike_register.h » ('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 2014 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/core/crypto/quic_server_info.h"
6
7 #include <limits>
8
9 #include "base/pickle.h"
10
11 using std::string;
12
13 namespace {
14
15 const int kQuicCryptoConfigVersion = 2;
16
17 } // namespace
18
19 namespace net {
20
21 QuicServerInfo::State::State() {}
22
23 QuicServerInfo::State::~State() {}
24
25 void QuicServerInfo::State::Clear() {
26 server_config.clear();
27 source_address_token.clear();
28 cert_sct.clear();
29 chlo_hash.clear();
30 server_config_sig.clear();
31 certs.clear();
32 }
33
34 QuicServerInfo::QuicServerInfo(const QuicServerId& server_id)
35 : server_id_(server_id) {}
36
37 QuicServerInfo::~QuicServerInfo() {}
38
39 const QuicServerInfo::State& QuicServerInfo::state() const {
40 return state_;
41 }
42
43 QuicServerInfo::State* QuicServerInfo::mutable_state() {
44 return &state_;
45 }
46
47 bool QuicServerInfo::Parse(const string& data) {
48 State* state = mutable_state();
49
50 state->Clear();
51
52 bool r = ParseInner(data);
53 if (!r)
54 state->Clear();
55 return r;
56 }
57
58 bool QuicServerInfo::ParseInner(const string& data) {
59 State* state = mutable_state();
60
61 // No data was read from the disk cache.
62 if (data.empty()) {
63 return false;
64 }
65
66 base::Pickle p(data.data(), data.size());
67 base::PickleIterator iter(p);
68
69 int version = -1;
70 if (!iter.ReadInt(&version)) {
71 DVLOG(1) << "Missing version";
72 return false;
73 }
74
75 if (version != kQuicCryptoConfigVersion) {
76 DVLOG(1) << "Unsupported version";
77 return false;
78 }
79
80 if (!iter.ReadString(&state->server_config)) {
81 DVLOG(1) << "Malformed server_config";
82 return false;
83 }
84 if (!iter.ReadString(&state->source_address_token)) {
85 DVLOG(1) << "Malformed source_address_token";
86 return false;
87 }
88 if (!iter.ReadString(&state->cert_sct)) {
89 DVLOG(1) << "Malformed cert_sct";
90 return false;
91 }
92 if (!iter.ReadString(&state->chlo_hash)) {
93 DVLOG(1) << "Malformed chlo_hash";
94 return false;
95 }
96 if (!iter.ReadString(&state->server_config_sig)) {
97 DVLOG(1) << "Malformed server_config_sig";
98 return false;
99 }
100
101 // Read certs.
102 uint32_t num_certs;
103 if (!iter.ReadUInt32(&num_certs)) {
104 DVLOG(1) << "Malformed num_certs";
105 return false;
106 }
107
108 for (uint32_t i = 0; i < num_certs; i++) {
109 string cert;
110 if (!iter.ReadString(&cert)) {
111 DVLOG(1) << "Malformed cert";
112 return false;
113 }
114 state->certs.push_back(cert);
115 }
116
117 return true;
118 }
119
120 string QuicServerInfo::Serialize() {
121 string pickled_data = SerializeInner();
122 state_.Clear();
123 return pickled_data;
124 }
125
126 string QuicServerInfo::SerializeInner() const {
127 base::Pickle p(sizeof(base::Pickle::Header));
128
129 if (!p.WriteInt(kQuicCryptoConfigVersion) ||
130 !p.WriteString(state_.server_config) ||
131 !p.WriteString(state_.source_address_token) ||
132 !p.WriteString(state_.cert_sct) || !p.WriteString(state_.chlo_hash) ||
133 !p.WriteString(state_.server_config_sig) ||
134 state_.certs.size() > std::numeric_limits<uint32_t>::max() ||
135 !p.WriteUInt32(state_.certs.size())) {
136 return string();
137 }
138
139 for (size_t i = 0; i < state_.certs.size(); i++) {
140 if (!p.WriteString(state_.certs[i])) {
141 return string();
142 }
143 }
144
145 return string(reinterpret_cast<const char*>(p.data()), p.size());
146 }
147
148 QuicServerInfoFactory::~QuicServerInfoFactory() {}
149
150 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/crypto/quic_server_info.h ('k') | net/quic/core/crypto/strike_register.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698