Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / crypto / secure_hash.h
blob23349b0be008f32a8a619495182fd054d31b609b
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.
5 #ifndef CRYPTO_SECURE_HASH_H_
6 #define CRYPTO_SECURE_HASH_H_
8 #include "base/basictypes.h"
9 #include "crypto/crypto_export.h"
11 namespace base {
12 class Pickle;
13 class PickleIterator;
16 namespace crypto {
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,
25 virtual ~SecureHash() {}
27 static SecureHash* Create(Algorithm type);
29 virtual void Update(const void* input, size_t len) = 0;
30 virtual void Finish(void* output, size_t len) = 0;
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;
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;
43 protected:
44 SecureHash() {}
46 private:
47 DISALLOW_COPY_AND_ASSIGN(SecureHash);
50 } // namespace crypto
52 #endif // CRYPTO_SECURE_HASH_H_