Skip to content

Commit 6cddd30

Browse files
authored
Add basic jwcrypto stubs (#12687)
1 parent 9f033bf commit 6cddd30

File tree

10 files changed

+389
-0
lines changed

10 files changed

+389
-0
lines changed

pyrightconfig.stricter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"stubs/influxdb-client",
5858
"stubs/jmespath",
5959
"stubs/jsonschema",
60+
"stubs/jwcrypto",
6061
"stubs/ldap3",
6162
"stubs/Markdown",
6263
"stubs/mysqlclient",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# test code does not need type hints
2+
jwcrypto.tests
3+
jwcrypto.tests-cookbook
4+
5+
# even if the deprecated decorator is applied, the attribute is not present
6+
jwcrypto.jwt.JWTMissingKeyID.__deprecated__

stubs/jwcrypto/METADATA.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version = "1.5.*"
2+
upstream_repository = "https://github.com/latchset/jwcrypto"
3+
requires = ["cryptography"]

stubs/jwcrypto/jwcrypto/__init__.pyi

Whitespace-only changes.

stubs/jwcrypto/jwcrypto/common.pyi

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from _typeshed import Incomplete
2+
from collections.abc import Iterator, MutableMapping
3+
from typing import Any, NamedTuple
4+
5+
def base64url_encode(payload: str | bytes) -> str: ...
6+
def base64url_decode(payload: str) -> bytes: ...
7+
def json_encode(string: str | bytes) -> str: ...
8+
9+
# The function returns json.loads which returns Any
10+
def json_decode(string: str | bytes) -> Any: ...
11+
12+
class JWException(Exception): ...
13+
14+
class InvalidJWAAlgorithm(JWException):
15+
def __init__(self, message: str | None = None) -> None: ...
16+
17+
class InvalidCEKeyLength(JWException):
18+
def __init__(self, expected: int, obtained: int) -> None: ...
19+
20+
class InvalidJWEOperation(JWException):
21+
def __init__(self, message: str | None = None, exception: BaseException | None = None) -> None: ...
22+
23+
class InvalidJWEKeyType(JWException):
24+
def __init__(self, expected: int, obtained: int) -> None: ...
25+
26+
class InvalidJWEKeyLength(JWException):
27+
def __init__(self, expected: int, obtained: int) -> None: ...
28+
29+
class InvalidJWSERegOperation(JWException):
30+
def __init__(self, message: str | None = None, exception: BaseException | None = None) -> None: ...
31+
32+
class JWKeyNotFound(JWException):
33+
def __init__(self, message: str | None = None) -> None: ...
34+
35+
class JWSEHeaderParameter(NamedTuple):
36+
description: str
37+
mustprotect: bool
38+
supported: bool
39+
check_fn: Incomplete | None
40+
41+
class JWSEHeaderRegistry(MutableMapping[str, JWSEHeaderParameter]):
42+
def __init__(self, init_registry: Incomplete | None = None) -> None: ...
43+
def check_header(self, h: str, value) -> bool: ...
44+
def __getitem__(self, key: str) -> JWSEHeaderParameter: ...
45+
def __iter__(self) -> Iterator[str]: ...
46+
def __delitem__(self, key: str) -> None: ...
47+
def __setitem__(self, h: str, jwse_header_param: JWSEHeaderParameter) -> None: ...
48+
def __len__(self) -> int: ...

stubs/jwcrypto/jwcrypto/jwa.pyi

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from abc import ABCMeta, abstractmethod
2+
from collections.abc import Mapping
3+
from typing import ClassVar
4+
5+
default_max_pbkdf2_iterations: int
6+
7+
class JWAAlgorithm(metaclass=ABCMeta):
8+
@property
9+
@abstractmethod
10+
def name(self) -> str: ...
11+
@property
12+
@abstractmethod
13+
def description(self) -> str: ...
14+
@property
15+
@abstractmethod
16+
def keysize(self) -> int: ...
17+
@property
18+
@abstractmethod
19+
def algorithm_usage_location(self) -> str: ...
20+
@property
21+
@abstractmethod
22+
def algorithm_use(self) -> str: ...
23+
@property
24+
def input_keysize(self) -> int: ...
25+
26+
class JWA:
27+
algorithms_registry: ClassVar[Mapping[str, JWAAlgorithm]]
28+
@classmethod
29+
def instantiate_alg(cls, name: str, use: str | None = None) -> JWAAlgorithm: ...
30+
@classmethod
31+
def signing_alg(cls, name: str) -> JWAAlgorithm: ...
32+
@classmethod
33+
def keymgmt_alg(cls, name: str) -> JWAAlgorithm: ...
34+
@classmethod
35+
def encryption_alg(cls, name: str) -> JWAAlgorithm: ...

stubs/jwcrypto/jwcrypto/jwe.pyi

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from _typeshed import Incomplete
2+
from collections.abc import Mapping, Sequence
3+
4+
from jwcrypto import common
5+
from jwcrypto.common import JWException, JWSEHeaderParameter
6+
from jwcrypto.jwk import JWK, JWKSet
7+
8+
default_max_compressed_size: int
9+
JWEHeaderRegistry: Mapping[str, JWSEHeaderParameter]
10+
default_allowed_algs: Sequence[str]
11+
12+
class InvalidJWEData(JWException):
13+
def __init__(self, message: str | None = None, exception: BaseException | None = None) -> None: ...
14+
15+
InvalidCEKeyLength = common.InvalidCEKeyLength
16+
InvalidJWEKeyLength = common.InvalidJWEKeyLength
17+
InvalidJWEKeyType = common.InvalidJWEKeyType
18+
InvalidJWEOperation = common.InvalidJWEOperation
19+
20+
class JWE:
21+
objects: Incomplete
22+
plaintext: Incomplete
23+
header_registry: Incomplete
24+
cek: Incomplete
25+
decryptlog: Incomplete
26+
def __init__(
27+
self,
28+
plaintext: bytes | None = None,
29+
protected: str | None = None,
30+
unprotected: str | None = None,
31+
aad: bytes | None = None,
32+
algs: Incomplete | None = None,
33+
recipient: str | None = None,
34+
header: Incomplete | None = None,
35+
header_registry: Incomplete | None = None,
36+
) -> None: ...
37+
@property
38+
def allowed_algs(self): ...
39+
@allowed_algs.setter
40+
def allowed_algs(self, algs) -> None: ...
41+
def add_recipient(self, key, header: Incomplete | None = None) -> None: ...
42+
def serialize(self, compact: bool = False): ...
43+
def decrypt(self, key: JWK | JWKSet) -> None: ...
44+
def deserialize(self, raw_jwe: str | bytes, key: JWK | JWKSet | None = None) -> None: ...
45+
@property
46+
def payload(self): ...
47+
@property
48+
def jose_header(self) -> dict[Incomplete, Incomplete]: ...
49+
@classmethod
50+
def from_jose_token(cls, token: str | bytes) -> JWE: ...
51+
def __eq__(self, other: object) -> bool: ...

stubs/jwcrypto/jwcrypto/jwk.pyi

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
from _typeshed import Incomplete
2+
from collections.abc import Sequence
3+
from enum import Enum
4+
from typing import Any, NamedTuple
5+
6+
from cryptography.hazmat.primitives.asymmetric.ed448 import Ed448PrivateKey as Ed448PrivateKey, Ed448PublicKey as Ed448PublicKey
7+
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
8+
Ed25519PrivateKey as Ed25519PrivateKey,
9+
Ed25519PublicKey as Ed25519PublicKey,
10+
)
11+
from cryptography.hazmat.primitives.asymmetric.x448 import X448PrivateKey as X448PrivateKey, X448PublicKey as X448PublicKey
12+
from cryptography.hazmat.primitives.asymmetric.x25519 import (
13+
X25519PrivateKey as X25519PrivateKey,
14+
X25519PublicKey as X25519PublicKey,
15+
)
16+
from jwcrypto.common import JWException
17+
18+
class UnimplementedOKPCurveKey:
19+
@classmethod
20+
def generate(cls) -> None: ...
21+
@classmethod
22+
def from_public_bytes(cls, *args) -> None: ...
23+
@classmethod
24+
def from_private_bytes(cls, *args) -> None: ...
25+
26+
ImplementedOkpCurves: Sequence[str]
27+
priv_bytes: Incomplete
28+
29+
JWKTypesRegistry: Incomplete
30+
31+
class ParmType(Enum):
32+
name: str
33+
b64: str
34+
b64u: str
35+
unsupported: str
36+
37+
class JWKParameter(NamedTuple):
38+
description: Incomplete
39+
public: Incomplete
40+
required: Incomplete
41+
type: Incomplete
42+
43+
JWKValuesRegistry: Incomplete
44+
JWKParamsRegistry: Incomplete
45+
JWKEllipticCurveRegistry: Incomplete
46+
JWKUseRegistry: Incomplete
47+
JWKOperationsRegistry: Incomplete
48+
JWKpycaCurveMap: Incomplete
49+
IANANamedInformationHashAlgorithmRegistry: Incomplete
50+
51+
class InvalidJWKType(JWException):
52+
value: Incomplete
53+
def __init__(self, value: Incomplete | None = None) -> None: ...
54+
55+
class InvalidJWKUsage(JWException):
56+
value: Incomplete
57+
use: Incomplete
58+
def __init__(self, use, value) -> None: ...
59+
60+
class InvalidJWKOperation(JWException):
61+
op: Incomplete
62+
values: Incomplete
63+
def __init__(self, operation, values) -> None: ...
64+
65+
class InvalidJWKValue(JWException): ...
66+
67+
class JWK(dict[str, Any]):
68+
def __init__(self, **kwargs) -> None: ...
69+
@classmethod
70+
def generate(cls, **kwargs): ...
71+
def generate_key(self, **params) -> None: ...
72+
def import_key(self, **kwargs) -> None: ...
73+
@classmethod
74+
def from_json(cls, key): ...
75+
def export(self, private_key: bool = True, as_dict: bool = False): ...
76+
def export_public(self, as_dict: bool = False): ...
77+
def export_private(self, as_dict: bool = False): ...
78+
def export_symmetric(self, as_dict: bool = False): ...
79+
def public(self): ...
80+
@property
81+
def has_public(self) -> bool: ...
82+
@property
83+
def has_private(self) -> bool: ...
84+
@property
85+
def is_symmetric(self) -> bool: ...
86+
@property
87+
def key_type(self): ...
88+
@property
89+
def key_id(self): ...
90+
@property
91+
def key_curve(self): ...
92+
def get_curve(self, arg): ...
93+
def get_op_key(self, operation: Incomplete | None = None, arg: Incomplete | None = None): ...
94+
def import_from_pyca(self, key) -> None: ...
95+
def import_from_pem(self, data, password: Incomplete | None = None, kid: Incomplete | None = None) -> None: ...
96+
def export_to_pem(self, private_key: bool = False, password: bool = False): ...
97+
@classmethod
98+
def from_pyca(cls, key): ...
99+
@classmethod
100+
def from_pem(cls, data, password: Incomplete | None = None): ...
101+
def thumbprint(self, hashalg=...): ...
102+
def thumbprint_uri(self, hname: str = "sha-256"): ...
103+
@classmethod
104+
def from_password(cls, password): ...
105+
def setdefault(self, key: str, default: Incomplete | None = None): ...
106+
107+
class JWKSet(dict[str, Any]):
108+
def add(self, elem) -> None: ...
109+
def export(self, private_keys: bool = True, as_dict: bool = False): ...
110+
def import_keyset(self, keyset) -> None: ...
111+
@classmethod
112+
def from_json(cls, keyset): ...
113+
def get_key(self, kid): ...
114+
def get_keys(self, kid): ...
115+
def setdefault(self, key: str, default: Incomplete | None = None): ...

