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