Skip to content

Commit fd3031a

Browse files
committed
reformat with ruff
1 parent cb9f5d2 commit fd3031a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+199
-334
lines changed

src/cryptojwt/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
from cryptojwt.key_jar import KeyJar
1212

1313
from .exception import BadSyntax
14-
from .utils import as_unicode
15-
from .utils import b64d
16-
from .utils import b64encode_item
17-
from .utils import split_token
14+
from .utils import as_unicode, b64d, b64encode_item, split_token
1815

1916
__version__ = version("cryptojwt")
2017

src/cryptojwt/jwe/aes.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
from struct import pack
33

44
from cryptography.hazmat.primitives import hmac
5-
from cryptography.hazmat.primitives.ciphers import Cipher
6-
from cryptography.hazmat.primitives.ciphers import algorithms
7-
from cryptography.hazmat.primitives.ciphers import modes
5+
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
86
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
97
from cryptography.hazmat.primitives.padding import PKCS7
108

11-
from ..exception import MissingKey
12-
from ..exception import Unsupported
13-
from ..exception import VerificationError
9+
from ..exception import MissingKey, Unsupported, VerificationError
1410
from . import Encrypter
1511
from .exception import UnsupportedBitLength
1612
from .utils import get_keys_seclen_dgst

src/cryptojwt/jwe/fernet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import base64
22
import os
3-
from typing import Optional
4-
from typing import Union
3+
from typing import Optional, Union
54

65
from cryptography.fernet import Fernet
76
from cryptography.hazmat.primitives import hashes

src/cryptojwt/jwe/jwe.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
from ..jwk.hmac import SYMKey
77
from ..jwk.jwk import key_from_jwk_dict
88
from ..jwx import JWx
9-
from .exception import DecryptionFailed
10-
from .exception import NoSuitableDecryptionKey
11-
from .exception import NoSuitableEncryptionKey
12-
from .exception import NotSupportedAlgorithm
13-
from .exception import WrongEncryptionAlgorithm
9+
from .exception import (
10+
DecryptionFailed,
11+
NoSuitableDecryptionKey,
12+
NoSuitableEncryptionKey,
13+
NotSupportedAlgorithm,
14+
WrongEncryptionAlgorithm,
15+
)
1416
from .jwe_ec import JWE_EC
1517
from .jwe_hmac import JWE_SYM
1618
from .jwe_rsa import JWE_RSA

src/cryptojwt/jwe/jwe_ec.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22
import struct
33

44
from cryptography.hazmat.primitives.asymmetric import ec
5-
from cryptography.hazmat.primitives.keywrap import aes_key_unwrap
6-
from cryptography.hazmat.primitives.keywrap import aes_key_wrap
7-
8-
from ..jwk.ec import NIST2SEC
9-
from ..jwk.ec import ECKey
10-
from ..utils import as_bytes
11-
from ..utils import as_unicode
12-
from ..utils import b64d
13-
from ..utils import b64e
5+
from cryptography.hazmat.primitives.keywrap import aes_key_unwrap, aes_key_wrap
6+
7+
from ..jwk.ec import NIST2SEC, ECKey
8+
from ..utils import as_bytes, as_unicode, b64d, b64e
149
from . import KEY_LEN
1510
from .jwekey import JWEKey
1611
from .jwenc import JWEnc
17-
from .utils import concat_sha256
18-
from .utils import get_random_bytes
12+
from .utils import concat_sha256, get_random_bytes
1913

2014

2115
def ecdh_derive_key(key, epk, apu, apv, alg, dk_len):

src/cryptojwt/jwe/jwe_hmac.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
import logging
33
import zlib
44

5-
from cryptography.hazmat.primitives.keywrap import aes_key_unwrap
6-
from cryptography.hazmat.primitives.keywrap import aes_key_wrap
5+
from cryptography.hazmat.primitives.keywrap import aes_key_unwrap, aes_key_wrap
76

8-
from ..exception import MissingKey
9-
from ..exception import WrongNumberOfParts
7+
from ..exception import MissingKey, WrongNumberOfParts
108
from ..jwk.hmac import SYMKey
11-
from ..utils import as_bytes
12-
from ..utils import intarr2str
9+
from ..utils import as_bytes, intarr2str
1310
from .jwekey import JWEKey
1411
from .jwenc import JWEnc
1512

