ssl.pyi 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from typing import Any, AnyStr, Dict, List, Optional, Type, TypeVar
  2. import OpenSSL.SSL
  3. # I don't like importing from _sslverify, but IOpenSSLTrustRoot isn't re-exported
  4. # anywhere else in twisted.
  5. from twisted.internet._sslverify import IOpenSSLTrustRoot
  6. from twisted.internet.interfaces import IOpenSSLClientConnectionCreator
  7. from zope.interface import implementer
  8. C = TypeVar("C")
  9. class Certificate:
  10. original: OpenSSL.crypto.X509
  11. @classmethod
  12. def loadPEM(cls: Type[C], data: AnyStr) -> C: ...
  13. def platformTrust() -> IOpenSSLTrustRoot: ...
  14. class PrivateCertificate(Certificate): ...
  15. class CertificateOptions:
  16. def __init__(
  17. self, trustRoot: Optional[IOpenSSLTrustRoot] = None, **kwargs: Any
  18. ): ...
  19. def _makeContext(self) -> OpenSSL.SSL.Context: ...
  20. def optionsForClientTLS(
  21. hostname: str,
  22. trustRoot: Optional[IOpenSSLTrustRoot] = None,
  23. clientCertificate: Optional[PrivateCertificate] = None,
  24. acceptableProtocols: Optional[List[bytes]] = None,
  25. *,
  26. # Shouldn't use extraCertificateOptions:
  27. # "any time you need to pass an option here that is a bug in this interface."
  28. extraCertificateOptions: Optional[Dict[Any, Any]] = None,
  29. ) -> IOpenSSLClientConnectionCreator: ...
  30. # Type safety: I don't want to respecify the methods on the interface that we
  31. # don't use.
  32. @implementer(IOpenSSLTrustRoot) # type: ignore[misc]
  33. class OpenSSLDefaultPaths: ...