diff options
author | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2014-01-18 10:19:56 -0500 |
---|---|---|
committer | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2014-01-18 10:19:56 -0500 |
commit | 63eab6970b658b34039a77cb809bbc9ee3934492 (patch) | |
tree | f5dcc4fec9224f55c4d3888d79b2bd47d31e2f05 | |
parent | add057026d4e6fb3e3fbabc1fdde7b656e850925 (diff) | |
download | pyopenssl-63eab6970b658b34039a77cb809bbc9ee3934492.tar.gz |
Accept bytes or text in set_cipher_list
-rw-r--r-- | OpenSSL/SSL.py | 8 | ||||
-rw-r--r-- | OpenSSL/test/test_ssl.py | 21 |
2 files changed, 24 insertions, 5 deletions
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py index 8da25e2..6ca8913 100644 --- a/OpenSSL/SSL.py +++ b/OpenSSL/SSL.py @@ -4,6 +4,9 @@ from itertools import count from weakref import WeakValueDictionary from errno import errorcode +from six import text_type as _text_type + + from OpenSSL._util import ( ffi as _ffi, lib as _lib, @@ -588,8 +591,11 @@ class Context(object): :param cipher_list: A cipher list, see ciphers(1) :return: None """ + if isinstance(cipher_list, _text_type): + cipher_list = cipher_list.encode("ascii") + if not isinstance(cipher_list, bytes): - raise TypeError("cipher_list must be a byte string") + raise TypeError("cipher_list must be bytes or unicode") result = _lib.SSL_CTX_set_cipher_list(self._context, cipher_list) if not result: diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py index 95cb538..a30e369 100644 --- a/OpenSSL/test/test_ssl.py +++ b/OpenSSL/test/test_ssl.py @@ -1057,10 +1057,11 @@ class ContextTests(TestCase, _LoopbackMixin): # XXX What should I assert here? -exarkun - def test_set_cipher_list(self): + def test_set_cipher_list_bytes(self): """ - :py:obj:`Context.set_cipher_list` accepts a :py:obj:`str` naming the ciphers which - connections created with the context object will be able to choose from. + :py:obj:`Context.set_cipher_list` accepts a :py:obj:`bytes` naming the + ciphers which connections created with the context object will be able + to choose from. """ context = Context(TLSv1_METHOD) context.set_cipher_list(b"hello world:EXP-RC4-MD5") @@ -1068,6 +1069,18 @@ class ContextTests(TestCase, _LoopbackMixin): self.assertEquals(conn.get_cipher_list(), ["EXP-RC4-MD5"]) + def test_set_cipher_list_text(self): + """ + :py:obj:`Context.set_cipher_list` accepts a :py:obj:`unicode` naming + the ciphers which connections created with the context object will be + able to choose from. + """ + context = Context(TLSv1_METHOD) + context.set_cipher_list(u"hello world:EXP-RC4-MD5") + conn = Connection(context, None) + self.assertEquals(conn.get_cipher_list(), ["EXP-RC4-MD5"]) + + def test_set_cipher_list_wrong_args(self): """ :py:obj:`Context.set_cipher_list` raises :py:obj:`TypeError` when passed @@ -1080,7 +1093,7 @@ class ContextTests(TestCase, _LoopbackMixin): self.assertRaises(TypeError, context.set_cipher_list, object()) self.assertRaises(TypeError, context.set_cipher_list, b"EXP-RC4-MD5", object()) - self.assertRaises(Error, context.set_cipher_list, b"imaginary-cipher") + self.assertRaises(Error, context.set_cipher_list, "imaginary-cipher") def test_set_session_cache_mode_wrong_args(self): |