Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #2578 -- implement __hash__ on SubjectKeyIdentifier #2583

Merged
merged 1 commit into from
Dec 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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