SecurityInnovation / PGPy

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

drop use of imghdr #443

Open dkg opened 1 year ago

dkg commented 1 year ago

imghdr is deprecated and will be removed in python 3.13 (see https://peps.python.org/pep-0594/#imghdr)

The relevant code in imghdr is just:

def test_jpeg(h, f):
    """JPEG data with JFIF or Exif markers; and raw JPEG"""
    if h[6:10] in (b'JFIF', b'Exif'):
        return 'jpeg'
    elif h[:4] == b'\xff\xd8\xff\xdb':
        return 'jpeg'

So we transplant it directly

jbkkd commented 11 months ago

Any chance this could get merged in the near future?

ktdreyer commented 10 months ago

@Commod0re would you please merge this PR and ship a new release to PyPI?

I've confirmed that the implementation here matches test_jpeg() in /usr/lib64/python3.11/imghdr.py. Also, I tested this conditional on a random JPG image and imagebytes[6:10] is indeed b'JFIF'.