diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py index 4dee72f065bd..ca323a3b5477 100644 --- a/src/cryptography/x509/extensions.py +++ b/src/cryptography/x509/extensions.py @@ -342,6 +342,9 @@ def __eq__(self, other): def __ne__(self, other): return not self == other + def __hash__(self): + return hash((self.ca, self.path_length)) + @utils.register_interface(ExtensionType) class CRLDistributionPoints(object): diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 67081b234cd3..898f9bcf05ea 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -837,6 +837,13 @@ def test_repr(self): "" ) + def test_hash(self): + na = x509.BasicConstraints(ca=True, path_length=None) + na2 = x509.BasicConstraints(ca=True, path_length=None) + na3 = x509.BasicConstraints(ca=True, path_length=0) + assert hash(na) == hash(na2) + assert hash(na) != hash(na3) + def test_eq(self): na = x509.BasicConstraints(ca=True, path_length=None) na2 = x509.BasicConstraints(ca=True, path_length=None)