|
1 | | -from __future__ import division |
2 | | - |
3 | 1 | import math |
4 | 2 | import warnings |
5 | 3 |
|
@@ -79,10 +77,10 @@ def __init__(self, key, algorithm, cryptography_backend=default_backend): |
79 | 77 | self.prepared_key = self._process_jwk(key) |
80 | 78 | return |
81 | 79 |
|
82 | | - if isinstance(key, six.string_types): |
| 80 | + if isinstance(key, str): |
83 | 81 | key = key.encode('utf-8') |
84 | 82 |
|
85 | | - if isinstance(key, six.binary_type): |
| 83 | + if isinstance(key, bytes): |
86 | 84 | # Attempt to load key. We don't know if it's |
87 | 85 | # a Public Key or a Private Key, so we try |
88 | 86 | # the Public Key first. |
@@ -258,10 +256,10 @@ def __init__(self, key, algorithm, cryptography_backend=default_backend): |
258 | 256 | self.prepared_key = self._process_jwk(key) |
259 | 257 | return |
260 | 258 |
|
261 | | - if isinstance(key, six.string_types): |
| 259 | + if isinstance(key, str): |
262 | 260 | key = key.encode('utf-8') |
263 | 261 |
|
264 | | - if isinstance(key, six.binary_type): |
| 262 | + if isinstance(key, bytes): |
265 | 263 | try: |
266 | 264 | if key.startswith(b'-----BEGIN CERTIFICATE-----'): |
267 | 265 | self._process_cert(key) |
@@ -468,15 +466,15 @@ def __init__(self, key, algorithm): |
468 | 466 | self._mode = self.MODES.get(self._algorithm) |
469 | 467 |
|
470 | 468 | if algorithm in self.KEY_128 and len(key) != 16: |
471 | | - raise JWKError("Key must be 128 bit for alg {}".format(algorithm)) |
| 469 | + raise JWKError(f"Key must be 128 bit for alg {algorithm}") |
472 | 470 | elif algorithm in self.KEY_192 and len(key) != 24: |
473 | | - raise JWKError("Key must be 192 bit for alg {}".format(algorithm)) |
| 471 | + raise JWKError(f"Key must be 192 bit for alg {algorithm}") |
474 | 472 | elif algorithm in self.KEY_256 and len(key) != 32: |
475 | | - raise JWKError("Key must be 256 bit for alg {}".format(algorithm)) |
| 473 | + raise JWKError(f"Key must be 256 bit for alg {algorithm}") |
476 | 474 | elif algorithm in self.KEY_384 and len(key) != 48: |
477 | | - raise JWKError("Key must be 384 bit for alg {}".format(algorithm)) |
| 475 | + raise JWKError(f"Key must be 384 bit for alg {algorithm}") |
478 | 476 | elif algorithm in self.KEY_512 and len(key) != 64: |
479 | | - raise JWKError("Key must be 512 bit for alg {}".format(algorithm)) |
| 477 | + raise JWKError(f"Key must be 512 bit for alg {algorithm}") |
480 | 478 |
|
481 | 479 | self._key = key |
482 | 480 |
|
@@ -575,10 +573,10 @@ def __init__(self, key, algorithm): |
575 | 573 | self.prepared_key = self._process_jwk(key) |
576 | 574 | return |
577 | 575 |
|
578 | | - if not isinstance(key, six.string_types) and not isinstance(key, bytes): |
| 576 | + if not isinstance(key, str) and not isinstance(key, bytes): |
579 | 577 | raise JWKError('Expecting a string- or bytes-formatted key.') |
580 | 578 |
|
581 | | - if isinstance(key, six.text_type): |
| 579 | + if isinstance(key, str): |
582 | 580 | key = key.encode('utf-8') |
583 | 581 |
|
584 | 582 | invalid_strings = [ |
|
0 commit comments