blob: 23349b0be008f32a8a619495182fd054d31b609b [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// 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
Viet-Trung Luu235cf3d2015-06-11 10:01:25 -070011namespace base {
James Robinson646469d2014-10-03 15:33:28 -070012class Pickle;
13class PickleIterator;
Viet-Trung Luu235cf3d2015-06-11 10:01:25 -070014}
James Robinson646469d2014-10-03 15:33:28 -070015
16namespace crypto {
17
18// A wrapper to calculate secure hashes incrementally, allowing to
19// be used when the full input is not known in advance.
20class 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.
Viet-Trung Luu235cf3d2015-06-11 10:01:25 -070035 virtual bool Serialize(base::Pickle* pickle) = 0;
James Robinson646469d2014-10-03 15:33:28 -070036
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.
Viet-Trung Luu235cf3d2015-06-11 10:01:25 -070041 virtual bool Deserialize(base::PickleIterator* data_iterator) = 0;
James Robinson646469d2014-10-03 15:33:28 -070042
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_