aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-05-17 12:46:01 -0400
committerAlex Gaynor <alex.gaynor@gmail.com>2015-05-17 12:46:01 -0400
commitb0391810fb74bd098592b03ffbb937daeed4561f (patch)
tree78ead3d4dfba1ef16bf661913da60c36482100f9
parent4825b9ed835866b50a0cc3feb9fad9bc81d57ec1 (diff)
parent58e870ca8ac61e4099fb9d5d9e10820d338f8671 (diff)
downloadcryptography-b0391810fb74bd098592b03ffbb937daeed4561f.tar.gz
cryptography-b0391810fb74bd098592b03ffbb937daeed4561f.tar.bz2
cryptography-b0391810fb74bd098592b03ffbb937daeed4561f.zip
Merge pull request #1968 from reaperhulk/ext-eq
x509 extension equality
-rw-r--r--src/cryptography/x509.py13
-rw-r--r--tests/test_x509_ext.py27
2 files changed, 40 insertions, 0 deletions
diff --git a/src/cryptography/x509.py b/src/cryptography/x509.py
index ec2092bb..325d6d62 100644
--- a/src/cryptography/x509.py
+++ b/src/cryptography/x509.py
@@ -278,6 +278,19 @@ class Extension(object):
return ("<Extension(oid={0.oid}, critical={0.critical}, "
"value={0.value})>").format(self)
+ def __eq__(self, other):
+ if not isinstance(other, Extension):
+ return NotImplemented
+
+ return (
+ self.oid == other.oid and
+ self.critical == other.critical and
+ self.value == other.value
+ )
+
+ def __ne__(self, other):
+ return not self == other
+
class ExtendedKeyUsage(object):
def __init__(self, usages):
diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py
index 72f2f9e4..572aa30c 100644
--- a/tests/test_x509_ext.py
+++ b/tests/test_x509_ext.py
@@ -38,6 +38,33 @@ class TestExtension(object):
"_length=None)>)>"
)
+ def test_eq(self):
+ ext1 = x509.Extension(
+ x509.ObjectIdentifier('1.2.3.4'), False, 'value'
+ )
+ ext2 = x509.Extension(
+ x509.ObjectIdentifier('1.2.3.4'), False, 'value'
+ )
+ assert ext1 == ext2
+
+ def test_ne(self):
+ ext1 = x509.Extension(
+ x509.ObjectIdentifier('1.2.3.4'), False, 'value'
+ )
+ ext2 = x509.Extension(
+ x509.ObjectIdentifier('1.2.3.5'), False, 'value'
+ )
+ ext3 = x509.Extension(
+ x509.ObjectIdentifier('1.2.3.4'), True, 'value'
+ )
+ ext4 = x509.Extension(
+ x509.ObjectIdentifier('1.2.3.4'), False, 'value4'
+ )
+ assert ext1 != ext2
+ assert ext1 != ext3
+ assert ext1 != ext4
+ assert ext1 != object()
+
class TestNoticeReference(object):
def test_notice_numbers_not_all_int(self):