Implement @alex's code review.
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py
index bd68767..48e3790 100644
--- a/OpenSSL/SSL.py
+++ b/OpenSSL/SSL.py
@@ -6,7 +6,7 @@
from six import text_type as _text_type
from six import integer_types as integer_types
-from six import int2byte, byte2int
+from six import int2byte, indexbytes
from OpenSSL._util import (
ffi as _ffi,
@@ -872,10 +872,7 @@
instr = _ffi.buffer(in_, inlen)
protolist = []
while instr:
- # This slightly insane syntax is to make sure we get a
- # bytestring: on Python 3, instr[0] would return an int and
- # this call would fail.
- l = byte2int(instr[0:1])
+ l = indexbytes(instr, 0)
proto = instr[1:l+1]
protolist.append(proto)
instr = instr[l+1:]
@@ -1658,10 +1655,7 @@
_lib.SSL_get0_next_proto_negotiated(self._ssl, data, data_len)
- if not data_len[0]:
- return b""
- else:
- return _ffi.string(data[0])
+ return _ffi.buffer(data[0], data_len[0])[:]
ConnectionType = Connection
diff --git a/doc/api/ssl.rst b/doc/api/ssl.rst
index fbee1fe..4b57ac5 100644
--- a/doc/api/ssl.rst
+++ b/doc/api/ssl.rst
@@ -835,7 +835,9 @@
.. py:method:: Connection.get_next_proto_negotiated():
- Get the protocol that was negotiated by Next Protocol Negotiation.
+ Get the protocol that was negotiated by Next Protocol Negotiation. Returns
+ a bytestring of the protocol name. If no protocol has been negotiated yet,
+ returns an empty string.
.. versionadded:: 0.15