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

Side by Side Diff: chrome/common/visitedlink_common.cc

Issue 7466003: MD5Update function uses StringPiece instead of raw buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added valid license Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
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/common/visitedlink_common.h" 5 #include "chrome/common/visitedlink_common.h"
6 6
7 #include <string.h> // for memset() 7 #include <string.h> // for memset()
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/md5.h" 10 #include "base/md5.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 // static 75 // static
76 VisitedLinkCommon::Fingerprint VisitedLinkCommon::ComputeURLFingerprint( 76 VisitedLinkCommon::Fingerprint VisitedLinkCommon::ComputeURLFingerprint(
77 const char* canonical_url, 77 const char* canonical_url,
78 size_t url_len, 78 size_t url_len,
79 const uint8 salt[LINK_SALT_LENGTH]) { 79 const uint8 salt[LINK_SALT_LENGTH]) {
80 DCHECK(url_len > 0) << "Canonical URLs should not be empty"; 80 DCHECK(url_len > 0) << "Canonical URLs should not be empty";
81 81
82 base::MD5Context ctx; 82 base::MD5Context ctx;
83 base::MD5Init(&ctx); 83 base::MD5Init(&ctx);
84 base::MD5Update(&ctx, salt, LINK_SALT_LENGTH * sizeof(uint8)); 84 base::MD5Update(&ctx, base::StringPiece(reinterpret_cast<const char*>(salt),
85 base::MD5Update(&ctx, canonical_url, url_len * sizeof(char)); 85 LINK_SALT_LENGTH));
86 base::MD5Update(&ctx, base::StringPiece(canonical_url, url_len));
86 87
87 base::MD5Digest digest; 88 base::MD5Digest digest;
88 base::MD5Final(&digest, &ctx); 89 base::MD5Final(&digest, &ctx);
89 90
90 // This is the same as "return *(Fingerprint*)&digest.a;" but if we do that 91 // This is the same as "return *(Fingerprint*)&digest.a;" but if we do that
91 // direct cast the alignment could be wrong, and we can't access a 64-bit int 92 // direct cast the alignment could be wrong, and we can't access a 64-bit int
92 // on arbitrary alignment on some processors. This reinterpret_casts it 93 // on arbitrary alignment on some processors. This reinterpret_casts it
93 // down to a char array of the same size as fingerprint, and then does the 94 // down to a char array of the same size as fingerprint, and then does the
94 // bit cast, which amounts to a memcpy. This does not handle endian issues. 95 // bit cast, which amounts to a memcpy. This does not handle endian issues.
95 return bit_cast<Fingerprint, uint8[8]>( 96 return bit_cast<Fingerprint, uint8[8]>(
96 *reinterpret_cast<uint8(*)[8]>(&digest.a)); 97 *reinterpret_cast<uint8(*)[8]>(&digest.a));
97 } 98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698