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