summaryrefslogtreecommitdiff
path: root/src/OpenSSL
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2021-10-04 16:22:33 +0800
committerGitHub <noreply@github.com>2021-10-04 01:22:33 -0700
commita42ec20880d44150022b8cd9c852fff6cca2dcaa (patch)
tree8cf9b1fdbd21fd50ebb07d9cf684bbfb40a7e764 /src/OpenSSL
parent91d670ff9353e1040ff87e369f3098167bd86ee0 (diff)
downloadpyopenssl-a42ec20880d44150022b8cd9c852fff6cca2dcaa.tar.gz
py27 going, going, gone (#1047)
* py27 going, going, gone * black * more black * ok then * forgot to remove pypy2
Diffstat (limited to 'src/OpenSSL')
-rw-r--r--src/OpenSSL/SSL.py36
-rw-r--r--src/OpenSSL/_util.py32
-rw-r--r--src/OpenSSL/crypto.py44
3 files changed, 43 insertions, 69 deletions
diff --git a/src/OpenSSL/SSL.py b/src/OpenSSL/SSL.py
index e71b044..59f21ce 100644
--- a/src/OpenSSL/SSL.py
+++ b/src/OpenSSL/SSL.py
@@ -6,8 +6,6 @@ from itertools import count, chain
from weakref import WeakValueDictionary
from errno import errorcode
-from six import integer_types, int2byte, indexbytes
-
from OpenSSL._util import (
UNSPECIFIED as _UNSPECIFIED,
exception_from_error_queue as _exception_from_error_queue,
@@ -381,7 +379,7 @@ class _ALPNSelectHelper(_CallbackExceptionHelper):
instr = _ffi.buffer(in_, inlen)[:]
protolist = []
while instr:
- encoded_len = indexbytes(instr, 0)
+ encoded_len = instr[0]
proto = instr[1 : encoded_len + 1]
protolist.append(proto)
instr = instr[encoded_len + 1 :]
@@ -551,15 +549,15 @@ class _OCSPClientCallbackHelper(_CallbackExceptionHelper):
def _asFileDescriptor(obj):
fd = None
- if not isinstance(obj, integer_types):
+ if not isinstance(obj, int):
meth = getattr(obj, "fileno", None)
if meth is not None:
obj = meth()
- if isinstance(obj, integer_types):
+ if isinstance(obj, int):
fd = obj
- if not isinstance(fd, integer_types):
+ if not isinstance(fd, int):
raise TypeError("argument must be an int, or have a fileno() method.")
elif fd < 0:
raise ValueError(
@@ -653,7 +651,7 @@ class Context(object):
)
def __init__(self, method):
- if not isinstance(method, integer_types):
+ if not isinstance(method, int):
raise TypeError("method must be an integer")
try:
@@ -897,7 +895,7 @@ class Context(object):
:return: None
"""
certfile = _path_string(certfile)
- if not isinstance(filetype, integer_types):
+ if not isinstance(filetype, int):
raise TypeError("filetype must be an integer")
use_result = _lib.SSL_CTX_use_certificate_file(
@@ -958,7 +956,7 @@ class Context(object):
if filetype is _UNSPECIFIED:
filetype = FILETYPE_PEM
- elif not isinstance(filetype, integer_types):
+ elif not isinstance(filetype, int):
raise TypeError("filetype must be an integer")
use_result = _lib.SSL_CTX_use_PrivateKey_file(
@@ -1035,7 +1033,7 @@ class Context(object):
.. versionadded:: 0.14
"""
- if not isinstance(mode, integer_types):
+ if not isinstance(mode, int):
raise TypeError("mode must be an integer")
return _lib.SSL_CTX_set_session_cache_mode(self._context, mode)
@@ -1070,7 +1068,7 @@ class Context(object):
See SSL_CTX_set_verify(3SSL) for further details.
"""
- if not isinstance(mode, integer_types):
+ if not isinstance(mode, int):
raise TypeError("mode must be an integer")
if callback is None:
@@ -1093,7 +1091,7 @@ class Context(object):
:param depth: An integer specifying the verify depth
:return: None
"""
- if not isinstance(depth, integer_types):
+ if not isinstance(depth, int):
raise TypeError("depth must be an integer")
_lib.SSL_CTX_set_verify_depth(self._context, depth)
@@ -1253,7 +1251,7 @@ class Context(object):
:param timeout: The timeout in (whole) seconds
:return: The previous session timeout
"""
- if not isinstance(timeout, integer_types):
+ if not isinstance(timeout, int):
raise TypeError("timeout must be an integer")
return _lib.SSL_CTX_set_timeout(self._context, timeout)
@@ -1356,7 +1354,7 @@ class Context(object):
:param options: The options to add.
:return: The new option bitmask.
"""
- if not isinstance(options, integer_types):
+ if not isinstance(options, int):
raise TypeError("options must be an integer")
return _lib.SSL_CTX_set_options(self._context, options)
@@ -1369,7 +1367,7 @@ class Context(object):
:param mode: The mode to add.
:return: The new mode bitmask.
"""
- if not isinstance(mode, integer_types):
+ if not isinstance(mode, int):
raise TypeError("mode must be an integer")
return _lib.SSL_CTX_set_mode(self._context, mode)
@@ -1426,7 +1424,7 @@ class Context(object):
# Take the list of protocols and join them together, prefixing them
# with their lengths.
protostr = b"".join(
- chain.from_iterable((int2byte(len(p)), p) for p in protos)
+ chain.from_iterable((bytes((len(p),)), p) for p in protos)
)
# Build a C string from the list. We don't need to save this off
@@ -1839,7 +1837,7 @@ class Connection(object):
if self._from_ssl is None:
raise TypeError("Connection sock was not None")
- if not isinstance(bufsiz, integer_types):
+ if not isinstance(bufsiz, int):
raise TypeError("bufsiz must be an integer")
buf = _no_zero_allocator("char[]", bufsiz)
@@ -2070,7 +2068,7 @@ class Connection(object):
:param state: bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN.
:return: None
"""
- if not isinstance(state, integer_types):
+ if not isinstance(state, int):
raise TypeError("state must be an integer")
_lib.SSL_set_shutdown(self._ssl, state)
@@ -2454,7 +2452,7 @@ class Connection(object):
# Take the list of protocols and join them together, prefixing them
# with their lengths.
protostr = b"".join(
- chain.from_iterable((int2byte(len(p)), p) for p in protos)
+ chain.from_iterable((bytes((len(p),)), p) for p in protos)
)
# Build a C string from the list. We don't need to save this off
diff --git a/src/OpenSSL/_util.py b/src/OpenSSL/_util.py
index 53c0b9e..8235f5b 100644
--- a/src/OpenSSL/_util.py
+++ b/src/OpenSSL/_util.py
@@ -1,8 +1,6 @@
import sys
import warnings
-from six import PY2, text_type
-
from cryptography.hazmat.bindings.openssl.binding import Binding
@@ -83,14 +81,10 @@ def native(s):
:raise TypeError: The input is neither :py:class:`bytes` nor
:py:class:`unicode`.
"""
- if not isinstance(s, (bytes, text_type)):
+ if not isinstance(s, (bytes, str)):
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, bytes):
- return s.decode("utf-8")
+ if isinstance(s, bytes):
+ return s.decode("utf-8")
return s
@@ -105,31 +99,21 @@ def path_string(s):
"""
if isinstance(s, bytes):
return s
- elif isinstance(s, text_type):
+ elif isinstance(s, str):
return s.encode(sys.getfilesystemencoding())
else:
raise TypeError("Path must be represented as bytes or unicode string")
-if PY2:
-
- def byte_string(s):
- return s
-
-
-else:
-
- def byte_string(s):
- return s.encode("charmap")
+def byte_string(s):
+ return s.encode("charmap")
# A marker object to observe whether some optional arguments are passed any
# value or not.
UNSPECIFIED = object()
-_TEXT_WARNING = (
- text_type.__name__ + " for {0} is no longer accepted, use bytes"
-)
+_TEXT_WARNING = "str for {0} is no longer accepted, use bytes"
def text_to_bytes_and_warn(label, obj):
@@ -145,7 +129,7 @@ def text_to_bytes_and_warn(label, obj):
UTF-8 encoding of that text is returned. Otherwise, ``obj`` itself is
returned.
"""
- if isinstance(obj, text_type):
+ if isinstance(obj, str):
warnings.warn(
_TEXT_WARNING.format(label),
category=DeprecationWarning,
diff --git a/src/OpenSSL/crypto.py b/src/OpenSSL/crypto.py
index eda4af6..151d7d1 100644
--- a/src/OpenSSL/crypto.py
+++ b/src/OpenSSL/crypto.py
@@ -5,12 +5,6 @@ from base64 import b16encode
from functools import partial
from operator import __eq__, __ne__, __lt__, __le__, __gt__, __ge__
-from six import (
- integer_types as _integer_types,
- text_type as _text_type,
- PY2 as _PY2,
-)
-
from cryptography import utils, x509
from cryptography.hazmat.primitives.asymmetric import dsa, rsa
@@ -411,18 +405,16 @@ class _EllipticCurve(object):
_curves = None
- if not _PY2:
- # This only necessary on Python 3. Moreover, it is broken on Python 2.
- def __ne__(self, other):
- """
- Implement cooperation with the right-hand side argument of ``!=``.
+ def __ne__(self, other):
+ """
+ Implement cooperation with the right-hand side argument of ``!=``.
- Python 3 seems to have dropped this cooperation in this very narrow
- circumstance.
- """
- if isinstance(other, _EllipticCurve):
- return super(_EllipticCurve, self).__ne__(other)
- return NotImplemented
+ Python 3 seems to have dropped this cooperation in this very narrow
+ circumstance.
+ """
+ if isinstance(other, _EllipticCurve):
+ return super(_EllipticCurve, self).__ne__(other)
+ return NotImplemented
@classmethod
def _load_elliptic_curves(cls, lib):
@@ -602,7 +594,7 @@ class X509Name(object):
_lib.X509_NAME_ENTRY_free(ent)
break
- if isinstance(value, _text_type):
+ if isinstance(value, str):
value = value.encode("utf-8")
add_result = _lib.X509_NAME_add_entry_by_NID(
@@ -1304,7 +1296,7 @@ class X509(object):
:return: :py:data`None`
"""
- if not isinstance(serial, _integer_types):
+ if not isinstance(serial, int):
raise TypeError("serial must be an integer")
hex_serial = hex(serial)[2:]
@@ -1957,7 +1949,7 @@ def load_certificate(type, buffer):
:return: The X509 object
"""
- if isinstance(buffer, _text_type):
+ if isinstance(buffer, str):
buffer = buffer.encode("ascii")
bio = _new_mem_buf(buffer)
@@ -2883,7 +2875,7 @@ def load_publickey(type, buffer):
:return: The PKey object.
:rtype: :class:`PKey`
"""
- if isinstance(buffer, _text_type):
+ if isinstance(buffer, str):
buffer = buffer.encode("ascii")
bio = _new_mem_buf(buffer)
@@ -2919,7 +2911,7 @@ def load_privatekey(type, buffer, passphrase=None):
:return: The PKey object
"""
- if isinstance(buffer, _text_type):
+ if isinstance(buffer, str):
buffer = buffer.encode("ascii")
bio = _new_mem_buf(buffer)
@@ -2980,7 +2972,7 @@ def load_certificate_request(type, buffer):
:param buffer: The buffer the certificate request is stored in
:return: The X509Req object
"""
- if isinstance(buffer, _text_type):
+ if isinstance(buffer, str):
buffer = buffer.encode("ascii")
bio = _new_mem_buf(buffer)
@@ -3109,7 +3101,7 @@ def load_crl(type, buffer):
:return: The PKey object
"""
- if isinstance(buffer, _text_type):
+ if isinstance(buffer, str):
buffer = buffer.encode("ascii")
bio = _new_mem_buf(buffer)
@@ -3138,7 +3130,7 @@ def load_pkcs7_data(type, buffer):
:param buffer: The buffer with the pkcs7 data.
:return: The PKCS7 object
"""
- if isinstance(buffer, _text_type):
+ if isinstance(buffer, str):
buffer = buffer.encode("ascii")
bio = _new_mem_buf(buffer)
@@ -3183,7 +3175,7 @@ def load_pkcs12(buffer, passphrase=None):
"""
passphrase = _text_to_bytes_and_warn("passphrase", passphrase)
- if isinstance(buffer, _text_type):
+ if isinstance(buffer, str):
buffer = buffer.encode("ascii")
bio = _new_mem_buf(buffer)