Skip to content

Commit 94ea39a

Browse files
committed
isort & black
1 parent 585cc31 commit 94ea39a

18 files changed

+38
-122
lines changed

src/cryptojwt/jwe/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@
2222
"ECDH-ES+A192KW",
2323
"ECDH-ES+A256KW",
2424
],
25-
"enc": [
26-
"A128CBC-HS256",
27-
"A192CBC-HS384",
28-
"A256CBC-HS512",
29-
"A128GCM",
30-
"A192GCM",
31-
"A256GCM",
32-
],
25+
"enc": ["A128CBC-HS256", "A192CBC-HS384", "A256CBC-HS512", "A128GCM", "A192GCM", "A256GCM",],
3326
}
3427

3528
DEPRECATED = {

src/cryptojwt/jwe/jwe_ec.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,7 @@ def dec_setup(self, token, key=None, **kwargs):
157157
raise Exception("Unknown key length for algorithm")
158158

159159
self.cek = ecdh_derive_key(
160-
key,
161-
epubkey.pub_key,
162-
apu,
163-
apv,
164-
str(self.headers["enc"]).encode(),
165-
dk_len,
160+
key, epubkey.pub_key, apu, apv, str(self.headers["enc"]).encode(), dk_len,
166161
)
167162
elif self.headers["alg"] in [
168163
"ECDH-ES+A128KW",

src/cryptojwt/jwe/rsa.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ def encrypt(self, msg, key, sign_padding="pkcs1_padding"):
2020
return key.encrypt(
2121
msg,
2222
_padding(
23-
mgf=padding.MGF1(algorithm=_chosen_hash()),
24-
algorithm=_chosen_hash(),
25-
label=None,
23+
mgf=padding.MGF1(algorithm=_chosen_hash()), algorithm=_chosen_hash(), label=None,
2624
),
2725
)
2826

src/cryptojwt/jwk/ec.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from cryptography.hazmat.backends import default_backend
22
from cryptography.hazmat.primitives.asymmetric import ec
3+
34
from cryptojwt.exception import KeyNotFound
45

56
from ..exception import DeSerializationNotPossible

src/cryptojwt/jwk/jwk.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ def key_from_jwk_dict(jwk_dict, private=None):
9393
else:
9494
# Ecdsa public key.
9595
ec_pub_numbers = ec.EllipticCurvePublicNumbers(
96-
base64url_to_long(_jwk_dict["x"]),
97-
base64url_to_long(_jwk_dict["y"]),
98-
curve,
96+
base64url_to_long(_jwk_dict["x"]), base64url_to_long(_jwk_dict["y"]), curve,
9997
)
10098
_jwk_dict["pub_key"] = ec_pub_numbers.public_key(backends.default_backend())
10199
return ECKey(**_jwk_dict)

src/cryptojwt/jwk/rsa.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from cryptography.hazmat.backends import default_backend
55
from cryptography.hazmat.primitives import serialization
66
from cryptography.hazmat.primitives.asymmetric import rsa
7+
78
from cryptojwt.exception import KeyNotFound
89

910
from ..exception import DeSerializationNotPossible

src/cryptojwt/jws/jws.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,7 @@ def verify_json(self, jws, keys=None, allow_none=False, at_least_one=False):
321321
for _sign in _signs:
322322
protected_headers = _sign.get("protected", "")
323323
token = b".".join(
324-
[
325-
protected_headers.encode(),
326-
_payload.encode(),
327-
_sign["signature"].encode(),
328-
]
324+
[protected_headers.encode(), _payload.encode(), _sign["signature"].encode(),]
329325
)
330326

331327
unprotected_headers = _sign.get("header", {})

src/cryptojwt/jws/pss.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def sign(self, msg, key):
3838
sig = key.sign(
3939
digest,
4040
padding.PSS(
41-
mgf=padding.MGF1(self.hash_algorithm()),
42-
salt_length=padding.PSS.MAX_LENGTH,
41+
mgf=padding.MGF1(self.hash_algorithm()), salt_length=padding.PSS.MAX_LENGTH,
4342
),
4443
utils.Prehashed(self.hash_algorithm()),
4544
)
@@ -60,8 +59,7 @@ def verify(self, msg, signature, key):
6059
signature,
6160
msg,
6261
padding.PSS(
63-
mgf=padding.MGF1(self.hash_algorithm()),
64-
salt_length=padding.PSS.MAX_LENGTH,
62+
mgf=padding.MGF1(self.hash_algorithm()), salt_length=padding.PSS.MAX_LENGTH,
6563
),
6664
self.hash_algorithm(),
6765
)

src/cryptojwt/key_bundle.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,7 @@ def do_remote(self):
484484
self.time_out = time.time() + self.cache_time
485485
else:
486486
LOGGER.warning(
487-
"HTTP status %d reading remote JWKS from %s",
488-
_http_resp.status_code,
489-
self.source,
487+
"HTTP status %d reading remote JWKS from %s", _http_resp.status_code, self.source,
490488
)
491489
self.ignore_errors_until = time.time() + self.ignore_errors_period
492490
raise UpdateFailed(REMOTE_FAILED.format(self.source, _http_resp.status_code))

src/cryptojwt/key_jar.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,7 @@ def dumps(self, exclude_issuers: Optional[List[str]] = None):
690690
return json.dumps(_dict)
691691

692692
def load(
693-
self,
694-
info: dict,
695-
init_args: Optional[dict] = None,
696-
load_args: Optional[dict] = None,
693+
self, info: dict, init_args: Optional[dict] = None, load_args: Optional[dict] = None,
697694
):
698695
"""
699696
@@ -814,11 +811,7 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, issuer_id=""):
814811

815812
@deprecated_alias(issuer="issuer_id", owner="issuer_id")
816813
def init_key_jar(
817-
public_path="",
818-
private_path="",
819-
key_defs="",
820-
issuer_id="",
821-
read_only=True,
814+
public_path="", private_path="", key_defs="", issuer_id="", read_only=True,
822815
):
823816
"""
824817
A number of cases here:
@@ -860,10 +853,7 @@ def init_key_jar(
860853
"""
861854

862855
_issuer = init_key_issuer(
863-
public_path=public_path,
864-
private_path=private_path,
865-
key_defs=key_defs,
866-
read_only=read_only,
856+
public_path=public_path, private_path=private_path, key_defs=key_defs, read_only=read_only,
867857
)
868858

869859
if _issuer is None:

src/cryptojwt/tools/keyconv.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ def pem2jwk(
115115

116116

117117
def export_jwk(
118-
jwk: JWK,
119-
private: bool = False,
120-
encrypt: bool = False,
121-
passphrase: Optional[str] = None,
118+
jwk: JWK, private: bool = False, encrypt: bool = False, passphrase: Optional[str] = None,
122119
) -> bytes:
123120
"""Export JWK as PEM/bin"""
124121

tests/test_01_simplejwt.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ def _eq(l1, l2):
1010
def test_pack_jwt():
1111
_jwt = SimpleJWT(**{"alg": "none", "cty": "jwt"})
1212
jwt = _jwt.pack(
13-
parts=[
14-
{"iss": "joe", "exp": 1300819380, "http://example.com/is_root": True},
15-
"",
16-
]
13+
parts=[{"iss": "joe", "exp": 1300819380, "http://example.com/is_root": True}, "",]
1714
)
1815

1916
p = jwt.split(".")

tests/test_02_jwk.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def test_verify_2():
171171
assert _key.verify()
172172
assert _key.key_len() == 1024 # default
173173

174+
174175
def test_cmp_rsa():
175176
_key1 = RSAKey()
176177
_key1.load_key(import_rsa_key_from_cert_file(CERT))
@@ -202,6 +203,7 @@ def test_new_ec_key():
202203
assert isinstance(ec_key, ECKey)
203204
assert ec_key.key_len() == 256
204205

206+
205207
def test_create_eckey():
206208
ec = new_ec_key("P-256")
207209
exp_key = ec.serialize()
@@ -631,6 +633,7 @@ def test_mint_new_sym_key():
631633
assert len(key.key) == 24
632634
assert key.key_len() == 24
633635

636+
634637
def test_dump_load():
635638
_ckey = import_rsa_key_from_cert_file(CERT)
636639
_key = jwk_wrap(_ckey, "sig", "kid1")
@@ -717,10 +720,7 @@ def test_x5t_calculation():
717720

718721
@pytest.mark.parametrize(
719722
"filename,key_type",
720-
[
721-
("ec-public.pem", ec.EllipticCurvePublicKey),
722-
("rsa-public.pem", rsa.RSAPublicKey),
723-
],
723+
[("ec-public.pem", ec.EllipticCurvePublicKey), ("rsa-public.pem", rsa.RSAPublicKey),],
724724
)
725725
def test_import_public_key_from_pem_file(filename, key_type):
726726
_file = full_path(filename)

tests/test_04_key_issuer.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,7 @@ def test_build_keyissuer_usage():
222222

223223
def test_build_keyissuer_missing(tmpdir):
224224
keys = [
225-
{
226-
"type": "RSA",
227-
"key": os.path.join(tmpdir.dirname, "missing_file"),
228-
"use": ["enc", "sig"],
229-
}
225+
{"type": "RSA", "key": os.path.join(tmpdir.dirname, "missing_file"), "use": ["enc", "sig"],}
230226
]
231227

232228
key_issuer = build_keyissuer(keys)
@@ -244,11 +240,7 @@ def test_build_RSA_keyissuer_from_file(tmpdir):
244240

245241
def test_build_EC_keyissuer_missing(tmpdir):
246242
keys = [
247-
{
248-
"type": "EC",
249-
"key": os.path.join(tmpdir.dirname, "missing_file"),
250-
"use": ["enc", "sig"],
251-
}
243+
{"type": "EC", "key": os.path.join(tmpdir.dirname, "missing_file"), "use": ["enc", "sig"],}
252244
]
253245

254246
key_issuer = build_keyissuer(keys)
@@ -625,10 +617,7 @@ def test_init_key_issuer_update():
625617

626618
# New set of keys, JWKSs with keys and public written to file
627619
_keyissuer_1 = init_key_issuer(
628-
private_path=PRIVATE_FILE,
629-
key_defs=KEYSPEC,
630-
public_path=PUBLIC_FILE,
631-
read_only=False,
620+
private_path=PRIVATE_FILE, key_defs=KEYSPEC, public_path=PUBLIC_FILE, read_only=False,
632621
)
633622
assert len(_keyissuer_1) == 2
634623

@@ -658,10 +647,7 @@ def test_init_key_issuer_update():
658647
assert len(_keyissuer_3.get("sig", "EC")) == 1
659648

660649
_keyissuer_4 = init_key_issuer(
661-
private_path=PRIVATE_FILE,
662-
key_defs=KEYSPEC_2,
663-
public_path=PUBLIC_FILE,
664-
read_only=False,
650+
private_path=PRIVATE_FILE, key_defs=KEYSPEC_2, public_path=PUBLIC_FILE, read_only=False,
665651
)
666652

667653
# Now it should

tests/test_04_key_jar.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,7 @@ def test_build_keyjar_usage():
229229

230230
def test_build_keyjar_missing(tmpdir):
231231
keys = [
232-
{
233-
"type": "RSA",
234-
"key": os.path.join(tmpdir.dirname, "missing_file"),
235-
"use": ["enc", "sig"],
236-
}
232+
{"type": "RSA", "key": os.path.join(tmpdir.dirname, "missing_file"), "use": ["enc", "sig"],}
237233
]
238234

239235
key_jar = build_keyjar(keys)
@@ -251,11 +247,7 @@ def test_build_RSA_keyjar_from_file(tmpdir):
251247

252248
def test_build_EC_keyjar_missing(tmpdir):
253249
keys = [
254-
{
255-
"type": "EC",
256-
"key": os.path.join(tmpdir.dirname, "missing_file"),
257-
"use": ["enc", "sig"],
258-
}
250+
{"type": "EC", "key": os.path.join(tmpdir.dirname, "missing_file"), "use": ["enc", "sig"],}
259251
]
260252

261253
key_jar = build_keyjar(keys)
@@ -311,8 +303,7 @@ def test_items(self):
311303
),
312304
)
313305
ks.add_kb(
314-
"http://www.example.org",
315-
keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
306+
"http://www.example.org", keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
316307
)
317308

318309
assert len(ks.items()) == 2
@@ -338,8 +329,7 @@ def test_issuer_extra_slash(self):
338329
),
339330
)
340331
ks.add_kb(
341-
"http://www.example.org",
342-
keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
332+
"http://www.example.org", keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
343333
)
344334

345335
assert ks.get("sig", "RSA", "http://www.example.org/")
@@ -365,8 +355,7 @@ def test_issuer_missing_slash(self):
365355
),
366356
)
367357
ks.add_kb(
368-
"http://www.example.org/",
369-
keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
358+
"http://www.example.org/", keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
370359
)
371360

372361
assert ks.get("sig", "RSA", "http://www.example.org")
@@ -392,8 +381,7 @@ def test_get_enc(self):
392381
),
393382
)
394383
ks.add_kb(
395-
"http://www.example.org/",
396-
keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
384+
"http://www.example.org/", keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
397385
)
398386

399387
assert ks.get("enc", "oct")
@@ -419,8 +407,7 @@ def test_get_enc_not_mine(self):
419407
),
420408
)
421409
ks.add_kb(
422-
"http://www.example.org/",
423-
keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
410+
"http://www.example.org/", keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
424411
)
425412

426413
assert ks.get("enc", "oct", "http://www.example.org/")
@@ -462,8 +449,7 @@ def test_provider(self):
462449
kj = KeyJar()
463450
_url = "https://connect-op.herokuapp.com/jwks.json"
464451
kj.load_keys(
465-
"https://connect-op.heroku.com",
466-
jwks_uri=_url,
452+
"https://connect-op.heroku.com", jwks_uri=_url,
467453
)
468454
iss_keys = kj.get_issuer_keys("https://connect-op.heroku.com")
469455
if not iss_keys:
@@ -988,10 +974,7 @@ def test_init_key_jar_update():
988974
assert len(_keyjar_3.get_signing_key("EC")) == 1
989975

990976
_keyjar_4 = init_key_jar(
991-
private_path=PRIVATE_FILE,
992-
key_defs=KEYSPEC_2,
993-
public_path=PUBLIC_FILE,
994-
read_only=False,
977+
private_path=PRIVATE_FILE, key_defs=KEYSPEC_2, public_path=PUBLIC_FILE, read_only=False,
995978
)
996979

997980
# Now it should

tests/test_06_jws.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,7 @@ def test_jws_mm():
431431

432432

433433
@pytest.mark.parametrize(
434-
"ec_func,alg",
435-
[(ec.SECP256R1, "ES256"), (ec.SECP384R1, "ES384"), (ec.SECP521R1, "ES512")],
434+
"ec_func,alg", [(ec.SECP256R1, "ES256"), (ec.SECP384R1, "ES384"), (ec.SECP521R1, "ES512")],
436435
)
437436
def test_signer_es(ec_func, alg):
438437
payload = "Please take a moment to register today"
@@ -707,9 +706,7 @@ def test_sign_json_dont_flatten_if_multiple_signatures():
707706
key = ECKey().load_key(P256())
708707
unprotected_headers = {"foo": "bar"}
709708
_jwt = JWS(msg="hello world", alg="ES256").sign_json(
710-
headers=[(None, unprotected_headers), (None, {"abc": "xyz"})],
711-
keys=[key],
712-
flatten=True,
709+
headers=[(None, unprotected_headers), (None, {"abc": "xyz"})], keys=[key], flatten=True,
713710
)
714711
assert "signatures" in json.loads(_jwt)
715712

0 commit comments

Comments
 (0)