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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "crypto/crypto_export.h" | 9 #include "crypto/crypto_export.h" |
10 | 10 |
| 11 namespace base { |
11 class Pickle; | 12 class Pickle; |
12 class PickleIterator; | 13 class PickleIterator; |
| 14 } |
13 | 15 |
14 namespace crypto { | 16 namespace crypto { |
15 | 17 |
16 // A wrapper to calculate secure hashes incrementally, allowing to | 18 // A wrapper to calculate secure hashes incrementally, allowing to |
17 // be used when the full input is not known in advance. | 19 // be used when the full input is not known in advance. |
18 class CRYPTO_EXPORT SecureHash { | 20 class CRYPTO_EXPORT SecureHash { |
19 public: | 21 public: |
20 enum Algorithm { | 22 enum Algorithm { |
21 SHA256, | 23 SHA256, |
22 }; | 24 }; |
23 virtual ~SecureHash() {} | 25 virtual ~SecureHash() {} |
24 | 26 |
25 static SecureHash* Create(Algorithm type); | 27 static SecureHash* Create(Algorithm type); |
26 | 28 |
27 virtual void Update(const void* input, size_t len) = 0; | 29 virtual void Update(const void* input, size_t len) = 0; |
28 virtual void Finish(void* output, size_t len) = 0; | 30 virtual void Finish(void* output, size_t len) = 0; |
29 | 31 |
30 // Serialize the context, so it can be restored at a later time. | 32 // Serialize the context, so it can be restored at a later time. |
31 // |pickle| will contain the serialized data. | 33 // |pickle| will contain the serialized data. |
32 // Returns whether or not |pickle| was filled. | 34 // Returns whether or not |pickle| was filled. |
33 virtual bool Serialize(Pickle* pickle) = 0; | 35 virtual bool Serialize(base::Pickle* pickle) = 0; |
34 | 36 |
35 // Restore the context that was saved earlier. | 37 // Restore the context that was saved earlier. |
36 // |data_iterator| allows this to be used as part of a larger pickle. | 38 // |data_iterator| allows this to be used as part of a larger pickle. |
37 // |pickle| holds the saved data. | 39 // |pickle| holds the saved data. |
38 // Returns success or failure. | 40 // Returns success or failure. |
39 virtual bool Deserialize(PickleIterator* data_iterator) = 0; | 41 virtual bool Deserialize(base::PickleIterator* data_iterator) = 0; |
40 | 42 |
41 protected: | 43 protected: |
42 SecureHash() {} | 44 SecureHash() {} |
43 | 45 |
44 private: | 46 private: |
45 DISALLOW_COPY_AND_ASSIGN(SecureHash); | 47 DISALLOW_COPY_AND_ASSIGN(SecureHash); |
46 }; | 48 }; |
47 | 49 |
48 } // namespace crypto | 50 } // namespace crypto |
49 | 51 |
50 #endif // CRYPTO_SECURE_HASH_H_ | 52 #endif // CRYPTO_SECURE_HASH_H_ |
OLD | NEW |