src/cryptojwt/jwe/jwe_rsa.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
from ..utils import as_bytes
55
from . import SUPPORTED
6-
from .exception import NotSupportedAlgorithm
7-
from .exception import ParameterError
6+
from .exception import NotSupportedAlgorithm, ParameterError
87
from .jwekey import JWEKey
98
from .jwenc import JWEnc
109
from .rsa import RSAEncrypter

src/cryptojwt/jwe/jwekey.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
from ..jwx import JWx
22
from . import KEY_LEN_BYTES
3-
from .aes import AES_CBCEncrypter
4-
from .aes import AES_GCMEncrypter
5-
from .exception import DecryptionFailed
6-
from .exception import NotSupportedAlgorithm
7-
from .utils import alg2keytype
8-
from .utils import get_random_bytes
9-
from .utils import split_ctx_and_tag
3+
from .aes import AES_CBCEncrypter, AES_GCMEncrypter
4+
from .exception import DecryptionFailed, NotSupportedAlgorithm
5+
from .utils import alg2keytype, get_random_bytes, split_ctx_and_tag
106

117

128
class JWEKey(JWx):

src/cryptojwt/jwe/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
from math import ceil
44

55
from cryptography.hazmat.primitives import hashes
6-
from cryptography.hazmat.primitives.hashes import SHA256
7-
from cryptography.hazmat.primitives.hashes import SHA384
8-
from cryptography.hazmat.primitives.hashes import SHA512
6+
from cryptography.hazmat.primitives.hashes import SHA256, SHA384, SHA512
97

108
LENMET = {32: (16, SHA256), 48: (24, SHA384), 64: (32, SHA512)}
119

src/cryptojwt/jwk/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
from typing import List
66

77
from ..exception import UnsupportedAlgorithm
8-
from ..utils import as_bytes
9-
from ..utils import as_unicode
10-
from ..utils import b64e
11-
from ..utils import base64url_to_long
8+
from ..utils import as_bytes, as_unicode, b64e, base64url_to_long
129
from .utils import DIGEST_HASH
1310

1411
USE = {"sign": "sig", "decrypt": "enc", "encrypt": "enc", "verify": "sig"}

src/cryptojwt/jwk/asym.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from . import JWK
2-
from . import USE
1+
from . import JWK, USE
32

43

54
class AsymmetricKey(JWK):

src/cryptojwt/jwk/ec.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
from cryptojwt.exception import KeyNotFound
44

5-
from ..exception import DeSerializationNotPossible
6-
from ..exception import JWKESTException
7-
from ..exception import UnsupportedECurve
8-
from ..utils import as_unicode
9-
from ..utils import deser
10-
from ..utils import long_to_base64
5+
from ..exception import DeSerializationNotPossible, JWKESTException, UnsupportedECurve
6+
from ..utils import as_unicode, deser, long_to_base64
117
from .asym import AsymmetricKey
12-
from .x509 import import_private_key_from_pem_file
13-
from .x509 import import_public_key_from_pem_data
14-
from .x509 import import_public_key_from_pem_file
8+
from .x509 import (
9+
import_private_key_from_pem_file,
10+
import_public_key_from_pem_data,
11+
import_public_key_from_pem_file,
12+
)
1513

1614
# This is used to translate between the curve representation in
1715
# Cryptography and the one used by NIST (and in RFC 7518)

src/cryptojwt/jwk/hmac.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@
33

44
from cryptojwt.exception import KeyNotFound
55

6-
from ..exception import JWKException
7-
from ..exception import UnsupportedAlgorithm
8-
from ..exception import WrongUsage
9-
from ..utils import as_bytes
10-
from ..utils import as_unicode
11-
from ..utils import b64d
12-
from ..utils import b64e
13-
from . import JWK
14-
from . import USE
15-
from .utils import sha256_digest
16-
from .utils import sha384_digest
17-
from .utils import sha512_digest
6+
from ..exception import JWKException, UnsupportedAlgorithm, WrongUsage
7+
from ..utils import as_bytes, as_unicode, b64d, b64e
8+
from . import JWK, USE
9+
from .utils import sha256_digest, sha384_digest, sha512_digest
1810

1911
logger = logging.getLogger(__name__)
2012

src/cryptojwt/jwk/jwk.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,12 @@
22
import json
33
import os
44

5-
from cryptography.hazmat.primitives.asymmetric import ec
6-
from cryptography.hazmat.primitives.asymmetric import ed448
7-
from cryptography.hazmat.primitives.asymmetric import ed25519
8-
from cryptography.hazmat.primitives.asymmetric import rsa
9-
from cryptography.hazmat.primitives.asymmetric.rsa import rsa_crt_dmp1
10-
from cryptography.hazmat.primitives.asymmetric.rsa import rsa_crt_dmq1
11-
from cryptography.hazmat.primitives.asymmetric.rsa import rsa_crt_iqmp
12-
13-
from ..exception import MissingValue
14-
from ..exception import UnknownKeyType
15-
from ..exception import UnsupportedAlgorithm
16-
from ..exception import WrongKeyType
5+
from cryptography.hazmat.primitives.asymmetric import ec, ed448, ed25519, rsa
6+
from cryptography.hazmat.primitives.asymmetric.rsa import rsa_crt_dmp1, rsa_crt_dmq1, rsa_crt_iqmp
7+
8+
from ..exception import MissingValue, UnknownKeyType, UnsupportedAlgorithm, WrongKeyType
179
from ..utils import base64url_to_long
18-
from .ec import NIST2SEC
19-
from .ec import ECKey
10+
from .ec import NIST2SEC, ECKey
2011
from .hmac import SYMKey
2112
from .okp import OKPKey
2213
from .rsa import RSAKey

src/cryptojwt/jwk/okp.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
from typing import Union
22

33
from cryptography.hazmat.primitives import serialization
4-
from cryptography.hazmat.primitives.asymmetric import ed448
5-
from cryptography.hazmat.primitives.asymmetric import ed25519
6-
from cryptography.hazmat.primitives.asymmetric import x448
7-
from cryptography.hazmat.primitives.asymmetric import x25519
4+
from cryptography.hazmat.primitives.asymmetric import ed448, ed25519, x448, x25519
85

96
from cryptojwt.exception import KeyNotFound
107

11-
from ..exception import DeSerializationNotPossible
12-
from ..exception import JWKESTException
13-
from ..exception import UnsupportedOKPCurve
14-
from ..utils import b64d
15-
from ..utils import b64e
8+
from ..exception import DeSerializationNotPossible, JWKESTException, UnsupportedOKPCurve
9+
from ..utils import b64d, b64e
1610
from .asym import AsymmetricKey
17-
from .x509 import import_private_key_from_pem_file
18-
from .x509 import import_public_key_from_pem_data
19-
from .x509 import import_public_key_from_pem_file
11+
from .x509 import (
12+
import_private_key_from_pem_file,
13+
import_public_key_from_pem_data,
14+
import_public_key_from_pem_file,
15+
)
2016

