-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add __eq__ to HashAlgorithm and padding instances #13271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
631283d
to
2be27b4
Compare
CHANGELOG.rst
Outdated
instances of classes in | ||
:mod:`~cryptography.hazmat.primitives.asymmetric.padding` | ||
comparable. | ||
* Added `salt_length` property to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put these in a separate PR. Whether or not we want to do __eq__
is possibly debateable, but if you want these properties to be public that's a separate discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @reaperhulk
Thanks for the feedback - I've updated this PR to only include the __eq__
instances. I'll make a separate PR for the extra properties.
kr, Mat
2be27b4
to
a68beff
Compare
Looking at the test failures here the issue is that scapy creates its own HashAlgorithm, which now fails because they don't implement |
Or it could be a breaking change and that lib would need to implement the method. Open to implement any solution, just let me know what you prefer! |
@alex do you have an opinion here? I'm reluctant to spend breakage budget on this when we could avoid it with a concrete implementation, but I'm interested in other opinions. |
I'm pretty ambivalent about this. We have a few choices:
Of these I think (1) is probably best. |
For 3 the default impl could raise NotImplementedError so you wouldn’t need to have a potentially incorrect impl |
That can break existing applications, to the extent they're relying on the default |
I'm also ambivalent, I defer to your call and will adapt as requested. Just option three (default Implementation) seems like a bad idea to me. Mat |
After thinking for too long, I'm okay with option 1 here. |
This PR:
__eq__()
to all subclasses of HashAlgorithm.__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 writeassert cert.cert.signature_hash_algorithm == hashes.SHA256()
. But once you start comparing to other data structures, it gets even uglier:I think this just looks a lot better and readable: