From f90e368cdd11654b7e68fbde98c561177b333671 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 11 Mar 2016 11:21:13 +0100 Subject: Fix set_cipher_list on modern OpenSSL Also port forward a few changes from #422. --- src/OpenSSL/_util.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/OpenSSL/_util.py') 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 -- cgit v1.2.1