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/core/crypto/crypto_handshake_message.h" | 5 #include "net/quic/core/crypto/crypto_handshake_message.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "net/quic/core/crypto/crypto_framer.h" | 9 #include "net/quic/core/crypto/crypto_framer.h" |
10 #include "net/quic/core/crypto/crypto_protocol.h" | 10 #include "net/quic/core/crypto/crypto_protocol.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 | 72 |
73 void CryptoHandshakeMessage::SetStringPiece(QuicTag tag, | 73 void CryptoHandshakeMessage::SetStringPiece(QuicTag tag, |
74 QuicStringPiece value) { | 74 QuicStringPiece value) { |
75 tag_value_map_[tag] = value.as_string(); | 75 tag_value_map_[tag] = value.as_string(); |
76 } | 76 } |
77 | 77 |
78 void CryptoHandshakeMessage::Erase(QuicTag tag) { | 78 void CryptoHandshakeMessage::Erase(QuicTag tag) { |
79 tag_value_map_.erase(tag); | 79 tag_value_map_.erase(tag); |
80 } | 80 } |
81 | 81 |
82 QuicErrorCode CryptoHandshakeMessage::GetTaglist(QuicTag tag, | 82 QuicErrorCode CryptoHandshakeMessage::GetTaglist( |
83 const QuicTag** out_tags, | 83 QuicTag tag, |
84 size_t* out_len) const { | 84 QuicTagVector* out_tags) const { |
85 QuicTagValueMap::const_iterator it = tag_value_map_.find(tag); | 85 QuicTagValueMap::const_iterator it = tag_value_map_.find(tag); |
86 QuicErrorCode ret = QUIC_NO_ERROR; | 86 QuicErrorCode ret = QUIC_NO_ERROR; |
87 | 87 |
88 if (it == tag_value_map_.end()) { | 88 if (it == tag_value_map_.end()) { |
89 ret = QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; | 89 ret = QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; |
90 } else if (it->second.size() % sizeof(QuicTag) != 0) { | 90 } else if (it->second.size() % sizeof(QuicTag) != 0) { |
91 ret = QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; | 91 ret = QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
92 } | 92 } |
93 | 93 |
94 if (ret != QUIC_NO_ERROR) { | 94 if (ret != QUIC_NO_ERROR) { |
95 *out_tags = nullptr; | 95 out_tags->clear(); |
96 *out_len = 0; | |
97 return ret; | 96 return ret; |
98 } | 97 } |
99 | 98 |
100 *out_tags = reinterpret_cast<const QuicTag*>(it->second.data()); | 99 size_t num_tags = it->second.size() / sizeof(QuicTag); |
101 *out_len = it->second.size() / sizeof(QuicTag); | 100 out_tags->resize(num_tags); |
101 for (size_t i = 0; i < num_tags; ++i) { | |
102 QuicTag tag; | |
103 memcpy(&tag, it->second.data() + i * sizeof(tag), sizeof(tag)); | |
Nico
2017/06/12 20:32:31
A few short weeks later, I suddenly remembered thi
Ryan Hamilton
2017/06/12 20:48:41
Ooo! That's good to know. We can depend on base (t
| |
104 (*out_tags)[i] = tag; | |
105 } | |
102 return ret; | 106 return ret; |
103 } | 107 } |
104 | 108 |
105 bool CryptoHandshakeMessage::GetStringPiece(QuicTag tag, | 109 bool CryptoHandshakeMessage::GetStringPiece(QuicTag tag, |
106 QuicStringPiece* out) const { | 110 QuicStringPiece* out) const { |
107 QuicTagValueMap::const_iterator it = tag_value_map_.find(tag); | 111 QuicTagValueMap::const_iterator it = tag_value_map_.find(tag); |
108 if (it == tag_value_map_.end()) { | 112 if (it == tag_value_map_.end()) { |
109 return false; | 113 return false; |
110 } | 114 } |
111 *out = it->second; | 115 *out = it->second; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 ret += "0x" + QuicTextUtils::HexEncode(it->second); | 333 ret += "0x" + QuicTextUtils::HexEncode(it->second); |
330 } | 334 } |
331 ret += "\n"; | 335 ret += "\n"; |
332 } | 336 } |
333 --indent; | 337 --indent; |
334 ret += string(2 * indent, ' ') + ">"; | 338 ret += string(2 * indent, ' ') + ">"; |
335 return ret; | 339 return ret; |
336 } | 340 } |
337 | 341 |
338 } // namespace net | 342 } // namespace net |
OLD | NEW |