Skip to content

Commit 43d1c0e

Browse files
committed
Improved oqs stub to use @Final for classes and TypedDict for details attributes & Removed init stub to be more flexible (when making edits directly down the line).
Signed-off-by: M-AlNoaimi <[email protected]>
1 parent 5fa614f commit 43d1c0e

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

oqs/__init__.pyi

Lines changed: 0 additions & 20 deletions
This file was deleted.

oqs/oqs.pyi

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ctypes
22
from types import TracebackType
3-
from typing import Final, TypeVar
3+
from typing import Final, TypeVar, final, TypedDict
44

55
_TKeyEncapsulation = TypeVar("_TKeyEncapsulation", bound="KeyEncapsulation")
66
_TSignature = TypeVar("_TSignature", bound="Signature")
@@ -22,6 +22,17 @@ class MechanismNotEnabledError(MechanismNotSupportedError):
2222
# alg_name and message are inherited from MechanismNotSupportedError
2323
def __init__(self, alg_name: str) -> None: ...
2424

25+
class KeyEncapsulationDetails(TypedDict):
26+
name: str
27+
version: str
28+
claimed_nist_level: int
29+
is_ind_cca: bool
30+
length_public_key: int
31+
length_secret_key: int
32+
length_ciphertext: int
33+
length_shared_secret: int
34+
35+
@final
2536
class KeyEncapsulation:
2637
# Attributes from the underlying ctypes.Structure, exposed with Python types
2738
method_name: bytes
@@ -35,7 +46,7 @@ class KeyEncapsulation:
3546

3647
# Custom attributes set during initialization
3748
alg_name: str
38-
details: dict[str, str | int | bool]
49+
details: KeyEncapsulationDetails
3950

4051
def __init__(self, alg_name: str, secret_key: int | bytes | None = None) -> None: ...
4152
def __enter__(self: _TKeyEncapsulation) -> _TKeyEncapsulation: ...
@@ -52,6 +63,17 @@ class KeyEncapsulation:
5263
def free(self) -> None: ...
5364
def __repr__(self) -> str: ...
5465

66+
class SignatureDetails(TypedDict):
67+
name: str
68+
version: str
69+
claimed_nist_level: int
70+
is_euf_cma: bool
71+
sig_with_ctx_support: bool
72+
length_public_key: int
73+
length_secret_key: int
74+
length_signature: int
75+
76+
@final
5577
class Signature:
5678
# Attributes from the underlying ctypes.Structure, exposed with Python types
5779
method_name: bytes
@@ -65,7 +87,7 @@ class Signature:
6587

6688
# Custom attributes set during initialization
6789
alg_name: str
68-
details: dict[str, str | int | bool]
90+
details: SignatureDetails
6991

7092
def __init__(self, alg_name: str, secret_key: int | bytes | None = None) -> None: ...
7193
def __enter__(self: _TSignature) -> _TSignature: ...
@@ -91,4 +113,4 @@ def get_enabled_kem_mechanisms() -> tuple[str, ...]: ...
91113
def get_supported_kem_mechanisms() -> tuple[str, ...]: ...
92114
def is_sig_enabled(alg_name: str) -> bool: ...
93115
def get_enabled_sig_mechanisms() -> tuple[str, ...]: ...
94-
def get_supported_sig_mechanisms() -> tuple[str, ...]: ...
116+
def get_supported_sig_mechanisms() -> tuple[str, ...]: ...

0 commit comments

Comments
 (0)