Skip to content

Commit e8458ff

Browse files
committed
Drop Python 2
1 parent 7d4e567 commit e8458ff

38 files changed

+139
-284
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
),
8080
include_package_data=True,
8181
python_requires=">=3.6",
82-
install_requires=["six >= 1.4.1"] + setup_requirements,
82+
install_requires=setup_requirements,
8383
setup_requires=setup_requirements,
8484
extras_require={
8585
"test": [

src/cryptography/fernet.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import struct
1111
import time
1212

13-
import six
14-
1513
from cryptography import utils
1614
from cryptography.exceptions import InvalidSignature
1715
from cryptography.hazmat.backends import _get_backend
@@ -97,7 +95,7 @@ def _get_unverified_token_data(token):
9795
except (TypeError, binascii.Error):
9896
raise InvalidToken
9997

100-
if not data or six.indexbytes(data, 0) != 0x80:
98+
if not data or data[0] != 0x80:
10199
raise InvalidToken
102100

103101
try:

src/cryptography/hazmat/_der.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
from __future__ import absolute_import, division, print_function
66

7-
import six
8-
97
from cryptography.utils import int_from_bytes, int_to_bytes
108

119

@@ -53,7 +51,7 @@ def check_empty(self):
5351
def read_byte(self):
5452
if len(self.data) < 1:
5553
raise ValueError("Invalid DER input: insufficient data")
56-
ret = six.indexbytes(self.data, 0)
54+
ret = self.data[0]
5755
self.data = self.data[1:]
5856
return ret
5957

@@ -111,20 +109,20 @@ def read_single_element(self, expected_tag):
111109
return self.read_element(expected_tag)
112110

113111
def read_optional_element(self, expected_tag):
114-
if len(self.data) > 0 and six.indexbytes(self.data, 0) == expected_tag:
112+
if len(self.data) > 0 and self.data[0] == expected_tag:
115113
return self.read_element(expected_tag)
116114
return None
117115

118116
def as_integer(self):
119117
if len(self.data) == 0:
120118
raise ValueError("Invalid DER input: empty integer contents")
121-
first = six.indexbytes(self.data, 0)
119+
first = self.data[0]
122120
if first & 0x80 == 0x80:
123121
raise ValueError("Negative DER integers are not supported")
124122
# The first 9 bits must not all be zero or all be ones. Otherwise, the
125123
# encoding should have been one byte shorter.
126124
if len(self.data) > 1:
127-
second = six.indexbytes(self.data, 1)
125+
second = self.data[1]
128126
if first == 0 and second & 0x80 == 0:
129127
raise ValueError(
130128
"Invalid DER input: integer not minimally-encoded"
@@ -133,7 +131,7 @@ def as_integer(self):
133131

134132

135133
def encode_der_integer(x):
136-
if not isinstance(x, six.integer_types):
134+
if not isinstance(x, int):
137135
raise ValueError("Value must be an integer")
138136
if x < 0:
139137
raise ValueError("Negative integers are not supported")
@@ -145,12 +143,12 @@ def encode_der(tag, *children):
145143
length = 0
146144
for child in children:
147145
length += len(child)
148-
chunks = [six.int2byte(tag)]
146+
chunks = [bytes([tag])]
149147
if length < 0x80:
150-
chunks.append(six.int2byte(length))
148+
chunks.append(bytes([length]))
151149
else:
152150
length_bytes = int_to_bytes(length)
153-
chunks.append(six.int2byte(0x80 | len(length_bytes)))
151+
chunks.append(bytes([0x80 | len(length_bytes)]))
154152
chunks.append(length_bytes)
155153
chunks.extend(children)
156154
return b"".join(chunks)

src/cryptography/hazmat/backends/interfaces.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66

77
import abc
88

9-
import six
109

11-
12-
@six.add_metaclass(abc.ABCMeta)
13-
class CipherBackend(object):
10+
class CipherBackend(metaclass=abc.ABCMeta):
1411
@abc.abstractmethod
1512
def cipher_supported(self, cipher, mode):
1613
"""
@@ -30,8 +27,7 @@ def create_symmetric_decryption_ctx(self, cipher, mode):
3027
"""
3128

3229

33-
@six.add_metaclass(abc.ABCMeta)
34-
class HashBackend(object):
30+
class HashBackend(metaclass=abc.ABCMeta):
3531
@abc.abstractmethod
3632
def hash_supported(self, algorithm):
3733
"""
@@ -45,8 +41,7 @@ def create_hash_ctx(self, algorithm):
4541
"""
4642

4743

48-
@six.add_metaclass(abc.ABCMeta)
49-
class HMACBackend(object):
44+
class HMACBackend(metaclass=abc.ABCMeta):
5045
@abc.abstractmethod
5146
def hmac_supported(self, algorithm):
5247
"""
@@ -61,8 +56,7 @@ def create_hmac_ctx(self, key, algorithm):
6156
"""
6257

6358

64-
@six.add_metaclass(abc.ABCMeta)
65-
class CMACBackend(object):
59+
class CMACBackend(metaclass=abc.ABCMeta):
6660
@abc.abstractmethod
6761
def cmac_algorithm_supported(self, algorithm):
6862
"""
@@ -76,8 +70,7 @@ def create_cmac_ctx(self, algorithm):
7670
"""
7771

7872

79-
@six.add_metaclass(abc.ABCMeta)
80-
class PBKDF2HMACBackend(object):
73+
class PBKDF2HMACBackend(metaclass=abc.ABCMeta):
8174
@abc.abstractmethod
8275
def pbkdf2_hmac_supported(self, algorithm):
8376
"""
@@ -94,8 +87,7 @@ def derive_pbkdf2_hmac(
9487
"""
9588

9689

97-
@six.add_metaclass(abc.ABCMeta)
98-
class RSABackend(object):
90+
class RSABackend(metaclass=abc.ABCMeta):
9991
@abc.abstractmethod
10092
def generate_rsa_private_key(self, public_exponent, key_size):
10193
"""
@@ -129,8 +121,7 @@ def load_rsa_public_numbers(self, numbers):
129121
"""
130122

131123

132-
@six.add_metaclass(abc.ABCMeta)
133-
class DSABackend(object):
124+
class DSABackend(metaclass=abc.ABCMeta):
134125
@abc.abstractmethod
135126
def generate_dsa_parameters(self, key_size):
136127
"""
@@ -181,8 +172,7 @@ def load_dsa_parameter_numbers(self, numbers):
181172
"""
182173

183174

184-
@six.add_metaclass(abc.ABCMeta)
185-
class EllipticCurveBackend(object):
175+
class EllipticCurveBackend(metaclass=abc.ABCMeta):
186176
@abc.abstractmethod
187177
def elliptic_curve_signature_algorithm_supported(
188178
self, signature_algorithm, curve
@@ -229,8 +219,7 @@ def derive_elliptic_curve_private_key(self, private_value, curve):
229219
"""
230220

231221

232-
@six.add_metaclass(abc.ABCMeta)
233-
class PEMSerializationBackend(object):
222+
class PEMSerializationBackend(metaclass=abc.ABCMeta):
234223
@abc.abstractmethod
235224
def load_pem_private_key(self, data, password):
236225
"""
@@ -251,8 +240,7 @@ def load_pem_parameters(self, data):
251240
"""
252241

253242

254-
@six.add_metaclass(abc.ABCMeta)
255-
class DERSerializationBackend(object):
243+
class DERSerializationBackend(metaclass=abc.ABCMeta):
256244
@abc.abstractmethod
257245
def load_der_private_key(self, data, password):
258246
"""
@@ -273,8 +261,7 @@ def load_der_parameters(self, data):
273261
"""
274262

275263

276-
@six.add_metaclass(abc.ABCMeta)
277-
class X509Backend(object):
264+
class X509Backend(metaclass=abc.ABCMeta):
278265
@abc.abstractmethod
279266
def load_pem_x509_certificate(self, data):
280267
"""
@@ -332,8 +319,7 @@ def x509_name_bytes(self, name):
332319
"""
333320

334321

335-
@six.add_metaclass(abc.ABCMeta)
336-
class DHBackend(object):
322+
class DHBackend(metaclass=abc.ABCMeta):
337323
@abc.abstractmethod
338324
def generate_dh_parameters(self, generator, key_size):
339325
"""
@@ -387,8 +373,7 @@ def dh_x942_serialization_supported(self):
387373
"""
388374

389375

390-
@six.add_metaclass(abc.ABCMeta)
391-
class ScryptBackend(object):
376+
class ScryptBackend(metaclass=abc.ABCMeta):
392377
@abc.abstractmethod
393378
def derive_scrypt(self, key_material, salt, length, n, r, p):
394379
"""

src/cryptography/hazmat/backends/openssl/backend.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import warnings
1111
from contextlib import contextmanager
1212

13-
from six.moves import range
14-
1513
from cryptography import utils, x509
1614
from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
1715
from cryptography.hazmat._der import (

src/cryptography/hazmat/backends/openssl/decode_asn1.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import datetime
88
import ipaddress
99

10-
import six
11-
1210
from cryptography import x509
1311
from cryptography.hazmat._der import DERReader, INTEGER, NULL, SEQUENCE
1412
from cryptography.x509.extensions import _TLS_FEATURE_TYPE_TO_ENUM
@@ -595,7 +593,7 @@ def _decode_dist_points(backend, cdps):
595593
def _decode_reasons(backend, reasons):
596594
# We will check each bit from RFC 5280
597595
enum_reasons = []
598-
for bit_position, reason in six.iteritems(_REASON_BIT_MAPPING):
596+
for bit_position, reason in _REASON_BIT_MAPPING.items():
599597
if backend._lib.ASN1_BIT_STRING_get_bit(reasons, bit_position):
600598
enum_reasons.append(reason)
601599

src/cryptography/hazmat/backends/openssl/encode_asn1.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import calendar
88
import ipaddress
99

10-
import six
11-
1210
from cryptography import utils, x509
1311
from cryptography.hazmat.backends.openssl.decode_asn1 import (
1412
_CRL_ENTRY_REASON_ENUM_TO_CODE,
@@ -206,7 +204,7 @@ def _encode_certificate_policies(backend, certificate_policies):
206204
backend.openssl_assert(pqi != backend._ffi.NULL)
207205
res = backend._lib.sk_POLICYQUALINFO_push(pqis, pqi)
208206
backend.openssl_assert(res >= 1)
209-
if isinstance(qualifier, six.text_type):
207+
if isinstance(qualifier, str):
210208
pqi.pqualid = _txt2obj(
211209
backend, x509.OID_CPS_QUALIFIER.dotted_string
212210
)

src/cryptography/hazmat/primitives/asymmetric/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66

77
import abc
88

9-
import six
109

11-
12-
@six.add_metaclass(abc.ABCMeta)
13-
class AsymmetricSignatureContext(object):
10+
class AsymmetricSignatureContext(metaclass=abc.ABCMeta):
1411
@abc.abstractmethod
1512
def update(self, data):
1613
"""
@@ -24,8 +21,7 @@ def finalize(self):
2421
"""
2522

2623

27-
@six.add_metaclass(abc.ABCMeta)
28-
class AsymmetricVerificationContext(object):
24+
class AsymmetricVerificationContext(metaclass=abc.ABCMeta):
2925
@abc.abstractmethod
3026
def update(self, data):
3127
"""

src/cryptography/hazmat/primitives/asymmetric/dh.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import abc
88

9-
import six
10-
119
from cryptography import utils
1210
from cryptography.hazmat.backends import _get_backend
1311

@@ -22,7 +20,7 @@ def generate_parameters(generator, key_size, backend=None):
2220

2321
class DHPrivateNumbers(object):
2422
def __init__(self, x, public_numbers):
25-
if not isinstance(x, six.integer_types):
23+
if not isinstance(x, int):
2624
raise TypeError("x must be an integer.")
2725

2826
if not isinstance(public_numbers, DHPublicNumbers):
@@ -55,7 +53,7 @@ def private_key(self, backend=None):
5553

5654
class DHPublicNumbers(object):
5755
def __init__(self, y, parameter_numbers):
58-
if not isinstance(y, six.integer_types):
56+
if not isinstance(y, int):
5957
raise TypeError("y must be an integer.")
6058

6159
if not isinstance(parameter_numbers, DHParameterNumbers):
@@ -88,11 +86,11 @@ def public_key(self, backend=None):
8886

8987
class DHParameterNumbers(object):
9088
def __init__(self, p, g, q=None):
91-
if not isinstance(p, six.integer_types) or not isinstance(
92-
g, six.integer_types
89+
if not isinstance(p, int) or not isinstance(
90+
g, int
9391
):
9492
raise TypeError("p and g must be integers")
95-
if q is not None and not isinstance(q, six.integer_types):
93+
if q is not None and not isinstance(q, int):
9694
raise TypeError("q must be integer or None")
9795

9896
if g < 2:
@@ -127,8 +125,7 @@ def parameters(self, backend=None):
127125
q = utils.read_only_property("_q")
128126

129127

130-
@six.add_metaclass(abc.ABCMeta)
131-
class DHParameters(object):
128+
class DHParameters(metaclass=abc.ABCMeta):
132129
@abc.abstractmethod
133130
def generate_private_key(self):
134131
"""
@@ -151,8 +148,7 @@ def parameter_numbers(self):
151148
DHParametersWithSerialization = DHParameters
152149

153150

154-
@six.add_metaclass(abc.ABCMeta)
155-
class DHPrivateKey(object):
151+
class DHPrivateKey(metaclass=abc.ABCMeta):
156152
@abc.abstractproperty
157153
def key_size(self):
158154
"""
@@ -179,8 +175,7 @@ def exchange(self, peer_public_key):
179175
"""
180176

181177

182-
@six.add_metaclass(abc.ABCMeta)
183-
class DHPrivateKeyWithSerialization(DHPrivateKey):
178+
class DHPrivateKeyWithSerialization(DHPrivateKey, metaclass=abc.ABCMeta):
184179
@abc.abstractmethod
185180
def private_numbers(self):
186181
"""
@@ -194,8 +189,7 @@ def private_bytes(self, encoding, format, encryption_algorithm):
194189
"""
195190

196191

197-
@six.add_metaclass(abc.ABCMeta)
198-
class DHPublicKey(object):
192+
class DHPublicKey(metaclass=abc.ABCMeta):
199193
@abc.abstractproperty
200194
def key_size(self):
201195
"""

0 commit comments

Comments
 (0)