summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@twistedmatrix.com>2014-04-30 18:17:41 -0400
committerJean-Paul Calderone <exarkun@twistedmatrix.com>2014-04-30 18:17:41 -0400
commit1be7708ebd00177499955850f4c98b16e2ae7848 (patch)
treea30d3521e8c679f1f3b31ace721dce91501301ac
parent9c7f069ab8d325957290ec85d99ea834c870680d (diff)
downloadpyopenssl-1be7708ebd00177499955850f4c98b16e2ae7848.tar.gz
Use that helper to define tests for equality of _EllipticCurve instances.
-rw-r--r--OpenSSL/test/test_crypto.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index b37dc94..8dc19cf 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -27,7 +27,7 @@ from OpenSSL.crypto import CRL, Revoked, load_crl
from OpenSSL.crypto import NetscapeSPKI, NetscapeSPKIType
from OpenSSL.crypto import (
sign, verify, get_elliptic_curve, get_elliptic_curves)
-from OpenSSL.test.util import TestCase
+from OpenSSL.test.util import EqualityTestsMixin, TestCase
from OpenSSL._util import native, lib
def normalize_certificate_pem(pem):
@@ -3135,5 +3135,46 @@ class EllipticCurveTests(TestCase):
curve._to_EC_KEY()
+
+class EllipticCurveFactory(object):
+ """
+ A helper to get the names of two curves.
+ """
+ def __init__(self):
+ curves = iter(get_elliptic_curves())
+ try:
+ self.curve_name = next(curves).name
+ self.another_curve_name = next(curves).name
+ except StopIteration:
+ self.curve_name = self.another_curve_name = None
+
+
+
+class EllipticCurveEqualityTests(TestCase, EqualityTestsMixin):
+ """
+ Tests :py:type:`_EllipticCurve`\ 's implementation of ``==`` and ``!=``.
+ """
+ curve_factory = EllipticCurveFactory()
+
+ if curve_factory.curve_name is None:
+ skip = "There are no curves available there can be no curve objects."
+
+
+ def anInstance(self):
+ """
+ Get the curve object for an arbitrary curve supported by the system.
+ """
+ return get_elliptic_curve(self.curve_factory.curve_name)
+
+
+ def anotherInstance(self):
+ """
+ Get the curve object for an arbitrary curve supported by the system -
+ but not the one returned by C{anInstance}.
+ """
+ return get_elliptic_curve(self.curve_factory.another_curve_name)
+
+
+
if __name__ == '__main__':
main()