diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py index 3e6fc3b32afe..fe9bcf9b772f 100644 --- a/src/cryptography/x509/extensions.py +++ b/src/cryptography/x509/extensions.py @@ -313,6 +313,9 @@ def __eq__(self, other): def __ne__(self, other): return not self == other + def __hash__(self): + return hash((self.access_method, self.access_location)) + access_method = utils.read_only_property("_access_method") access_location = utils.read_only_property("_access_location") diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index ff82645827f4..b13405de4de8 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -2228,6 +2228,22 @@ def test_ne(self): assert ad != ad3 assert ad != object() + def test_hash(self): + ad = x509.AccessDescription( + AuthorityInformationAccessOID.OCSP, + x509.UniformResourceIdentifier(u"http://ocsp.domain.com") + ) + ad2 = x509.AccessDescription( + AuthorityInformationAccessOID.OCSP, + x509.UniformResourceIdentifier(u"http://ocsp.domain.com") + ) + ad3 = x509.AccessDescription( + AuthorityInformationAccessOID.CA_ISSUERS, + x509.UniformResourceIdentifier(u"http://ocsp.domain.com") + ) + assert hash(ad) == hash(ad2) + assert hash(ad) != hash(ad3) + class TestAuthorityInformationAccess(object): def test_invalid_descriptions(self):