From 07d5cae4be47933f5001e8d28d0dddab6edeec3e Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 27 Dec 2015 15:30:39 -0500 Subject: [PATCH] Refs #2578 -- implement __hash__ on CRLReason --- src/cryptography/x509/extensions.py | 3 +++ tests/test_x509_ext.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py index 4dee72f065bd..ed29b54ce98a 100644 --- a/src/cryptography/x509/extensions.py +++ b/src/cryptography/x509/extensions.py @@ -1019,6 +1019,9 @@ def __eq__(self, other): def __ne__(self, other): return not self == other + def __hash__(self): + return hash(self.reason) + reason = utils.read_only_property("_reason") diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 67081b234cd3..8f961b0b16d4 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -140,6 +140,14 @@ def test_ne(self): assert reason1 != reason2 assert reason1 != object() + def test_hash(self): + reason1 = x509.CRLReason(x509.ReasonFlags.unspecified) + reason2 = x509.CRLReason(x509.ReasonFlags.unspecified) + reason3 = x509.CRLReason(x509.ReasonFlags.ca_compromise) + + assert hash(reason1) == hash(reason2) + assert hash(reason1) != hash(reason3) + def test_repr(self): reason1 = x509.CRLReason(x509.ReasonFlags.unspecified) assert repr(reason1) == (