diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-06 22:00:11 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-06 22:00:11 +0000 |
commit | c28986ee4a9bcd79297e5f96178c908627e8f395 (patch) | |
tree | da00b64efae510c655ccc4fd285e1d778d645df8 /crypto/hmac.h | |
parent | 083072ff2d098c5bed10032f240655e372e125f1 (diff) | |
download | chromium_src-c28986ee4a9bcd79297e5f96178c908627e8f395.zip chromium_src-c28986ee4a9bcd79297e5f96178c908627e8f395.tar.gz chromium_src-c28986ee4a9bcd79297e5f96178c908627e8f395.tar.bz2 |
Change HMAC::Sign() to take base::StringPiece instead of string.
Do this to avoid memory copying when signning data in char*.
base::StringPiece nicely handles both cases.
BUG=None
TEST=crypto_unittests
Review URL: http://codereview.chromium.org/7033035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88049 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/hmac.h')
-rw-r--r-- | crypto/hmac.h | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/crypto/hmac.h b/crypto/hmac.h index c0706d8..d31373a 100644 --- a/crypto/hmac.h +++ b/crypto/hmac.h @@ -9,10 +9,9 @@ #define CRYPTO_HMAC_H_ #pragma once -#include <string> - #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "base/string_piece.h" namespace crypto { @@ -42,7 +41,7 @@ class HMAC { // Initializes this instance using |key|. Call Init only once. It returns // false on the second or later calls. - bool Init(const std::string& key) { + bool Init(const base::StringPiece& key) { return Init(reinterpret_cast<const unsigned char*>(key.data()), static_cast<int>(key.size())); } @@ -51,8 +50,7 @@ class HMAC { // 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. // TODO(abarth): digest_length should be a size_t. - bool Sign(const std::string& data, - unsigned char* digest, + bool Sign(const base::StringPiece& data, unsigned char* digest, int digest_length) const; // TODO(albertb): Add a Verify method. |