Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CRYPTO_HMAC_H_ | 8 #ifndef CRYPTO_HMAC_H_ |
| 9 #define CRYPTO_HMAC_H_ | 9 #define CRYPTO_HMAC_H_ |
| 10 #pragma once | 10 #pragma once |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 // false on the second or later calls. | 44 // false on the second or later calls. |
| 45 bool Init(const std::string& key) { | 45 bool Init(const std::string& key) { |
| 46 return Init(reinterpret_cast<const unsigned char*>(key.data()), | 46 return Init(reinterpret_cast<const unsigned char*>(key.data()), |
| 47 static_cast<int>(key.size())); | 47 static_cast<int>(key.size())); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Calculates the HMAC for the message in |data| using the algorithm supplied | 50 // Calculates the HMAC for the message in |data| using the algorithm supplied |
| 51 // to the constructor and the key supplied to the Init method. The HMAC is | 51 // to the constructor and the key supplied to the Init method. The HMAC is |
| 52 // returned in |digest|, which has |digest_length| bytes of storage available. | 52 // returned in |digest|, which has |digest_length| bytes of storage available. |
| 53 // TODO(abarth): digest_length should be a size_t. | 53 // TODO(abarth): digest_length should be a size_t. |
| 54 bool Sign(const std::string& data, unsigned char* digest, int digest_length); | 54 bool Sign( |
| 55 const std::string& data, unsigned char* digest, int digest_length) const; | |
|
wtc
2011/05/16 23:23:29
Nit: the Style Guide seems to recommend we format
Denis Lagno
2011/05/17 22:15:08
Done.
| |
| 55 | 56 |
| 56 // TODO(albertb): Add a Verify method. | 57 // TODO(albertb): Add a Verify method. |
| 57 | 58 |
| 58 private: | 59 private: |
| 59 HashAlgorithm hash_alg_; | 60 HashAlgorithm hash_alg_; |
| 60 scoped_ptr<HMACPlatformData> plat_; | 61 scoped_ptr<HMACPlatformData> plat_; |
| 61 | 62 |
| 62 DISALLOW_COPY_AND_ASSIGN(HMAC); | 63 DISALLOW_COPY_AND_ASSIGN(HMAC); |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 } // namespace crypto | 66 } // namespace crypto |
| 66 | 67 |
| 67 #endif // CRYPTO_HMAC_H_ | 68 #endif // CRYPTO_HMAC_H_ |
| OLD | NEW |