aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-05-12 07:10:13 -0400
committerAlex Gaynor <alex.gaynor@gmail.com>2015-05-12 07:10:13 -0400
commitcb599d3be59d05ef102759d02069c50466db869c (patch)
treefec5a629729f72d8373b2a3aa14618c84a62d608
parentc6f6a247bf281d4307bcb76be873a743660d0438 (diff)
parentc56ab62c5bce544948825051cdcbf039093d1da4 (diff)
downloadcryptography-cb599d3be59d05ef102759d02069c50466db869c.tar.gz
cryptography-cb599d3be59d05ef102759d02069c50466db869c.tar.bz2
cryptography-cb599d3be59d05ef102759d02069c50466db869c.zip
Merge pull request #1928 from reaperhulk/cp-eq
add eq/ne methods for all certificate policies classes
-rw-r--r--src/cryptography/x509.py45
-rw-r--r--tests/test_x509_ext.py78
2 files changed, 123 insertions, 0 deletions
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index 50fae716..cdddfb57 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -481,6 +481,15 @@ class CertificatePolicies(object):
def __repr__(self):
return "<CertificatePolicies({0})>".format(self._policies)
+ def __eq__(self, other):
+ if not isinstance(other, CertificatePolicies):
+ return NotImplemented
+
+ return self._policies == other._policies
+
+ def __ne__(self, other):
+ return not self == other
+
class PolicyInformation(object):
def __init__(self, policy_identifier, policy_qualifiers):
@@ -506,6 +515,18 @@ class PolicyInformation(object):
"y_qualifiers={0.policy_qualifiers})>".format(self)
)
+ def __eq__(self, other):
+ if not isinstance(other, PolicyInformation):
+ return NotImplemented
+
+ return (
+ self.policy_identifier == other.policy_identifier and
+ self.policy_qualifiers == other.policy_qualifiers
+ )
+
+ def __ne__(self, other):
+ return not self == other
+
policy_identifier = utils.read_only_property("_policy_identifier")
policy_qualifiers = utils.read_only_property("_policy_qualifiers")
@@ -528,6 +549,18 @@ class UserNotice(object):
"{0.explicit_text!r})>".format(self)
)
+ def __eq__(self, other):
+ if not isinstance(other, UserNotice):
+ return NotImplemented
+
+ return (
+ self.notice_reference == other.notice_reference and
+ self.explicit_text == other.explicit_text
+ )
+
+ def __ne__(self, other):
+ return not self == other
+
notice_reference = utils.read_only_property("_notice_reference")
explicit_text = utils.read_only_property("_explicit_text")
@@ -550,6 +583,18 @@ class NoticeReference(object):
"{0.notice_numbers})>".format(self)
)
+ def __eq__(self, other):
+ if not isinstance(other, NoticeReference):
+ return NotImplemented
+
+ return (
+ self.organization == other.organization and
+ self.notice_numbers == other.notice_numbers
+ )
+
+ def __ne__(self, other):
+ return not self == other
+
organization = utils.read_only_property("_organization")
notice_numbers = utils.read_only_property("_notice_numbers")
diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py
index ae69f5fc..f07792d5 100644
--- a/tests/test_x509_ext.py
+++ b/tests/test_x509_ext.py
@@ -63,6 +63,19 @@ class TestNoticeReference(object):
"4])>"
)
+ def test_eq(self):
+ nr = x509.NoticeReference("org", [1, 2])
+ nr2 = x509.NoticeReference("org", [1, 2])
+ assert nr == nr2
+
+ def test_ne(self):
+ nr = x509.NoticeReference("org", [1, 2])
+ nr2 = x509.NoticeReference("org", [1])
+ nr3 = x509.NoticeReference(None, [1, 2])
+ assert nr != nr2
+ assert nr != nr3
+ assert nr != object()
+
class TestUserNotice(object):
def test_notice_reference_invalid(self):
@@ -87,6 +100,23 @@ class TestUserNotice(object):
"'org', notice_numbers=None)>, explicit_text=u'text')>"
)
+ def test_eq(self):
+ nr = x509.NoticeReference("org", [1, 2])
+ nr2 = x509.NoticeReference("org", [1, 2])
+ un = x509.UserNotice(nr, "text")
+ un2 = x509.UserNotice(nr2, "text")
+ assert un == un2
+
+ def test_ne(self):
+ nr = x509.NoticeReference("org", [1, 2])
+ nr2 = x509.NoticeReference("org", [1])
+ un = x509.UserNotice(nr, "text")
+ un2 = x509.UserNotice(nr2, "text")
+ un3 = x509.UserNotice(nr, "text3")
+ assert un != un2
+ assert un != un3
+ assert un != object()
+
class TestPolicyInformation(object):
def test_invalid_policy_identifier(self):
@@ -124,6 +154,31 @@ class TestPolicyInformation(object):
"otice(notice_reference=None, explicit_text=u'hi')>])>"
)
+ def test_eq(self):
+ pi = x509.PolicyInformation(
+ x509.ObjectIdentifier("1.2.3"),
+ [u"string", x509.UserNotice(None, u"hi")]
+ )
+ pi2 = x509.PolicyInformation(
+ x509.ObjectIdentifier("1.2.3"),
+ [u"string", x509.UserNotice(None, u"hi")]
+ )
+ assert pi == pi2
+
+ def test_ne(self):
+ pi = x509.PolicyInformation(
+ x509.ObjectIdentifier("1.2.3"), [u"string"]
+ )
+ pi2 = x509.PolicyInformation(
+ x509.ObjectIdentifier("1.2.3"), [u"string2"]
+ )
+ pi3 = x509.PolicyInformation(
+ x509.ObjectIdentifier("1.2.3.4"), [u"string"]
+ )
+ assert pi != pi2
+ assert pi != pi3
+ assert pi != object()
+
class TestCertificatePolicies(object):
def test_invalid_policies(self):
@@ -157,6 +212,29 @@ class TestCertificatePolicies(object):
"ers=[u'string'])>])>"
)
+ def test_eq(self):
+ pi = x509.PolicyInformation(
+ x509.ObjectIdentifier("1.2.3"), [u"string"]
+ )
+ cp = x509.CertificatePolicies([pi])
+ pi2 = x509.PolicyInformation(
+ x509.ObjectIdentifier("1.2.3"), [u"string"]
+ )
+ cp2 = x509.CertificatePolicies([pi2])
+ assert cp == cp2
+
+ def test_ne(self):
+ pi = x509.PolicyInformation(
+ x509.ObjectIdentifier("1.2.3"), [u"string"]
+ )
+ cp = x509.CertificatePolicies([pi])
+ pi2 = x509.PolicyInformation(
+ x509.ObjectIdentifier("1.2.3"), [u"string2"]
+ )
+ cp2 = x509.CertificatePolicies([pi2])
+ assert cp != cp2
+ assert cp != object()
+
class TestKeyUsage(object):
def test_key_agreement_false_encipher_decipher_true(self):