From a6e049026c3ff62048a717a88f32988278f8951c Mon Sep 17 00:00:00 2001 From: Michal Charemza Date: Wed, 3 Jan 2024 17:12:03 +0000 Subject: [PATCH] refactor: flags dynamic based on if encryption is used At the moment, encryption is never used, so this is just a refactor --- stream_zip.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/stream_zip.py b/stream_zip.py index ab2bd3e..f5d2461 100644 --- a/stream_zip.py +++ b/stream_zip.py @@ -148,7 +148,10 @@ def _zip_64_local_header_and_data(name_encoded, mod_at_ms_dos, mod_at_unix_extra 0, # Compressed size - since data descriptor ) + mod_at_unix_extra + aes_extra - flags = b'\x08\x08' # data descriptor and utf-8 file names + # (encryption,) data descriptor and utf-8 file names + flags = \ + b'\x88\x08' if aes_extra else \ + b'\x08\x08' yield from _(local_header_signature) yield from _(local_header_struct.pack( @@ -209,7 +212,10 @@ def _zip_32_local_header_and_data(name_encoded, mod_at_ms_dos, mod_at_unix_extra extra = mod_at_unix_extra + aes_extra - flags = b'\x08\x08' # data descriptor and utf-8 file names + # (encryption,) data descriptor and utf-8 file names + flags = \ + b'\x88\x08' if aes_extra else \ + b'\x08\x08' yield from _(local_header_signature) yield from _(local_header_struct.pack( @@ -297,7 +303,10 @@ def _no_compression_64_local_header_and_data(name_encoded, mod_at_ms_dos, mod_at size, # Compressed ) + mod_at_unix_extra + aes_extra - flags = b'\x00\x08' # utf-8 file names + # (encryption and) utf-8 file names + flags = \ + b'\x80\x08' if aes_extra else \ + b'\x00\x08' yield from _(local_header_signature) yield from _(local_header_struct.pack( @@ -352,7 +361,10 @@ def _no_compression_32_local_header_and_data(name_encoded, mod_at_ms_dos, mod_at chunks, size, crc_32 = _no_compression_buffered_data_size_crc_32(chunks, maximum_size=0xffffffff) - flags = b'\x00\x08' # utf-8 file names + # (encryption and) utf-8 file names + flags = \ + b'\x80\x08' if aes_extra else \ + b'\x00\x08' extra = mod_at_unix_extra + aes_extra yield from _(local_header_signature) @@ -424,7 +436,10 @@ def _no_compression_streamed_64_local_header_and_data(name_encoded, mod_at_ms_do uncompressed_size, # Compressed ) + mod_at_unix_extra + aes_extra - flags = b'\x00\x08' # utf-8 file names + # (encryption and) utf-8 file names + flags = \ + b'\x80\x08' if aes_extra else \ + b'\x00\x08' yield from _(local_header_signature) yield from _(local_header_struct.pack( @@ -478,7 +493,10 @@ def _no_compression_streamed_32_local_header_and_data(name_encoded, mod_at_ms_do extra = mod_at_unix_extra + aes_extra - flags = b'\x00\x08' # utf-8 file names + # (encryption and) utf-8 file names + flags = \ + b'\x80\x08' if aes_extra else \ + b'\x00\x08' yield from _(local_header_signature) yield from _(local_header_struct.pack(