| 1 | from __future__ import annotations |
| 2 | |
| 3 | from typing import Union, Callable, Optional, Tuple, Dict, NamedTuple, Any, overload, Literal |
| 4 | from typing_extensions import TypedDict, Unpack, NotRequired |
| 5 | |
| 6 | from Crypto.Math.Numbers import Integer |
| 7 | from Crypto.IO._PBES import ProtParams |
| 8 | |
| 9 | RNG = Callable[[int], bytes] |
| 10 | |
| 11 | |
| 12 | class UnsupportedEccFeature(ValueError): |
| 13 | ... |
| 14 | |
| 15 | |
| 16 | class EccPoint(object): |
| 17 | def __init__(self, |
| 18 | x: Union[int, Integer], |
| 19 | y: Union[int, Integer], |
| 20 | curve: Optional[str] = ...) -> None: ... |
| 21 | |
| 22 | def set(self, point: EccPoint) -> EccPoint: ... |
| 23 | def __eq__(self, point: object) -> bool: ... |
| 24 | def __neg__(self) -> EccPoint: ... |
| 25 | def copy(self) -> EccPoint: ... |
| 26 | def is_point_at_infinity(self) -> bool: ... |
| 27 | def point_at_infinity(self) -> EccPoint: ... |
| 28 | @property |
| 29 | def x(self) -> int: ... |
| 30 | @property |
| 31 | def y(self) -> int: ... |
| 32 | @property |
| 33 | def xy(self) -> Tuple[int, int]: ... |
| 34 | def size_in_bytes(self) -> int: ... |
| 35 | def size_in_bits(self) -> int: ... |
| 36 | def double(self) -> EccPoint: ... |
| 37 | def __iadd__(self, point: EccPoint) -> EccPoint: ... |
| 38 | def __add__(self, point: EccPoint) -> EccPoint: ... |
| 39 | def __imul__(self, scalar: int) -> EccPoint: ... |
| 40 | def __mul__(self, scalar: int) -> EccPoint: ... |
| 41 | |
| 42 | |
| 43 | class ExportParams(TypedDict): |
| 44 | passphrase: NotRequired[Union[bytes, str]] |
| 45 | use_pkcs8: NotRequired[bool] |
| 46 | protection: NotRequired[str] |
| 47 | compress: NotRequired[bool] |
| 48 | prot_params: NotRequired[ProtParams] |
| 49 | |
| 50 | |
| 51 | class EccKey(object): |
| 52 | curve: str |
| 53 | def __init__(self, *, curve: str = ..., d: int = ..., point: EccPoint = ...) -> None: ... |
| 54 | def __eq__(self, other: object) -> bool: ... |
| 55 | def __repr__(self) -> str: ... |
| 56 | def has_private(self) -> bool: ... |
| 57 | @property |
| 58 | def d(self) -> int: ... |
| 59 | @property |
| 60 | def pointQ(self) -> EccPoint: ... |
| 61 | def public_key(self) -> EccKey: ... |
| 62 | |
| 63 | @overload |
| 64 | def export_key(self, |
| 65 | *, |
| 66 | format: Literal['PEM', 'OpenSSH'], |
| 67 | **kwargs: Unpack[ExportParams]) -> str: ... |
| 68 | |
| 69 | @overload |
| 70 | def export_key(self, |
| 71 | *, |
| 72 | format: Literal['DER', 'SEC1', 'raw'], |
| 73 | **kwargs: Unpack[ExportParams]) -> bytes: ... |
| 74 | |
| 75 | |
| 76 | _Curve = NamedTuple("_Curve", [('p', Integer), |
| 77 | ('order', Integer), |
| 78 | ('b', Integer), |
| 79 | ('Gx', Integer), |
| 80 | ('Gy', Integer), |
| 81 | ('G', EccPoint), |
| 82 | ('modulus_bits', int), |
| 83 | ('oid', str), |
| 84 | ('context', Any), |
| 85 | ('desc', str), |
| 86 | ('openssh', Union[str, None]), |
| 87 | ]) |
| 88 | |
| 89 | _curves: Dict[str, _Curve] |
| 90 | |
| 91 | |
| 92 | def generate(**kwargs: Union[str, RNG]) -> EccKey: ... |
| 93 | def construct(**kwargs: Union[str, int]) -> EccKey: ... |
| 94 | |
| 95 | |
| 96 | def import_key(encoded: Union[bytes, str], |
| 97 | passphrase: Optional[str] = None, |
| 98 | curve_name: Optional[str] = None) -> EccKey: ... |
| 99 | |
| 100 | |
| 101 | def _import_ed25519_public_key(encoded: bytes) -> EccKey: ... |
| 102 | def _import_ed448_public_key(encoded: bytes) -> EccKey: ... |