11from collections .abc import Callable , Sequence
22from enum import Enum
33from typing import Any , Literal , NamedTuple , TypeVar , overload
4- from typing_extensions import Self , deprecated
4+ from typing_extensions import Self , TypeAlias , deprecated
55
66from cryptography .hazmat .primitives import hashes
77from cryptography .hazmat .primitives .asymmetric import ec , rsa
@@ -46,7 +46,8 @@ class _X448_CURVE(NamedTuple):
4646 pubkey : UnimplementedOKPCurveKey
4747 privkey : UnimplementedOKPCurveKey
4848
49- JWKTypesRegistry : dict [str , str ]
49+ _JWKKeyTypeSupported : TypeAlias = Literal ["oct" , "RSA" , "EC" , "OKP" ]
50+ JWKTypesRegistry : dict [_JWKKeyTypeSupported , str ]
5051
5152class ParmType (Enum ):
5253 name = "A string with a name" # pyright: ignore[reportAssignmentType]
@@ -63,8 +64,12 @@ class JWKParameter(NamedTuple):
6364JWKValuesRegistry : dict [str , dict [str , JWKParameter ]]
6465JWKParamsRegistry : dict [str , JWKParameter ]
6566JWKEllipticCurveRegistry : dict [str , str ]
66- JWKUseRegistry : dict [str , str ]
67- JWKOperationsRegistry : dict [str , str ]
67+ _JWKUseSupported : TypeAlias = Literal ["sig" , "enc" ]
68+ JWKUseRegistry : dict [_JWKUseSupported , str ]
69+ _JWKOperationSupported : TypeAlias = Literal [
70+ "sign" , "verify" , "encrypt" , "decrypt" , "wrapKey" , "unwrapKey" , "deriveKey" , "deriveBits"
71+ ]
72+ JWKOperationsRegistry : dict [_JWKOperationSupported , str ]
6873JWKpycaCurveMap : dict [str , str ]
6974IANANamedInformationHashAlgorithmRegistry : dict [
7075 str ,
@@ -98,9 +103,26 @@ class InvalidJWKValue(JWException): ...
98103
99104class JWK (dict [str , Any ]):
100105 def __init__ (self , ** kwargs ) -> None : ...
106+ # `kty` and the other keyword arguments are passed as `params` to the called generator
107+ # function. The possible arguments depend on the value of `kty`.
108+ # TODO: Add overloads for the individual `kty` values.
109+ @classmethod
110+ @overload
111+ def generate (
112+ cls ,
113+ * ,
114+ kty : Literal ["RSA" ],
115+ public_exponent : int | None = None ,
116+ size : int | None = None ,
117+ kid : str | None = None ,
118+ alg : str | None = None ,
119+ use : _JWKUseSupported | None = None ,
120+ key_ops : list [_JWKOperationSupported ] | None = None ,
121+ ) -> Self : ...
101122 @classmethod
102- def generate (cls , ** kwargs ) -> Self : ...
103- def generate_key (self , ** params ) -> None : ...
123+ @overload
124+ def generate (cls , * , kty : _JWKKeyTypeSupported , ** kwargs ) -> Self : ...
125+ def generate_key (self , * , kty : _JWKKeyTypeSupported , ** kwargs ) -> None : ...
104126 def import_key (self , ** kwargs ) -> None : ...
105127 @classmethod
106128 def from_json (cls , key ) -> Self : ...
0 commit comments