diff options
-rw-r--r-- | src/cryptography/x509.py | 9 | ||||
-rw-r--r-- | tests/test_x509_ext.py | 13 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py index 2b7ec317..71ba9042 100644 --- a/src/cryptography/x509.py +++ b/src/cryptography/x509.py @@ -333,6 +333,15 @@ class BasicConstraints(object): return ("<BasicConstraints(ca={0.ca}, " "path_length={0.path_length})>").format(self) + def __eq__(self, other): + if not isinstance(other, BasicConstraints): + return NotImplemented + + return self.ca == other.ca and self.path_length == other.path_length + + def __ne__(self, other): + return not self == other + class KeyUsage(object): def __init__(self, digital_signature, content_commitment, key_encipherment, diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 15f06664..a833bf37 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -673,6 +673,19 @@ class TestBasicConstraints(object): "<BasicConstraints(ca=True, path_length=None)>" ) + def test_eq(self): + na = x509.BasicConstraints(ca=True, path_length=None) + na2 = x509.BasicConstraints(ca=True, path_length=None) + assert na == na2 + + def test_ne(self): + na = x509.BasicConstraints(ca=True, path_length=None) + na2 = x509.BasicConstraints(ca=True, path_length=1) + na3 = x509.BasicConstraints(ca=False, path_length=None) + assert na != na2 + assert na != na3 + assert na != object() + class TestExtendedKeyUsage(object): def test_not_all_oids(self): |