Skip to content

Commit 16da314

Browse files
committed
Use string type annotations where required
1 parent 7cf5a54 commit 16da314

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

jwt/algorithms.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class RSAAlgorithm(Algorithm):
314314
def __init__(self, hash_alg: Type[hashes.HashAlgorithm]) -> None:
315315
self.hash_alg = hash_alg
316316

317-
def prepare_key(self, key: Union[AllowedRSAKeys, AnyStr]) -> AllowedRSAKeys:
317+
def prepare_key(self, key: Union["AllowedRSAKeys", AnyStr]) -> "AllowedRSAKeys":
318318
if isinstance(key, (RSAPrivateKey, RSAPublicKey)):
319319
return key
320320

@@ -334,7 +334,7 @@ def prepare_key(self, key: Union[AllowedRSAKeys, AnyStr]) -> AllowedRSAKeys:
334334
return cast(RSAPublicKey, load_pem_public_key(key_bytes))
335335

336336
@staticmethod
337-
def to_jwk(key_obj: AllowedRSAKeys) -> str:
337+
def to_jwk(key_obj: "AllowedRSAKeys") -> str:
338338
obj: Optional[Dict[str, Any]] = None
339339

340340
if hasattr(key_obj, "private_numbers"):
@@ -370,7 +370,7 @@ def to_jwk(key_obj: AllowedRSAKeys) -> str:
370370
return json.dumps(obj)
371371

372372
@staticmethod
373-
def from_jwk(jwk: Union[str, JWKDict]) -> AllowedRSAKeys:
373+
def from_jwk(jwk: Union[str, JWKDict]) -> "AllowedRSAKeys":
374374
try:
375375
if isinstance(jwk, str):
376376
obj = json.loads(jwk)
@@ -464,7 +464,7 @@ class ECAlgorithm(Algorithm):
464464
def __init__(self, hash_alg: Type[hashes.HashAlgorithm]) -> None:
465465
self.hash_alg = hash_alg
466466

467-
def prepare_key(self, key: Union[AllowedECKeys, AnyStr]) -> AllowedECKeys:
467+
def prepare_key(self, key: Union["AllowedECKeys", AnyStr]) -> "AllowedECKeys":
468468
if isinstance(key, (EllipticCurvePrivateKey, EllipticCurvePublicKey)):
469469
return key
470470

@@ -499,7 +499,7 @@ def sign(self, msg: bytes, key: EllipticCurvePrivateKey) -> bytes:
499499

500500
return der_to_raw_signature(der_sig, key.curve)
501501

502-
def verify(self, msg: bytes, key: AllowedECKeys, sig: bytes) -> bool:
502+
def verify(self, msg: bytes, key: "AllowedECKeys", sig: bytes) -> bool:
503503
try:
504504
der_sig = raw_to_der_signature(sig, key.curve)
505505
except ValueError:
@@ -517,7 +517,7 @@ def verify(self, msg: bytes, key: AllowedECKeys, sig: bytes) -> bool:
517517
return False
518518

519519
@staticmethod
520-
def to_jwk(key_obj: AllowedECKeys) -> str:
520+
def to_jwk(key_obj: "AllowedECKeys") -> str:
521521
if isinstance(key_obj, EllipticCurvePrivateKey):
522522
public_numbers = key_obj.public_key().public_numbers()
523523
elif isinstance(key_obj, EllipticCurvePublicKey):
@@ -553,7 +553,7 @@ def to_jwk(key_obj: AllowedECKeys) -> str:
553553
@staticmethod
554554
def from_jwk(
555555
jwk: Union[str, JWKDict],
556-
) -> AllowedECKeys:
556+
) -> "AllowedECKeys":
557557
try:
558558
if isinstance(jwk, str):
559559
obj = json.loads(jwk)
@@ -660,7 +660,7 @@ class OKPAlgorithm(Algorithm):
660660
def __init__(self, **kwargs: Any) -> None:
661661
pass
662662

663-
def prepare_key(self, key: Union[AllowedOKPKeys, str, bytes]) -> AllowedOKPKeys:
663+
def prepare_key(self, key: Union["AllowedOKPKeys", str, bytes]) -> "AllowedOKPKeys":
664664
if isinstance(key, (bytes, str)):
665665
key_str = key.decode("utf-8") if isinstance(key, bytes) else key
666666
key_bytes = key.encode("utf-8") if isinstance(key, str) else key
@@ -697,7 +697,7 @@ def sign(
697697
return key.sign(msg_bytes)
698698

699699
def verify(
700-
self, msg: Union[str, bytes], key: AllowedOKPKeys, sig: Union[str, bytes]
700+
self, msg: Union[str, bytes], key: "AllowedOKPKeys", sig: Union[str, bytes]
701701
) -> bool:
702702
"""
703703
Verify a given ``msg`` against a signature ``sig`` using the EdDSA key ``key``
@@ -723,7 +723,7 @@ def verify(
723723
return False
724724

725725
@staticmethod
726-
def to_jwk(key: AllowedOKPKeys) -> str:
726+
def to_jwk(key: "AllowedOKPKeys") -> str:
727727
if isinstance(key, (Ed25519PublicKey, Ed448PublicKey)):
728728
x = key.public_bytes(
729729
encoding=Encoding.Raw,
@@ -763,7 +763,7 @@ def to_jwk(key: AllowedOKPKeys) -> str:
763763
raise InvalidKeyError("Not a public or private key")
764764

765765
@staticmethod
766-
def from_jwk(jwk: Union[str, JWKDict]) -> AllowedOKPKeys:
766+
def from_jwk(jwk: Union[str, JWKDict]) -> "AllowedOKPKeys":
767767
try:
768768
if isinstance(jwk, str):
769769
obj = json.loads(jwk)

0 commit comments

Comments
 (0)