| Amin Hassani | 7982100 | 2019-05-06 17:40:49 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright 2019 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
|  | 16 |  | 
|  | 17 | #ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_PROPERTIES_H_ | 
|  | 18 | #define UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_PROPERTIES_H_ | 
|  | 19 |  | 
|  | 20 | #include <string> | 
|  | 21 |  | 
|  | 22 | #include <brillo/key_value_store.h> | 
|  | 23 | #include <brillo/secure_blob.h> | 
|  | 24 |  | 
|  | 25 | namespace chromeos_update_engine { | 
|  | 26 |  | 
|  | 27 | // A class for extracting information about a payload from the payload file | 
|  | 28 | // itself. Currently the metadata can be exported as a json file or a key/value | 
|  | 29 | // properties file. But more can be added if required. | 
|  | 30 | class PayloadProperties { | 
|  | 31 | public: | 
|  | 32 | explicit PayloadProperties(const std::string& payload_path); | 
|  | 33 | ~PayloadProperties() = default; | 
|  | 34 |  | 
|  | 35 | // Get the properties in a json format. The json file will be used in | 
|  | 36 | // autotests, cros flash, etc. Mainly in Chrome OS. | 
|  | 37 | bool GetPropertiesAsJson(std::string* json_str); | 
|  | 38 |  | 
|  | 39 | // Get the properties of the payload as a key/value store. This is mainly used | 
|  | 40 | // in Android. | 
|  | 41 | bool GetPropertiesAsKeyValue(std::string* key_value_str); | 
|  | 42 |  | 
|  | 43 | private: | 
|  | 44 | // Does the main job of reading the payload and extracting information from | 
|  | 45 | // it. | 
|  | 46 | bool LoadFromPayload(); | 
|  | 47 |  | 
|  | 48 | // The path to the payload file. | 
|  | 49 | std::string payload_path_; | 
|  | 50 |  | 
|  | 51 | // The version of the metadata json format. If the output json file changes | 
|  | 52 | // format, this needs to be increased. | 
|  | 53 | int version_{2}; | 
|  | 54 |  | 
|  | 55 | size_t metadata_size_; | 
|  | 56 | std::string metadata_hash_; | 
|  | 57 | std::string metadata_signatures_; | 
|  | 58 |  | 
|  | 59 | size_t payload_size_; | 
|  | 60 | std::string payload_hash_; | 
|  | 61 |  | 
|  | 62 | // Whether the payload is a delta (true) or full (false). | 
|  | 63 | bool is_delta_; | 
|  | 64 |  | 
|  | 65 | std::string target_version_; | 
|  | 66 | std::string source_version_; | 
|  | 67 |  | 
|  | 68 | DISALLOW_COPY_AND_ASSIGN(PayloadProperties); | 
|  | 69 | }; | 
|  | 70 |  | 
|  | 71 | }  // namespace chromeos_update_engine | 
|  | 72 |  | 
|  | 73 | #endif  // UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_PROPERTIES_H_ |