Skip to content

Commit 338384c

Browse files
committed
Add stubs for wolfcrypt
1 parent 3e1b90b commit 338384c

File tree

12 files changed

+398
-0
lines changed

12 files changed

+398
-0
lines changed

pyrightconfig.stricter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"stubs/tensorflow",
9393
"stubs/tqdm",
9494
"stubs/vobject",
95+
"stubs/wolfcrypt",
9596
"stubs/workalendar",
9697
"stubs/xmldiff",
9798
],

stubs/wolfcrypt/METADATA.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = "5.8.*"
2+
upstream_repository = "https://github.com/wolfssl/wolfcrypt-py"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from wolfcrypt._version import __version__ as __version__
2+
3+
__all__ = [
4+
"__title__",
5+
"__summary__",
6+
"__uri__",
7+
"__version__",
8+
"__author__",
9+
"__email__",
10+
"__license__",
11+
"__copyright__",
12+
"ciphers",
13+
"hashes",
14+
"random",
15+
"pwdbased",
16+
]
17+
18+
__title__: str
19+
__summary__: str
20+
__uri__: str
21+
__author__: str
22+
__email__: str
23+
__license__: str
24+
__copyright__: str
25+
26+
# Names in __all__ with no definition:
27+
# ciphers
28+
# hashes
29+
# pwdbased
30+
# random

stubs/wolfcrypt/wolfcrypt/_ffi.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import _cffi_backend
2+
3+
ffi: _cffi_backend.FFI
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__wolfssl_version__: str
2+
__version__: str

