RSA.pyi 2.0 KB

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