Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1193)

Side by Side Diff: components/safe_browsing_db/v4_protocol_manager_util.cc

Issue 2928793002: Use the substr API correctly in FullHashToHashPrefix. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_protocol_manager_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/safe_browsing_db/v4_protocol_manager_util.h" 5 #include "components/safe_browsing_db/v4_protocol_manager_util.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/hash.h" 8 #include "base/hash.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 298 }
299 } 299 }
300 300
301 // static 301 // static
302 bool V4ProtocolManagerUtil::FullHashToHashPrefix(const FullHash& full_hash, 302 bool V4ProtocolManagerUtil::FullHashToHashPrefix(const FullHash& full_hash,
303 PrefixSize prefix_size, 303 PrefixSize prefix_size,
304 HashPrefix* hash_prefix) { 304 HashPrefix* hash_prefix) {
305 if (full_hash.size() < prefix_size) { 305 if (full_hash.size() < prefix_size) {
306 return false; 306 return false;
307 } 307 }
308 *hash_prefix = full_hash.substr(prefix_size); 308 *hash_prefix = full_hash.substr(0, prefix_size);
309 return true; 309 return true;
310 } 310 }
311 311
312 // static 312 // static
313 bool V4ProtocolManagerUtil::FullHashToSmallestHashPrefix( 313 bool V4ProtocolManagerUtil::FullHashToSmallestHashPrefix(
314 const FullHash& full_hash, 314 const FullHash& full_hash,
315 HashPrefix* hash_prefix) { 315 HashPrefix* hash_prefix) {
316 return FullHashToHashPrefix(full_hash, kMinHashPrefixLength, hash_prefix); 316 return FullHashToHashPrefix(full_hash, kMinHashPrefixLength, hash_prefix);
317 } 317 }
318 318
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 573
574 const std::string hash = base::SHA1HashString(packed_ip); 574 const std::string hash = base::SHA1HashString(packed_ip);
575 DCHECK_EQ(20u, hash.size()); 575 DCHECK_EQ(20u, hash.size());
576 hashed_encoded_ip->resize(hash.size() + 1); 576 hashed_encoded_ip->resize(hash.size() + 1);
577 hashed_encoded_ip->replace(0, hash.size(), hash); 577 hashed_encoded_ip->replace(0, hash.size(), hash);
578 (*hashed_encoded_ip)[hash.size()] = static_cast<unsigned char>(128); 578 (*hashed_encoded_ip)[hash.size()] = static_cast<unsigned char>(128);
579 return true; 579 return true;
580 } 580 }
581 581
582 } // namespace safe_browsing 582 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_protocol_manager_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698