2117
OKPPublicKey = Union[
2218
ed25519.Ed25519PublicKey, ed448.Ed448PublicKey, x25519.X25519PublicKey, x448.X448PublicKey

src/cryptojwt/jwk/rsa.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66

77
from cryptojwt.exception import KeyNotFound
88

9-
from ..exception import DeSerializationNotPossible
10-
from ..exception import JWKESTException
11-
from ..exception import SerializationNotPossible
12-
from ..exception import UnsupportedKeyType
13-
from ..utils import as_unicode
14-
from ..utils import deser
15-
from ..utils import long_to_base64
9+
from ..exception import (
10+
DeSerializationNotPossible,
11+
JWKESTException,
12+
SerializationNotPossible,
13+
UnsupportedKeyType,
14+
)
15+
from ..utils import as_unicode, deser, long_to_base64
1616
from . import JWK
1717
from .asym import AsymmetricKey
18-
from .x509 import der_cert
19-
from .x509 import import_private_key_from_pem_file
20-
from .x509 import import_public_key_from_pem_data
21-
from .x509 import import_public_key_from_pem_file
22-
from .x509 import x5t_calculation
18+
from .x509 import (
19+
der_cert,
20+
import_private_key_from_pem_file,
21+
import_public_key_from_pem_data,
22+
import_public_key_from_pem_file,
23+
x5t_calculation,
24+
)
2325

2426
logger = logging.getLogger(__name__)
2527

src/cryptojwt/jwk/x509.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
from cryptography import x509
66
from cryptography.hazmat.primitives import serialization
7-
from cryptography.hazmat.primitives.asymmetric import ec
8-
from cryptography.hazmat.primitives.asymmetric import rsa
7+
from cryptography.hazmat.primitives.asymmetric import ec, rsa
98

109
from cryptojwt.utils import b64e
1110

src/cryptojwt/jws/dsa.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from cryptography.exceptions import InvalidSignature
22
from cryptography.hazmat.primitives import hashes
33
from cryptography.hazmat.primitives.asymmetric import ec
4-
from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature
5-
from cryptography.hazmat.primitives.asymmetric.utils import encode_dss_signature
4+
from cryptography.hazmat.primitives.asymmetric.utils import (
5+
decode_dss_signature,
6+
encode_dss_signature,
7+
)
68

7-
from ..exception import BadSignature
8-
from ..exception import Unsupported
9+
from ..exception import BadSignature, Unsupported
910
from . import Signer
1011

1112

src/cryptojwt/jws/eddsa.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from cryptography.exceptions import InvalidSignature
2-
from cryptography.hazmat.primitives.asymmetric import ed448
3-
from cryptography.hazmat.primitives.asymmetric import ed25519
2+
from cryptography.hazmat.primitives.asymmetric import ed448, ed25519
43

54
from ..exception import BadSignature
65
from . import Signer

src/cryptojwt/jws/hmac.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from cryptography.hazmat.primitives import hashes
2-
from cryptography.hazmat.primitives import hmac
1+
from cryptography.hazmat.primitives import hashes, hmac
32

43
from ..exception import Unsupported
54
from . import Signer

src/cryptojwt/jws/jws.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55

66
from cryptojwt.jws.exception import JWSException
77

8-
from ..exception import BadSignature
9-
from ..exception import UnknownAlgorithm
10-
from ..exception import WrongNumberOfParts
8+
from ..exception import BadSignature, UnknownAlgorithm, WrongNumberOfParts
119
from ..jwk.asym import AsymmetricKey
1210
from ..jwx import JWx
1311
from ..simple_jwt import SimpleJWT
14-
from ..utils import b64d_enc_dec
15-
from ..utils import b64e_enc_dec
16-
from ..utils import b64encode_item
12+
from ..utils import b64d_enc_dec, b64e_enc_dec, b64encode_item
1713
from .dsa import ECDSASigner
1814
from .eddsa import EDDSASigner
19-
from .exception import FormatError
20-
from .exception import NoSuitableSigningKeys
21-
from .exception import SignerAlgError
15+
from .exception import FormatError, NoSuitableSigningKeys, SignerAlgError
2216
from .hmac import HMACSigner
2317
from .pss import PSSSigner
2418
from .rsa import RSASigner

src/cryptojwt/jws/pss.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
from cryptography.exceptions import InvalidSignature
44
from cryptography.hazmat.primitives import hashes
5-
from cryptography.hazmat.primitives.asymmetric import padding
6-
from cryptography.hazmat.primitives.asymmetric import utils
5+
from cryptography.hazmat.primitives.asymmetric import padding, utils
76

8-
from ..exception import BadSignature
9-
from ..exception import Unsupported
7+
from ..exception import BadSignature, Unsupported
108
from . import Signer
119

1210
logger = logging.getLogger(__name__)

src/cryptojwt/jws/utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
from cryptography.hazmat.primitives.asymmetric import padding
55

66
from ..exception import UnsupportedAlgorithm
7-
from ..jwk.hmac import sha256_digest
8-
from ..jwk.hmac import sha384_digest
9-
from ..jwk.hmac import sha512_digest
10-
from ..utils import as_unicode
11-
from ..utils import b64e
7+
from ..jwk.hmac import sha256_digest, sha384_digest, sha512_digest
8+
from ..utils import as_unicode, b64e
129

1310

1411
def left_hash(msg, func="HS256"):

0 commit comments

Comments
 (0)