summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlzheng@chromium.org <lzheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-14 23:30:40 +0000
committerlzheng@chromium.org <lzheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-14 23:30:40 +0000
commit29e52cf1071c34a0e49b634ed46b2f6037321383 (patch)
tree46726a2cca3ea20f370e100346bbf4177349cc86
parentbd707a60326fbf47ecafba43480028178dfa109f (diff)
downloadchromium_src-29e52cf1071c34a0e49b634ed46b2f6037321383.zip
chromium_src-29e52cf1071c34a0e49b634ed46b2f6037321383.tar.gz
chromium_src-29e52cf1071c34a0e49b634ed46b2f6037321383.tar.bz2
Convert hash explicitly to string with the size of the char array.
TEST=safe_browsing_util_unittest BUG=76013 Review URL: http://codereview.chromium.org/6679046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78124 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.cc4
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_util.cc4
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_util.h2
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_util_unittest.cc5
4 files changed, 12 insertions, 3 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc
index c96930b9..45643d0 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -138,7 +138,9 @@ void SafeBrowsingService::Client::OnSafeBrowsingResult(
OnBrowseUrlCheckResult(*(check.url), check.result);
OnDownloadUrlCheckResult(*(check.url), check.result);
} else if (check.full_hash.get()) {
- OnDownloadHashCheckResult(check.full_hash->full_hash, check.result);
+ OnDownloadHashCheckResult(
+ safe_browsing_util::SBFullHashToString(*check.full_hash),
+ check.result);
} else {
NOTREACHED();
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_util.cc b/chrome/browser/safe_browsing/safe_browsing_util.cc
index 376c136..d42ba79 100644
--- a/chrome/browser/safe_browsing/safe_browsing_util.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_util.cc
@@ -524,4 +524,8 @@ void StringToSBFullHash(const std::string& hash_in, SBFullHash* hash_out) {
memcpy(hash_out->full_hash, hash_in.data(), base::SHA256_LENGTH);
}
+std::string SBFullHashToString(const SBFullHash& hash) {
+ DCHECK_EQ(static_cast<size_t>(base::SHA256_LENGTH), sizeof(hash.full_hash));
+ return std::string(hash.full_hash, sizeof(hash.full_hash));
+}
} // namespace safe_browsing_util
diff --git a/chrome/browser/safe_browsing/safe_browsing_util.h b/chrome/browser/safe_browsing/safe_browsing_util.h
index 78e652e..45dd00b 100644
--- a/chrome/browser/safe_browsing/safe_browsing_util.h
+++ b/chrome/browser/safe_browsing/safe_browsing_util.h
@@ -320,7 +320,7 @@ GURL GeneratePhishingReportUrl(const std::string& report_page,
const std::string& url_to_report);
void StringToSBFullHash(const std::string& hash_in, SBFullHash* hash_out);
-
+std::string SBFullHashToString(const SBFullHash& hash_out);
} // namespace safe_browsing_util
#endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
diff --git a/chrome/browser/safe_browsing/safe_browsing_util_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_util_unittest.cc
index a12c3ff..0cc0b3b 100644
--- a/chrome/browser/safe_browsing/safe_browsing_util_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_util_unittest.cc
@@ -335,11 +335,14 @@ TEST(SafeBrowsingUtilTest, ListIdVerification) {
EXPECT_EQ(1, safe_browsing_util::BINHASH % 2);
}
-TEST(SafeBrowsingUtilTest, StringToSBFullHash) {
+TEST(SafeBrowsingUtilTest, StringToSBFullHashAndSBFullHashToString) {
// 31 chars plus the last \0 as full_hash.
const std::string hash_in = "12345678902234567890323456789012";
SBFullHash hash_out;
safe_browsing_util::StringToSBFullHash(hash_in, &hash_out);
EXPECT_EQ(0x34333231, hash_out.prefix);
EXPECT_EQ(0, memcmp(hash_in.data(), hash_out.full_hash, sizeof(SBFullHash)));
+
+ std::string hash_final = safe_browsing_util::SBFullHashToString(hash_out);
+ EXPECT_EQ(hash_in, hash_final);
}