Skip to content

Commit d7cd0bf

Browse files
committed
isort & black
1 parent 94ea39a commit d7cd0bf

16 files changed

+122
-33
lines changed

src/cryptojwt/jwe/__init__.py

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

2835
DEPRECATED = {

src/cryptojwt/jwe/jwe_ec.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ 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, epubkey.pub_key, apu, apv, str(self.headers["enc"]).encode(), dk_len,
160+
key,
161+
epubkey.pub_key,
162+
apu,
163+
apv,
164+
str(self.headers["enc"]).encode(),
165+
dk_len,
161166
)
162167
elif self.headers["alg"] in [
163168
"ECDH-ES+A128KW",

src/cryptojwt/jwe/rsa.py

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

src/cryptojwt/jwk/jwk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ 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"]), base64url_to_long(_jwk_dict["y"]), curve,
96+
base64url_to_long(_jwk_dict["x"]),
97+
base64url_to_long(_jwk_dict["y"]),
98+
curve,
9799
)
98100
_jwk_dict["pub_key"] = ec_pub_numbers.public_key(backends.default_backend())
99101
return ECKey(**_jwk_dict)

src/cryptojwt/jws/jws.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ 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-
[protected_headers.encode(), _payload.encode(), _sign["signature"].encode(),]
324+
[
325+
protected_headers.encode(),
326+
_payload.encode(),
327+
_sign["signature"].encode(),
328+
]
325329
)
326330

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

src/cryptojwt/jws/pss.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def sign(self, msg, key):
3838
sig = key.sign(
3939
digest,
4040
padding.PSS(
41-
mgf=padding.MGF1(self.hash_algorithm()), salt_length=padding.PSS.MAX_LENGTH,
41+
mgf=padding.MGF1(self.hash_algorithm()),
42+
salt_length=padding.PSS.MAX_LENGTH,
4243
),
4344
utils.Prehashed(self.hash_algorithm()),
4445
)
@@ -59,7 +60,8 @@ def verify(self, msg, signature, key):
5960
signature,
6061
msg,
6162
padding.PSS(
62-
mgf=padding.MGF1(self.hash_algorithm()), salt_length=padding.PSS.MAX_LENGTH,
63+
mgf=padding.MGF1(self.hash_algorithm()),
64+
salt_length=padding.PSS.MAX_LENGTH,
6365
),
6466
self.hash_algorithm(),
6567
)

src/cryptojwt/key_bundle.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,9 @@ 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", _http_resp.status_code, self.source,
487+
"HTTP status %d reading remote JWKS from %s",
488+
_http_resp.status_code,
489+
self.source,
488490
)
489491
self.ignore_errors_until = time.time() + self.ignore_errors_period
490492
raise UpdateFailed(REMOTE_FAILED.format(self.source, _http_resp.status_code))

src/cryptojwt/key_jar.py

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

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

812815
@deprecated_alias(issuer="issuer_id", owner="issuer_id")
813816
def init_key_jar(
814-
public_path="", private_path="", key_defs="", issuer_id="", read_only=True,
817+
public_path="",
818+
private_path="",
819+
key_defs="",
820+
issuer_id="",
821+
read_only=True,
815822
):
816823
"""
817824
A number of cases here:
@@ -853,7 +860,10 @@ def init_key_jar(
853860
"""
854861

855862
_issuer = init_key_issuer(
856-
public_path=public_path, private_path=private_path, key_defs=key_defs, read_only=read_only,
863+
public_path=public_path,
864+
private_path=private_path,
865+
key_defs=key_defs,
866+
read_only=read_only,
857867
)
858868

859869
if _issuer is None:

src/cryptojwt/tools/keyconv.py

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

116116

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

tests/test_01_simplejwt.py

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

1619
p = jwt.split(".")

tests/test_02_jwk.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,10 @@ def test_x5t_calculation():
720720

721721
@pytest.mark.parametrize(
722722
"filename,key_type",
723-
[("ec-public.pem", ec.EllipticCurvePublicKey), ("rsa-public.pem", rsa.RSAPublicKey),],
723+
[
724+
("ec-public.pem", ec.EllipticCurvePublicKey),
725+
("rsa-public.pem", rsa.RSAPublicKey),
726+
],
724727
)
725728
def test_import_public_key_from_pem_file(filename, key_type):
726729
_file = full_path(filename)

tests/test_04_key_issuer.py

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

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

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

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

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

618626
# New set of keys, JWKSs with keys and public written to file
619627
_keyissuer_1 = init_key_issuer(
620-
private_path=PRIVATE_FILE, key_defs=KEYSPEC, public_path=PUBLIC_FILE, read_only=False,
628+
private_path=PRIVATE_FILE,
629+
key_defs=KEYSPEC,
630+
public_path=PUBLIC_FILE,
631+
read_only=False,
621632
)
622633
assert len(_keyissuer_1) == 2
623634

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

