1
1
from collections .abc import Callable , Sequence
2
2
from enum import Enum
3
3
from typing import Any , Literal , NamedTuple , TypeVar , overload
4
- from typing_extensions import Self , deprecated
4
+ from typing_extensions import Self , TypeAlias , deprecated
5
5
6
6
from cryptography .hazmat .primitives import hashes
7
7
from cryptography .hazmat .primitives .asymmetric import ec , rsa
@@ -46,7 +46,8 @@ class _X448_CURVE(NamedTuple):
46
46
pubkey : UnimplementedOKPCurveKey
47
47
privkey : UnimplementedOKPCurveKey
48
48
49
- JWKTypesRegistry : dict [str , str ]
49
+ _JWKKeyTypeSupported : TypeAlias = Literal ["oct" , "RSA" , "EC" , "OKP" ]
50
+ JWKTypesRegistry : dict [_JWKKeyTypeSupported , str ]
50
51
51
52
class ParmType (Enum ):
52
53
name = "A string with a name" # pyright: ignore[reportAssignmentType]
@@ -63,8 +64,12 @@ class JWKParameter(NamedTuple):
63
64
JWKValuesRegistry : dict [str , dict [str , JWKParameter ]]
64
65
JWKParamsRegistry : dict [str , JWKParameter ]
65
66
JWKEllipticCurveRegistry : 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 ]
68
73
JWKpycaCurveMap : dict [str , str ]
69
74
IANANamedInformationHashAlgorithmRegistry : dict [
70
75
str ,
@@ -79,7 +84,6 @@ IANANamedInformationHashAlgorithmRegistry: dict[
79
84
| hashes .BLAKE2b
80
85
| None ,
81
86
]
82
- JWKKeyTypeSupported = Literal ["oct" , "RSA" , "EC" , "OKP" ]
83
87
84
88
class InvalidJWKType (JWException ):
85
89
value : str | None
@@ -103,8 +107,22 @@ class JWK(dict[str, Any]):
103
107
# function. The possible arguments depend on the value of `kty`.
104
108
# TODO: Add overloads for the individual `kty` values.
105
109
@classmethod
106
- def generate (cls , kty : JWKKeyTypeSupported , ** kwargs ) -> Self : ...
107
- def generate_key (self , kty : JWKKeyTypeSupported , ** kwargs ) -> None : ...
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 : ...
122
+ @classmethod
123
+ @overload
124
+ def generate (cls , * , kty : _JWKKeyTypeSupported , ** kwargs ) -> Self : ...
125
+ def generate_key (self , * , kty : _JWKKeyTypeSupported , ** kwargs ) -> None : ...
108
126
def import_key (self , ** kwargs ) -> None : ...
109
127
@classmethod
110
128
def from_json (cls , key ) -> Self : ...
0 commit comments