aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-04-30 18:41:17 -0400
committerAlex Gaynor <alex.gaynor@gmail.com>2015-04-30 18:41:17 -0400
commit12953e390654ae5ea0195558a4f78cf2ae01cb8f (patch)
treed1542ec6c10e9ca7f37eaeb88ae4362632a3b77f /src
parentdd1d15143e2690d1aba58dc1dab8282e40706ba5 (diff)
parent8bbdc6f5af5a47bd2b069314c1d3d87da1da1874 (diff)
downloadcryptography-12953e390654ae5ea0195558a4f78cf2ae01cb8f.tar.gz
cryptography-12953e390654ae5ea0195558a4f78cf2ae01cb8f.tar.bz2
cryptography-12953e390654ae5ea0195558a4f78cf2ae01cb8f.zip
Merge pull request #1883 from reaperhulk/fix-1866
add support for equality testing to x509.Certificate
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/openssl/x509.py10
-rw-r--r--src/cryptography/hazmat/bindings/openssl/x509.py1
-rw-r--r--src/cryptography/x509.py12
3 files changed, 23 insertions, 0 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py
index 5558f140..7f633c76 100644
--- a/src/cryptography/hazmat/backends/openssl/x509.py
+++ b/src/cryptography/hazmat/backends/openssl/x509.py
@@ -123,6 +123,16 @@ class _Certificate(object):
self._backend = backend
self._x509 = x509
+ def __eq__(self, other):
+ if not isinstance(other, x509.Certificate):
+ return NotImplemented
+
+ res = self._backend._lib.X509_cmp(self._x509, other._x509)
+ return res == 0
+
+ def __ne__(self, other):
+ return not self == other
+
def fingerprint(self, algorithm):
h = hashes.Hash(algorithm, self._backend)
bio = self._backend._create_mem_bio()
diff --git a/src/cryptography/hazmat/bindings/openssl/x509.py b/src/cryptography/hazmat/bindings/openssl/x509.py
index fd7a12a2..a1fb7ffb 100644
--- a/src/cryptography/hazmat/bindings/openssl/x509.py
+++ b/src/cryptography/hazmat/bindings/openssl/x509.py
@@ -115,6 +115,7 @@ FUNCTIONS = """
X509 *X509_new(void);
void X509_free(X509 *);
X509 *X509_dup(X509 *);
+int X509_cmp(const X509 *, const X509 *);
int X509_print_ex(BIO *, X509 *, unsigned long, unsigned long);
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index dd6ea926..b22ac8be 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -730,6 +730,18 @@ class Certificate(object):
in the certificate.
"""
+ @abc.abstractmethod
+ def __eq__(self, other):
+ """
+ Checks equality.
+ """
+
+ @abc.abstractmethod
+ def __ne__(self, other):
+ """
+ Checks not equal.
+ """
+
@six.add_metaclass(abc.ABCMeta)
class CertificateSigningRequest(object):