OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CRYPTO_SECURE_HASH_H_ | 5 #ifndef CRYPTO_SECURE_HASH_H_ |
6 #define CRYPTO_SECURE_HASH_H_ | 6 #define CRYPTO_SECURE_HASH_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
| 10 #include <memory> |
| 11 |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "crypto/crypto_export.h" | 13 #include "crypto/crypto_export.h" |
12 | 14 |
13 namespace crypto { | 15 namespace crypto { |
14 | 16 |
15 // A wrapper to calculate secure hashes incrementally, allowing to | 17 // A wrapper to calculate secure hashes incrementally, allowing to |
16 // be used when the full input is not known in advance. | 18 // be used when the full input is not known in advance. |
17 class CRYPTO_EXPORT SecureHash { | 19 class CRYPTO_EXPORT SecureHash { |
18 public: | 20 public: |
19 enum Algorithm { | 21 enum Algorithm { |
20 SHA256, | 22 SHA256, |
21 }; | 23 }; |
22 virtual ~SecureHash() {} | 24 virtual ~SecureHash() {} |
23 | 25 |
24 static SecureHash* Create(Algorithm type); | 26 static std::unique_ptr<SecureHash> Create(Algorithm type); |
25 | 27 |
26 virtual void Update(const void* input, size_t len) = 0; | 28 virtual void Update(const void* input, size_t len) = 0; |
27 virtual void Finish(void* output, size_t len) = 0; | 29 virtual void Finish(void* output, size_t len) = 0; |
28 virtual size_t GetHashLength() const = 0; | 30 virtual size_t GetHashLength() const = 0; |
29 | 31 |
30 // Create a clone of this SecureHash. The returned clone and this both | 32 // Create a clone of this SecureHash. The returned clone and this both |
31 // represent the same hash state. But from this point on, calling | 33 // represent the same hash state. But from this point on, calling |
32 // Update()/Finish() on either doesn't affect the state of the other. | 34 // Update()/Finish() on either doesn't affect the state of the other. |
33 virtual SecureHash* Clone() const = 0; | 35 virtual std::unique_ptr<SecureHash> Clone() const = 0; |
34 | 36 |
35 protected: | 37 protected: |
36 SecureHash() {} | 38 SecureHash() {} |
37 | 39 |
38 private: | 40 private: |
39 DISALLOW_COPY_AND_ASSIGN(SecureHash); | 41 DISALLOW_COPY_AND_ASSIGN(SecureHash); |
40 }; | 42 }; |
41 | 43 |
42 } // namespace crypto | 44 } // namespace crypto |
43 | 45 |
44 #endif // CRYPTO_SECURE_HASH_H_ | 46 #endif // CRYPTO_SECURE_HASH_H_ |
OLD | NEW |