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/crypto/crypto_handshake_message.h" | 5 #include "net/quic/crypto/crypto_handshake_message.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "net/quic/crypto/crypto_framer.h" | 9 #include "net/quic/crypto/crypto_framer.h" |
10 #include "net/quic/crypto/crypto_protocol.h" | 10 #include "net/quic/crypto/crypto_protocol.h" |
11 #include "net/quic/quic_socket_address_coder.h" | 11 #include "net/quic/quic_socket_address_coder.h" |
12 #include "net/quic/quic_utils.h" | 12 #include "net/quic/quic_utils.h" |
13 | 13 |
14 using base::StringPiece; | 14 using base::StringPiece; |
15 using base::StringPrintf; | 15 using base::StringPrintf; |
16 using std::string; | 16 using std::string; |
17 using std::vector; | 17 using std::vector; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 CryptoHandshakeMessage::CryptoHandshakeMessage() | 21 CryptoHandshakeMessage::CryptoHandshakeMessage() : tag_(0), minimum_size_(0) { |
22 : tag_(0), | 22 } |
23 minimum_size_(0) {} | |
24 | 23 |
25 CryptoHandshakeMessage::CryptoHandshakeMessage( | 24 CryptoHandshakeMessage::CryptoHandshakeMessage( |
26 const CryptoHandshakeMessage& other) | 25 const CryptoHandshakeMessage& other) |
27 : tag_(other.tag_), | 26 : tag_(other.tag_), |
28 tag_value_map_(other.tag_value_map_), | 27 tag_value_map_(other.tag_value_map_), |
29 minimum_size_(other.minimum_size_) { | 28 minimum_size_(other.minimum_size_) { |
30 // Don't copy serialized_. scoped_ptr doesn't have a copy constructor. | 29 // Don't copy serialized_. scoped_ptr doesn't have a copy constructor. |
31 // The new object can lazily reconstruct serialized_. | 30 // The new object can lazily reconstruct serialized_. |
32 } | 31 } |
33 | 32 |
34 CryptoHandshakeMessage::~CryptoHandshakeMessage() {} | 33 CryptoHandshakeMessage::~CryptoHandshakeMessage() { |
| 34 } |
35 | 35 |
36 CryptoHandshakeMessage& CryptoHandshakeMessage::operator=( | 36 CryptoHandshakeMessage& CryptoHandshakeMessage::operator=( |
37 const CryptoHandshakeMessage& other) { | 37 const CryptoHandshakeMessage& other) { |
38 tag_ = other.tag_; | 38 tag_ = other.tag_; |
39 tag_value_map_ = other.tag_value_map_; | 39 tag_value_map_ = other.tag_value_map_; |
40 // Don't copy serialized_. scoped_ptr doesn't have an assignment operator. | 40 // Don't copy serialized_. scoped_ptr doesn't have an assignment operator. |
41 // However, invalidate serialized_. | 41 // However, invalidate serialized_. |
42 serialized_.reset(); | 42 serialized_.reset(); |
43 minimum_size_ = other.minimum_size_; | 43 minimum_size_ = other.minimum_size_; |
44 return *this; | 44 return *this; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 uint32* out) const { | 174 uint32* out) const { |
175 return GetPOD(tag, out, sizeof(uint32)); | 175 return GetPOD(tag, out, sizeof(uint32)); |
176 } | 176 } |
177 | 177 |
178 QuicErrorCode CryptoHandshakeMessage::GetUint64(QuicTag tag, | 178 QuicErrorCode CryptoHandshakeMessage::GetUint64(QuicTag tag, |
179 uint64* out) const { | 179 uint64* out) const { |
180 return GetPOD(tag, out, sizeof(uint64)); | 180 return GetPOD(tag, out, sizeof(uint64)); |
181 } | 181 } |
182 | 182 |
183 size_t CryptoHandshakeMessage::size() const { | 183 size_t CryptoHandshakeMessage::size() const { |
184 size_t ret = sizeof(QuicTag) + | 184 size_t ret = sizeof(QuicTag) + sizeof(uint16) /* number of entries */ + |
185 sizeof(uint16) /* number of entries */ + | |
186 sizeof(uint16) /* padding */; | 185 sizeof(uint16) /* padding */; |
187 ret += (sizeof(QuicTag) + sizeof(uint32) /* end offset */) * | 186 ret += (sizeof(QuicTag) + sizeof(uint32) /* end offset */) * |
188 tag_value_map_.size(); | 187 tag_value_map_.size(); |
189 for (QuicTagValueMap::const_iterator i = tag_value_map_.begin(); | 188 for (QuicTagValueMap::const_iterator i = tag_value_map_.begin(); |
190 i != tag_value_map_.end(); ++i) { | 189 i != tag_value_map_.end(); |
| 190 ++i) { |
191 ret += i->second.size(); | 191 ret += i->second.size(); |
192 } | 192 } |
193 | 193 |
194 return ret; | 194 return ret; |
195 } | 195 } |
196 | 196 |
197 void CryptoHandshakeMessage::set_minimum_size(size_t min_bytes) { | 197 void CryptoHandshakeMessage::set_minimum_size(size_t min_bytes) { |
198 if (min_bytes == minimum_size_) { | 198 if (min_bytes == minimum_size_) { |
199 return; | 199 return; |
200 } | 200 } |
201 serialized_.reset(); | 201 serialized_.reset(); |
202 minimum_size_ = min_bytes; | 202 minimum_size_ = min_bytes; |
203 } | 203 } |
204 | 204 |
205 size_t CryptoHandshakeMessage::minimum_size() const { | 205 size_t CryptoHandshakeMessage::minimum_size() const { |
206 return minimum_size_; | 206 return minimum_size_; |
207 } | 207 } |
208 | 208 |
209 string CryptoHandshakeMessage::DebugString() const { | 209 string CryptoHandshakeMessage::DebugString() const { |
210 return DebugStringInternal(0); | 210 return DebugStringInternal(0); |
211 } | 211 } |
212 | 212 |
213 QuicErrorCode CryptoHandshakeMessage::GetPOD( | 213 QuicErrorCode CryptoHandshakeMessage::GetPOD(QuicTag tag, |
214 QuicTag tag, void* out, size_t len) const { | 214 void* out, |
| 215 size_t len) const { |
215 QuicTagValueMap::const_iterator it = tag_value_map_.find(tag); | 216 QuicTagValueMap::const_iterator it = tag_value_map_.find(tag); |
216 QuicErrorCode ret = QUIC_NO_ERROR; | 217 QuicErrorCode ret = QUIC_NO_ERROR; |
217 | 218 |
218 if (it == tag_value_map_.end()) { | 219 if (it == tag_value_map_.end()) { |
219 ret = QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; | 220 ret = QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; |
220 } else if (it->second.size() != len) { | 221 } else if (it->second.size() != len) { |
221 ret = QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; | 222 ret = QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
222 } | 223 } |
223 | 224 |
224 if (ret != QUIC_NO_ERROR) { | 225 if (ret != QUIC_NO_ERROR) { |
225 memset(out, 0, len); | 226 memset(out, 0, len); |
226 return ret; | 227 return ret; |
227 } | 228 } |
228 | 229 |
229 memcpy(out, it->second.data(), len); | 230 memcpy(out, it->second.data(), len); |
230 return ret; | 231 return ret; |
231 } | 232 } |
232 | 233 |
233 string CryptoHandshakeMessage::DebugStringInternal(size_t indent) const { | 234 string CryptoHandshakeMessage::DebugStringInternal(size_t indent) const { |
234 string ret = string(2 * indent, ' ') + QuicUtils::TagToString(tag_) + "<\n"; | 235 string ret = string(2 * indent, ' ') + QuicUtils::TagToString(tag_) + "<\n"; |
235 ++indent; | 236 ++indent; |
236 for (QuicTagValueMap::const_iterator it = tag_value_map_.begin(); | 237 for (QuicTagValueMap::const_iterator it = tag_value_map_.begin(); |
237 it != tag_value_map_.end(); ++it) { | 238 it != tag_value_map_.end(); |
| 239 ++it) { |
238 ret += string(2 * indent, ' ') + QuicUtils::TagToString(it->first) + ": "; | 240 ret += string(2 * indent, ' ') + QuicUtils::TagToString(it->first) + ": "; |
239 | 241 |
240 bool done = false; | 242 bool done = false; |
241 switch (it->first) { | 243 switch (it->first) { |
242 case kICSL: | 244 case kICSL: |
243 case kIFCW: | 245 case kIFCW: |
244 case kIRTT: | 246 case kIRTT: |
245 case kKATO: | 247 case kKATO: |
246 case kMSPC: | 248 case kMSPC: |
247 case kSWND: | 249 case kSWND: |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 ret += "0x" + base::HexEncode(it->second.data(), it->second.size()); | 310 ret += "0x" + base::HexEncode(it->second.data(), it->second.size()); |
309 } | 311 } |
310 ret += "\n"; | 312 ret += "\n"; |
311 } | 313 } |
312 --indent; | 314 --indent; |
313 ret += string(2 * indent, ' ') + ">"; | 315 ret += string(2 * indent, ' ') + ">"; |
314 return ret; | 316 return ret; |
315 } | 317 } |
316 | 318 |
317 } // namespace net | 319 } // namespace net |
OLD | NEW |