Skip to content

Commit cba4132

Browse files
committed
fix: using built-in types since python 3.8 is dropped.
1 parent 67fa7b7 commit cba4132

File tree

17 files changed

+44
-44
lines changed

17 files changed

+44
-44
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ exclude_lines = [
103103

104104
[tool.mypy]
105105
strict = true
106-
python_version = "3.8"
106+
python_version = "3.9"
107107
files = ["src/joserfc"]
108108
show_error_codes = true
109109
pretty = true

src/joserfc/_keys.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class JWKRegistry:
4444
key = JWKRegistry.import_key(data)
4545
"""
4646

47-
key_types: t.Dict[str, t.Type[Key]] = {
47+
key_types: dict[str, t.Type[Key]] = {
4848
OctKey.key_type: OctKey,
4949
RSAKey.key_type: RSAKey,
5050
ECKey.key_type: ECKey,
@@ -103,15 +103,15 @@ def generate_key(
103103
return key_cls.generate_key(crv_or_size, parameters, private, auto_kid) # type: ignore[arg-type]
104104

105105

106-
KeySetSerialization = t.TypedDict("KeySetSerialization", {"keys": t.List[DictKey]})
106+
KeySetSerialization = t.TypedDict("KeySetSerialization", {"keys": list[DictKey]})
107107

108108

109109
class KeySet:
110110
#: keys in the key set
111111
keys: list[Key]
112112

113113
registry_cls: t.Type[JWKRegistry] = JWKRegistry
114-
algorithm_keys: t.ClassVar[t.Dict[str, list[str]]] = {}
114+
algorithm_keys: t.ClassVar[dict[str, list[str]]] = {}
115115

116116
def __init__(self, keys: list[Key]):
117117
for key in keys:

src/joserfc/_rfc7515/compact.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def detach_compact_content(value: str) -> str:
4343
return ".".join(parts)
4444

4545

46-
def decode_header(header_segment: bytes) -> t.Dict[str, t.Any]:
46+
def decode_header(header_segment: bytes) -> dict[str, t.Any]:
4747
try:
48-
protected: t.Dict[str, t.Any] = json_b64decode(header_segment)
48+
protected: dict[str, t.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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def verify_signature(
147147
return alg.verify(signing_input, sig, key)
148148

149149

150-
def detach_json_content(value: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
150+
def detach_json_content(value: dict[str, t.Any]) -> dict[str, t.Any]:
151151
# https://www.rfc-editor.org/rfc/rfc7515#appendix-F
152152
rv = copy.deepcopy(value) # don't alter original value
153153
if "payload" in rv:

src/joserfc/_rfc7515/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class JSONSignatureDict(t.TypedDict, total=False):
3030
@t.final
3131
class GeneralJSONSerialization(t.TypedDict):
3232
payload: str
33-
signatures: t.List[JSONSignatureDict]
33+
signatures: list[JSONSignatureDict]
3434

3535

3636
@t.final

src/joserfc/_rfc7516/json.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def represent_flattened_json(obj: FlattenedJSONEncryption) -> FlattenedJSONSeria
5656

5757

5858
def __represent_json_serialization(obj: BaseJSONEncryption): # type: ignore[no-untyped-def]
59-
data: t.Dict[str, t.Union[str, Header, t.List[Header]]] = {
59+
data: dict[str, t.Union[str, Header, list[Header]]] = {
6060
"protected": to_str(json_b64encode(obj.protected)),
6161
"iv": to_str(obj.base64_segments["iv"]),
6262
"ciphertext": to_str(obj.base64_segments["ciphertext"]),
@@ -102,13 +102,13 @@ def extract_flattened_json(data: FlattenedJSONSerialization) -> FlattenedJSONEnc
102102

103103
def __extract_segments(
104104
data: t.Union[GeneralJSONSerialization, FlattenedJSONSerialization],
105-
) -> t.Tuple[t.Dict[str, bytes], t.Dict[str, bytes], t.Optional[bytes]]:
106-
base64_segments: t.Dict[str, bytes] = {
105+
) -> tuple[dict[str, bytes], dict[str, bytes], t.Optional[bytes]]:
106+
base64_segments: dict[str, bytes] = {
107107
"iv": to_bytes(data["iv"]),
108108
"ciphertext": to_bytes(data["ciphertext"]),
109109
"tag": to_bytes(data["tag"]),
110110
}
111-
bytes_segments: t.Dict[str, bytes] = {
111+
bytes_segments: dict[str, bytes] = {
112112
"iv": urlsafe_b64decode(base64_segments["iv"]),
113113
"ciphertext": urlsafe_b64decode(base64_segments["ciphertext"]),
114114
"tag": urlsafe_b64decode(base64_segments["tag"]),

src/joserfc/_rfc7516/message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ def _perform_decrypt(obj: EncryptionData, registry: JWERegistry) -> None:
136136

137137

138138
def pre_encrypt_recipients(
139-
enc: JWEEncModel, recipients: t.List[Recipient[t.Any]], registry: JWERegistry
140-
) -> t.Tuple[bytes, t.List[t.Tuple[JWEKeyAgreement, Recipient[t.Any]]]]:
139+
enc: JWEEncModel, recipients: list[Recipient[t.Any]], registry: JWERegistry
140+
) -> tuple[bytes, list[tuple[JWEKeyAgreement, Recipient[t.Any]]]]:
141141
cek: bytes = b""
142-
delayed_tasks: t.List[t.Tuple[JWEKeyAgreement, Recipient[t.Any]]] = []
142+
delayed_tasks: list[tuple[JWEKeyAgreement, Recipient[t.Any]]] = []
143143
for recipient in recipients:
144144
alg = __prepare_recipient_algorithm(recipient, registry)
145145

@@ -201,7 +201,7 @@ def __pre_encrypt_direct_mode(alg: JWEAlgModel, enc: JWEEncModel, recipient: Rec
201201

202202

203203
def post_encrypt_recipients(
204-
enc: JWEEncModel, tasks: t.List[t.Tuple[JWEKeyAgreement, Recipient[t.Any]]], cek: bytes, tag: bytes
204+
enc: JWEEncModel, tasks: list[tuple[JWEKeyAgreement, Recipient[t.Any]]], cek: bytes, tag: bytes
205205
) -> None:
206206
for alg, recipient in tasks:
207207
if alg.tag_aware:

src/joserfc/_rfc7516/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def __init__(self, protected: Header, plaintext: bytes | None = None):
7171
#: the plaintext in bytes
7272
self.plaintext = plaintext
7373
self.recipient: Recipient[t.Any] | None = None
74-
self.bytes_segments: t.Dict[str, bytes] = {} # store the decoded segments
75-
self.base64_segments: t.Dict[str, bytes] = {} # store the encoded segments
74+
self.bytes_segments: dict[str, bytes] = {} # store the decoded segments
75+
self.base64_segments: dict[str, bytes] = {} # store the encoded segments
7676

7777
def headers(self) -> Header:
7878
"""Returns the protected header values in dict."""
@@ -109,7 +109,7 @@ class BaseJSONEncryption(metaclass=ABCMeta):
109109
#: an optional additional authenticated data
110110
aad: t.Optional[bytes]
111111
#: a list of recipients
112-
recipients: t.List[Recipient[t.Any]]
112+
recipients: list[Recipient[t.Any]]
113113

114114
def __init__(
115115
self,
@@ -123,8 +123,8 @@ def __init__(
123123
self.unprotected = unprotected
124124
self.aad = aad
125125
self.recipients = []
126-
self.bytes_segments: t.Dict[str, bytes] = {} # store the decoded segments
127-
self.base64_segments: t.Dict[str, bytes] = {} # store the encoded segments
126+
self.bytes_segments: dict[str, bytes] = {} # store the decoded segments
127+
self.base64_segments: dict[str, bytes] = {} # store the encoded segments
128128

129129
@abstractmethod
130130
def add_recipient(self, header: Header | None = None, key: Key | None = None) -> None:
@@ -230,7 +230,7 @@ class KeyManagement:
230230
description: str
231231
recommended: bool = False
232232
key_size: int | None = None
233-
key_types: t.List[str]
233+
key_types: list[str]
234234
security_warning: str | None = None
235235

236236
algorithm_type: t.Literal["JWE"] = "JWE"

src/joserfc/_rfc7516/registry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
AlgorithmsDict = t.TypedDict(
2424
"AlgorithmsDict",
2525
{
26-
"alg": t.Dict[str, JWEAlgModel],
27-
"enc": t.Dict[str, JWEEncModel],
28-
"zip": t.Dict[str, JWEZipModel],
26+
"alg": dict[str, JWEAlgModel],
27+
"enc": dict[str, JWEEncModel],
28+
"zip": dict[str, JWEZipModel],
2929
},
3030
)
3131

@@ -46,7 +46,7 @@ class JWERegistry:
4646
"enc": {},
4747
"zip": {},
4848
}
49-
recommended: t.ClassVar[t.List[str]] = []
49+
recommended: t.ClassVar[list[str]] = []
5050

5151
def __init__(
5252
self,

src/joserfc/_rfc7516/types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88

99

1010
class JSONRecipientDict(t.TypedDict, total=False):
11-
header: t.Dict[str, t.Any]
11+
header: dict[str, t.Any]
1212
encrypted_key: str
1313

1414

1515
class GeneralJSONSerialization(t.TypedDict, total=False):
1616
protected: str
17-
unprotected: t.Dict[str, t.Any]
17+
unprotected: dict[str, t.Any]
1818
iv: str
1919
aad: str
2020
ciphertext: str
2121
tag: str
22-
recipients: t.List[JSONRecipientDict]
22+
recipients: list[JSONRecipientDict]
2323

2424

2525
class FlattenedJSONSerialization(t.TypedDict, total=False):
2626
protected: str
27-
unprotected: t.Dict[str, t.Any]
27+
unprotected: dict[str, t.Any]
2828
iv: str
2929
aad: str
3030
ciphertext: str
3131
tag: str
32-
header: t.Dict[str, t.Any]
32+
header: dict[str, t.Any]
3333
encrypted_key: str

0 commit comments

Comments
 (0)