Return unicode from these new APIs rather than the native string type.
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py
index d3572dd..4a497f1 100644
--- a/OpenSSL/SSL.py
+++ b/OpenSSL/SSL.py
@@ -1427,13 +1427,14 @@
:returns: The name of the currently used cipher or :py:obj:`None`
if no connection has been established.
- :rtype: :py:class:`str` or :py:class:`NoneType`
+ :rtype: :py:class:`unicode` or :py:class:`NoneType`
"""
cipher = _lib.SSL_get_current_cipher(self._ssl)
if cipher == _ffi.NULL:
return None
else:
- return _native(_ffi.string(_lib.SSL_CIPHER_get_name(cipher)))
+ name = _ffi.string(_lib.SSL_CIPHER_get_name(cipher))
+ return name.decode("utf-8")
def get_cipher_bits(self):
@@ -1457,13 +1458,14 @@
:returns: The protocol name of the currently used cipher
or :py:obj:`None` if no connection has been established.
- :rtype: :py:class:`str` or :py:class:`NoneType`
+ :rtype: :py:class:`unicode` or :py:class:`NoneType`
"""
cipher = _lib.SSL_get_current_cipher(self._ssl)
if cipher == _ffi.NULL:
return None
else:
- return _native(_ffi.string(_lib.SSL_CIPHER_get_version(cipher)))
+ version =_ffi.string(_lib.SSL_CIPHER_get_version(cipher))
+ return version.decode("utf-8")
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py
index 7a8a932..406bc04 100644
--- a/OpenSSL/test/test_ssl.py
+++ b/OpenSSL/test/test_ssl.py
@@ -14,7 +14,7 @@
from unittest import main
from weakref import ref
-from six import PY3, u
+from six import PY3, text_type, u
from OpenSSL.crypto import TYPE_RSA, FILETYPE_PEM
from OpenSSL.crypto import PKey, X509, X509Extension, X509Store
@@ -1944,15 +1944,15 @@
def test_get_cipher_name(self):
"""
- :py:obj:`Connection.get_cipher_name` returns the name of the currently
- used cipher.
+ :py:obj:`Connection.get_cipher_name` returns a :py:class:`unicode`
+ string giving the name of the currently used cipher.
"""
server, client = self._loopback()
server_cipher_name, client_cipher_name = \
server.get_cipher_name(), client.get_cipher_name()
- self.assertIsInstance(server_cipher_name, str)
- self.assertIsInstance(client_cipher_name, str)
+ self.assertIsInstance(server_cipher_name, text_type)
+ self.assertIsInstance(client_cipher_name, text_type)
self.assertEqual(server_cipher_name, client_cipher_name)
@@ -1969,15 +1969,15 @@
def test_get_cipher_version(self):
"""
- :py:obj:`Connection.get_cipher_version` returns the protocol name of the currently
- used cipher.
+ :py:obj:`Connection.get_cipher_version` returns a :py:class:`unicode`
+ string giving the protocol name of the currently used cipher.
"""
server, client = self._loopback()
server_cipher_version, client_cipher_version = \
server.get_cipher_version(), client.get_cipher_version()
- self.assertIsInstance(server_cipher_version, str)
- self.assertIsInstance(client_cipher_version, str)
+ self.assertIsInstance(server_cipher_version, text_type)
+ self.assertIsInstance(client_cipher_version, text_type)
self.assertEqual(server_cipher_version, client_cipher_version)