summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@twistedmatrix.com>2014-04-30 18:18:01 -0400
committerJean-Paul Calderone <exarkun@twistedmatrix.com>2014-04-30 18:18:01 -0400
commit73945e3fbc15ad19fd098af00cbf31d4c4bbaf7a (patch)
tree6b2981cd688e7e65e5e29b57322c8d3fe5f37c7c
parent1be7708ebd00177499955850f4c98b16e2ae7848 (diff)
downloadpyopenssl-73945e3fbc15ad19fd098af00cbf31d4c4bbaf7a.tar.gz
Cache the _EllipticCurve instances so the inherited-from-object equality does what we want.
-rw-r--r--OpenSSL/crypto.py34
1 files changed, 28 insertions, 6 deletions
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index 380593b..1312c0a 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -266,15 +266,23 @@ PKeyType = PKey
class _EllipticCurve(object):
"""
A representation of a supported elliptic curve.
+
+ @cvar _curves: :py:obj:`None` until an attempt is made to load the curves.
+ Thereafter, a :py:type:`set` containing :py:type:`_EllipticCurve`
+ instances each of which represents one curve supported by the system.
+ @type _curves: :py:type:`NoneType` or :py:type:`set`
"""
+ _curves = None
+
@classmethod
- def _get_elliptic_curves(cls, lib):
+ def _load_elliptic_curves(cls, lib):
"""
- Load the names of the supported elliptic curves from OpenSSL.
+ Get the curves supported by OpenSSL.
:param lib: The OpenSSL library binding object.
- :return: A set of :py:obj:`unicode` giving the names of the elliptic curves
- the underlying library supports.
+
+ :return: A :py:type:`set` of ``cls`` instances giving the names of the
+ elliptic curves the underlying library supports.
"""
if lib.Cryptography_HAS_EC:
num_curves = lib.EC_get_builtin_curves(_ffi.NULL, 0)
@@ -286,8 +294,22 @@ class _EllipticCurve(object):
return set(
cls.from_nid(lib, c.nid)
for c in builtin_curves)
- else:
- return set()
+ return set()
+
+
+ @classmethod
+ def _get_elliptic_curves(cls, lib):
+ """
+ Get, cache, and return the curves supported by OpenSSL.
+
+ :param lib: The OpenSSL library binding object.
+
+ :return: A :py:type:`set` of ``cls`` instances giving the names of the
+ elliptic curves the underlying library supports.
+ """
+ if cls._curves is None:
+ cls._curves = cls._load_elliptic_curves(lib)
+ return cls._curves
@classmethod