summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2019-11-18 00:18:50 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2019-11-18 13:18:50 +0800
commit1257600e1603ed57455d92758eb1da857cd61725 (patch)
tree5a5829854150a0b092b54803723fa842e6222ad6
parentdaf6f0060959c896fd724da5ade401ec70a8d1e5 (diff)
downloadpyopenssl-git-1257600e1603ed57455d92758eb1da857cd61725.tar.gz
Random cleanup around our usage of binary_type (#879)
-rw-r--r--src/OpenSSL/SSL.py8
-rw-r--r--src/OpenSSL/_util.py8
-rw-r--r--tests/test_crypto.py8
3 files changed, 10 insertions, 14 deletions
diff --git a/src/OpenSSL/SSL.py b/src/OpenSSL/SSL.py
index a228b73..ca39930 100644
--- a/src/OpenSSL/SSL.py
+++ b/src/OpenSSL/SSL.py
@@ -7,9 +7,7 @@ from itertools import count, chain
from weakref import WeakValueDictionary
from errno import errorcode
-from six import (
- binary_type as _binary_type, integer_types as integer_types, int2byte,
- indexbytes)
+from six import integer_types, int2byte, indexbytes
from OpenSSL._util import (
UNSPECIFIED as _UNSPECIFIED,
@@ -461,7 +459,7 @@ class _ALPNSelectHelper(_CallbackExceptionHelper):
if outbytes is NO_OVERLAPPING_PROTOCOLS:
outbytes = b''
any_accepted = False
- elif not isinstance(outbytes, _binary_type):
+ elif not isinstance(outbytes, bytes):
raise TypeError(
"ALPN callback must return a bytestring or the "
"special NO_OVERLAPPING_PROTOCOLS sentinel value."
@@ -529,7 +527,7 @@ class _OCSPServerCallbackHelper(_CallbackExceptionHelper):
# Call the callback.
ocsp_data = callback(conn, data)
- if not isinstance(ocsp_data, _binary_type):
+ if not isinstance(ocsp_data, bytes):
raise TypeError("OCSP callback must return a bytestring.")
# If the OCSP data was provided, we will pass it to OpenSSL.
diff --git a/src/OpenSSL/_util.py b/src/OpenSSL/_util.py
index d8e3f66..9f2d724 100644
--- a/src/OpenSSL/_util.py
+++ b/src/OpenSSL/_util.py
@@ -1,7 +1,7 @@
import sys
import warnings
-from six import PY2, binary_type, text_type
+from six import PY2, text_type
from cryptography.hazmat.bindings.openssl.binding import Binding
@@ -79,13 +79,13 @@ def native(s):
:raise TypeError: The input is neither :py:class:`bytes` nor
:py:class:`unicode`.
"""
- if not isinstance(s, (binary_type, text_type)):
+ if not isinstance(s, (bytes, text_type)):
raise TypeError("%r is neither bytes nor unicode" % s)
if PY2:
if isinstance(s, text_type):
return s.encode("utf-8")
else:
- if isinstance(s, binary_type):
+ if isinstance(s, bytes):
return s.decode("utf-8")
return s
@@ -99,7 +99,7 @@ def path_string(s):
:return: An instance of :py:class:`bytes`.
"""
- if isinstance(s, binary_type):
+ if isinstance(s, bytes):
return s
elif isinstance(s, text_type):
return s.encode(sys.getfilesystemencoding())
diff --git a/tests/test_crypto.py b/tests/test_crypto.py
index 9d943a9..b0e8e8b 100644
--- a/tests/test_crypto.py
+++ b/tests/test_crypto.py
@@ -13,8 +13,6 @@ from datetime import datetime, timedelta
import pytest
-from six import binary_type
-
from cryptography import x509
from cryptography.hazmat.backends.openssl.backend import backend
from cryptography.hazmat.primitives import serialization
@@ -2662,7 +2660,7 @@ class TestFunction(object):
passphrase = b"foo"
key = load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)
pem = dump_privatekey(FILETYPE_PEM, key, GOOD_CIPHER, passphrase)
- assert isinstance(pem, binary_type)
+ assert isinstance(pem, bytes)
loadedKey = load_privatekey(FILETYPE_PEM, pem, passphrase)
assert isinstance(loadedKey, PKey)
assert loadedKey.type() == key.type()
@@ -2802,7 +2800,7 @@ class TestFunction(object):
return passphrase
key = load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)
pem = dump_privatekey(FILETYPE_PEM, key, GOOD_CIPHER, cb)
- assert isinstance(pem, binary_type)
+ assert isinstance(pem, bytes)
assert called == [True]
loadedKey = load_privatekey(FILETYPE_PEM, pem, passphrase)
assert isinstance(loadedKey, PKey)
@@ -2982,7 +2980,7 @@ class TestNetscapeSPKI(_PKeyInteractionTestsMixin):
"""
nspki = NetscapeSPKI()
blob = nspki.b64_encode()
- assert isinstance(blob, binary_type)
+ assert isinstance(blob, bytes)
class TestRevoked(object):