SecurityInnovation / PGPy

Pretty Good Privacy for Python
BSD 3-Clause "New" or "Revised" License
313 stars 98 forks source link

imghdr is deprecated and slated for removal in Python 3.13 #462

Open elibon99 opened 9 months ago

elibon99 commented 9 months ago

The imghdr module is deprecated in Python 3.11 (see here) and slated for removal in Python 3.13.

imghdr is used to determine image type: https://github.com/SecurityInnovation/PGPy/blob/30a757181ab02f918a94f8549f354d93639b95e6/pgpy/constants.py#L430-L435

If just looking for the JPEG type, maybe a simple fix to get rid of imghdr would be to look at the signature in the first few bytes of the image data like:

...
# Check for JPEG signature (first three bytes are b'\xFF\xD8\xFF')
if imagebytes.startswith(b'\xFF\xD8\xFF'):
    return ImageEncoding.JPEG
return ImageEncoding.Unknown

?