OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/quic_server_info.h" | 5 #include "net/quic/crypto/quic_server_info.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 | 10 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 if (!iter.ReadString(&state->source_address_token)) { | 82 if (!iter.ReadString(&state->source_address_token)) { |
83 DVLOG(1) << "Malformed source_address_token"; | 83 DVLOG(1) << "Malformed source_address_token"; |
84 return false; | 84 return false; |
85 } | 85 } |
86 if (!iter.ReadString(&state->server_config_sig)) { | 86 if (!iter.ReadString(&state->server_config_sig)) { |
87 DVLOG(1) << "Malformed server_config_sig"; | 87 DVLOG(1) << "Malformed server_config_sig"; |
88 return false; | 88 return false; |
89 } | 89 } |
90 | 90 |
91 // Read certs. | 91 // Read certs. |
92 uint32 num_certs; | 92 uint32_t num_certs; |
93 if (!iter.ReadUInt32(&num_certs)) { | 93 if (!iter.ReadUInt32(&num_certs)) { |
94 DVLOG(1) << "Malformed num_certs"; | 94 DVLOG(1) << "Malformed num_certs"; |
95 return false; | 95 return false; |
96 } | 96 } |
97 | 97 |
98 for (uint32 i = 0; i < num_certs; i++) { | 98 for (uint32_t i = 0; i < num_certs; i++) { |
99 string cert; | 99 string cert; |
100 if (!iter.ReadString(&cert)) { | 100 if (!iter.ReadString(&cert)) { |
101 DVLOG(1) << "Malformed cert"; | 101 DVLOG(1) << "Malformed cert"; |
102 return false; | 102 return false; |
103 } | 103 } |
104 state->certs.push_back(cert); | 104 state->certs.push_back(cert); |
105 } | 105 } |
106 | 106 |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 string QuicServerInfo::Serialize() { | 110 string QuicServerInfo::Serialize() { |
111 string pickled_data = SerializeInner(); | 111 string pickled_data = SerializeInner(); |
112 state_.Clear(); | 112 state_.Clear(); |
113 return pickled_data; | 113 return pickled_data; |
114 } | 114 } |
115 | 115 |
116 string QuicServerInfo::SerializeInner() const { | 116 string QuicServerInfo::SerializeInner() const { |
117 base::Pickle p(sizeof(base::Pickle::Header)); | 117 base::Pickle p(sizeof(base::Pickle::Header)); |
118 | 118 |
119 if (!p.WriteInt(kQuicCryptoConfigVersion) || | 119 if (!p.WriteInt(kQuicCryptoConfigVersion) || |
120 !p.WriteString(state_.server_config) || | 120 !p.WriteString(state_.server_config) || |
121 !p.WriteString(state_.source_address_token) || | 121 !p.WriteString(state_.source_address_token) || |
122 !p.WriteString(state_.server_config_sig) || | 122 !p.WriteString(state_.server_config_sig) || |
123 state_.certs.size() > std::numeric_limits<uint32>::max() || | 123 state_.certs.size() > std::numeric_limits<uint32_t>::max() || |
124 !p.WriteUInt32(state_.certs.size())) { | 124 !p.WriteUInt32(state_.certs.size())) { |
125 return string(); | 125 return string(); |
126 } | 126 } |
127 | 127 |
128 for (size_t i = 0; i < state_.certs.size(); i++) { | 128 for (size_t i = 0; i < state_.certs.size(); i++) { |
129 if (!p.WriteString(state_.certs[i])) { | 129 if (!p.WriteString(state_.certs[i])) { |
130 return string(); | 130 return string(); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 return string(reinterpret_cast<const char*>(p.data()), p.size()); | 134 return string(reinterpret_cast<const char*>(p.data()), p.size()); |
135 } | 135 } |
136 | 136 |
137 QuicServerInfoFactory::~QuicServerInfoFactory() {} | 137 QuicServerInfoFactory::~QuicServerInfoFactory() {} |
138 | 138 |
139 } // namespace net | 139 } // namespace net |
OLD | NEW |