Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: base/hmac.h

Issue 5009: Fix some issues found looking at the code.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Utility class for calculating the HMAC for a given message. We currently 5 // Utility class for calculating the HMAC for a given message. We currently
6 // only support SHA1 for the hash algorithm, but this can be extended easily. 6 // only support SHA1 for the hash algorithm, but this can be extended easily.
7 7
8 #ifndef BASE_HMAC_H_ 8 #ifndef BASE_HMAC_H_
9 #define BASE_HMAC_H_ 9 #define BASE_HMAC_H_
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/scoped_ptr.h"
14 15
15 namespace base { 16 namespace base {
16 17
17 // Simplify the interface and reduce includes by abstracting out the internals. 18 // Simplify the interface and reduce includes by abstracting out the internals.
18 struct HMACPlatformData; 19 struct HMACPlatformData;
19 20
20 class HMAC { 21 class HMAC {
21 public: 22 public:
22 // The set of supported hash functions. Extend as required. 23 // The set of supported hash functions. Extend as required.
23 enum HashAlgorithm { 24 enum HashAlgorithm {
24 SHA1 25 SHA1
25 }; 26 };
26 27
27 HMAC(HashAlgorithm hash_alg, const unsigned char* key, int key_length); 28 HMAC(HashAlgorithm hash_alg, const unsigned char* key, int key_length);
28 ~HMAC(); 29 ~HMAC();
29 30
30 // Calculates the HMAC for the message in |data| using the algorithm and key 31 // Calculates the HMAC for the message in |data| using the algorithm and key
31 // supplied to the constructor. The HMAC is returned in |digest|, which 32 // supplied to the constructor. The HMAC is returned in |digest|, which
32 // has |digest_length| bytes of storage available. 33 // has |digest_length| bytes of storage available.
33 bool Sign(const std::string& data, unsigned char* digest, int digest_length); 34 bool Sign(const std::string& data, unsigned char* digest, int digest_length);
34 35
35 private: 36 private:
36 HashAlgorithm hash_alg_; 37 HashAlgorithm hash_alg_;
37 HMACPlatformData* plat_; 38 scoped_ptr<HMACPlatformData> plat_;
38 39
39 DISALLOW_COPY_AND_ASSIGN(HMAC); 40 DISALLOW_COPY_AND_ASSIGN(HMAC);
40 }; 41 };
41 42
42 } // namespace base 43 } // namespace base
43 44
44 #endif // BASE_HMAC_H_ 45 #endif // BASE_HMAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698