stubs/wolfcrypt/wolfcrypt/asn.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from wolfcrypt.hashes import _Hash
2+
3+
def pem_to_der(pem:bytes, pem_type:int)->bytes: ...
4+
def der_to_pem(der:bytes, pem_type:int)->bytes: ...
5+
def hash_oid_from_class(hash_cls: type[_Hash])->int: ...
6+
def make_signature(data: bytes, hash_cls:type[_Hash], key:str|bytes=None)->bytes: ...
7+
def check_signature(signature: bytes, data:bytes, hash_cls:type[_Hash], pub_key)->bool: ...
Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
from _typeshed import Incomplete
2+
from enum import IntEnum
3+
from typing import Literal, overload
4+
5+
MODE_ECB = Literal[1]
6+
MODE_CBC = Literal[2]
7+
MODE_CFB = Literal[3]
8+
MODE_OFB = Literal[5]
9+
MODE_CTR = Literal[6]
10+
_FEEDBACK_MODES = Literal[MODE_ECB, MODE_CBC, MODE_CFB, MODE_OFB, MODE_CTR]
11+
12+
ECC_CURVE_INVALID: int
13+
ECC_CURVE_DEF: int
14+
ECC_SECP192R1: int
15+
ECC_PRIME192V2: int
16+
ECC_PRIME192V3: int
17+
ECC_PRIME239V1: int
18+
ECC_PRIME239V2: int
19+
ECC_PRIME239V3: int
20+
ECC_SECP256R1: int
21+
ECC_SECP112R1: int
22+
ECC_SECP112R2: int
23+
ECC_SECP128R1: int
24+
ECC_SECP128R2: int
25+
ECC_SECP160R1: int
26+
ECC_SECP160R2: int
27+
ECC_SECP224R1: int
28+
ECC_SECP384R1: int
29+
ECC_SECP521R1: int
30+
ECC_SECP160K1: int
31+
ECC_SECP192K1: int
32+
ECC_SECP224K1: int
33+
ECC_SECP256K1: int
34+
ECC_BRAINPOOLP160R1: int
35+
ECC_BRAINPOOLP192R1: int
36+
ECC_BRAINPOOLP224R1: int
37+
ECC_BRAINPOOLP256R1: int
38+
ECC_BRAINPOOLP320R1: int
39+
ECC_BRAINPOOLP384R1: int
40+
ECC_BRAINPOOLP512R1: int
41+
42+
MGF1NONE: int
43+
MGF1SHA1: int
44+
MGF1SHA224: int
45+
MGF1SHA256: int
46+
MGF1SHA384: int
47+
MGF1SHA512: int
48+
HASH_TYPE_NONE: int
49+
HASH_TYPE_MD2: int
50+
HASH_TYPE_MD4: int
51+
HASH_TYPE_MD5: int
52+
HASH_TYPE_SHA: int
53+
HASH_TYPE_SHA224: int
54+
HASH_TYPE_SHA256: int
55+
HASH_TYPE_SHA384: int
56+
HASH_TYPE_SHA512: int
57+
HASH_TYPE_MD5_SHA: int
58+
HASH_TYPE_SHA3_224: int
59+
HASH_TYPE_SHA3_256: int
60+
HASH_TYPE_SHA3_384: int
61+
HASH_TYPE_SHA3_512: int
62+
HASH_TYPE_BLAKE2B: int
63+
HASH_TYPE_BLAKE2S: int
64+
65+
66+
class _Cipher:
67+
mode: _FEEDBACK_MODES
68+
@overload
69+
def __init__(self, key:str| bytes, mode: Literal[MODE_CBC, MODE_CTR], IV:str| bytes) -> None: ...
70+
@overload
71+
def __init__(self, key:str| bytes, mode: _FEEDBACK_MODES, IV:str| bytes|None=None) -> None: ...
72+
@overload
73+
@classmethod
74+
def new(cls, key:str| bytes, mode: Literal[MODE_CBC, MODE_CTR], IV:str| bytes, **kwargs): ...
75+
@overload
76+
@classmethod
77+
def new(cls, key:str| bytes, mode: _FEEDBACK_MODES, IV:str| bytes|None=None, **kwargs): ...
78+
def encrypt(self, string: str|bytes)->bytes: ...
79+
def decrypt(self, string: str|bytes)->bytes: ...
80+
81+
class Aes(_Cipher):
82+
block_size: int
83+
key_size: None
84+
85+
class AesGcmStream:
86+
block_size: int
87+
def __init__(self, key: str|bytes, IV: str|bytes, tag_bytes: int = 16) -> None: ...
88+
def set_aad(self, data: str|bytes) -> None: ...
89+
def get_aad(self)->bytes: ...
90+
def encrypt(self, data: str|bytes)->bytes: ...
91+
def decrypt(self, data: str|bytes)->bytes: ...
92+
def final(self, authTag=None): ...
93+
94+
class ChaCha(_Cipher):
95+
block_size: int
96+
key_size: int
97+
def __init__(self, key: str = "", size: int = 32) -> None: ...
98+
def set_iv(self, nonce, counter: int = 0) -> None: ...
99+
100+
class ChaCha20Poly1305:
101+
block_size: int
102+
def __init__(self, key, IV, aad, tag_bytes: int = 16) -> None: ...
103+
def set_aad(self, data) -> None: ...
104+
def get_aad(self): ...
105+
def encrypt(self, inPlainText): ...
106+
def decrypt(self, inGeneratedAuthTag, inGeneratedCipher): ...
107+
def checkTag(self, authTag) -> None: ...
108+
def final(self, authTag=None): ...
109+
110+
class Des3(_Cipher):
111+
block_size: int
112+
key_size: int
113+
114+
class _Rsa:
115+
RSA_MIN_PAD_SIZE: int
116+
native_object: Incomplete
117+
def __init__(self) -> None: ...
118+
def __del__(self) -> None: ...
119+
def set_mgf(self, mgf) -> None: ...
120+
121+
class RsaPublic(_Rsa):
122+
output_size: Incomplete
123+
size: Incomplete
124+
def __init__(self, key=None, hash_type=None) -> None: ...
125+
@classmethod
126+
def from_pem(cls, file, hash_type=None): ...
127+
def encrypt(self, plaintext): ...
128+
def encrypt_oaep(self, plaintext, label: str = ""): ...
129+
def verify(self, signature): ...
130+
def verify_pss(self, plaintext, signature): ...
131+
132+
class RsaPrivate(RsaPublic):
133+
@classmethod
134+
def make_key(cls, size, rng=..., hash_type=None): ...
135+
size: Incomplete
136+
output_size: Incomplete
137+
def __init__(self, key=None, hash_type=None) -> None: ...
138+
@classmethod
139+
def from_pem(cls, file, hash_type=None): ...
140+
def encode_key(self): ...
141+
def decrypt(self, ciphertext): ...
142+
def decrypt_oaep(self, ciphertext, label: str = ""): ...
143+
def sign(self, plaintext): ...
144+
def sign_pss(self, plaintext): ...
145+
146+
class _Ecc:
147+
native_object: Incomplete
148+
def __init__(self) -> None: ...
149+
def __del__(self) -> None: ...
150+
@property
151+
def size(self): ...
152+
@property
153+
def max_signature_size(self): ...
154+
155+
class EccPublic(_Ecc):
156+
def __init__(self, key=None) -> None: ...
157+
def decode_key(self, key) -> None: ...
158+
def decode_key_raw(self, qx, qy, curve_id=7) -> None: ...
159+
def encode_key(self, with_curve: bool = True): ...
160+
def encode_key_raw(self): ...
161+
def import_x963(self, x963) -> None: ...
162+
def export_x963(self): ...
163+
def verify(self, signature, data): ...
164+
def verify_raw(self, R, S, data): ...
165+
166+
class EccPrivate(EccPublic):
167+
@classmethod
168+
def make_key(cls, size, rng=...): ...
169+
def decode_key(self, key) -> None: ...
170+
def decode_key_raw(self, qx, qy, d, curve_id=7) -> None: ...
171+
def encode_key(self): ...
172+
def encode_key_raw(self): ...
173+
def shared_secret(self, peer): ...
174+
def sign(self, plaintext, rng=...): ...
175+
def sign_raw(self, plaintext, rng=...): ...
176+
177+
class _Ed25519:
178+
native_object: Incomplete
179+
def __init__(self) -> None: ...
180+
def __del__(self) -> None: ...
181+
@property
182+
def size(self): ...
183+
@property
184+
def max_signature_size(self): ...
185+
186+
class Ed25519Public(_Ed25519):
187+
def __init__(self, key=None) -> None: ...
188+
def decode_key(self, key) -> None: ...
189+
def encode_key(self): ...
190+
def verify(self, signature, data): ...
191+
192+
class Ed25519Private(Ed25519Public):
193+
def __init__(self, key=None, pub=None) -> None: ...
194+
@classmethod
195+
def make_key(cls, size, rng=...): ...
196+
def decode_key(self, key, pub=None) -> None: ...
197+
def encode_key(self): ...
198+
def sign(self, plaintext): ...
199+
200+
class _Ed448:
201+
native_object: Incomplete
202+
def __init__(self) -> None: ...
203+
def __del__(self) -> None: ...
204+
@property
205+
def size(self): ...
206+
@property
207+
def max_signature_size(self): ...
208+
209+
class Ed448Public(_Ed448):
210+
def __init__(self, key=None) -> None: ...
211+
def decode_key(self, key) -> None: ...
212+
def encode_key(self): ...
213+
def verify(self, signature, data, ctx=None): ...
214+
215+
class Ed448Private(Ed448Public):
216+
def __init__(self, key=None, pub=None) -> None: ...
217+
@classmethod
218+
def make_key(cls, size, rng=...): ...
219+
def decode_key(self, key, pub=None) -> None: ...
220+
def encode_key(self): ...
221+
def sign(self, plaintext, ctx=None): ...
222+
223+
class MlKemType(IntEnum):
224+
ML_KEM_512 = ...
225+
ML_KEM_768 = ...
226+
ML_KEM_1024 = ...
227+
228+
class _MlKemBase:
229+
INVALID_DEVID: Incomplete
230+
init_done: bool
231+
native_object: Incomplete
232+
def __init__(self, mlkem_type) -> None: ...
233+
def __del__(self) -> None: ...
234+
@property
235+
def ct_size(self): ...
236+
@property
237+
def ss_size(self): ...
238+
239+
class MlKemPublic(_MlKemBase):
240+
@property
241+
def key_size(self): ...
242+
def encode_key(self): ...
243+
def decode_key(self, pub_key) -> None: ...
244+
def encapsulate(self, rng=...): ...
245+
def encapsulate_with_random(self, rand): ...
246+
247+
class MlKemPrivate(_MlKemBase):
248+
@classmethod
249+
def make_key(cls, mlkem_type, rng=...): ...
250+
@classmethod
251+
def make_key_with_random(cls, mlkem_type, rand): ...
252+
@property
253+
def pub_key_size(self): ...
254+
@property
255+
def priv_key_size(self): ...
256+
def encode_pub_key(self): ...
257+
def encode_priv_key(self): ...
258+
def decode_key(self, priv_key: tuple[bytes, str]): ...
259+
native_object: Incomplete
260+
def decapsulate(self, ct): ...
261+
262+
class MlDsaType(IntEnum):
263+
ML_DSA_44 = ...
264+
ML_DSA_65 = ...
265+
ML_DSA_87 = ...
266+
267+
class _MlDsaBase:
268+
INVALID_DEVID: Incomplete
269+
native_object: Incomplete
270+
def __init__(self, mldsa_type) -> None: ...
271+
def __del__(self) -> None: ...
272+
@property
273+
def sig_size(self): ...
274+
def verify(self, signature, message): ...
275+
276+
class MlDsaPrivate(_MlDsaBase):
277+
@classmethod
278+
def make_key(cls, mldsa_type, rng=...): ...
279+
@property
280+
def pub_key_size(self): ...
281+
@property
282+
def priv_key_size(self): ...
283+
def encode_pub_key(self): ...
284+
def encode_priv_key(self): ...
285+
def decode_key(self, priv_key, pub_key=None) -> None: ...
286+
def sign(self, message, rng=...): ...
287+
288+
class MlDsaPublic(_MlDsaBase):
289+
@property
290+
def key_size(self): ...
291+
def decode_key(self, pub_key): ...
292+
def encode_key(self): ...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class WolfCryptError(Exception): ...

0 commit comments

Comments
 (0)