• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PKG_INFO_UTILS_H
17 #define PKG_INFO_UTILS_H
18 
19 #include <functional>
20 #include <string>
21 #include <vector>
22 #include "package/package.h"
23 
24 namespace Hpackage {
25 struct FileInfo;
26 struct PkgInfo;
27 using FileInfoPtr = FileInfo *;
28 using PkgInfoPtr = PkgInfo *;
29 
30 /**
31  * Error code definition
32  */
33 enum {
34     PKG_SUCCESS = 0,
35     PKG_ERROR_BASE = 100,
36     PKG_INVALID_NAME,
37     PKG_INVALID_PARAM,
38     PKG_INVALID_FILE,
39     PKG_INVALID_SIGNATURE,
40     PKG_INVALID_PKG_FORMAT,
41     PKG_INVALID_ALGORITHM,
42     PKG_INVALID_DIGEST,
43     PKG_INVALID_STREAM,
44     PKG_INVALID_VERSION,
45     PKG_INVALID_STATE,
46     PKG_INVALID_LZ4,
47     PKG_NONE_PERMISSION,
48     PKG_NONE_MEMORY,
49     PKG_VERIFY_FAIL,
50 };
51 
52 enum {
53     POST_TYPE_UPLOAD_PKG = 0,
54     POST_TYPE_DECODE_PKG,
55     POST_TYPE_VERIFY_PKG,
56     POST_TYPE_WRITE_PARTITION
57 };
58 
59 /**
60  * Package information
61  */
62 struct PkgInfo {
63     uint32_t entryCount = 0;
64     uint32_t updateFileHeadLen = 0;
65     uint8_t signMethod;
66     uint8_t digestMethod;
67     uint8_t pkgType;
68     uint8_t pkgFlags;
69 };
70 
71 /**
72  * File information
73  */
74 struct FileInfo {
75     uint8_t flags = 0;
76     uint8_t digestMethod = 0;
77     uint16_t packMethod = 0;
78     time_t modifiedTime = 0;
79     size_t packedSize = 0;
80     size_t unpackedSize = 0;
81     size_t headerOffset = 0;
82     size_t dataOffset = 0;
83     std::string identity;
84 };
85 
86 /**
87  * Header information of the update package
88  */
89 struct UpgradePkgInfo {
90     PkgInfo pkgInfo;
91     uint32_t updateFileVersion = 0;
92     std::string productUpdateId;
93     std::string softwareVersion;
94     std::string date;
95     std::string time;
96     std::string descriptPackageId;
97 };
98 
99 /**
100  * Component information of the update package
101  */
102 struct ComponentInfo {
103     FileInfo fileInfo;
104     std::string version;
105     uint8_t digest[DIGEST_MAX_LEN];
106     uint16_t id;
107     uint8_t resType;
108     uint8_t type;
109     uint8_t compFlags;
110     size_t originalSize;
111 };
112 
113 /**
114  * Lz4 file configuration information
115  */
116 struct Lz4FileInfo {
117     FileInfo fileInfo;
118     int8_t compressionLevel;
119     int8_t blockIndependence;
120     int8_t contentChecksumFlag;
121     int8_t blockSizeID;
122     int8_t autoFlush = 1;
123 };
124 
125 /**
126  * Zip file configuration information
127  */
128 struct ZipFileInfo {
129     FileInfo fileInfo;
130     int32_t method = -1; // The system automatically uses the default value if the value is -1.
131     int32_t level;
132     int32_t windowBits;
133     int32_t memLevel;
134     int32_t strategy;
135 };
136 
137 /**
138  * buff definition used for parsing
139  */
140 struct PkgBuffer {
141     uint8_t *buffer;
142     size_t length = 0; // buffer size
143 
144     std::vector<uint8_t> data;
145 
PkgBufferPkgBuffer146     PkgBuffer()
147     {
148         this->buffer = nullptr;
149         this->length = 0;
150     }
151 
PkgBufferPkgBuffer152     PkgBuffer(uint8_t *buffer, size_t bufferSize)
153     {
154         this->buffer = buffer;
155         this->length = bufferSize;
156     }
157 
PkgBufferPkgBuffer158     PkgBuffer(std::vector<uint8_t> &buffer)
159     {
160         this->buffer = buffer.data();
161         this->length = buffer.capacity();
162     }
163 
PkgBufferPkgBuffer164     PkgBuffer(size_t bufferSize)
165     {
166         data.resize(bufferSize, 0);
167         this->buffer = data.data();
168         this->length = bufferSize;
169     }
170 };
171 } // namespace Hpackage
172 #endif // PKG_MANAGER_H
173