649660
_keyissuer_4 = init_key_issuer(
650-
private_path=PRIVATE_FILE, key_defs=KEYSPEC_2, public_path=PUBLIC_FILE, read_only=False,
661+
private_path=PRIVATE_FILE,
662+
key_defs=KEYSPEC_2,
663+
public_path=PUBLIC_FILE,
664+
read_only=False,
651665
)
652666

653667
# Now it should

tests/test_04_key_jar.py

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

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

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

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

253261
key_jar = build_keyjar(keys)
@@ -303,7 +311,8 @@ def test_items(self):
303311
),
304312
)
305313
ks.add_kb(
306-
"http://www.example.org", keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
314+
"http://www.example.org",
315+
keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
307316
)
308317

309318
assert len(ks.items()) == 2
@@ -329,7 +338,8 @@ def test_issuer_extra_slash(self):
329338
),
330339
)
331340
ks.add_kb(
332-
"http://www.example.org", keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
341+
"http://www.example.org",
342+
keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
333343
)
334344

335345
assert ks.get("sig", "RSA", "http://www.example.org/")
@@ -355,7 +365,8 @@ def test_issuer_missing_slash(self):
355365
),
356366
)
357367
ks.add_kb(
358-
"http://www.example.org/", keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
368+
"http://www.example.org/",
369+
keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
359370
)
360371

361372
assert ks.get("sig", "RSA", "http://www.example.org")
@@ -381,7 +392,8 @@ def test_get_enc(self):
381392
),
382393
)
383394
ks.add_kb(
384-
"http://www.example.org/", keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
395+
"http://www.example.org/",
396+
keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
385397
)
386398

387399
assert ks.get("enc", "oct")
@@ -407,7 +419,8 @@ def test_get_enc_not_mine(self):
407419
),
408420
)
409421
ks.add_kb(
410-
"http://www.example.org/", keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
422+
"http://www.example.org/",
423+
keybundle_from_local_file(RSAKEY, "der", ["ver", "sig"]),
411424
)
412425

413426
assert ks.get("enc", "oct", "http://www.example.org/")
@@ -449,7 +462,8 @@ def test_provider(self):
449462
kj = KeyJar()
450463
_url = "https://connect-op.herokuapp.com/jwks.json"
451464
kj.load_keys(
452-
"https://connect-op.heroku.com", jwks_uri=_url,
465+
"https://connect-op.heroku.com",
466+
jwks_uri=_url,
453467
)
454468
iss_keys = kj.get_issuer_keys("https://connect-op.heroku.com")
455469
if not iss_keys:
@@ -974,7 +988,10 @@ def test_init_key_jar_update():
974988
assert len(_keyjar_3.get_signing_key("EC")) == 1
975989

976990
_keyjar_4 = init_key_jar(
977-
private_path=PRIVATE_FILE, key_defs=KEYSPEC_2, public_path=PUBLIC_FILE, read_only=False,
991+
private_path=PRIVATE_FILE,
992+
key_defs=KEYSPEC_2,
993+
public_path=PUBLIC_FILE,
994+
read_only=False,
978995
)
979996

980997
# Now it should

tests/test_06_jws.py

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

432432

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

tests/test_09_jwt.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,27 @@ def full_path(local_file):
2525
# k2 = import_private_rsa_key_from_file(full_path('size2048.key'))
2626

2727
kb1 = KeyBundle(
28-
source="file://{}".format(full_path("rsa.key")), fileformat="der", keyusage="sig", kid="1",
28+
source="file://{}".format(full_path("rsa.key")),
29+
fileformat="der",
30+
keyusage="sig",
31+
kid="1",
2932
)
3033
kb2 = KeyBundle(
31-
source="file://{}".format(full_path("size2048.key")), fileformat="der", keyusage="enc", kid="2",
34+
source="file://{}".format(full_path("size2048.key")),
35+
fileformat="der",
36+
keyusage="enc",
37+
kid="2",
3238
)
3339

3440
ALICE_KEY_JAR = KeyJar()
3541
ALICE_KEY_JAR.add_kb(ALICE, kb1)
3642
ALICE_KEY_JAR.add_kb(ALICE, kb2)
3743

3844
kb3 = KeyBundle(
39-
source="file://{}".format(full_path("server.key")), fileformat="der", keyusage="enc", kid="3",
45+
source="file://{}".format(full_path("server.key")),
46+
fileformat="der",
47+
keyusage="enc",
48+
kid="3",
4049
)
4150

4251
BOB_KEY_JAR = KeyJar()

tests/test_50_argument_alias.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ def test_init_key_jar_update():
172172
assert len(_keyjar_3.get_signing_key("EC")) == 1
173173

174174
_keyjar_4 = init_key_jar(
175-
private_path=PRIVATE_FILE, key_defs=KEYSPEC_2, public_path=PUBLIC_FILE, read_only=False,
175+
private_path=PRIVATE_FILE,
176+
key_defs=KEYSPEC_2,
177+
public_path=PUBLIC_FILE,
178+
read_only=False,
176179
)
177180

178181
# Now it should

0 commit comments

Comments
 (0)