From 70c8f8b4d96f6a26f016e43d61005ad12027cc1e Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 6 Jul 2015 21:02:54 -0400 Subject: Fixed #2121 -- added __eq__ and __ne__ to CSRs --- src/cryptography/hazmat/backends/openssl/x509.py | 8 ++++++++ src/cryptography/x509.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) (limited to 'src') diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index 7bfeb2ce..d49147ad 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -701,6 +701,14 @@ class _CertificateSigningRequest(object): self._backend = backend self._x509_req = x509_req + def __eq__(self, other): + if not isinstance(other, _CertificateSigningRequest): + return NotImplemented + + self_bytes = self.public_bytes(serialization.Encoding.DER) + other_bytes = other.public_bytes(serialization.Encoding.DER) + return self_bytes == other_bytes + def public_key(self): pkey = self._backend._lib.X509_REQ_get_pubkey(self._x509_req) assert pkey != self._backend._ffi.NULL diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py index afd28f20..b36258a4 100644 --- a/src/cryptography/x509.py +++ b/src/cryptography/x509.py @@ -1391,6 +1391,18 @@ class CertificateRevocationList(object): @six.add_metaclass(abc.ABCMeta) class CertificateSigningRequest(object): + @abc.abstracmethod + def __eq__(self, other): + """ + Checks equality. + """ + + @abc.abstractmethod + def __ne__(self, other): + """ + Checks not equal. + """ + @abc.abstractmethod def public_key(self): """ -- cgit v1.2.3 From 935f6ca1a7d2cf31687c716c92e642372b9a7017 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 6 Jul 2015 21:03:46 -0400 Subject: typo fix --- src/cryptography/x509.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py index b36258a4..fb21be2b 100644 --- a/src/cryptography/x509.py +++ b/src/cryptography/x509.py @@ -1391,7 +1391,7 @@ class CertificateRevocationList(object): @six.add_metaclass(abc.ABCMeta) class CertificateSigningRequest(object): - @abc.abstracmethod + @abc.abstractmethod def __eq__(self, other): """ Checks equality. -- cgit v1.2.3 From 78a15f0621b7735e3033a5e1ceea6c6f9b3b9044 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 6 Jul 2015 21:47:47 -0400 Subject: added forgotten __ne__ method --- src/cryptography/hazmat/backends/openssl/x509.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py index d49147ad..3b1ff790 100644 --- a/src/cryptography/hazmat/backends/openssl/x509.py +++ b/src/cryptography/hazmat/backends/openssl/x509.py @@ -709,6 +709,9 @@ class _CertificateSigningRequest(object): other_bytes = other.public_bytes(serialization.Encoding.DER) return self_bytes == other_bytes + def __ne__(self, other): + return not self == other + def public_key(self): pkey = self._backend._lib.X509_REQ_get_pubkey(self._x509_req) assert pkey != self._backend._ffi.NULL -- cgit v1.2.3