FLAGS_OFFSET HEADER_SIZE 10 gzip FCOMMENT 16 def sign_archive pkey cer

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
FLAGS_OFFSET = 3
HEADER_SIZE = 10
gzip.FCOMMENT = 16
def sign_archive(pkey, cert, package, **kwargs) -> None:
with gzip.open(package) as fs:
signature = sign(pkey=pkey, data=iter(partial(fs.read, 64000), b""), digest="SHA1") # массив байтов
with open(package, "ab") as fs:
fs.write(make_gzip_comment_frame(str(signature)))
def make_gzip_comment_frame(comment):
if '\0' in comment:
raise ValueError("comment should not contain zero-characters")
buf = bytearray(gzip.compress(b''))
buf[FLAGS_OFFSET] |= gzip.FCOMMENT
buf[HEADER_SIZE:HEADER_SIZE] = bytes(comment, 'utf8') + bytes(str(len(comment)), 'utf8') + b'\0'
return buf