diff options
author | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2014-04-17 18:54:32 -0400 |
---|---|---|
committer | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2014-04-17 18:54:32 -0400 |
commit | f43678bc99019f55908752f9885f680cd70d42ca (patch) | |
tree | 9f5b70b81962867ff790df505b230d1e7126d6b7 | |
parent | 279909731305d97681a30172a0675a6e362feed5 (diff) | |
download | pyopenssl-f43678bc99019f55908752f9885f680cd70d42ca.tar.gz |
Get rid of some top-level code, remove the code that reflects a weird edge case (but the weird edge case is still there inside OpenSSL), and add a bit of docs.
-rw-r--r-- | OpenSSL/SSL.py | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py index 86410c0..e5ae085 100644 --- a/OpenSSL/SSL.py +++ b/OpenSSL/SSL.py @@ -124,18 +124,29 @@ SSL_CB_CONNECT_EXIT = _lib.SSL_CB_CONNECT_EXIT SSL_CB_HANDSHAKE_START = _lib.SSL_CB_HANDSHAKE_START SSL_CB_HANDSHAKE_DONE = _lib.SSL_CB_HANDSHAKE_DONE -_Cryptography_HAS_EC = _lib.Cryptography_HAS_EC -ELLIPTIC_CURVE_DESCRIPTIONS = {} # In case there's no EC support -if _Cryptography_HAS_EC: - _num_curves = _lib.EC_get_builtin_curves(_ffi.NULL, 0) - _curves = _ffi.new('EC_builtin_curve[]', _num_curves) - if _lib.EC_get_builtin_curves(_curves, _num_curves) == _num_curves: - ELLIPTIC_CURVE_DESCRIPTIONS = dict( - (_ffi.string(_lib.OBJ_nid2sn(c.nid)).decode('ascii'), - _ffi.string(c.comment).decode('utf-8')) - for c in _curves) - del _num_curves - del _curves +def _get_elliptic_curves(lib): + """ + Load the names of the supported elliptic curves from 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. + """ + if lib.Cryptography_HAS_EC: + num_curves = lib.EC_get_builtin_curves(_ffi.NULL, 0) + builtin_curves = _ffi.new('EC_builtin_curve[]', num_curves) + # The return value on this call should be num_curves again. We could + # check it to make sure but if it *isn't* then.. what could we do? + # Abort the whole process, I suppose...? -exarkun + lib.EC_get_builtin_curves(builtin_curves, num_curves) + return set( + _ffi.string(lib.OBJ_nid2sn(c.nid)).decode("ascii") + for c in builtin_curves) + else: + return set() + +ELLIPTIC_CURVES = _get_elliptic_curves() + class Error(Exception): |