aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2016-01-31 18:06:41 -0500
committerAlex Gaynor <alex.gaynor@gmail.com>2016-01-31 18:06:41 -0500
commit874e865af094ad667cacb3df5e6d72f31e08c615 (patch)
treeadb61f4e04bdf10d06cab1cde444ba0123fb492e
parentd7ef98b1827b96e01f13fe7a11e76ff0ad03a9c9 (diff)
parentd8e0d8534fb49c23d436716fb445ea7e54e08735 (diff)
downloadcryptography-874e865af094ad667cacb3df5e6d72f31e08c615.tar.gz
cryptography-874e865af094ad667cacb3df5e6d72f31e08c615.tar.bz2
cryptography-874e865af094ad667cacb3df5e6d72f31e08c615.zip
Merge pull request #2704 from eeshangarg/access-description-hash
Refs #2578 -- implement __hash__ on AccessDescription
-rw-r--r--src/cryptography/x509/extensions.py3
-rw-r--r--tests/test_x509_ext.py16
2 files changed, 19 insertions, 0 deletions
diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py
index 3e6fc3b3..fe9bcf9b 100644
--- a/src/cryptography/x509/extensions.py
+++ b/src/cryptography/x509/extensions.py
@@ -313,6 +313,9 @@ class AccessDescription(object):
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 ff826458..b13405de 100644
--- a/tests/test_x509_ext.py
+++ b/tests/test_x509_ext.py
@@ -2228,6 +2228,22 @@ class TestAccessDescription(object):
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):