Lines Matching refs:self
75 def __init__(self, head_list, component_list, save_path, key_path):
76 self.head_list = head_list
77 self.component_list = component_list
78 self.save_path = save_path
79 self.key_path = key_path
80 self.compinfo_offset = 0
81 self.component_offset = 0
82 self.sign_offset = 0
83 self.hash_info_offset = 0
86 self.upgrade_compinfo_size = UPGRADE_COMPINFO_SIZE
87 self.header_tlv_type = HEADER_TLV_TYPE
89 self.upgrade_compinfo_size = UPGRADE_COMPINFO_SIZE_L2
90 self.header_tlv_type = HEADER_TLV_TYPE_L2
92 def verify_param(self):
93 if self.head_list is None or self.component_list is None or \
94 self.save_path is None or self.key_path is None:
97 if os.path.isdir(self.key_path):
100 if self.head_list.__sizeof__() <= 0 or self.component_list.__sizeof__() <= 0:
105 def write_pkginfo(self, package_file):
108 header_tlv = struct.pack(TLV_FMT, self.header_tlv_type, UPGRADE_PKG_HEADER_SIZE)
112 self.upgrade_compinfo_size * self.head_list.entry_count
114 UPGRADE_PKG_HEADER_FMT, pkg_info_length, self.head_list.update_file_version,
115 self.head_list.product_update_id, self.head_list.software_version)
120 UPGRADE_PKG_TIME_FMT, self.head_list.date, self.head_list.time)
124 TLV_FMT, 0x05, self.upgrade_compinfo_size * self.head_list.entry_count)
139 def write_component_info(self, component, package_file):
141 % self.compinfo_offset)
148 package_file.seek(self.compinfo_offset)
150 self.compinfo_offset += component_addr_size
152 package_file.seek(self.compinfo_offset)
157 self.compinfo_offset += COMPONENT_INFO_FMT_SIZE
159 package_file.seek(self.compinfo_offset)
161 self.compinfo_offset += COMPONENT_VERSION_SIZE
163 package_file.seek(self.compinfo_offset)
167 self.compinfo_offset += COMPONENT_SIZE_FMT_SIZE
169 package_file.seek(self.compinfo_offset)
171 self.compinfo_offset += COMPONENT_DIGEST_SIZE
176 def write_component(self, component, package_file):
178 % self.component_offset)
182 package_file.seek(self.component_offset)
185 self.component_offset += component_len
192 def calculate_hash(self, package_file):
194 remain_len = self.component_offset
204 def calculate_header_hash(self, package_file):
206 remain_len = self.hash_info_offset
216 def sign_digest_with_pss(self, digest):
218 with open(self.key_path, 'rb') as f_r:
234 def sign_digest(self, digest):
236 with open(self.key_path, 'rb') as f_r:
247 def sign(self, sign_algo):
248 with open(self.save_path, "rb+") as package_file:
250 digest = self.calculate_hash(package_file)
258 signature = self.sign_digest(digest)
260 signature = self.sign_digest_with_pss(digest)
269 self.sign_offset += SIGN_SHA256_LEN
272 package_file.seek(self.sign_offset)
275 ".bin package signing success! SignOffset: %s" % self.sign_offset)
278 def sign_header(self, sign_algo, hash_check_data, package_file):
280 digest = self.calculate_header_hash(package_file)
288 signature = self.sign_digest(digest)
290 signature = self.sign_digest_with_pss(digest)
300 package_file.seek(self.hash_info_offset)
302 self.hash_info_offset += len(hash_check_data.signdata)
304 ".bin package header signing success! SignOffset: %s" % self.hash_info_offset)
307 def create_package(self):
312 if not self.verify_param():
316 hash_check_data = CreateHash(HashType.SHA256, self.head_list.entry_count)
318 package_fd = os.open(self.save_path, os.O_RDWR | os.O_CREAT, 0o755)
321 if not self.write_pkginfo(package_file):
325 self.compinfo_offset = UPGRADE_FILE_HEADER_LEN
326 self.component_offset = UPGRADE_FILE_HEADER_LEN + \
327 self.head_list.entry_count * self.upgrade_compinfo_size + \
329 for i in range(0, self.head_list.entry_count):
330 UPDATE_LOGGER.print_log("Add component %s" % self.component_list[i].component_addr)
331 if not self.write_component_info(self.component_list[i], package_file):
333 % self.component_list[i].component_addr, UPDATE_LOGGER.ERROR_LOG)
335 if OPTIONS_MANAGER.sd_card and (not hash_check_data.write_component_hash_data(self.component_list[i])):
337 % self.component_list[i].component_addr, UPDATE_LOGGER.ERROR_LOG)
342 package_file.seek(self.compinfo_offset)
344 (self.head_list.describe_package_id.decode().ljust(UPGRADE_RESERVE_LEN, "\0")).encode())
348 self.hash_info_offset = self.compinfo_offset + UPGRADE_RESERVE_LEN
353 package_file.seek(self.hash_info_offset)
355 self.hash_info_offset += len(hash_check_data.hashinfo_value + hash_check_data.hashdata)
360 self.sign_header(SIGN_ALGO_RSA, hash_check_data, package_file)
361 self.component_offset = self.hash_info_offset
362 for i in range(0, self.head_list.entry_count):
363 if not self.write_component(self.component_list[i], package_file):
365 % self.component_list[i].component_addr, UPDATE_LOGGER.ERROR_LOG)