ECC.pyi 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 pointQ(self) -> EccPoint: ...
  27. def public_key(self) -> EccKey: ...
  28. @overload
  29. def export_key(self,
  30. *,
  31. format: Literal['PEM', 'OpenSSH'],
  32. **kwargs: Unpack[ExportParams]) -> str: ...
  33. @overload
  34. def export_key(self,
  35. *,
  36. format: Literal['DER', 'SEC1', 'raw'],
  37. **kwargs: Unpack[ExportParams]) -> bytes: ...
  38. _Curve = NamedTuple("_Curve", [('p', Integer),
  39. ('order', Integer),
  40. ('b', Integer),
  41. ('Gx', Integer),
  42. ('Gy', Integer),
  43. ('G', EccPoint),
  44. ('modulus_bits', int),
  45. ('oid', str),
  46. ('context', Any),
  47. ('desc', str),
  48. ('openssh', Union[str, None]),
  49. ])
  50. _curves: Dict[str, _Curve]
  51. def _import_rfc5915_der(encoded: bytes,
  52. passphrase: Optional[str] = None,
  53. curve_oid: Optional[str] = None) -> EccKey: ...
  54. def generate(**kwargs: Union[str, RNG]) -> EccKey: ...
  55. def construct(**kwargs: Union[str, int]) -> EccKey: ...
  56. def import_key(encoded: Union[bytes, str],
  57. passphrase: Optional[str] = None,
  58. curve_name: Optional[str] = None) -> EccKey: ...
  59. def _import_ed25519_public_key(encoded: bytes) -> EccKey: ...
  60. def _import_ed448_public_key(encoded: bytes) -> EccKey: ...