diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-05 23:55:59 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-05 23:55:59 +0000 |
commit | d91f84376fe8dd249770ac19b7c08f8fcc20f446 (patch) | |
tree | 8d66a665eac06063bfcf50236fca05f2e4f8f1ea /base/hmac_mac.cc | |
parent | a92b86497b6ee02c99a2e4b4a8cf7fb458ab6310 (diff) | |
download | chromium_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_mac.cc')
-rw-r--r-- | base/hmac_mac.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/base/hmac_mac.cc b/base/hmac_mac.cc index 668b306..bbc9330 100644 --- a/base/hmac_mac.cc +++ b/base/hmac_mac.cc @@ -14,9 +14,22 @@ struct HMACPlatformData { std::string key_; }; -HMAC::HMAC(HashAlgorithm hash_alg, const unsigned char* key, int key_length) +HMAC::HMAC(HashAlgorithm hash_alg) : hash_alg_(hash_alg), plat_(new HMACPlatformData()) { + // Only SHA-1 digest is supported now. + DCHECK(hash_alg_ == SHA1); +} + +bool HMAC::Init(const unsigned char *key, int key_length) { + if (!plat_->key_.empty()) { + // Init must not be called more than once on the same HMAC object. + NOTREACHED(); + return false; + } + plat_->key_.assign(reinterpret_cast<const char*>(key), key_length); + + return true; } HMAC::~HMAC() { |