cryptography icon indicating copy to clipboard operation
cryptography copied to clipboard

Add __eq__ to HashAlgorithm and padding instances

Open mathiasertl opened this issue 4 months ago • 12 comments

This PR:

  1. Adds __eq__() to all subclasses of HashAlgorithm.
  2. Adds __eq__() to all padding classes.

My primary use case is testing. First, it's really un-pythonic to me (obviously very subjective, but it feels just not right to me) to write assert isinstance(cert.cert.signature_hash_algorithm, hashes.SHA256()), when I could write assert cert.cert.signature_hash_algorithm == hashes.SHA256(). But once you start comparing to other data structures, it gets even uglier:

def test_something() -> None:
    ...
    assert isinstance(cert.signature_hash_algorithm, type(other.signature_hash_algorithm))

I think this just looks a lot better and readable:

def test_something() -> None:
    ...
    assert cert.signature_hash_algorithm == other.signature_hash_algorithm

mathiasertl avatar Aug 09 '25 09:08 mathiasertl