Skip to content

Commit

Permalink
Refs pyca#2578 -- implement __hash__ on SubjectKeyIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Dec 26, 2015
1 parent f9a77b6 commit 410fe35
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cryptography/x509/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def __eq__(self, other):
def __ne__(self, other):
return not self == other

def __hash__(self):
return hash(self.digest)


@utils.register_interface(ExtensionType)
class AuthorityInformationAccess(object):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_x509_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,20 @@ def test_ne(self):
assert ski != ski2
assert ski != object()

def test_hash(self):
ski1 = x509.SubjectKeyIdentifier(
binascii.unhexlify(b"092384932230498bc980aa8098456f6ff7ff3ac9")
)
ski2 = x509.SubjectKeyIdentifier(
binascii.unhexlify(b"092384932230498bc980aa8098456f6ff7ff3ac9")
)
ski3 = x509.SubjectKeyIdentifier(
binascii.unhexlify(b"aa8098456f6ff7ff3ac9092384932230498bc980")
)

assert hash(ski1) == hash(ski2)
assert hash(ski1) != hash(ski3)


class TestAuthorityKeyIdentifier(object):
def test_authority_cert_issuer_not_generalname(self):
Expand Down

0 comments on commit 410fe35

Please sign in to comment.