OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/safe_browsing/client_side_detection_service.h" | 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 // static | 560 // static |
561 void ClientSideDetectionService::SetBadSubnets(const ClientSideModel& model, | 561 void ClientSideDetectionService::SetBadSubnets(const ClientSideModel& model, |
562 BadSubnetMap* bad_subnets) { | 562 BadSubnetMap* bad_subnets) { |
563 bad_subnets->clear(); | 563 bad_subnets->clear(); |
564 for (int i = 0; i < model.bad_subnet_size(); ++i) { | 564 for (int i = 0; i < model.bad_subnet_size(); ++i) { |
565 int size = model.bad_subnet(i).size(); | 565 int size = model.bad_subnet(i).size(); |
566 if (size < 0 || size > static_cast<int>(net::kIPv6AddressSize) * 8) { | 566 if (size < 0 || size > static_cast<int>(net::kIPv6AddressSize) * 8) { |
567 DLOG(ERROR) << "Invalid bad subnet size: " << size; | 567 DLOG(ERROR) << "Invalid bad subnet size: " << size; |
568 continue; | 568 continue; |
569 } | 569 } |
570 if (model.bad_subnet(i).prefix().size() != crypto::SHA256_LENGTH) { | 570 if (model.bad_subnet(i).prefix().size() != crypto::kSHA256Length) { |
571 DLOG(ERROR) << "Invalid bad subnet prefix length: " | 571 DLOG(ERROR) << "Invalid bad subnet prefix length: " |
572 << model.bad_subnet(i).prefix().size(); | 572 << model.bad_subnet(i).prefix().size(); |
573 continue; | 573 continue; |
574 } | 574 } |
575 // We precompute the mask for the given subnet size to speed up lookups. | 575 // We precompute the mask for the given subnet size to speed up lookups. |
576 // Basically we need to create a 16B long string which has the highest | 576 // Basically we need to create a 16B long string which has the highest |
577 // |size| bits sets to one. | 577 // |size| bits sets to one. |
578 std::string mask(net::kIPv6AddressSize, '\x00'); | 578 std::string mask(net::kIPv6AddressSize, '\x00'); |
579 mask.replace(0, size / 8, size / 8, '\xFF'); | 579 mask.replace(0, size / 8, size / 8, '\xFF'); |
580 if (size % 8) { | 580 if (size % 8) { |
(...skipping 21 matching lines...) Expand all Loading... |
602 } | 602 } |
603 } | 603 } |
604 for (int i = 0; i < model.page_word_size(); ++i) { | 604 for (int i = 0; i < model.page_word_size(); ++i) { |
605 if (model.page_word(i) < 0 || model.page_word(i) > max_index) { | 605 if (model.page_word(i) < 0 || model.page_word(i) > max_index) { |
606 return false; | 606 return false; |
607 } | 607 } |
608 } | 608 } |
609 return true; | 609 return true; |
610 } | 610 } |
611 } // namespace safe_browsing | 611 } // namespace safe_browsing |
OLD | NEW |