ECC.pyi 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from __future__ import annotations
  2. from typing import Union, Callable, Optional, Tuple, Dict, NamedTuple, Any, overload, Literal
  3. from typing_extensions import TypedDict, Unpack, NotRequired
  4. from Crypto.Math.Numbers import Integer
  5. from Crypto.IO._PBES import ProtParams
  6. from ._point import EccPoint as EccPoint
  7. from ._point import EccXPoint as EccXPoint
  8. RNG = Callable[[int], bytes]
  9. class UnsupportedEccFeature(ValueError):
  10. ...
  11. class ExportParams(TypedDict):
  12. passphrase: NotRequired[Union[bytes, str]]
  13. use_pkcs8: NotRequired[bool]
  14. protection: NotRequired[str]
  15. compress: NotRequired[bool]
  16. prot_params: NotRequired[ProtParams]
  17. class EccKey(object):
  18. curve: str
  19. def __init__(self, *, curve: str = ..., d: int = ..., point: EccPoint = ...) -> None: ...
  20. def __eq__(self, other: object) -> bool: ...
  21. def __repr__(self) -> str: ...
  22. def has_private(self) -> bool: ...
  23. @property
  24. def d(self) -> int: ...
  25. @property
  26. def seed(self) -> bytes: ...
  27. @property
  28. def pointQ(self) -> EccPoint: ...
  29. def public_key(self) -> EccKey: ...
  30. @overload
  31. def export_key(self,
  32. *,
  33. format: Literal['PEM', 'OpenSSH'],
  34. **kwargs: Unpack[ExportParams]) -> str: ...
  35. @overload
  36. def export_key(self,
  37. *,
  38. format: Literal['DER', 'SEC1', 'raw'],
  39. **kwargs: Unpack[ExportParams]) -> bytes: ...
  40. _Curve = NamedTuple("_Curve", [('p', Integer),
  41. ('order', Integer),
  42. ('b', Integer),
  43. ('Gx', Integer),
  44. ('Gy', Integer),
  45. ('G', EccPoint),
  46. ('modulus_bits', int),
  47. ('oid', str),
  48. ('context', Any),
  49. ('desc', str),
  50. ('openssh', Union[str, None]),
  51. ])
  52. _curves: Dict[str, _Curve]
  53. def _import_rfc5915_der(encoded: bytes,
  54. passphrase: Optional[str] = None,
  55. curve_oid: Optional[str] = None) -> EccKey: ...
  56. def generate(**kwargs: Union[str, RNG]) -> EccKey: ...
  57. def construct(**kwargs: Union[str, int]) -> EccKey: ...
  58. def import_key(encoded: Union[bytes, str],
  59. passphrase: Optional[str] = None,
  60. curve_name: Optional[str] = None) -> EccKey: ...
  61. def _import_ed25519_public_key(encoded: bytes) -> EccKey: ...
  62. def _import_ed448_public_key(encoded: bytes) -> EccKey: ...