pyzipper icon indicating copy to clipboard operation
pyzipper copied to clipboard

Set AESZipFile encryption default to WZ_AES

Open rpkilby opened this issue 3 years ago • 2 comments

Hi @danifus 👋 , I was testing out pyzipper and ran into some unexpected behavior when writing a zipfile. e.g.,

with pyzipper.AESZipFile("archive.zip", "w") as archive:
    archive.setpassword(b"password")
    with archive.open("file.txt", "w") as file:
        ...

The above resulted in this traceback:

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "./.venv/lib/python3.9/site-packages/pyzipper/zipfile.py", line 2006, in open
    return self._open_to_write(zinfo, force_zip64=force_zip64, pwd=pwd)
  File "./.venv/lib/python3.9/site-packages/pyzipper/zipfile.py", line 2049, in _open_to_write
    encrypter.update_zipinfo(zinfo)
AttributeError: 'NoneType' object has no attribute 'update_zipinfo'

This was simply caused by my not specifying the encryption in the constructor, or via the setencryption method. However, it would seem sensible that AESZipFile would default to encryption=WZ_AES? Is there a reason why this shouldn't be the default? Thanks.

rpkilby avatar May 19 '22 00:05 rpkilby

Hi,

That's a good idea. Thanks for the patch! I'll need to adjust some of the tests before I can merge it

danifus avatar May 23 '22 04:05 danifus

Just a thought.. it's a good idea if the encryption setting only applies when a password is set. Meaning, AESZipFile still needs to act like python's zipfile.ZipFile if no password is set to still be a drop in replacement.

While I'm commenting... curious why pyzipper changes have not been merged (PR) into Python's core zipfile?

eljeffeg avatar Sep 07 '22 21:09 eljeffeg