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