stubs/jwcrypto/jwcrypto/jws.pyi

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from _typeshed import Incomplete
2+
3+
from jwcrypto.common import JWException
4+
5+
JWSHeaderRegistry: Incomplete
6+
default_allowed_algs: Incomplete
7+
8+
class InvalidJWSSignature(JWException):
9+
def __init__(self, message: str | None = None, exception: BaseException | None = None) -> None: ...
10+
11+
class InvalidJWSObject(JWException):
12+
def __init__(self, message: str | None = None, exception: BaseException | None = None) -> None: ...
13+
14+
class InvalidJWSOperation(JWException):
15+
def __init__(self, message: str | None = None, exception: BaseException | None = None) -> None: ...
16+
17+
class JWSCore:
18+
alg: Incomplete
19+
engine: Incomplete
20+
key: Incomplete
21+
header: Incomplete
22+
protected: Incomplete
23+
payload: Incomplete
24+
def __init__(self, alg, key, header, payload, algs: Incomplete | None = None) -> None: ...
25+
def sign(self): ...
26+
def verify(self, signature): ...
27+
28+
class JWS:
29+
objects: Incomplete
30+
verifylog: Incomplete
31+
header_registry: Incomplete
32+
def __init__(self, payload: Incomplete | None = None, header_registry: Incomplete | None = None) -> None: ...
33+
@property
34+
def allowed_algs(self): ...
35+
@allowed_algs.setter
36+
def allowed_algs(self, algs) -> None: ...
37+
@property
38+
def is_valid(self): ...
39+
def verify(self, key, alg: Incomplete | None = None, detached_payload: Incomplete | None = None) -> None: ...
40+
def deserialize(self, raw_jws, key: Incomplete | None = None, alg: Incomplete | None = None) -> None: ...
41+
def add_signature(
42+
self, key, alg: Incomplete | None = None, protected: Incomplete | None = None, header: Incomplete | None = None
43+
) -> None: ...
44+
def serialize(self, compact: bool = False): ...
45+
@property
46+
def payload(self): ...
47+
def detach_payload(self) -> None: ...
48+
@property
49+
def jose_header(self): ...
50+
@classmethod
51+
def from_jose_token(cls, token): ...
52+
def __eq__(self, other: object) -> bool: ...

0 commit comments

Comments
 (0)