1- import typing as t
1+ from __future__ import annotations
22from typing import overload
33from .rfc7516 .types import (
44 GeneralJSONSerialization ,
@@ -69,11 +69,11 @@ def register_algorithms() -> None:
6969
7070def encrypt_compact (
7171 protected : Header ,
72- plaintext : t . Union [ bytes , str ] ,
72+ plaintext : bytes | str ,
7373 public_key : KeyFlexible ,
74- algorithms : t . Optional [ t . List [ str ]] = None ,
75- registry : t . Optional [ JWERegistry ] = None ,
76- sender_key : t . Optional [ t . Union [ ECKey , OKPKey , KeySet ]] = None ) -> str :
74+ algorithms : list [ str ] | None = None ,
75+ registry : JWERegistry | None = None ,
76+ sender_key : ECKey | OKPKey | KeySet | None = None ) -> str :
7777 """Generate a JWE Compact Serialization. The JWE Compact Serialization represents
7878 encrypted content as a compact, URL-safe string. This string is::
7979
@@ -111,11 +111,11 @@ def encrypt_compact(
111111
112112
113113def decrypt_compact (
114- value : t . Union [ bytes , str ] ,
114+ value : bytes | str ,
115115 private_key : KeyFlexible ,
116- algorithms : t . Optional [ t . List [ str ]] = None ,
117- registry : t . Optional [ JWERegistry ] = None ,
118- sender_key : t . Optional [ t . Union [ ECKey , OKPKey , KeySet ]] = None ) -> CompactEncryption :
116+ algorithms : list [ str ] | None = None ,
117+ registry : JWERegistry | None = None ,
118+ sender_key : ECKey | OKPKey | KeySet | None = None ) -> CompactEncryption :
119119 """Extract and validate the JWE Compact Serialization (in string, or bytes)
120120 with the given key. An JWE Compact Serialization looks like:
121121
@@ -156,30 +156,30 @@ def decrypt_compact(
156156@overload
157157def encrypt_json (
158158 obj : GeneralJSONEncryption ,
159- public_key : t . Optional [ KeyFlexible ] ,
160- algorithms : t . Optional [ t . List [ str ]] = None ,
161- registry : t . Optional [ JWERegistry ] = None ,
162- sender_key : t . Optional [ t . Union [ ECKey , OKPKey , KeySet ]] = None ) -> GeneralJSONSerialization :
159+ public_key : KeyFlexible | None ,
160+ algorithms : list [ str ] | None = None ,
161+ registry : JWERegistry | None = None ,
162+ sender_key : ECKey | OKPKey | KeySet | None = None ) -> GeneralJSONSerialization :
163163 ...
164164
165165
166166@overload
167167def encrypt_json (
168168 obj : FlattenedJSONEncryption ,
169- public_key : t . Optional [ KeyFlexible ] ,
170- algorithms : t . Optional [ t . List [ str ]] = None ,
171- registry : t . Optional [ JWERegistry ] = None ,
172- sender_key : t . Optional [ t . Union [ ECKey , OKPKey , KeySet ]] = None ) -> FlattenedJSONSerialization :
169+ public_key : KeyFlexible | None ,
170+ algorithms : list [ str ] | None = None ,
171+ registry : JWERegistry | None = None ,
172+ sender_key : ECKey | OKPKey | KeySet | None = None ) -> FlattenedJSONSerialization :
173173 ...
174174
175175
176176def encrypt_json (
177- obj : t . Union [ GeneralJSONEncryption , FlattenedJSONEncryption ] ,
178- public_key : t . Optional [ KeyFlexible ] ,
179- algorithms : t . Optional [ t . List [ str ]] = None ,
180- registry : t . Optional [ JWERegistry ] = None ,
181- sender_key : t . Optional [ t . Union [ ECKey , OKPKey , KeySet ]] = None
182- ) -> t . Union [ GeneralJSONSerialization , FlattenedJSONSerialization ] :
177+ obj : GeneralJSONEncryption | FlattenedJSONEncryption ,
178+ public_key : KeyFlexible | None ,
179+ algorithms : list [ str ] | None = None ,
180+ registry : JWERegistry | None = None ,
181+ sender_key : ECKey | OKPKey | KeySet | None = None
182+ ) -> GeneralJSONSerialization | FlattenedJSONSerialization :
183183 """Generate a JWE JSON Serialization (in dict). The JWE JSON Serialization
184184 represents encrypted content as a JSON object. This representation is neither
185185 optimized for compactness nor URL safe.
@@ -228,12 +228,12 @@ def encrypt_json(
228228
229229
230230def decrypt_json (
231- data : t . Union [ GeneralJSONSerialization , FlattenedJSONSerialization ] ,
231+ data : GeneralJSONSerialization | FlattenedJSONSerialization ,
232232 private_key : KeyFlexible ,
233- algorithms : t . Optional [ t . List [ str ]] = None ,
234- registry : t . Optional [ JWERegistry ] = None ,
235- sender_key : t . Optional [ t . Union [ ECKey , OKPKey , KeySet ]] = None
236- ) -> t . Union [ GeneralJSONEncryption , FlattenedJSONEncryption ] :
233+ algorithms : list [ str ] | None = None ,
234+ registry : JWERegistry | None = None ,
235+ sender_key : ECKey | OKPKey | KeySet | None = None
236+ ) -> GeneralJSONEncryption | FlattenedJSONEncryption :
237237 """Decrypt the JWE JSON Serialization (in dict) to a
238238 ``GeneralJSONEncryption`` or ``FlattenedJSONEncryption`` object.
239239
@@ -262,9 +262,9 @@ def decrypt_json(
262262
263263
264264def _attach_recipient_keys (
265- recipients : t . List [Recipient [Key ]],
265+ recipients : list [Recipient [Key ]],
266266 private_key : KeyFlexible ,
267- sender_key : t . Optional [ t . Union [ ECKey , OKPKey , KeySet ]] = None ) -> None :
267+ sender_key : ECKey | OKPKey | KeySet | None = None ) -> None :
268268 for recipient in recipients :
269269 key = guess_key (private_key , recipient )
270270 key .check_use ("enc" )
@@ -275,8 +275,8 @@ def _attach_recipient_keys(
275275
276276def _guess_sender_key (
277277 recipient : Recipient [Key ],
278- key : t . Union [ ECKey , OKPKey , KeySet ] ,
279- use_random : bool = False ) -> t . Union [ ECKey , OKPKey ] :
278+ key : ECKey | OKPKey | KeySet ,
279+ use_random : bool = False ) -> ECKey | OKPKey :
280280 if isinstance (key , KeySet ):
281281 headers = recipient .headers ()
282282 skid = headers .get ('skid' )
0 commit comments