aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-05-13 12:13:06 -0400
committerAlex Gaynor <alex.gaynor@gmail.com>2015-05-13 12:13:06 -0400
commit3fa86454cc94053abc976bf992604eb0ab7c7d56 (patch)
tree225bda4cc0401c0925a179bd9384c9d22e2f4ee6
parent91ea3a91fe67ecf2577b3f88955c4baad4d4f131 (diff)
parent8565f5ed4e76dbb9ff46cc9c112aa0eb6b259186 (diff)
downloadcryptography-3fa86454cc94053abc976bf992604eb0ab7c7d56.tar.gz
cryptography-3fa86454cc94053abc976bf992604eb0ab7c7d56.tar.bz2
cryptography-3fa86454cc94053abc976bf992604eb0ab7c7d56.zip
Merge pull request #1942 from reaperhulk/ku-eq
add eq/ne support to KeyUsage
-rw-r--r--src/cryptography/x509.py19
-rw-r--r--tests/test_x509_ext.py51
2 files changed, 70 insertions, 0 deletions
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index b0a4a352..5eca5d64 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -397,6 +397,25 @@ class KeyUsage(object):
"encipher_only={1}, decipher_only={2})>").format(
self, encipher_only, decipher_only)
+ def __eq__(self, other):
+ if not isinstance(other, KeyUsage):
+ return NotImplemented
+
+ return (
+ self.digital_signature == other.digital_signature and
+ self.content_commitment == other.content_commitment and
+ self.key_encipherment == other.key_encipherment and
+ self.data_encipherment == other.data_encipherment and
+ self.key_agreement == other.key_agreement and
+ self.key_cert_sign == other.key_cert_sign and
+ self.crl_sign == other.crl_sign and
+ self._encipher_only == other._encipher_only and
+ self._decipher_only == other._decipher_only
+ )
+
+ def __ne__(self, other):
+ return not self == other
+
class AuthorityInformationAccess(object):
def __init__(self, descriptions):
diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py
index 2852776b..e1312b6c 100644
--- a/tests/test_x509_ext.py
+++ b/tests/test_x509_ext.py
@@ -463,6 +463,57 @@ class TestKeyUsage(object):
"only=False)>"
)
+ def test_eq(self):
+ ku = x509.KeyUsage(
+ digital_signature=False,
+ content_commitment=False,
+ key_encipherment=False,
+ data_encipherment=False,
+ key_agreement=True,
+ key_cert_sign=False,
+ crl_sign=False,
+ encipher_only=False,
+ decipher_only=True
+ )
+ ku2 = x509.KeyUsage(
+ digital_signature=False,
+ content_commitment=False,
+ key_encipherment=False,
+ data_encipherment=False,
+ key_agreement=True,
+ key_cert_sign=False,
+ crl_sign=False,
+ encipher_only=False,
+ decipher_only=True
+ )
+ assert ku == ku2
+
+ def test_ne(self):
+ ku = x509.KeyUsage(
+ digital_signature=False,
+ content_commitment=False,
+ key_encipherment=False,
+ data_encipherment=False,
+ key_agreement=True,
+ key_cert_sign=False,
+ crl_sign=False,
+ encipher_only=False,
+ decipher_only=True
+ )
+ ku2 = x509.KeyUsage(
+ digital_signature=False,
+ content_commitment=False,
+ key_encipherment=False,
+ data_encipherment=False,
+ key_agreement=False,
+ key_cert_sign=False,
+ crl_sign=False,
+ encipher_only=False,
+ decipher_only=False
+ )
+ assert ku != ku2
+ assert ku != object()
+
class TestSubjectKeyIdentifier(object):
def test_properties(self):