| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Parse the data returned from the SafeBrowsing v2.1 protocol response. | 5 // Parse the data returned from the SafeBrowsing v2.1 protocol response. |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 bool SafeBrowsingProtocolParser::ReadChunkId( | 445 bool SafeBrowsingProtocolParser::ReadChunkId( |
| 446 const char** data, int* remaining, int* chunk_id) { | 446 const char** data, int* remaining, int* chunk_id) { |
| 447 // Protocol says four bytes, not sizeof(int). Make sure those | 447 // Protocol says four bytes, not sizeof(int). Make sure those |
| 448 // values are the same. | 448 // values are the same. |
| 449 DCHECK_EQ(sizeof(*chunk_id), 4u); | 449 DCHECK_EQ(sizeof(*chunk_id), 4u); |
| 450 if (static_cast<size_t>(*remaining) < sizeof(*chunk_id)) | 450 if (static_cast<size_t>(*remaining) < sizeof(*chunk_id)) |
| 451 return false; | 451 return false; |
| 452 memcpy(chunk_id, *data, sizeof(*chunk_id)); | 452 memcpy(chunk_id, *data, sizeof(*chunk_id)); |
| 453 *data += sizeof(*chunk_id); | 453 *data += sizeof(*chunk_id); |
| 454 *remaining -= sizeof(*chunk_id); | 454 *remaining -= sizeof(*chunk_id); |
| 455 *chunk_id = htonl(*chunk_id); | 455 *chunk_id = base::HostToNet32(*chunk_id); |
| 456 DCHECK_GE(*remaining, 0); | 456 DCHECK_GE(*remaining, 0); |
| 457 return true; | 457 return true; |
| 458 } | 458 } |
| 459 | 459 |
| 460 bool SafeBrowsingProtocolParser::ReadPrefixes( | 460 bool SafeBrowsingProtocolParser::ReadPrefixes( |
| 461 const char** data, int* remaining, SBEntry* entry, int count) { | 461 const char** data, int* remaining, SBEntry* entry, int count) { |
| 462 int hash_len = entry->HashLen(); | 462 int hash_len = entry->HashLen(); |
| 463 for (int i = 0; i < count; ++i) { | 463 for (int i = 0; i < count; ++i) { |
| 464 if (entry->IsSub()) { | 464 if (entry->IsSub()) { |
| 465 int chunk_id; | 465 int chunk_id; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 520 |
| 521 data += line.size() + 1; | 521 data += line.size() + 1; |
| 522 remaining -= static_cast<int>(line.size()) + 1; | 522 remaining -= static_cast<int>(line.size()) + 1; |
| 523 } | 523 } |
| 524 | 524 |
| 525 if (client_key->empty() || wrapped_key->empty()) | 525 if (client_key->empty() || wrapped_key->empty()) |
| 526 return false; | 526 return false; |
| 527 | 527 |
| 528 return true; | 528 return true; |
| 529 } | 529 } |
| OLD | NEW |