summaryrefslogtreecommitdiffstats
path: root/base/hmac.h
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.h
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.h')
-rw-r--r--base/hmac.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/base/hmac.h b/base/hmac.h
index bbfe855..bdd23a9 100644
--- a/base/hmac.h
+++ b/base/hmac.h
@@ -25,12 +25,23 @@ class HMAC {
SHA1
};
- HMAC(HashAlgorithm hash_alg, const unsigned char* key, int key_length);
+ explicit HMAC(HashAlgorithm hash_alg);
~HMAC();
- // Calculates the HMAC for the message in |data| using the algorithm and key
- // supplied to the constructor. The HMAC is returned in |digest|, which
- // has |digest_length| bytes of storage available.
+ // Initializes this instance using |key| of the length |key_length|. Call Init
+ // only once. It returns false on the second or later calls.
+ bool Init(const unsigned char* key, int key_length);
+
+ // Initializes this instance using |key|. Call Init only once. It returns
+ // false on the second or later calls.
+ bool Init(const std::string& key) {
+ return Init(reinterpret_cast<const unsigned char*>(key.data()),
+ static_cast<int>(key.size()));
+ }
+
+ // Calculates the HMAC for the message in |data| using the algorithm supplied
+ // to the constructor and the key supplied to the Init method. The HMAC is
+ // returned in |digest|, which has |digest_length| bytes of storage available.
bool Sign(const std::string& data, unsigned char* digest, int digest_length);
private: