summaryrefslogtreecommitdiff
path: root/src/OpenSSL/_util.py
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2016-03-11 11:21:13 +0100
committerHynek Schlawack <hs@ox.cx>2016-03-11 11:24:17 +0100
commitf90e368cdd11654b7e68fbde98c561177b333671 (patch)
treeeda22e540a56f1827e94306ad7f9c81e599a04c6 /src/OpenSSL/_util.py
parentc488deaa02eed0df890204721018e4e5b2493ac0 (diff)
downloadpyopenssl-f90e368cdd11654b7e68fbde98c561177b333671.tar.gz
Fix set_cipher_list on modern OpenSSL
Also port forward a few changes from #422.
Diffstat (limited to 'src/OpenSSL/_util.py')
-rw-r--r--src/OpenSSL/_util.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/OpenSSL/_util.py b/src/OpenSSL/_util.py
index 074ef3d..cba72ad 100644
--- a/src/OpenSSL/_util.py
+++ b/src/OpenSSL/_util.py
@@ -1,9 +1,11 @@
-from warnings import warn
import sys
+import warnings
from six import PY3, binary_type, text_type
from cryptography.hazmat.bindings.openssl.binding import Binding
+
+
binding = Binding()
binding.init_static_locks()
ffi = binding.ffi
@@ -47,6 +49,21 @@ def exception_from_error_queue(exception_type):
raise exception_type(errors)
+def make_assert(error):
+ """
+ Create an assert function that uses :func:`exception_from_error_queue` to
+ raise an exception wrapped by *error*.
+ """
+ def openssl_assert(ok):
+ """
+ If ok is not true-ish, retrieve the error from OpenSSL and raise it.
+ """
+ if not ok:
+ exception_from_error_queue(error)
+
+ return openssl_assert
+
+
def native(s):
"""
Convert :py:class:`bytes` or :py:class:`unicode` to the native
@@ -116,7 +133,7 @@ def text_to_bytes_and_warn(label, obj):
returned.
"""
if isinstance(obj, text_type):
- warn(
+ warnings.warn(
_TEXT_WARNING.format(label),
category=DeprecationWarning,
stacklevel=3