|
1 | 1 | from _typeshed import Incomplete |
| 2 | +from collections.abc import Callable |
| 3 | +from re import Pattern |
| 4 | +from typing import Any, Final, Generic, TypedDict, TypeVar, overload, type_check_only |
| 5 | +from typing_extensions import TypeAlias |
| 6 | + |
| 7 | +from ..rfc7517 import KeySet |
| 8 | +from .claims import JWTClaims |
| 9 | + |
| 10 | +_T = TypeVar("_T") |
| 11 | + |
| 12 | +_LoadKey: TypeAlias = Callable[[Incomplete, Incomplete], Incomplete] |
2 | 13 |
|
3 | 14 | class JsonWebToken: |
4 | | - SENSITIVE_NAMES: Incomplete |
5 | | - SENSITIVE_VALUES: Incomplete |
| 15 | + SENSITIVE_NAMES: Final[tuple[str, ...]] |
| 16 | + SENSITIVE_VALUES: Final[Pattern[str]] |
| 17 | + |
6 | 18 | def __init__(self, algorithms, private_headers=None) -> None: ... |
7 | 19 | def check_sensitive_data(self, payload) -> None: ... |
8 | 20 | def encode(self, header, payload, key, check: bool = True): ... |
9 | | - def decode(self, s, key, claims_cls=None, claims_options=None, claims_params=None): ... |
| 21 | + @overload |
| 22 | + def decode( |
| 23 | + self, |
| 24 | + s: str | bytes, |
| 25 | + key: _LoadKey | KeySet | tuple[Incomplete, ...] | list[Incomplete] | str, |
| 26 | + claims_cls: None = None, |
| 27 | + claims_options=None, |
| 28 | + claims_params=None, |
| 29 | + ) -> JWTClaims: ... |
| 30 | + @overload |
| 31 | + def decode( |
| 32 | + self, |
| 33 | + s: str | bytes, |
| 34 | + key: _LoadKey | KeySet | tuple[Incomplete, ...] | list[Incomplete] | str, |
| 35 | + claims_cls: type[_T], |
| 36 | + claims_options=None, |
| 37 | + claims_params=None, |
| 38 | + ) -> _T: ... |
10 | 39 |
|
11 | 40 | def decode_payload(bytes_payload): ... |
12 | | -def prepare_raw_key(raw): ... |
| 41 | + |
| 42 | +_TL = TypeVar("_TL", bound=tuple[Any, ...] | list[Any]) |
| 43 | + |
| 44 | +@type_check_only |
| 45 | +class _Keys(TypedDict, Generic[_TL]): |
| 46 | + keys: _TL |
| 47 | + |
| 48 | +@overload |
| 49 | +def prepare_raw_key(raw: KeySet) -> KeySet: ... |
| 50 | +@overload |
| 51 | +def prepare_raw_key(raw: str) -> dict[str, Any] | str: ... # dict is a JSON object |
| 52 | +@overload |
| 53 | +def prepare_raw_key(raw: _TL) -> _Keys[_TL]: ... |
13 | 54 | def find_encode_key(key, header): ... |
14 | | -def create_load_key(key): ... |
| 55 | +def create_load_key(key: KeySet | _Keys[Incomplete] | Incomplete) -> _LoadKey: ... |
0 commit comments