Skip to content

Commit 2fc1ce5

Browse files
committed
reformat
1 parent b229393 commit 2fc1ce5

File tree

6 files changed

+31
-26
lines changed

6 files changed

+31
-26
lines changed

jwt_rsa/rsa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def int_to_base64url(value: int) -> str:
111111

112112
@overload
113113
def rsa_to_jwk(
114-
key: RSAPublicKey, *, kid: str = "", alg: AlgorithmType = "RS256", use: str = "sig"
114+
key: RSAPublicKey, *, kid: str = "", alg: AlgorithmType = "RS256", use: str = "sig",
115115
) -> RSAJWKPublicKey: ...
116116

117117

jwt_rsa/token.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
from jwt import PyJWT
99

10-
from .types import AlgorithmType, RSAPrivateKey, RSAPublicKey, DateType
10+
from .types import AlgorithmType, DateType, RSAPrivateKey, RSAPublicKey
11+
1112

1213
R = TypeVar("R")
1314
DAY = 86400
@@ -51,12 +52,12 @@ def __init__(
5152
algorithm: AlgorithmType = "RS512",
5253
algorithms: Sequence[AlgorithmType] = ALGORITHMS,
5354
):
54-
super().__setattr__('public_key', key)
55-
super().__setattr__('jwt', PyJWT(options))
56-
super().__setattr__('expires', expires)
57-
super().__setattr__('nbf_delta', nbf_delta)
58-
super().__setattr__('algorithm', algorithm)
59-
super().__setattr__('algorithms', algorithms)
55+
super().__setattr__("public_key", key)
56+
super().__setattr__("jwt", PyJWT(options))
57+
super().__setattr__("expires", expires)
58+
super().__setattr__("nbf_delta", nbf_delta)
59+
super().__setattr__("algorithm", algorithm)
60+
super().__setattr__("algorithms", algorithms)
6061

6162
def decode(self, token: str, verify: bool = True, **kwargs: Any) -> Dict[str, Any]:
6263
return self.jwt.decode(token, key=self.public_key, verify=verify, algorithms=self.algorithms, **kwargs)
@@ -67,12 +68,12 @@ class JWTSigner(JWTDecoder):
6768
private_key: RSAPrivateKey = field(repr=False, compare=True)
6869

6970
def __init__(self, key: RSAPrivateKey, *, options: Optional[Dict[str, Any]] = None, **kwargs: Any):
70-
super(JWTDecoder, self).__setattr__('private_key', key)
71+
super(JWTDecoder, self).__setattr__("private_key", key)
7172
super().__init__(key.public_key(), options=options, **kwargs)
7273

7374
def encode(self, expired: DateType | EllipsisType = ..., nbf: DateType | EllipsisType = ..., **claims: Any) -> str:
74-
claims.setdefault('exp', int(date_to_timestamp(expired, lambda: time.time() + self.expires)))
75-
claims.setdefault('nbf', int(date_to_timestamp(nbf, lambda: time.time() - self.nbf_delta, timedelta_func=sub)))
75+
claims.setdefault("exp", int(date_to_timestamp(expired, lambda: time.time() + self.expires)))
76+
claims.setdefault("nbf", int(date_to_timestamp(nbf, lambda: time.time() - self.nbf_delta, timedelta_func=sub)))
7677
return self.jwt.encode(claims, self.private_key, algorithm=self.algorithm)
7778

7879

jwt_rsa/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import timedelta, datetime
1+
from datetime import datetime, timedelta
22
from typing import Literal
33

44
from cryptography.hazmat.primitives import serialization

jwt_rsa/verify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from types import SimpleNamespace
44

55
from .rsa import generate_rsa, load_private_key, load_public_key
6-
from .token import JWT, JWTSigner, JWTDecoder
6+
from .token import JWT, JWTDecoder, JWTSigner
77

88

99
def main(arguments: SimpleNamespace) -> None:

tests/test_cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_keygen_no_force(capsys, tmp_path):
9595
parser.parse_args([
9696
"keygen", "-o", "pem",
9797
"-K", str(private_path), "-k", str(public_path),
98-
])
98+
]),
9999
)
100100

101101
assert private_path.exists()
@@ -112,7 +112,7 @@ def test_keygen_no_force(capsys, tmp_path):
112112
parser.parse_args([
113113
"keygen", "-o", "pem",
114114
"-K", str(private_path), "-k", str(public_path),
115-
])
115+
]),
116116
)
117117

118118
assert public_content == public_path.read_text()
@@ -122,7 +122,7 @@ def test_keygen_no_force(capsys, tmp_path):
122122
parser.parse_args([
123123
"keygen", "-o", "pem", "-f",
124124
"-K", str(private_path), "-k", str(public_path),
125-
])
125+
]),
126126
)
127127

128128
assert public_content != public_path.read_text()

tests/test_rsa.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from jwt.exceptions import InvalidAlgorithmError, InvalidSignatureError
1212

1313
from jwt_rsa import rsa
14-
from jwt_rsa.types import serialization
1514
from jwt_rsa.token import JWT
15+
from jwt_rsa.types import serialization
1616

1717

1818
def test_rsa_sign():
@@ -173,17 +173,21 @@ def test_load_public_key(tmp_path):
173173
private_path = tmp_path / "private.pem"
174174

175175
with open(public_path, "wb") as fp:
176-
fp.write(public.public_bytes(
177-
encoding=serialization.Encoding.PEM,
178-
format=serialization.PublicFormat.SubjectPublicKeyInfo,
179-
))
176+
fp.write(
177+
public.public_bytes(
178+
encoding=serialization.Encoding.PEM,
179+
format=serialization.PublicFormat.SubjectPublicKeyInfo,
180+
),
181+
)
180182

181183
with open(private_path, "wb") as fp:
182-
fp.write(key.private_bytes(
183-
encoding=serialization.Encoding.PEM,
184-
format=serialization.PrivateFormat.PKCS8,
185-
encryption_algorithm=serialization.NoEncryption(),
186-
))
184+
fp.write(
185+
key.private_bytes(
186+
encoding=serialization.Encoding.PEM,
187+
format=serialization.PrivateFormat.PKCS8,
188+
encryption_algorithm=serialization.NoEncryption(),
189+
),
190+
)
187191

188192
assert rsa.load_public_key(public_path)
189193
assert rsa.load_public_key(public_path.read_text())

0 commit comments

Comments
 (0)