Skip to content

Commit 1257600

Browse files
alexreaperhulk
authored andcommitted
Random cleanup around our usage of binary_type (#879)
1 parent daf6f00 commit 1257600

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

src/OpenSSL/SSL.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
from weakref import WeakValueDictionary
88
from errno import errorcode
99

10-
from six import (
11-
binary_type as _binary_type, integer_types as integer_types, int2byte,
12-
indexbytes)
10+
from six import integer_types, int2byte, indexbytes
1311

1412
from OpenSSL._util import (
1513
UNSPECIFIED as _UNSPECIFIED,
@@ -461,7 +459,7 @@ def wrapper(ssl, out, outlen, in_, inlen, arg):
461459
if outbytes is NO_OVERLAPPING_PROTOCOLS:
462460
outbytes = b''
463461
any_accepted = False
464-
elif not isinstance(outbytes, _binary_type):
462+
elif not isinstance(outbytes, bytes):
465463
raise TypeError(
466464
"ALPN callback must return a bytestring or the "
467465
"special NO_OVERLAPPING_PROTOCOLS sentinel value."
@@ -529,7 +527,7 @@ def wrapper(ssl, cdata):
529527
# Call the callback.
530528
ocsp_data = callback(conn, data)
531529

532-
if not isinstance(ocsp_data, _binary_type):
530+
if not isinstance(ocsp_data, bytes):
533531
raise TypeError("OCSP callback must return a bytestring.")
534532

535533
# If the OCSP data was provided, we will pass it to OpenSSL.

src/OpenSSL/_util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
import warnings
33

4-
from six import PY2, binary_type, text_type
4+
from six import PY2, text_type
55

66
from cryptography.hazmat.bindings.openssl.binding import Binding
77

@@ -79,13 +79,13 @@ def native(s):
7979
:raise TypeError: The input is neither :py:class:`bytes` nor
8080
:py:class:`unicode`.
8181
"""
82-
if not isinstance(s, (binary_type, text_type)):
82+
if not isinstance(s, (bytes, text_type)):
8383
raise TypeError("%r is neither bytes nor unicode" % s)
8484
if PY2:
8585
if isinstance(s, text_type):
8686
return s.encode("utf-8")
8787
else:
88-
if isinstance(s, binary_type):
88+
if isinstance(s, bytes):
8989
return s.decode("utf-8")
9090
return s
9191

@@ -99,7 +99,7 @@ def path_string(s):
9999
100100
:return: An instance of :py:class:`bytes`.
101101
"""
102-
if isinstance(s, binary_type):
102+
if isinstance(s, bytes):
103103
return s
104104
elif isinstance(s, text_type):
105105
return s.encode(sys.getfilesystemencoding())

tests/test_crypto.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
import pytest
1515

16-
from six import binary_type
17-
1816
from cryptography import x509
1917
from cryptography.hazmat.backends.openssl.backend import backend
2018
from cryptography.hazmat.primitives import serialization
@@ -2662,7 +2660,7 @@ def test_dump_privatekey_passphrase(self):
26622660
passphrase = b"foo"
26632661
key = load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)
26642662
pem = dump_privatekey(FILETYPE_PEM, key, GOOD_CIPHER, passphrase)
2665-
assert isinstance(pem, binary_type)
2663+
assert isinstance(pem, bytes)
26662664
loadedKey = load_privatekey(FILETYPE_PEM, pem, passphrase)
26672665
assert isinstance(loadedKey, PKey)
26682666
assert loadedKey.type() == key.type()
@@ -2802,7 +2800,7 @@ def cb(writing):
28022800
return passphrase
28032801
key = load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)
28042802
pem = dump_privatekey(FILETYPE_PEM, key, GOOD_CIPHER, cb)
2805-
assert isinstance(pem, binary_type)
2803+
assert isinstance(pem, bytes)
28062804
assert called == [True]
28072805
loadedKey = load_privatekey(FILETYPE_PEM, pem, passphrase)
28082806
assert isinstance(loadedKey, PKey)
@@ -2982,7 +2980,7 @@ def test_b64_encode(self):
29822980
"""
29832981
nspki = NetscapeSPKI()
29842982
blob = nspki.b64_encode()
2985-
assert isinstance(blob, binary_type)
2983+
assert isinstance(blob, bytes)
29862984

29872985

29882986
class TestRevoked(object):

0 commit comments

Comments
 (0)