| 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" |
| 11 #include "net/quic/core/crypto/crypto_utils.h" | 11 #include "net/quic/core/crypto/crypto_utils.h" |
| 12 #include "net/quic/core/quic_socket_address_coder.h" | 12 #include "net/quic/core/quic_socket_address_coder.h" |
| 13 #include "net/quic/core/quic_utils.h" | 13 #include "net/quic/core/quic_utils.h" |
| 14 #include "net/quic/platform/api/quic_map_util.h" | 14 #include "net/quic/platform/api/quic_map_util.h" |
| 15 #include "net/quic/platform/api/quic_str_cat.h" | 15 #include "net/quic/platform/api/quic_str_cat.h" |
| 16 #include "net/quic/platform/api/quic_text_utils.h" | 16 #include "net/quic/platform/api/quic_text_utils.h" |
| 17 | 17 |
| 18 using base::StringPiece; | |
| 19 using std::string; | 18 using std::string; |
| 20 | 19 |
| 21 namespace net { | 20 namespace net { |
| 22 | 21 |
| 23 CryptoHandshakeMessage::CryptoHandshakeMessage() : tag_(0), minimum_size_(0) {} | 22 CryptoHandshakeMessage::CryptoHandshakeMessage() : tag_(0), 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_), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 if (!serialized_.get()) { | 60 if (!serialized_.get()) { |
| 62 serialized_.reset(CryptoFramer::ConstructHandshakeMessage(*this)); | 61 serialized_.reset(CryptoFramer::ConstructHandshakeMessage(*this)); |
| 63 } | 62 } |
| 64 return *serialized_; | 63 return *serialized_; |
| 65 } | 64 } |
| 66 | 65 |
| 67 void CryptoHandshakeMessage::MarkDirty() { | 66 void CryptoHandshakeMessage::MarkDirty() { |
| 68 serialized_.reset(); | 67 serialized_.reset(); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void CryptoHandshakeMessage::SetStringPiece(QuicTag tag, StringPiece value) { | 70 void CryptoHandshakeMessage::SetStringPiece(QuicTag tag, |
| 71 QuicStringPiece value) { |
| 72 tag_value_map_[tag] = value.as_string(); | 72 tag_value_map_[tag] = value.as_string(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void CryptoHandshakeMessage::Erase(QuicTag tag) { | 75 void CryptoHandshakeMessage::Erase(QuicTag tag) { |
| 76 tag_value_map_.erase(tag); | 76 tag_value_map_.erase(tag); |
| 77 } | 77 } |
| 78 | 78 |
| 79 QuicErrorCode CryptoHandshakeMessage::GetTaglist(QuicTag tag, | 79 QuicErrorCode CryptoHandshakeMessage::GetTaglist(QuicTag tag, |
| 80 const QuicTag** out_tags, | 80 const QuicTag** out_tags, |
| 81 size_t* out_len) const { | 81 size_t* out_len) const { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 *out_len = 0; | 93 *out_len = 0; |
| 94 return ret; | 94 return ret; |
| 95 } | 95 } |
| 96 | 96 |
| 97 *out_tags = reinterpret_cast<const QuicTag*>(it->second.data()); | 97 *out_tags = reinterpret_cast<const QuicTag*>(it->second.data()); |
| 98 *out_len = it->second.size() / sizeof(QuicTag); | 98 *out_len = it->second.size() / sizeof(QuicTag); |
| 99 return ret; | 99 return ret; |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool CryptoHandshakeMessage::GetStringPiece(QuicTag tag, | 102 bool CryptoHandshakeMessage::GetStringPiece(QuicTag tag, |
| 103 StringPiece* out) const { | 103 QuicStringPiece* out) const { |
| 104 QuicTagValueMap::const_iterator it = tag_value_map_.find(tag); | 104 QuicTagValueMap::const_iterator it = tag_value_map_.find(tag); |
| 105 if (it == tag_value_map_.end()) { | 105 if (it == tag_value_map_.end()) { |
| 106 return false; | 106 return false; |
| 107 } | 107 } |
| 108 *out = it->second; | 108 *out = it->second; |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool CryptoHandshakeMessage::HasStringPiece(QuicTag tag) const { | 112 bool CryptoHandshakeMessage::HasStringPiece(QuicTag tag) const { |
| 113 return QuicContainsKey(tag_value_map_, tag); | 113 return QuicContainsKey(tag_value_map_, tag); |
| 114 } | 114 } |
| 115 | 115 |
| 116 QuicErrorCode CryptoHandshakeMessage::GetNthValue24(QuicTag tag, | 116 QuicErrorCode CryptoHandshakeMessage::GetNthValue24( |
| 117 unsigned index, | 117 QuicTag tag, |
| 118 StringPiece* out) const { | 118 unsigned index, |
| 119 StringPiece value; | 119 QuicStringPiece* out) const { |
| 120 QuicStringPiece value; |
| 120 if (!GetStringPiece(tag, &value)) { | 121 if (!GetStringPiece(tag, &value)) { |
| 121 return QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; | 122 return QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; |
| 122 } | 123 } |
| 123 | 124 |
| 124 for (unsigned i = 0;; i++) { | 125 for (unsigned i = 0;; i++) { |
| 125 if (value.empty()) { | 126 if (value.empty()) { |
| 126 return QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND; | 127 return QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND; |
| 127 } | 128 } |
| 128 if (value.size() < 3) { | 129 if (value.size() < 3) { |
| 129 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; | 130 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
| 130 } | 131 } |
| 131 | 132 |
| 132 const unsigned char* data = | 133 const unsigned char* data = |
| 133 reinterpret_cast<const unsigned char*>(value.data()); | 134 reinterpret_cast<const unsigned char*>(value.data()); |
| 134 size_t size = static_cast<size_t>(data[0]) | | 135 size_t size = static_cast<size_t>(data[0]) | |
| 135 (static_cast<size_t>(data[1]) << 8) | | 136 (static_cast<size_t>(data[1]) << 8) | |
| 136 (static_cast<size_t>(data[2]) << 16); | 137 (static_cast<size_t>(data[2]) << 16); |
| 137 value.remove_prefix(3); | 138 value.remove_prefix(3); |
| 138 | 139 |
| 139 if (value.size() < size) { | 140 if (value.size() < size) { |
| 140 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; | 141 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
| 141 } | 142 } |
| 142 | 143 |
| 143 if (i == index) { | 144 if (i == index) { |
| 144 *out = StringPiece(value.data(), size); | 145 *out = QuicStringPiece(value.data(), size); |
| 145 return QUIC_NO_ERROR; | 146 return QUIC_NO_ERROR; |
| 146 } | 147 } |
| 147 | 148 |
| 148 value.remove_prefix(size); | 149 value.remove_prefix(size); |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 | 152 |
| 152 QuicErrorCode CryptoHandshakeMessage::GetUint32(QuicTag tag, | 153 QuicErrorCode CryptoHandshakeMessage::GetUint32(QuicTag tag, |
| 153 uint32_t* out) const { | 154 uint32_t* out) const { |
| 154 return GetPOD(tag, out, sizeof(uint32_t)); | 155 return GetPOD(tag, out, sizeof(uint32_t)); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 ret += "0x" + QuicTextUtils::HexEncode(it->second); | 321 ret += "0x" + QuicTextUtils::HexEncode(it->second); |
| 321 } | 322 } |
| 322 ret += "\n"; | 323 ret += "\n"; |
| 323 } | 324 } |
| 324 --indent; | 325 --indent; |
| 325 ret += string(2 * indent, ' ') + ">"; | 326 ret += string(2 * indent, ' ') + ">"; |
| 326 return ret; | 327 return ret; |
| 327 } | 328 } |
| 328 | 329 |
| 329 } // namespace net | 330 } // namespace net |
| OLD | NEW |