ECC.pyi 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. RNG = Callable[[int], bytes]
  7. class UnsupportedEccFeature(ValueError):
  8. ...
  9. class EccPoint(object):
  10. def __init__(self,
  11. x: Union[int, Integer],
  12. y: Union[int, Integer],
  13. curve: Optional[str] = ...) -> None: ...
  14. def set(self, point: EccPoint) -> EccPoint: ...
  15. def __eq__(self, point: object) -> bool: ...
  16. def __neg__(self) -> EccPoint: ...
  17. def copy(self) -> EccPoint: ...
  18. def is_point_at_infinity(self) -> bool: ...
  19. def point_at_infinity(self) -> EccPoint: ...
  20. @property
  21. def x(self) -> int: ...
  22. @property
  23. def y(self) -> int: ...
  24. @property
  25. def xy(self) -> Tuple[int, int]: ...
  26. def size_in_bytes(self) -> int: ...
  27. def size_in_bits(self) -> int: ...
  28. def double(self) -> EccPoint: ...
  29. def __iadd__(self, point: EccPoint) -> EccPoint: ...
  30. def __add__(self, point: EccPoint) -> EccPoint: ...
  31. def __imul__(self, scalar: int) -> EccPoint: ...
  32. def __mul__(self, scalar: int) -> EccPoint: ...
  33. class ExportParams(TypedDict):
  34. passphrase: NotRequired[Union[bytes, str]]
  35. use_pkcs8: NotRequired[bool]
  36. protection: NotRequired[str]
  37. compress: NotRequired[bool]
  38. prot_params: NotRequired[ProtParams]
  39. class EccKey(object):
  40. curve: str
  41. def __init__(self, *, curve: str = ..., d: int = ..., point: EccPoint = ...) -> None: ...
  42. def __eq__(self, other: object) -> bool: ...
  43. def __repr__(self) -> str: ...
  44. def has_private(self) -> bool: ...
  45. @property
  46. def d(self) -> int: ...
  47. @property
  48. def pointQ(self) -> EccPoint: ...
  49. def public_key(self) -> EccKey: ...
  50. @overload
  51. def export_key(self,
  52. *,
  53. format: Literal['PEM', 'OpenSSH'],
  54. **kwargs: Unpack[ExportParams]) -> str: ...
  55. @overload
  56. def export_key(self,
  57. *,
  58. format: Literal['DER', 'SEC1', 'raw'],
  59. **kwargs: Unpack[ExportParams]) -> bytes: ...
  60. _Curve = NamedTuple("_Curve", [('p', Integer),
  61. ('order', Integer),
  62. ('b', Integer),
  63. ('Gx', Integer),
  64. ('Gy', Integer),
  65. ('G', EccPoint),
  66. ('modulus_bits', int),
  67. ('oid', str),
  68. ('context', Any),
  69. ('desc', str),
  70. ('openssh', Union[str, None]),
  71. ])
  72. _curves: Dict[str, _Curve]
  73. def generate(**kwargs: Union[str, RNG]) -> EccKey: ...
  74. def construct(**kwargs: Union[str, int]) -> EccKey: ...
  75. def import_key(encoded: Union[bytes, str],
  76. passphrase: Optional[str] = None,
  77. curve_name: Optional[str] = None) -> EccKey: ...
  78. def _import_ed25519_public_key(encoded: bytes) -> EccKey: ...
  79. def _import_ed448_public_key(encoded: bytes) -> EccKey: ...