Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: omaha_hash_calculator.h

Issue 3588015: AU: Include the old/new kernel/rootfs size/hash in the update metadata. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: no need to close negative handles Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
10 #include <openssl/sha.h> 11 #include <openssl/sha.h>
11 #include "base/basictypes.h" 12 #include <base/basictypes.h>
12 #include "base/logging.h" 13 #include <base/logging.h>
13 14
14 // Omaha uses base64 encoded SHA-256 as the hash. This class provides a simple 15 // Omaha uses base64 encoded SHA-256 as the hash. This class provides a simple
15 // wrapper around OpenSSL providing such a formatted hash of data passed in. 16 // wrapper around OpenSSL providing such a formatted hash of data passed in.
16 // The methods of this class must be called in a very specific order: First the 17 // The methods of this class must be called in a very specific order: First the
17 // ctor (of course), then 0 or more calls to Update(), then Finalize(), then 0 18 // ctor (of course), then 0 or more calls to Update(), then Finalize(), then 0
18 // or more calls to hash(). 19 // or more calls to hash().
19 20
20 namespace chromeos_update_engine { 21 namespace chromeos_update_engine {
21 22
22 class OmahaHashCalculator { 23 class OmahaHashCalculator {
23 public: 24 public:
24 OmahaHashCalculator(); 25 OmahaHashCalculator();
25 26
26 // Update is called with all of the data that should be hashed in order. 27 // Update is called with all of the data that should be hashed in order.
27 // Update will read |length| bytes of |data|. 28 // Update will read |length| bytes of |data|.
28 // Returns true on success. 29 // Returns true on success.
29 bool Update(const char* data, size_t length); 30 bool Update(const char* data, size_t length);
30 31
32 // Updates the hash with up to |length| bytes of data from |file|. If |length|
33 // is negative, reads in and updates with the whole file. Returns the number
34 // of bytes that the hash was updated with, or -1 on error.
35 off_t UpdateFile(const std::string& name, off_t length);
36
31 // Call Finalize() when all data has been passed in. This method tells 37 // Call Finalize() when all data has been passed in. This method tells
32 // OpenSSl that no more data will come in and base64 encodes the resulting 38 // OpenSSl that no more data will come in and base64 encodes the resulting
33 // hash. 39 // hash.
34 // Returns true on success. 40 // Returns true on success.
35 bool Finalize(); 41 bool Finalize();
36 42
37 // Gets the hash. Finalize() must have been called. 43 // Gets the hash. Finalize() must have been called.
38 const std::string& hash() const { 44 const std::string& hash() const {
39 DCHECK(!hash_.empty()) << "Call Finalize() first"; 45 DCHECK(!hash_.empty()) << "Call Finalize() first";
40 return hash_; 46 return hash_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 bool valid_; 78 bool valid_;
73 79
74 // The hash state used by OpenSSL 80 // The hash state used by OpenSSL
75 SHA256_CTX ctx_; 81 SHA256_CTX ctx_;
76 DISALLOW_COPY_AND_ASSIGN(OmahaHashCalculator); 82 DISALLOW_COPY_AND_ASSIGN(OmahaHashCalculator);
77 }; 83 };
78 84
79 } // namespace chromeos_update_engine 85 } // namespace chromeos_update_engine
80 86
81 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__ 87 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__
OLDNEW
« no previous file with comments | « delta_performer_unittest.cc ('k') | omaha_hash_calculator.cc » ('j') | omaha_hash_calculator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698