aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-07-08 16:35:25 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-07-08 16:35:25 -0500
commit366b0f8385bc1a35c25a4316f315c33a84348261 (patch)
treeb1e82ae01e878f7ab1104f11747ef1dad67d982a /src
parent28ab45482ec35b9ce417352151cac9b213bae6f2 (diff)
parent5119125467c7cfe68f052ad804ac6ba88635739c (diff)
downloadcryptography-366b0f8385bc1a35c25a4316f315c33a84348261.tar.gz
cryptography-366b0f8385bc1a35c25a4316f315c33a84348261.tar.bz2
cryptography-366b0f8385bc1a35c25a4316f315c33a84348261.zip
Merge pull request #2124 from alex/hash-cert
Fixed #2120 -- added __hash__ to x509.Cert
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/openssl/x509.py11
-rw-r--r--src/cryptography/x509.py6
2 files changed, 10 insertions, 7 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py
index 3b1ff790..68104e69 100644
--- a/src/cryptography/hazmat/backends/openssl/x509.py
+++ b/src/cryptography/hazmat/backends/openssl/x509.py
@@ -226,15 +226,12 @@ class _Certificate(object):
def __ne__(self, other):
return not self == other
+ def __hash__(self):
+ return hash(self.public_bytes(serialization.Encoding.DER))
+
def fingerprint(self, algorithm):
h = hashes.Hash(algorithm, self._backend)
- bio = self._backend._create_mem_bio()
- res = self._backend._lib.i2d_X509_bio(
- bio, self._x509
- )
- assert res == 1
- der = self._backend._read_mem_bio(bio)
- h.update(der)
+ h.update(self.public_bytes(serialization.Encoding.DER))
return h.finalize()
@property
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index fb21be2b..f8134958 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -1324,6 +1324,12 @@ class Certificate(object):
"""
@abc.abstractmethod
+ def __hash__(self):
+ """
+ Computes a hash.
+ """
+
+ @abc.abstractmethod
def public_bytes(self, encoding):
"""
Serializes the certificate to PEM or DER format.