OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include <openssl/sha.h> | 10 #include <openssl/sha.h> |
(...skipping 22 matching lines...) Expand all Loading... |
33 // hash. | 33 // hash. |
34 // Returns true on success. | 34 // Returns true on success. |
35 bool Finalize(); | 35 bool Finalize(); |
36 | 36 |
37 // Gets the hash. Finalize() must have been called. | 37 // Gets the hash. Finalize() must have been called. |
38 const std::string& hash() const { | 38 const std::string& hash() const { |
39 DCHECK(!hash_.empty()) << "Call Finalize() first"; | 39 DCHECK(!hash_.empty()) << "Call Finalize() first"; |
40 return hash_; | 40 return hash_; |
41 } | 41 } |
42 | 42 |
| 43 const std::vector<char>& raw_hash() const { |
| 44 DCHECK(!raw_hash_.empty()) << "Call Finalize() first"; |
| 45 return raw_hash_; |
| 46 } |
| 47 |
43 static bool RawHashOfData(const std::vector<char>& data, | 48 static bool RawHashOfData(const std::vector<char>& data, |
44 std::vector<char>* out_hash); | 49 std::vector<char>* out_hash); |
45 | 50 |
46 // Used by tests | 51 // Used by tests |
47 static std::string OmahaHashOfBytes(const void* data, size_t length); | 52 static std::string OmahaHashOfBytes(const void* data, size_t length); |
48 static std::string OmahaHashOfString(const std::string& str); | 53 static std::string OmahaHashOfString(const std::string& str); |
49 static std::string OmahaHashOfData(const std::vector<char>& data); | 54 static std::string OmahaHashOfData(const std::vector<char>& data); |
50 | 55 |
51 private: | 56 private: |
52 // If non-empty, the final base64 encoded hash. Will only be set to | 57 // If non-empty, the final base64 encoded hash and the raw hash. Will only be |
53 // non-empty when Finalize is called. | 58 // set to non-empty when Finalize is called. |
54 std::string hash_; | 59 std::string hash_; |
| 60 std::vector<char> raw_hash_; |
55 | 61 |
56 // Init success | 62 // Init success |
57 bool valid_; | 63 bool valid_; |
58 | 64 |
59 // The hash state used by OpenSSL | 65 // The hash state used by OpenSSL |
60 SHA256_CTX ctx_; | 66 SHA256_CTX ctx_; |
61 DISALLOW_COPY_AND_ASSIGN(OmahaHashCalculator); | 67 DISALLOW_COPY_AND_ASSIGN(OmahaHashCalculator); |
62 }; | 68 }; |
63 | 69 |
64 } // namespace chromeos_update_engine | 70 } // namespace chromeos_update_engine |
65 | 71 |
66 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__ | 72 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__ |
OLD | NEW |