diff options
author | Jim Shaver <dcypherd@gmail.com> | 2015-05-27 09:15:55 -0400 |
---|---|---|
committer | Jim Shaver <dcypherd@gmail.com> | 2015-05-27 17:39:57 -0400 |
commit | abff188a6bfda1e624d49d33a3e109904c440a38 (patch) | |
tree | f91aa5e0b54dc22c03f5d819a78319b814d94c27 | |
parent | f00513f42509c868756ece9d71cc1dbc5727060d (diff) | |
download | pyopenssl-git-abff188a6bfda1e624d49d33a3e109904c440a38.tar.gz |
differentiated the two functions. Updated docs, and tests
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | OpenSSL/SSL.py | 8 | ||||
-rw-r--r-- | OpenSSL/test/test_ssl.py | 21 | ||||
-rw-r--r-- | doc/api/ssl.rst | 15 |
4 files changed, 38 insertions, 12 deletions
@@ -7,9 +7,11 @@ 2015-04-15 Paul Kehrer <paul.l.kehrer@gmail.com> - * OpenSSL/SSL.py, : Add ``get_protocol_version()`` to Connection + * OpenSSL/SSL.py, : Add ``get_protocol_version()`` and + ``get_protocol_version_name()`` to Connection Based on work from Rich Moore - * OpenSSL/test/test_crypto.py: tests for ``get_protocol_version`` + * OpenSSL/test/test_crypto.py: tests for ``get_protocol_version()`` + and ``get_protocol_version_name()`` 2015-04-15 Paul Kehrer <paul.l.kehrer@gmail.com> diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py index aaaea87..85cf976 100644 --- a/OpenSSL/SSL.py +++ b/OpenSSL/SSL.py @@ -1883,16 +1883,16 @@ class Connection(object): return version.decode("utf-8") - def get_protocol_version(self): + def get_protocol_version_name(self): """ Obtain the protocol version of the current connection. :returns: The TLS version of the current connection, for example - the value for TLS 1.2 would be ``TLSv1.2``. + the value for TLS 1.2 would be ``b'TLSv1.2'``. :rtype: :py:class:`unicode` """ - version = _ffi.string(_lib.SSL_get_version(self._ssl)) - return version.decode("utf-8") + version = _lib.SSL_get_version(self._ssl) + return version @_requires_npn diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py index e118c15..01a76c1 100644 --- a/OpenSSL/test/test_ssl.py +++ b/OpenSSL/test/test_ssl.py @@ -2745,17 +2745,32 @@ class ConnectionTests(TestCase, _LoopbackMixin): self.assertEqual(server_cipher_bits, client_cipher_bits) + def test_get_protocol_version_name(self): + """ + :py:obj:`Connection.get_protocol_version_name()` returns a string + giving the protocol version of the current connection. + """ + server, client = self._loopback() + client_protocol_version_name = client.get_protocol_version_name() + server_protocol_version_name = server.get_protocol_version_name() + + self.assertIsInstance(server_protocol_version_name, bytes) + self.assertIsInstance(client_protocol_version_name, bytes) + + self.assertEqual(server_protocol_version_name, client_protocol_version_name) + + def test_get_protocol_version(self): """ - :py:obj:`Connection.get_protocol_version()` returns a string + :py:obj:`Connection.get_protocol_version()` returns an integer giving the protocol version of the current connection. """ server, client = self._loopback() client_protocol_version = client.get_protocol_version() server_protocol_version = server.get_protocol_version() - self.assertIsInstance(server_protocol_version, text_type) - self.assertIsInstance(client_protocol_version, text_type) + self.assertIsInstance(server_protocol_version, int) + self.assertIsInstance(client_protocol_version, int) self.assertEqual(server_protocol_version, client_protocol_version) diff --git a/doc/api/ssl.rst b/doc/api/ssl.rst index 2ab29fd..38f0d33 100644 --- a/doc/api/ssl.rst +++ b/doc/api/ssl.rst @@ -600,9 +600,18 @@ Connection objects have the following methods: .. py:method:: Connection.get_protocol_version() - Retrieve the version of the SSL or TLS protocol used by the Connection. For - example, it will return ``TLSv1`` for connections made over TLS version 1, or - ``Unknown`` for connections that were not successfully established. + Retrieve the version of the SSL or TLS protocol used by the Connection. + For example, it will return ``0x303`` for connections made over TLS + version 1.2, or ``Unknown`` for connections that were not successfully + established. + + +.. py:method:: Connection.get_protocol_version_name() + + Retrieve the version of the SSL or TLS protocol used by the Connection. + For example, it will return ``TLSv1`` in bytes for connections made over + TLS version 1, or ``Unknown`` for connections that were not successfully + established. .. py:method:: Connection.get_client_ca_list() |