Skip to content

Commit 1ddca8f

Browse files
committed
fix(typing): update type hints for dropping python 3.9
1 parent fe1d746 commit 1ddca8f

34 files changed

Lines changed: 89 additions & 125 deletions

src/joserfc/_keys.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import annotations
21
import typing as t
32
import random
43
from ._rfc7517.types import AnyKey, KeyParameters, DictKey
@@ -44,7 +43,7 @@ class JWKRegistry:
4443
key = JWKRegistry.import_key(data)
4544
"""
4645

47-
key_types: dict[str, t.Type[Key]] = {
46+
key_types: dict[str, type[Key]] = {
4847
OctKey.key_type: OctKey,
4948
RSAKey.key_type: RSAKey,
5049
ECKey.key_type: ECKey,
@@ -110,7 +109,7 @@ class KeySet:
110109
#: keys in the key set
111110
keys: list[Key]
112111

113-
registry_cls: t.Type[JWKRegistry] = JWKRegistry
112+
registry_cls: type[JWKRegistry] = JWKRegistry
114113
algorithm_keys: t.ClassVar[dict[str, list[str]]] = {}
115114

116115
def __init__(self, keys: list[Key]):

src/joserfc/_rfc7515/compact.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import typing as t
1+
from typing import Any
22
from .model import JWSAlgModel, CompactSignature
33
from ..errors import (
44
DecodeError,
@@ -19,15 +19,15 @@
1919
]
2020

2121

22-
def sign_compact(obj: CompactSignature, alg: JWSAlgModel, key: t.Any) -> bytes:
22+
def sign_compact(obj: CompactSignature, alg: JWSAlgModel, key: Any) -> bytes:
2323
header_segment = json_b64encode(obj.headers())
2424
payload_segment = urlsafe_b64encode(obj.payload)
2525
signing_input = header_segment + b"." + payload_segment
2626
signature = urlsafe_b64encode(alg.sign(signing_input, key))
2727
return signing_input + b"." + signature
2828

2929

30-
def verify_compact(obj: CompactSignature, alg: JWSAlgModel, key: t.Any) -> bool:
30+
def verify_compact(obj: CompactSignature, alg: JWSAlgModel, key: Any) -> bool:
3131
signing_input = obj.segments["header"] + b"." + obj.segments["payload"]
3232
try:
3333
sig = urlsafe_b64decode(obj.segments["signature"])
@@ -43,9 +43,9 @@ def detach_compact_content(value: str) -> str:
4343
return ".".join(parts)
4444

4545

46-
def decode_header(header_segment: bytes) -> dict[str, t.Any]:
46+
def decode_header(header_segment: bytes) -> dict[str, Any]:
4747
try:
48-
protected: dict[str, t.Any] = json_b64decode(header_segment)
48+
protected: dict[str, Any] = json_b64decode(header_segment)
4949
if "alg" not in protected:
5050
raise MissingAlgorithmError()
5151
except (TypeError, ValueError):

src/joserfc/_rfc7515/json.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from __future__ import annotations
2-
import typing as t
31
import copy
2+
from typing import Any, Callable
43
from .model import (
54
HeaderMember,
65
GeneralJSONSignature,
@@ -33,7 +32,7 @@
3332
"detach_json_content",
3433
]
3534

36-
FindKey = t.Callable[[HeaderMember], t.Any]
35+
FindKey = Callable[[HeaderMember], Any]
3736

3837

3938
def sign_general_json(
@@ -156,7 +155,7 @@ def verify_signature(
156155
return alg.verify(signing_input, sig, key)
157156

158157

159-
def detach_json_content(value: dict[str, t.Any]) -> dict[str, t.Any]:
158+
def detach_json_content(value: dict[str, Any]) -> dict[str, Any]:
160159
# https://www.rfc-editor.org/rfc/rfc7515#appendix-F
161160
rv = copy.deepcopy(value) # don't alter original value
162161
if "payload" in rv:

src/joserfc/_rfc7515/model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import annotations
21
from typing import Any, ClassVar, Literal
32
from abc import ABCMeta, abstractmethod
43
from .types import SegmentsDict, JSONSignatureDict

src/joserfc/_rfc7515/registry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import annotations
21
import warnings
32
from typing import Any
43
from collections.abc import Collection

src/joserfc/_rfc7515/types.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import typing as t
1+
from typing import TypedDict, final
22
from ..registry import Header
33

44
__all__ = [
@@ -10,31 +10,31 @@
1010
]
1111

1212

13-
class SegmentsDict(t.TypedDict, total=False):
13+
class SegmentsDict(TypedDict, total=False):
1414
header: bytes
1515
payload: bytes
1616
signature: bytes
1717

1818

19-
class HeaderDict(t.TypedDict, total=False):
19+
class HeaderDict(TypedDict, total=False):
2020
protected: Header
2121
header: Header
2222

2323

24-
class JSONSignatureDict(t.TypedDict, total=False):
24+
class JSONSignatureDict(TypedDict, total=False):
2525
protected: str
2626
header: Header
2727
signature: str
2828

2929

30-
@t.final
31-
class GeneralJSONSerialization(t.TypedDict):
30+
@final
31+
class GeneralJSONSerialization(TypedDict):
3232
payload: str
3333
signatures: list[JSONSignatureDict]
3434

3535

36-
@t.final
37-
class FlattenedJSONSerialization(t.TypedDict, total=False):
36+
@final
37+
class FlattenedJSONSerialization(TypedDict, total=False):
3838
payload: str
3939
protected: str
4040
header: Header

src/joserfc/_rfc7516/json.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from __future__ import annotations
2-
import typing as t
1+
from typing import Any
32
from .models import (
43
BaseJSONEncryption,
54
GeneralJSONEncryption,
@@ -56,8 +55,8 @@ def represent_flattened_json(obj: FlattenedJSONEncryption) -> FlattenedJSONSeria
5655
return data
5756

5857

59-
def __represent_json_serialization(obj: BaseJSONEncryption) -> t.Any:
60-
data: dict[str, t.Any] = {
58+
def __represent_json_serialization(obj: BaseJSONEncryption) -> Any:
59+
data: dict[str, Any] = {
6160
"protected": to_str(json_b64encode(obj.protected)),
6261
"iv": to_str(obj.base64_segments["iv"]),
6362
"ciphertext": to_str(obj.base64_segments["ciphertext"]),
@@ -103,9 +102,9 @@ def extract_flattened_json(data: FlattenedJSONSerialization, registry: JWERegist
103102

104103

105104
def __extract_segments(
106-
data: t.Union[GeneralJSONSerialization, FlattenedJSONSerialization],
105+
data: GeneralJSONSerialization | FlattenedJSONSerialization,
107106
registry: JWERegistry,
108-
) -> tuple[dict[str, bytes], dict[str, bytes], t.Optional[bytes]]:
107+
) -> tuple[dict[str, bytes], dict[str, bytes], bytes | None]:
109108
base64_segments: dict[str, bytes] = {
110109
"iv": to_bytes(data["iv"]),
111110
"ciphertext": to_bytes(data["ciphertext"]),

src/joserfc/_rfc7516/message.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import secrets
2-
import typing as t
2+
from typing import Any, Union
33

44
from .models import (
55
CompactEncryption,
@@ -33,7 +33,7 @@
3333
"perform_decrypt",
3434
]
3535

36-
EncryptionData = t.Union[CompactEncryption, GeneralJSONEncryption, FlattenedJSONEncryption]
36+
EncryptionData = Union[CompactEncryption, GeneralJSONEncryption, FlattenedJSONEncryption]
3737

3838

3939
def perform_encrypt(obj: EncryptionData, registry: JWERegistry) -> None:
@@ -137,10 +137,10 @@ def _perform_decrypt(obj: EncryptionData, registry: JWERegistry) -> None:
137137

138138

139139
def pre_encrypt_recipients(
140-
enc: JWEEncModel, recipients: list[Recipient[t.Any]], registry: JWERegistry
141-
) -> tuple[bytes, list[tuple[JWEKeyAgreement, Recipient[t.Any]]]]:
140+
enc: JWEEncModel, recipients: list[Recipient[Any]], registry: JWERegistry
141+
) -> tuple[bytes, list[tuple[JWEKeyAgreement, Recipient[Any]]]]:
142142
cek: bytes = b""
143-
delayed_tasks: list[tuple[JWEKeyAgreement, Recipient[t.Any]]] = []
143+
delayed_tasks: list[tuple[JWEKeyAgreement, Recipient[Any]]] = []
144144
for recipient in recipients:
145145
alg = __prepare_recipient_algorithm(recipient, registry)
146146

@@ -167,7 +167,7 @@ def pre_encrypt_recipients(
167167
return cek, delayed_tasks
168168

169169

170-
def __prepare_recipient_algorithm(recipient: Recipient[t.Any], registry: JWERegistry) -> JWEAlgModel:
170+
def __prepare_recipient_algorithm(recipient: Recipient[Any], registry: JWERegistry) -> JWEAlgModel:
171171
headers = recipient.headers()
172172
registry.check_header(headers)
173173
# 1. Determine the Key Management Mode employed by the algorithm used
@@ -181,7 +181,7 @@ def __prepare_recipient_algorithm(recipient: Recipient[t.Any], registry: JWERegi
181181
return alg
182182

183183

184-
def __pre_encrypt_direct_mode(alg: JWEAlgModel, enc: JWEEncModel, recipient: Recipient[t.Any]) -> bytes:
184+
def __pre_encrypt_direct_mode(alg: JWEAlgModel, enc: JWEEncModel, recipient: Recipient[Any]) -> bytes:
185185
cek: bytes
186186
if isinstance(alg, JWEKeyAgreement):
187187
# 3. When Direct Key Agreement is employed,
@@ -202,7 +202,7 @@ def __pre_encrypt_direct_mode(alg: JWEAlgModel, enc: JWEEncModel, recipient: Rec
202202

203203

204204
def post_encrypt_recipients(
205-
enc: JWEEncModel, tasks: list[tuple[JWEKeyAgreement, Recipient[t.Any]]], cek: bytes, tag: bytes
205+
enc: JWEEncModel, tasks: list[tuple[JWEKeyAgreement, Recipient[Any]]], cek: bytes, tag: bytes
206206
) -> None:
207207
for alg, recipient in tasks:
208208
if alg.tag_aware:
@@ -214,7 +214,7 @@ def post_encrypt_recipients(
214214
recipient.encrypted_key = alg.wrap_cek_with_auk(cek, agreed_upon_key)
215215

216216

217-
def decrypt_recipient(alg: JWEAlgModel, enc: JWEEncModel, recipient: Recipient[t.Any], tag: bytes) -> bytes:
217+
def decrypt_recipient(alg: JWEAlgModel, enc: JWEEncModel, recipient: Recipient[Any], tag: bytes) -> bytes:
218218
cek: bytes
219219
if alg.direct_mode:
220220
# 10. When Direct Key Agreement or Direct Encryption are employed,

src/joserfc/_rfc7516/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import annotations
21
import typing as t
32
import secrets
43
from abc import ABCMeta, abstractmethod

src/joserfc/_rfc7516/registry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import annotations
21
import warnings
32
import typing as t
43
from collections.abc import Collection

0 commit comments

Comments
 (0)