merge alex/aint-no-reason-things-are-this-way
diff --git a/OpenSSL/_util.py b/OpenSSL/_util.py
index de292be..5e2b256 100644
--- a/OpenSSL/_util.py
+++ b/OpenSSL/_util.py
@@ -15,6 +15,8 @@
:return: :class:`str`
"""
+ if not charp:
+ return ""
return native(ffi.string(charp))
diff --git a/OpenSSL/test/test_util.py b/OpenSSL/test/test_util.py
new file mode 100644
index 0000000..f585354
--- /dev/null
+++ b/OpenSSL/test/test_util.py
@@ -0,0 +1,15 @@
+from OpenSSL._util import exception_from_error_queue, lib
+from OpenSSL.test.util import TestCase
+
+
+
+class TestErrors(TestCase):
+ def test_exception_from_error_queue_nonexistent_reason(self):
+ """
+ :py:func:`exception_from_error_queue` does not raise a ``TypeError``
+ when it encounters an OpenSSL error code which does not have a reason
+ string.
+ """
+ lib.ERR_put_error(lib.ERR_LIB_EVP, 0, 1112, b"", 10)
+ exc = self.assertRaises(ValueError, exception_from_error_queue, ValueError)
+ self.assertEqual(exc.args[0][0][2], "")