summaryrefslogtreecommitdiffstats
path: root/base/hmac_unittest.cc
diff options
context:
space:
mode:
authorwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-05 23:55:59 +0000
committerwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-05 23:55:59 +0000
commitd91f84376fe8dd249770ac19b7c08f8fcc20f446 (patch)
tree8d66a665eac06063bfcf50236fca05f2e4f8f1ea /base/hmac_unittest.cc
parenta92b86497b6ee02c99a2e4b4a8cf7fb458ab6310 (diff)
downloadchromium_src-d91f84376fe8dd249770ac19b7c08f8fcc20f446.zip
chromium_src-d91f84376fe8dd249770ac19b7c08f8fcc20f446.tar.gz
chromium_src-d91f84376fe8dd249770ac19b7c08f8fcc20f446.tar.bz2
Separate the key setting code in the constructor of HMAC class into the Init
method. Overload the Init method for char* and std::string. Add DCHECKs to the destruction methods in ~HMAC in hmac_win.cc. The patch is written by Takeshi Yoshino <tyoshino@google.com>. Original code review: http://codereview.chromium.org/88062 R=wtc http://crbug.com/2297 TEST=base_unittests should pass. Safe browsing should continue to work. Review URL: http://codereview.chromium.org/113001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15353 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/hmac_unittest.cc')
-rw-r--r--base/hmac_unittest.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/base/hmac_unittest.cc b/base/hmac_unittest.cc
index 9881369..56b811a 100644
--- a/base/hmac_unittest.cc
+++ b/base/hmac_unittest.cc
@@ -51,7 +51,8 @@ TEST(HMACTest, HmacSafeBrowsingResponseTest) {
std::string message_data(kMessage);
- base::HMAC hmac(base::HMAC::SHA1, kClientKey, kKeySize);
+ base::HMAC hmac(base::HMAC::SHA1);
+ ASSERT_TRUE(hmac.Init(kClientKey, kKeySize));
unsigned char calculated_hmac[kDigestSize];
EXPECT_TRUE(hmac.Sign(message_data, calculated_hmac, kDigestSize));
@@ -119,9 +120,9 @@ TEST(HMACTest, RFC2202TestCases) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
- base::HMAC hmac(base::HMAC::SHA1,
- reinterpret_cast<const unsigned char*>(cases[i].key),
- cases[i].key_len);
+ base::HMAC hmac(base::HMAC::SHA1);
+ ASSERT_TRUE(hmac.Init(reinterpret_cast<const unsigned char*>(cases[i].key),
+ cases[i].key_len));
std::string data_string(cases[i].data, cases[i].data_len);
unsigned char digest[kDigestSize];
EXPECT_TRUE(hmac.Sign(data_string, digest, kDigestSize));
@@ -152,8 +153,8 @@ TEST(HMACTest, HMACObjectReuse) {
"\xBB\xFF\x1A\x91" }
};
- base::HMAC hmac(base::HMAC::SHA1,
- reinterpret_cast<const unsigned char*>(key), key_len);
+ base::HMAC hmac(base::HMAC::SHA1);
+ ASSERT_TRUE(hmac.Init(reinterpret_cast<const unsigned char*>(key), key_len));
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
std::string data_string(cases[i].data, cases[i].data_len);
unsigned char digest[kDigestSize];