From 410fe35dab3eb60fbcc5791e5ef24584ab45c324 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 26 Dec 2015 15:01:25 -0500 Subject: Refs #2578 -- implement __hash__ on SubjectKeyIdentifier --- src/cryptography/x509/extensions.py | 3 +++ tests/test_x509_ext.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py index 2363d2bf..5ef7a28b 100644 --- a/src/cryptography/x509/extensions.py +++ b/src/cryptography/x509/extensions.py @@ -234,6 +234,9 @@ class SubjectKeyIdentifier(object): def __ne__(self, other): return not self == other + def __hash__(self): + return hash(self.digest) + @utils.register_interface(ExtensionType) class AuthorityInformationAccess(object): diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 49a3433c..0f5d7823 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -656,6 +656,20 @@ class TestSubjectKeyIdentifier(object): 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): -- cgit v1.2.3