diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/x509.py | 10 | ||||
-rw-r--r-- | src/cryptography/hazmat/bindings/openssl/x509.py | 1 | ||||
-rw-r--r-- | src/cryptography/x509.py | 12 |
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): |