RSA.pyi 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from typing import Callable, Union, Tuple, Optional, overload, Literal
  2. from Crypto.Math.Numbers import Integer
  3. from Crypto.IO._PBES import ProtParams
  4. __all__ = ['generate', 'construct', 'import_key',
  5. 'RsaKey', 'oid']
  6. RNG = Callable[[int], bytes]
  7. class RsaKey(object):
  8. def __init__(self, **kwargs: int) -> None: ...
  9. @property
  10. def n(self) -> int: ...
  11. @property
  12. def e(self) -> int: ...
  13. @property
  14. def d(self) -> int: ...
  15. @property
  16. def p(self) -> int: ...
  17. @property
  18. def q(self) -> int: ...
  19. @property
  20. def u(self) -> int: ...
  21. @property
  22. def invp(self) -> int: ...
  23. @property
  24. def invq(self) -> int: ...
  25. def size_in_bits(self) -> int: ...
  26. def size_in_bytes(self) -> int: ...
  27. def has_private(self) -> bool: ...
  28. def can_encrypt(self) -> bool: ... # legacy
  29. def can_sign(self) -> bool:... # legacy
  30. def public_key(self) -> RsaKey: ...
  31. def __eq__(self, other: object) -> bool: ...
  32. def __ne__(self, other: object) -> bool: ...
  33. def __getstate__(self) -> None: ...
  34. def __repr__(self) -> str: ...
  35. def __str__(self) -> str: ...
  36. @overload
  37. def export_key(self,
  38. format: Optional[str]="PEM",
  39. passphrase: Optional[str]=None,
  40. pkcs: Optional[int]=1,
  41. protection: Optional[str]=None,
  42. randfunc: Optional[RNG]=None
  43. ) -> bytes: ...
  44. @overload
  45. def export_key(self, *,
  46. format: Optional[str]="PEM",
  47. passphrase: str,
  48. pkcs: Literal[8],
  49. protection: str,
  50. randfunc: Optional[RNG]=None,
  51. prot_params: ProtParams,
  52. ) -> bytes: ...
  53. # Backward compatibility
  54. exportKey = export_key
  55. publickey = public_key
  56. Int = Union[int, Integer]
  57. def generate(bits: int, randfunc: Optional[RNG]=None, e: Optional[int]=65537) -> RsaKey: ...
  58. def construct(rsa_components: Union[Tuple[Int, Int], # n, e
  59. Tuple[Int, Int, Int], # n, e, d
  60. Tuple[Int, Int, Int, Int, Int], # n, e, d, p, q
  61. Tuple[Int, Int, Int, Int, Int, Int]], # n, e, d, p, q, crt_q
  62. consistency_check: Optional[bool]=True) -> RsaKey: ...
  63. def import_key(extern_key: Union[str, bytes], passphrase: Optional[str]=None) -> RsaKey: ...
  64. # Backward compatibility
  65. importKey = import_key
  66. oid: str