From 969f3a50c491b76a39261e3413277c3135050d97 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 6 Jul 2015 18:52:41 -0400 Subject: Fixed #2120 -- added __hash__ to x509.Cert --- src/cryptography/hazmat/backends/openssl/x509.py | 4 ++++ src/cryptography/x509.py | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'src') diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index 7bfeb2ce..5e42b8e4 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -226,6 +226,10 @@ class _Certificate(object): def __ne__(self, other): return not self == other + def __hash__(self): + # TODO: Using fingerprint() with SHA256 is way overkill. + return hash(self.fingerprint(hashes.SHA256())) + def fingerprint(self, algorithm): h = hashes.Hash(algorithm, self._backend) bio = self._backend._create_mem_bio() diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py index afd28f20..8d28c35c 100644 --- a/src/cryptography/x509.py +++ b/src/cryptography/x509.py @@ -1323,6 +1323,12 @@ class Certificate(object): Checks not equal. """ + @abc.abstractmethod + def __hash__(self): + """ + Computes a hash. + """ + @abc.abstractmethod def public_bytes(self, encoding): """ -- cgit v1.2.3