| 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" |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 i != crl_set->crls_.end(); ++i) { | 513 i != crl_set->crls_.end(); ++i) { |
| 514 len += i->first.size() + 4 /* num serials */; | 514 len += i->first.size() + 4 /* num serials */; |
| 515 for (std::vector<std::string>::const_iterator j = i->second.begin(); | 515 for (std::vector<std::string>::const_iterator j = i->second.begin(); |
| 516 j != i->second.end(); ++j) { | 516 j != i->second.end(); ++j) { |
| 517 len += 1 /* serial length */ + j->size(); | 517 len += 1 /* serial length */ + j->size(); |
| 518 } | 518 } |
| 519 } | 519 } |
| 520 | 520 |
| 521 std::string ret; | 521 std::string ret; |
| 522 uint8_t* out = reinterpret_cast<uint8_t*>( | 522 uint8_t* out = reinterpret_cast<uint8_t*>( |
| 523 WriteInto(&ret, len + 1 /* to include final NUL */)); | 523 base::WriteInto(&ret, len + 1 /* to include final NUL */)); |
| 524 size_t off = 0; | 524 size_t off = 0; |
| 525 CHECK(base::IsValueInRangeForNumericType<uint16_t>(header.size())); | 525 CHECK(base::IsValueInRangeForNumericType<uint16_t>(header.size())); |
| 526 out[off++] = static_cast<uint8_t>(header.size()); | 526 out[off++] = static_cast<uint8_t>(header.size()); |
| 527 out[off++] = static_cast<uint8_t>(header.size() >> 8); | 527 out[off++] = static_cast<uint8_t>(header.size() >> 8); |
| 528 memcpy(out + off, header.data(), header.size()); | 528 memcpy(out + off, header.data(), header.size()); |
| 529 off += header.size(); | 529 off += header.size(); |
| 530 | 530 |
| 531 for (CRLSet::CRLList::const_iterator i = crl_set->crls_.begin(); | 531 for (CRLSet::CRLList::const_iterator i = crl_set->crls_.begin(); |
| 532 i != crl_set->crls_.end(); ++i) { | 532 i != crl_set->crls_.end(); ++i) { |
| 533 memcpy(out + off, i->first.data(), i->first.size()); | 533 memcpy(out + off, i->first.data(), i->first.size()); |
| 534 off += i->first.size(); | 534 off += i->first.size(); |
| 535 const uint32_t num_serials = i->second.size(); | 535 const uint32_t num_serials = i->second.size(); |
| 536 memcpy(out + off, &num_serials, sizeof(num_serials)); | 536 memcpy(out + off, &num_serials, sizeof(num_serials)); |
| 537 off += sizeof(num_serials); | 537 off += sizeof(num_serials); |
| 538 | 538 |
| 539 for (std::vector<std::string>::const_iterator j = i->second.begin(); | 539 for (std::vector<std::string>::const_iterator j = i->second.begin(); |
| 540 j != i->second.end(); ++j) { | 540 j != i->second.end(); ++j) { |
| 541 CHECK(base::IsValueInRangeForNumericType<uint8_t>(j->size())); | 541 CHECK(base::IsValueInRangeForNumericType<uint8_t>(j->size())); |
| 542 out[off++] = static_cast<uint8_t>(j->size()); | 542 out[off++] = static_cast<uint8_t>(j->size()); |
| 543 memcpy(out + off, j->data(), j->size()); | 543 memcpy(out + off, j->data(), j->size()); |
| 544 off += j->size(); | 544 off += j->size(); |
| 545 } | 545 } |
| 546 } | 546 } |
| 547 | 547 |
| 548 CHECK_EQ(off, len); | 548 CHECK_EQ(off, len); |
| 549 return ret; | 549 return ret; |
| 550 } | 550 } |
| 551 | 551 |
| 552 } // namespace net | 552 } // namespace net |
| OLD | NEW |