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/cert/crl_set_storage.h" | 5 #include "net/cert/crl_set_storage.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "crypto/sha2.h" | 14 #include "crypto/sha2.h" |
15 #include "third_party/zlib/zlib.h" | 15 #include "third_party/zlib/zlib.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 // Decompress zlib decompressed |in| into |out|. |out_len| is the number of | 19 // Decompress zlib decompressed |in| into |out|. |out_len| is the number of |
20 // bytes at |out| and must be exactly equal to the size of the decompressed | 20 // bytes at |out| and must be exactly equal to the size of the decompressed |
21 // data. | 21 // data. |
22 static bool DecompressZlib(uint8* out, int out_len, base::StringPiece in) { | 22 static bool DecompressZlib(uint8_t* out, int out_len, base::StringPiece in) { |
23 z_stream z; | 23 z_stream z; |
24 memset(&z, 0, sizeof(z)); | 24 memset(&z, 0, sizeof(z)); |
25 | 25 |
26 z.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(in.data())); | 26 z.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(in.data())); |
27 z.avail_in = in.size(); | 27 z.avail_in = in.size(); |
28 z.next_out = reinterpret_cast<Bytef*>(out); | 28 z.next_out = reinterpret_cast<Bytef*>(out); |
29 z.avail_out = out_len; | 29 z.avail_out = out_len; |
30 | 30 |
31 if (inflateInit(&z) != Z_OK) | 31 if (inflateInit(&z) != Z_OK) |
32 return false; | 32 return false; |
(...skipping 11 matching lines...) Expand all Loading... | |
44 } | 44 } |
45 | 45 |
46 // CRLSet format: | 46 // CRLSet format: |
47 // | 47 // |
48 // uint16le header_len | 48 // uint16le header_len |
49 // byte[header_len] header_bytes | 49 // byte[header_len] header_bytes |
50 // repeated { | 50 // repeated { |
51 // byte[32] parent_spki_sha256 | 51 // byte[32] parent_spki_sha256 |
52 // uint32le num_serials | 52 // uint32le num_serials |
53 // [num_serials] { | 53 // [num_serials] { |
54 // uint8 serial_length; | 54 // uint8_t serial_length; |
55 // byte[serial_length] serial; | 55 // byte[serial_length] serial; |
56 // } | 56 // } |
57 // | 57 // |
58 // header_bytes consists of a JSON dictionary with the following keys: | 58 // header_bytes consists of a JSON dictionary with the following keys: |
59 // Version (int): currently 0 | 59 // Version (int): currently 0 |
60 // ContentType (string): "CRLSet" or "CRLSetDelta" (magic value) | 60 // ContentType (string): "CRLSet" or "CRLSetDelta" (magic value) |
61 // DeltaFrom (int32): if this is a delta update (see below), then this | 61 // DeltaFrom (int32_t): if this is a delta update (see below), then this |
62 // contains the sequence number of the base CRLSet. | 62 // contains the sequence number of the base CRLSet. |
63 // Sequence (int32): the monotonic sequence number of this CRL set. | 63 // Sequence (int32_t): the monotonic sequence number of this CRL set. |
64 // | 64 // |
65 // A delta CRLSet is similar to a CRLSet: | 65 // A delta CRLSet is similar to a CRLSet: |
66 // | 66 // |
67 // struct CompressedChanges { | 67 // struct CompressedChanges { |
68 // uint32le uncompressed_size | 68 // uint32le uncompressed_size |
69 // uint32le compressed_size | 69 // uint32le compressed_size |
70 // byte[compressed_size] zlib_data | 70 // byte[compressed_size] zlib_data |
71 // } | 71 // } |
72 // | 72 // |
73 // uint16le header_len | 73 // uint16le header_len |
(...skipping 10 matching lines...) Expand all Loading... | |
84 // // CRL deleted | 84 // // CRL deleted |
85 // case 3: | 85 // case 3: |
86 // // CRL changed | 86 // // CRL changed |
87 // CompressedChanges serials_changes | 87 // CompressedChanges serials_changes |
88 // [serials_changes.uncompressed_size] { | 88 // [serials_changes.uncompressed_size] { |
89 // switch (serials_changes[i]) { | 89 // switch (serials_changes[i]) { |
90 // case 0: | 90 // case 0: |
91 // // the serial is the same | 91 // // the serial is the same |
92 // case 1: | 92 // case 1: |
93 // // serial inserted | 93 // // serial inserted |
94 // uint8 serial_length | 94 // uint8_t serial_length |
95 // byte[serial_length] serial | 95 // byte[serial_length] serial |
96 // case 2: | 96 // case 2: |
97 // // serial deleted | 97 // // serial deleted |
98 // } | 98 // } |
99 // } | 99 // } |
100 // } | 100 // } |
101 // } | 101 // } |
102 // | 102 // |
103 // A delta CRLSet applies to a specific CRL set as given in the | 103 // A delta CRLSet applies to a specific CRL set as given in the |
104 // header's "DeltaFrom" value. The delta describes the changes to each CRL | 104 // header's "DeltaFrom" value. The delta describes the changes to each CRL |
105 // in turn with a zlib compressed array of options: either the CRL is the same, | 105 // in turn with a zlib compressed array of options: either the CRL is the same, |
106 // a new CRL is inserted, the CRL is deleted or the CRL is updated. In the case | 106 // a new CRL is inserted, the CRL is deleted or the CRL is updated. In the case |
107 // of an update, the serials in the CRL are considered in the same fashion | 107 // of an update, the serials in the CRL are considered in the same fashion |
108 // except there is no delta update of a serial number: they are either | 108 // except there is no delta update of a serial number: they are either |
109 // inserted, deleted or left the same. | 109 // inserted, deleted or left the same. |
110 | 110 |
111 // ReadHeader reads the header (including length prefix) from |data| and | 111 // ReadHeader reads the header (including length prefix) from |data| and |
112 // updates |data| to remove the header on return. Caller takes ownership of the | 112 // updates |data| to remove the header on return. Caller takes ownership of the |
113 // returned pointer. | 113 // returned pointer. |
114 static base::DictionaryValue* ReadHeader(base::StringPiece* data) { | 114 static base::DictionaryValue* ReadHeader(base::StringPiece* data) { |
115 if (data->size() < 2) | 115 if (data->size() < 2) |
116 return NULL; | 116 return NULL; |
117 uint16 header_len; | 117 uint16_t header_len; |
118 memcpy(&header_len, data->data(), 2); // assumes little-endian. | 118 memcpy(&header_len, data->data(), 2); // Assumes little-endian. |
eroman
2015/06/03 22:10:39
your translation is correct fine. however it seems
wtc
2015/06/04 01:03:04
Done. See https://codereview.chromium.org/11704930
| |
119 data->remove_prefix(2); | 119 data->remove_prefix(2); |
120 | 120 |
121 if (data->size() < header_len) | 121 if (data->size() < header_len) |
122 return NULL; | 122 return NULL; |
123 | 123 |
124 const base::StringPiece header_bytes(data->data(), header_len); | 124 const base::StringPiece header_bytes(data->data(), header_len); |
125 data->remove_prefix(header_len); | 125 data->remove_prefix(header_len); |
126 | 126 |
127 scoped_ptr<base::Value> header(base::JSONReader::DeprecatedRead( | 127 scoped_ptr<base::Value> header(base::JSONReader::DeprecatedRead( |
128 header_bytes, base::JSON_ALLOW_TRAILING_COMMAS)); | 128 header_bytes, base::JSON_ALLOW_TRAILING_COMMAS)); |
129 if (header.get() == NULL) | 129 if (header.get() == NULL) |
130 return NULL; | 130 return NULL; |
131 | 131 |
132 if (!header->IsType(base::Value::TYPE_DICTIONARY)) | 132 if (!header->IsType(base::Value::TYPE_DICTIONARY)) |
133 return NULL; | 133 return NULL; |
134 return reinterpret_cast<base::DictionaryValue*>(header.release()); | 134 return reinterpret_cast<base::DictionaryValue*>(header.release()); |
135 } | 135 } |
136 | 136 |
137 // kCurrentFileVersion is the version of the CRLSet file format that we | 137 // kCurrentFileVersion is the version of the CRLSet file format that we |
138 // currently implement. | 138 // currently implement. |
139 static const int kCurrentFileVersion = 0; | 139 static const int kCurrentFileVersion = 0; |
140 | 140 |
141 static bool ReadCRL(base::StringPiece* data, std::string* out_parent_spki_hash, | 141 static bool ReadCRL(base::StringPiece* data, std::string* out_parent_spki_hash, |
142 std::vector<std::string>* out_serials) { | 142 std::vector<std::string>* out_serials) { |
143 if (data->size() < crypto::kSHA256Length) | 143 if (data->size() < crypto::kSHA256Length) |
144 return false; | 144 return false; |
145 out_parent_spki_hash->assign(data->data(), crypto::kSHA256Length); | 145 out_parent_spki_hash->assign(data->data(), crypto::kSHA256Length); |
146 data->remove_prefix(crypto::kSHA256Length); | 146 data->remove_prefix(crypto::kSHA256Length); |
147 | 147 |
148 if (data->size() < sizeof(uint32)) | 148 if (data->size() < sizeof(uint32_t)) |
149 return false; | 149 return false; |
150 uint32 num_serials; | 150 uint32_t num_serials; |
151 memcpy(&num_serials, data->data(), sizeof(uint32)); // assumes little endian | 151 // Assumes little endian. |
152 memcpy(&num_serials, data->data(), sizeof(uint32_t)); | |
eroman
2015/06/03 22:10:39
for instance here sizeof(num_serials) would be mor
wtc
2015/06/04 01:03:04
ARM, MIPS, and PowerPC can be configured to be big
| |
152 if (num_serials > 32 * 1024 * 1024) // Sanity check. | 153 if (num_serials > 32 * 1024 * 1024) // Sanity check. |
153 return false; | 154 return false; |
154 | 155 |
155 out_serials->reserve(num_serials); | 156 out_serials->reserve(num_serials); |
156 data->remove_prefix(sizeof(uint32)); | 157 data->remove_prefix(sizeof(uint32_t)); |
157 | 158 |
158 for (uint32 i = 0; i < num_serials; ++i) { | 159 for (uint32_t i = 0; i < num_serials; ++i) { |
159 if (data->size() < sizeof(uint8)) | 160 if (data->size() < sizeof(uint8_t)) |
160 return false; | 161 return false; |
161 | 162 |
162 uint8 serial_length = data->data()[0]; | 163 uint8_t serial_length = data->data()[0]; |
163 data->remove_prefix(sizeof(uint8)); | 164 data->remove_prefix(sizeof(uint8_t)); |
164 | 165 |
165 if (data->size() < serial_length) | 166 if (data->size() < serial_length) |
166 return false; | 167 return false; |
167 | 168 |
168 out_serials->push_back(std::string()); | 169 out_serials->push_back(std::string()); |
169 out_serials->back().assign(data->data(), serial_length); | 170 out_serials->back().assign(data->data(), serial_length); |
170 data->remove_prefix(serial_length); | 171 data->remove_prefix(serial_length); |
171 } | 172 } |
172 | 173 |
173 return true; | 174 return true; |
(...skipping 30 matching lines...) Expand all Loading... | |
204 | 205 |
205 return true; | 206 return true; |
206 } | 207 } |
207 | 208 |
208 // kMaxUncompressedChangesLength is the largest changes array that we'll | 209 // kMaxUncompressedChangesLength is the largest changes array that we'll |
209 // accept. This bounds the number of CRLs in the CRLSet as well as the number | 210 // accept. This bounds the number of CRLs in the CRLSet as well as the number |
210 // of serial numbers in a given CRL. | 211 // of serial numbers in a given CRL. |
211 static const unsigned kMaxUncompressedChangesLength = 1024 * 1024; | 212 static const unsigned kMaxUncompressedChangesLength = 1024 * 1024; |
212 | 213 |
213 static bool ReadChanges(base::StringPiece* data, | 214 static bool ReadChanges(base::StringPiece* data, |
214 std::vector<uint8>* out_changes) { | 215 std::vector<uint8_t>* out_changes) { |
215 uint32 uncompressed_size, compressed_size; | 216 uint32_t uncompressed_size, compressed_size; |
216 if (data->size() < 2 * sizeof(uint32)) | 217 if (data->size() < 2 * sizeof(uint32_t)) |
217 return false; | 218 return false; |
218 // assumes little endian. | 219 // Assumes little endian. |
219 memcpy(&uncompressed_size, data->data(), sizeof(uint32)); | 220 memcpy(&uncompressed_size, data->data(), sizeof(uint32_t)); |
220 data->remove_prefix(4); | 221 data->remove_prefix(4); |
221 memcpy(&compressed_size, data->data(), sizeof(uint32)); | 222 memcpy(&compressed_size, data->data(), sizeof(uint32_t)); |
222 data->remove_prefix(4); | 223 data->remove_prefix(4); |
223 | 224 |
224 if (uncompressed_size > kMaxUncompressedChangesLength) | 225 if (uncompressed_size > kMaxUncompressedChangesLength) |
225 return false; | 226 return false; |
226 if (data->size() < compressed_size) | 227 if (data->size() < compressed_size) |
227 return false; | 228 return false; |
228 | 229 |
229 out_changes->clear(); | 230 out_changes->clear(); |
230 if (uncompressed_size == 0) | 231 if (uncompressed_size == 0) |
231 return true; | 232 return true; |
232 | 233 |
233 out_changes->resize(uncompressed_size); | 234 out_changes->resize(uncompressed_size); |
234 base::StringPiece compressed(data->data(), compressed_size); | 235 base::StringPiece compressed(data->data(), compressed_size); |
235 data->remove_prefix(compressed_size); | 236 data->remove_prefix(compressed_size); |
236 return DecompressZlib(&(*out_changes)[0], uncompressed_size, compressed); | 237 return DecompressZlib(&(*out_changes)[0], uncompressed_size, compressed); |
237 } | 238 } |
238 | 239 |
239 // These are the range coder symbols used in delta updates. | 240 // These are the range coder symbols used in delta updates. |
240 enum { | 241 enum { |
241 SYMBOL_SAME = 0, | 242 SYMBOL_SAME = 0, |
242 SYMBOL_INSERT = 1, | 243 SYMBOL_INSERT = 1, |
243 SYMBOL_DELETE = 2, | 244 SYMBOL_DELETE = 2, |
244 SYMBOL_CHANGED = 3, | 245 SYMBOL_CHANGED = 3, |
245 }; | 246 }; |
246 | 247 |
247 static bool ReadDeltaCRL(base::StringPiece* data, | 248 static bool ReadDeltaCRL(base::StringPiece* data, |
248 const std::vector<std::string>& old_serials, | 249 const std::vector<std::string>& old_serials, |
249 std::vector<std::string>* out_serials) { | 250 std::vector<std::string>* out_serials) { |
250 std::vector<uint8> changes; | 251 std::vector<uint8_t> changes; |
251 if (!ReadChanges(data, &changes)) | 252 if (!ReadChanges(data, &changes)) |
252 return false; | 253 return false; |
253 | 254 |
254 size_t i = 0; | 255 size_t i = 0; |
255 for (std::vector<uint8>::const_iterator k = changes.begin(); | 256 for (std::vector<uint8_t>::const_iterator k = changes.begin(); |
256 k != changes.end(); ++k) { | 257 k != changes.end(); ++k) { |
257 if (*k == SYMBOL_SAME) { | 258 if (*k == SYMBOL_SAME) { |
258 if (i >= old_serials.size()) | 259 if (i >= old_serials.size()) |
259 return false; | 260 return false; |
260 out_serials->push_back(old_serials[i]); | 261 out_serials->push_back(old_serials[i]); |
261 i++; | 262 i++; |
262 } else if (*k == SYMBOL_INSERT) { | 263 } else if (*k == SYMBOL_INSERT) { |
263 uint8 serial_length; | 264 uint8_t serial_length; |
264 if (data->size() < sizeof(uint8)) | 265 if (data->size() < sizeof(uint8_t)) |
265 return false; | 266 return false; |
266 memcpy(&serial_length, data->data(), sizeof(uint8)); | 267 memcpy(&serial_length, data->data(), sizeof(uint8_t)); |
267 data->remove_prefix(sizeof(uint8)); | 268 data->remove_prefix(sizeof(uint8_t)); |
268 | 269 |
269 if (data->size() < serial_length) | 270 if (data->size() < serial_length) |
270 return false; | 271 return false; |
271 const std::string serial(data->data(), serial_length); | 272 const std::string serial(data->data(), serial_length); |
272 data->remove_prefix(serial_length); | 273 data->remove_prefix(serial_length); |
273 | 274 |
274 out_serials->push_back(serial); | 275 out_serials->push_back(serial); |
275 } else if (*k == SYMBOL_DELETE) { | 276 } else if (*k == SYMBOL_DELETE) { |
276 if (i >= old_serials.size()) | 277 if (i >= old_serials.size()) |
277 return false; | 278 return false; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 | 324 |
324 double not_after; | 325 double not_after; |
325 if (!header_dict->GetDouble("NotAfter", ¬_after)) { | 326 if (!header_dict->GetDouble("NotAfter", ¬_after)) { |
326 // NotAfter is optional for now. | 327 // NotAfter is optional for now. |
327 not_after = 0; | 328 not_after = 0; |
328 } | 329 } |
329 if (not_after < 0) | 330 if (not_after < 0) |
330 return false; | 331 return false; |
331 | 332 |
332 scoped_refptr<CRLSet> crl_set(new CRLSet()); | 333 scoped_refptr<CRLSet> crl_set(new CRLSet()); |
333 crl_set->sequence_ = static_cast<uint32>(sequence); | 334 crl_set->sequence_ = static_cast<uint32_t>(sequence); |
334 crl_set->not_after_ = static_cast<uint64>(not_after); | 335 crl_set->not_after_ = static_cast<uint64_t>(not_after); |
335 crl_set->crls_.reserve(64); // Value observed experimentally. | 336 crl_set->crls_.reserve(64); // Value observed experimentally. |
336 | 337 |
337 for (size_t crl_index = 0; !data.empty(); crl_index++) { | 338 for (size_t crl_index = 0; !data.empty(); crl_index++) { |
338 // Speculatively push back a pair and pass it to ReadCRL() to avoid | 339 // Speculatively push back a pair and pass it to ReadCRL() to avoid |
339 // unnecessary copies. | 340 // unnecessary copies. |
340 crl_set->crls_.push_back( | 341 crl_set->crls_.push_back( |
341 std::make_pair(std::string(), std::vector<std::string>())); | 342 std::make_pair(std::string(), std::vector<std::string>())); |
342 std::pair<std::string, std::vector<std::string> >* const back_pair = | 343 std::pair<std::string, std::vector<std::string> >* const back_pair = |
343 &crl_set->crls_.back(); | 344 &crl_set->crls_.back(); |
344 | 345 |
(...skipping 29 matching lines...) Expand all Loading... | |
374 return false; | 375 return false; |
375 | 376 |
376 int version; | 377 int version; |
377 if (!header_dict->GetInteger("Version", &version) || | 378 if (!header_dict->GetInteger("Version", &version) || |
378 version != kCurrentFileVersion) { | 379 version != kCurrentFileVersion) { |
379 return false; | 380 return false; |
380 } | 381 } |
381 | 382 |
382 int sequence, delta_from; | 383 int sequence, delta_from; |
383 if (!header_dict->GetInteger("Sequence", &sequence) || | 384 if (!header_dict->GetInteger("Sequence", &sequence) || |
384 !header_dict->GetInteger("DeltaFrom", &delta_from) || | 385 !header_dict->GetInteger("DeltaFrom", &delta_from) || delta_from < 0 || |
385 delta_from < 0 || | 386 static_cast<uint32_t>(delta_from) != in_crl_set->sequence_) { |
386 static_cast<uint32>(delta_from) != in_crl_set->sequence_) { | |
387 return false; | 387 return false; |
388 } | 388 } |
389 | 389 |
390 double not_after; | 390 double not_after; |
391 if (!header_dict->GetDouble("NotAfter", ¬_after)) { | 391 if (!header_dict->GetDouble("NotAfter", ¬_after)) { |
392 // NotAfter is optional for now. | 392 // NotAfter is optional for now. |
393 not_after = 0; | 393 not_after = 0; |
394 } | 394 } |
395 if (not_after < 0) | 395 if (not_after < 0) |
396 return false; | 396 return false; |
397 | 397 |
398 scoped_refptr<CRLSet> crl_set(new CRLSet); | 398 scoped_refptr<CRLSet> crl_set(new CRLSet); |
399 crl_set->sequence_ = static_cast<uint32>(sequence); | 399 crl_set->sequence_ = static_cast<uint32_t>(sequence); |
400 crl_set->not_after_ = static_cast<uint64>(not_after); | 400 crl_set->not_after_ = static_cast<uint64_t>(not_after); |
401 | 401 |
402 if (!CopyBlockedSPKIsFromHeader(crl_set.get(), header_dict.get())) | 402 if (!CopyBlockedSPKIsFromHeader(crl_set.get(), header_dict.get())) |
403 return false; | 403 return false; |
404 | 404 |
405 std::vector<uint8> crl_changes; | 405 std::vector<uint8_t> crl_changes; |
406 | 406 |
407 if (!ReadChanges(&data, &crl_changes)) | 407 if (!ReadChanges(&data, &crl_changes)) |
408 return false; | 408 return false; |
409 | 409 |
410 size_t i = 0, j = 0; | 410 size_t i = 0, j = 0; |
411 for (std::vector<uint8>::const_iterator k = crl_changes.begin(); | 411 for (std::vector<uint8_t>::const_iterator k = crl_changes.begin(); |
412 k != crl_changes.end(); ++k) { | 412 k != crl_changes.end(); ++k) { |
413 if (*k == SYMBOL_SAME) { | 413 if (*k == SYMBOL_SAME) { |
414 if (i >= in_crl_set->crls_.size()) | 414 if (i >= in_crl_set->crls_.size()) |
415 return false; | 415 return false; |
416 crl_set->crls_.push_back(in_crl_set->crls_[i]); | 416 crl_set->crls_.push_back(in_crl_set->crls_[i]); |
417 crl_set->crls_index_by_issuer_[in_crl_set->crls_[i].first] = j; | 417 crl_set->crls_index_by_issuer_[in_crl_set->crls_[i].first] = j; |
418 i++; | 418 i++; |
419 j++; | 419 j++; |
420 } else if (*k == SYMBOL_INSERT) { | 420 } else if (*k == SYMBOL_INSERT) { |
421 std::string parent_spki_hash; | 421 std::string parent_spki_hash; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 for (std::vector<std::string>::const_iterator j = i->second.begin(); | 514 for (std::vector<std::string>::const_iterator j = i->second.begin(); |
515 j != i->second.end(); ++j) { | 515 j != i->second.end(); ++j) { |
516 len += 1 /* serial length */ + j->size(); | 516 len += 1 /* serial length */ + j->size(); |
517 } | 517 } |
518 } | 518 } |
519 | 519 |
520 std::string ret; | 520 std::string ret; |
521 uint8_t* out = reinterpret_cast<uint8_t*>( | 521 uint8_t* out = reinterpret_cast<uint8_t*>( |
522 WriteInto(&ret, len + 1 /* to include final NUL */)); | 522 WriteInto(&ret, len + 1 /* to include final NUL */)); |
523 size_t off = 0; | 523 size_t off = 0; |
524 CHECK(base::IsValueInRangeForNumericType<uint16>(header.size())); | 524 CHECK(base::IsValueInRangeForNumericType<uint16_t>(header.size())); |
525 out[off++] = static_cast<uint8_t>(header.size()); | 525 out[off++] = static_cast<uint8_t>(header.size()); |
526 out[off++] = static_cast<uint8_t>(header.size() >> 8); | 526 out[off++] = static_cast<uint8_t>(header.size() >> 8); |
527 memcpy(out + off, header.data(), header.size()); | 527 memcpy(out + off, header.data(), header.size()); |
528 off += header.size(); | 528 off += header.size(); |
529 | 529 |
530 for (CRLSet::CRLList::const_iterator i = crl_set->crls_.begin(); | 530 for (CRLSet::CRLList::const_iterator i = crl_set->crls_.begin(); |
531 i != crl_set->crls_.end(); ++i) { | 531 i != crl_set->crls_.end(); ++i) { |
532 memcpy(out + off, i->first.data(), i->first.size()); | 532 memcpy(out + off, i->first.data(), i->first.size()); |
533 off += i->first.size(); | 533 off += i->first.size(); |
534 const uint32 num_serials = i->second.size(); | 534 const uint32_t num_serials = i->second.size(); |
535 memcpy(out + off, &num_serials, sizeof(num_serials)); | 535 memcpy(out + off, &num_serials, sizeof(num_serials)); |
536 off += sizeof(num_serials); | 536 off += sizeof(num_serials); |
537 | 537 |
538 for (std::vector<std::string>::const_iterator j = i->second.begin(); | 538 for (std::vector<std::string>::const_iterator j = i->second.begin(); |
539 j != i->second.end(); ++j) { | 539 j != i->second.end(); ++j) { |
540 CHECK(base::IsValueInRangeForNumericType<uint8_t>(j->size())); | 540 CHECK(base::IsValueInRangeForNumericType<uint8_t>(j->size())); |
541 out[off++] = static_cast<uint8_t>(j->size()); | 541 out[off++] = static_cast<uint8_t>(j->size()); |
542 memcpy(out + off, j->data(), j->size()); | 542 memcpy(out + off, j->data(), j->size()); |
543 off += j->size(); | 543 off += j->size(); |
544 } | 544 } |
545 } | 545 } |
546 | 546 |
547 CHECK_EQ(off, len); | 547 CHECK_EQ(off, len); |
548 return ret; | 548 return ret; |
549 } | 549 } |
550 | 550 |
551 } // namespace net | 551 } // namespace net |
OLD | NEW |