8000 Improved OpenSSL stubs by jolaf · Pull Request #5645 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Improved OpenSSL stubs #5645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0a41f92
Merge pull request #1 from python/master
jolaf Oct 7, 2019
6147b57
Merge pull request #2 from python/master
jolaf Oct 21, 2019
24ccd88
Merge remote-tracking branch 'upstream/master'
Nov 7, 2020
8a67575
Merge remote-tracking branch 'upstream/master'
Nov 11, 2020
7208709
Merge remote-tracking branch 'upstream/master'
Nov 16, 2020
fb441f4
Merge remote-tracking branch 'upstream/master'
Jan 23, 2021
6842d78
Merge remote-tracking branch 'upstream/master'
Feb 28, 2021
84897db
Stubs for pyaudio added
Feb 28, 2021
f7a40e8
Fixed for new format
Feb 28, 2021
3204ff5
Trying to backport for Python 3.6
Feb 28, 2021
e2b2552
Fixed according to build checks
Feb 28, 2021
c5d7d62
Fixed according to build checks
Feb 28, 2021
1524136
Fixed according to build checks
Feb 28, 2021
42c500f
Avoiding Literal as causing too much trouble in actual use
Feb 28, 2021
3be6149
Trying Python 2 compatibility 8000
Feb 28, 2021
6f8d928
Fixed error in annotation
Feb 28, 2021
03e4dca
Empty commit to trigger timed out build check
Feb 28, 2021
605c18d
Revert "Empty commit to trigger timed out build check"
Feb 28, 2021
e4a364d
Added _ before auxiliary type names
Mar 23, 2021
d2a5e1c
Provided the actual version number
Mar 23, 2021
1821870
Fixed AssertionError: Unsupported Python version 0.2.11
Mar 23, 2021
8fa12cd
Merge remote-tracking branch 'upstream/master'
Jun 15, 2021
80d773e
Added missing OpenSSL stubs
Jun 15, 2021
0419f58
Improved imports
Jun 15, 2021
b354973
Fixed _StrLike and _BytesLike annotations, as well as passphrase call…
Jun 15, 2021
fe4aa2a
More annotation fixes
Jun 15, 2021
5e6fd23
Reordering classes according to official documentation per https://ww…
Jun 15, 2021
4b9a50d
Added missing OpenSSL stubs
Jun 15, 2021
1ab37de
Reordering class fields according to official documentation per https…
Jun 15, 2021
4798d01
Formatting fixes
Jun 15, 2021
ab5ae9f
Formatting fixes
Jun 15, 2021
037ccc2
Updated per review by @srittau
Jun 16, 2021
d8d2531
More fixes
Jun 16, 2021
714d9d2
Replaced Optional with | syntax
Jun 16, 2021
ec63bbf
Reverted version for now
Jun 16, 2021
f0b16bc
Temporarily disable stubtest
srittau Jun 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated per review by @srittau
  • Loading branch information
Vasily Zakharov committed Jun 16, 2021
commit 037ccc25f05e7198c901c8f9b93d77835789db80
2 changes: 1 addition & 1 deletion stubs/openssl-python/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.1"
python2 = true
python3 = false
python3 = true
requires = ["types-cryptography"]
24 changes: 12 additions & 12 deletions stubs/openssl-python/OpenSSL/SSL.pyi
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from socket import socket
from typing import Callable, Optional, Sequence, Union
from typing import Callable, Optional, Sequence

from OpenSSL.crypto import X509

TLSv1_2_METHOD: int = ...
OP_NO_SSLv2: int = ...
OP_NO_SSLv3: int = ...
OP_NO_TLSv1: int = ...
OP_NO_TLSv1_1: int = ...
OP_NO_TLSv1_2: int = ...
OP_NO_TLSv1_3: int = ...
VERIFY_PEER: int = ...
TLSv1_2_METHOD: int
OP_NO_SSLv2: int
OP_NO_SSLv3: int
OP_NO_TLSv1: int
OP_NO_TLSv1_1: int
OP_NO_TLSv1_2: int
OP_NO_TLSv1_3: int
VERIFY_PEER: int

class Connection:
def __init__(self, context: Context, _socket: Optional[socket] = ...) -> None: ...
def connect(self, addr: Union[str, bytes, Sequence[Union[str, int]]]) -> None: ...
def __init__(self, context: Context, _socket: Optional[socket]) -> None: ...
def connect(self, addr: str | bytes | Sequence[str | int]) -> None: ...
def do_handshake(self) -> None: ...
def get_peer_certificate(self) -> X509: ...
def set_tlsext_host_name(self, name: bytes) -> None: ...

class Context:
def __init__(self, method: int) -> None: ...
def load_verify_locations(self, cafile: Optional[str], capath: Optional[str] = ...) -> None: ...
def load_verify_locations(self, cafile: Optional[str], capath: Optional[str]) -> None: ...
def set_options(self, options: int) -> None: ...
def set_verify(self, mode: int, callback: Callable[[Connection, X509, int, int, int], bool]) -> None: ...
138 changes: 64 additions & 74 deletions stubs/openssl-python/OpenSSL/crypto.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import sys
from datetime import datetime
from typing import Callable, Iterable, List, Optional, Sequence, Set, Text, Tuple, Union
from typing import Callable, Iterable, List, Optional, Sequence, Set, Text, Tuple

from cryptography.hazmat.primitives.asymmetric.dsa import DSAPrivateKey, DSAPublicKey
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey
from cryptography.x509 import Certificate, CertificateRevocationList, CertificateSigningRequest

if sys.version_info >= (3, 0):
_BytesLike = bytes
_StrLike = str
_TextLike = Union[_BytesLike, _StrLike]
else:
_BytesLike = str
_StrLike = Union[str, unicode]
_TextLike = _StrLike

_Key = Union[DSAPrivateKey, DSAPublicKey, RSAPrivateKey, RSAPublicKey]
_Key = DSAPrivateKey | DSAPublicKey | RSAPrivateKey | RSAPublicKey

FILETYPE_PEM: int
FILETYPE_ASN1: int
Expand All @@ -40,52 +30,52 @@ class PKey:
def type(self) -> int: ...

class X509Name:
countryName: _StrLike
C: _StrLike
stateOrProvinceName: _StrLike
ST: _StrLike
localityName: _StrLike
L: _StrLike
organizationName: _StrLike
O: _StrLike
organizationalUnitName: _StrLike
OU: _StrLike
commonName: _StrLike
CN: _StrLike
emailAddress: _StrLike
countryName: Text
C: Text
stateOrProvinceName: Text
ST: Text
localityName: Text
L: Text
organizationName: Text
O: Text
organizationalUnitName: Text
OU: Text
commonName: Text
CN: Text
emailAddress: Text
def __init__(self, name: X509Name) -> None: ...
def der(self) -> _BytesLike: ...
def der(self) -> bytes: ...
def get_components(self) -> List[Tuple[str, str]]: ...
def hash(self) -> int: ...

class X509:
def __init__(self) -> None: ...
def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ...
def digest(self, digest_name: _BytesLike) -> _BytesLike: ...
def digest(self, digest_name: bytes) -> bytes: ...
@classmethod
def from_cryptography(cls, crypto_key: Certificate) -> X509: ...
def get_extension(self, index: int) -> X509Extension: ...
def get_extension_count(self) -> int: ...
def get_issuer(self) -> X509Name: ...
def get_notAfter(self) -> Optional[_BytesLike]: ...
def get_notBefore(self) -> Optional[_BytesLike]: ...
def get_notAfter(self) -> Optional[bytes]: ...
def get_notBefore(self) -> Optional[bytes]: ...
def get_pubkey(self) -> PKey: ...
def get_serial_number(self) -> int: ...
def get_signature_algorithm(self) -> _BytesLike: ...
def get_signature_algorithm(self) -> bytes: ...
def get_subject(self) -> X509Name: ...
def get_version(self) -> int: ...
def gmtime_adj_notAfter(self, amount: int) -> None: ...
def gmtime_adj_notBefore(self, amount: int) -> None: ...
def has_expired(self) -> bool: ...
def set_issuer(self, issuer: X509Name) -> None: ...
def set_notAfter(self, when: _BytesLike) -> None: ...
def set_notBefore(self, when: _BytesLike) -> None: ...
def set_notAfter(self, when: bytes) -> None: ...
def set_notBefore(self, when: bytes) -> None: ...
def set_pubkey(self, pkey: PKey) -> None: ...
def set_serial_number(self, serial: int) -> None: ...
def set_subject(self, subject: X509Name) -> None: ...
def set_version(self, version: int) -> None: ...
def sign(self, pkey: PKey, digest: _TextLike) -> None: ...
def subject_name_hash(self) -> _BytesLike: ...
def sign(self, pkey: PKey, digest: Text | bytes) -> None: ...
def subject_name_hash(self) -> bytes: ...
def to_cryptography(self) -> Certificate: ...

class X509Req:
Expand All @@ -99,52 +89,52 @@ class X509Req:
def get_version(self) -> int: ...
def set_pubkey(self, pkey: PKey) -> None: ...
def set_version(self, version: int) -> None: ...
def sign(self, pkey: PKey, digest: _TextLike) -> None: ...
def sign(self, pkey: PKey, digest: Text | bytes) -> None: ...
def to_cryptography(self) -> CertificateSigningRequest: ...
def verify(self, pkey: PKey) -> bool: ...

class X509Extension:
def __init__(
self,
type_name: _BytesLike,
type_name: bytes,
critical: bool,
value: _BytesLike,
value: bytes,
subject: Optional[X509] = ...,
issuer: Optional[X509] = ...,
) -> None: ...
def get_critical(self) -> bool: ...
def get_data(self) -> _BytesLike: ...
def get_short_name(self) -> _BytesLike: ...
def get_data(self) -> bytes: ...
def get_short_name(self) -> bytes: ...

class Revoked:
def __init__(self) -> None: ...
def all_reasons(self) -> List[_BytesLike]: ...
def get_reason(self) -> Optional[_BytesLike]: ...
def get_rev_date(self) -> _BytesLike: ...
def get_serial(self) -> _BytesLike: ...
def set_reason(self, reason: Optional[_BytesLike]) -> None: ...
def set_rev_date(self, when: _BytesLike) -> None: ...
def set_serial(self, hex_str: _BytesLike) -> None: ...
def all_reasons(self) -> List[bytes]: ...
def get_reason(self) -> Optional[bytes]: ...
def get_rev_date(self) -> bytes: ...
def get_serial(self) -> bytes: ...
def set_reason(self, reason: Optional[bytes]) -> None: ...
def set_rev_date(self, when: bytes) -> None: ...
def set_serial(self, hex_str: bytes) -> None: ...

class CRL:
def __init__(self) -> None: ...
def add_revoked(self, revoked: Revoked) -> None: ...
def export(self, cert: X509, key: PKey, type: int = ..., days: int = ..., digest: _BytesLike = ...) -> _BytesLike: ...
def export(self, cert: X509, key: PKey, type: int = ..., days: int = ..., digest: bytes = ...) -> bytes: ...
@classmethod
def from_cryptography(cls, crypto_crl: CertificateRevocationList) -> CRL: ...
def get_issuer(self) -> X509Name: ...
def get_revoked(self) -> Tuple[Revoked, ...]: ...
def set_lastUpdate(self, when: _BytesLike) -> None: ...
def set_nextUpdate(self, when: _BytesLike) -> None: ...
def set_lastUpdate(self, when: bytes) -> None: ...
def set_nextUpdate(self, when: bytes) -> None: ...
def set_version(self, version: int) -> None: ...
def sign(self, issuer_cert: X509, issuer_key: PKey, digest: _BytesLike) -> None: ...
def sign(self, issuer_cert: X509, issuer_key: PKey, digest: bytes) -> None: ...
def to_cryptography(self) -> CertificateRevocationList: ...

class X509Store:
def __init__(self) -> None: ...
def add_cert(self, cert: X509) -> None: ...
def add_crl(self, crl: CRL) -> None: ...
def load_locations(self, cafile: _TextLike, capath: _TextLike) -> None: ...
def load_locations(self, cafile: Text | bytes, capath: Text | bytes) -> None: ...
def set_flags(self, flags: int) -> None: ...
def set_time(self, vfy_time: datetime) -> None: ...

Expand All @@ -156,7 +146,7 @@ class X509StoreContext:

class X509StoreContextError(Exception):
certificate: X509
def __init__(self, message: _TextLike, certificate: X509) -> None: ...
def __init__(self, message: Text | bytes, certificate: X509) -> None: . 1E0A ..

class X509StoreFlags:
CRL_CHECK: int
Expand All @@ -172,49 +162,49 @@ class X509StoreFlags:
CB_ISSUER_CHECK: int

class PKCS7:
def get_type_name(self) -> _StrLike: ...
def get_type_name(self) -> Text: ...
def type_is_data(self) -> bool: ...
def type_is_enveloped(self) -> bool: ...
def type_is_signed(self) -> bool: ...
def type_is_signedAndEnveloped(self) -> bool: ...

class PKCS12:
def __init__(self) -> None: ...
def export(self, passphrase: Optional[_BytesLike] = ..., iter: int = ..., maciter: int = ...) -> _BytesLike: ...
def export(self, passphrase: Optional[bytes] = ..., iter: int = ..., maciter: int = ...) -> bytes: ...
def get_ca_certificates(self) -> Tuple[X509, ...]: ...
def get_certificate(self) -> X509: ...
def get_friendlyname(self) -> Optional[_BytesLike]: ...
def get_friendlyname(self) -> Optional[bytes]: ...
def get_privatekey(self) -> PKey: ...
def set_ca_certificates(self, cacerts: Optional[Iterable[X509]]) -> None: ...
def set_certificate(self, cert: X509) -> None: ...
def set_friendlyname(self, name: Optional[_BytesLike]) -> None: ...
def set_friendlyname(self, name: Optional[bytes]) -> None: ...
def set_privatekey(self, pkey: PKey) -> None: ...

class NetscapeSPKI:
def __init__(self) -> None: ...
def b64_encode(self) -> _BytesLike: ...
def b64_encode(self) -> bytes: ...
def get_pubkey(self) -> PKey: ...
def set_pubkey(self, pkey: PKey) -> None: ...
def sign(self, pkey: PKey, digest: _BytesLike) -> None: ...
def sign(self, pkey: PKey, digest: bytes) -> None: ...
def verify(self, key: PKey) -> bool: ...

def get_elliptic_curves() -> Set[_EllipticCurve]: ...
def get_elliptic_curve(name: _StrLike) -> _EllipticCurve: ...
def dump_certificate(type: int, cert: X509) -> _BytesLike: ...
def load_certificate(type: int, buffer: _BytesLike) -> X509: ...
def dump_certificate_request(type: int, cert: X509Req) -> _BytesLike: ...
def load_certificate_request(type: int, buffer: _BytesLike) -> X509Req: ...
def get_elliptic_curve(name: Text) -> _EllipticCurve: ...
def dump_certificate(type: int, cert: X509) -> bytes: ...
def load_certificate(type: int, buffer: bytes) -> X509: ...
def dump_certificate_request(type: int, cert: X509Req) -> bytes: ...
def load_certificate_request(type: int, buffer: bytes) -> X509Req: ...
def dump_privatekey(
type: int, pkey: PKey, cipher: Optional[_BytesLike] = ..., passphrase: Union[_BytesLike, Callable[[], _BytesLike], None] = ...
) -> _BytesLike: ...
type: int, pkey: PKey, cipher: Optional[bytes] = ..., passphrase: bytes | Callable[[], bytes] | None = ...
) -> bytes: ...
def load_privatekey(
type: int, buffer: _TextLike, passphrase: Union[_BytesLike, Callable[[], _BytesLike], None] = ...
type: int, buffer: Text | bytes, passphrase: bytes | Callable[[], bytes] | None = ...
) -> PKey: ...
def dump_publickey(type: int, pkey: PKey) -> _BytesLike: ...
def load_publickey(type: int, buffer: _TextLike) -> PKey: ...
def dump_crl(type: int, crl: CRL) -> _BytesLike: ...
def load_crl(type: int, buffer: _TextLike) -> CRL: ...
def load_pkcs7_data(type: int, buffer: _TextLike) -> PKCS7: ...
def load_pkcs12(buffer: _TextLike, passphrase: Optional[_BytesLike] = ...) -> PKCS12: ...
def sign(pkey: PKey, data: _TextLike, digest: _TextLike) -> _BytesLike: ...
def verify(cert: X509, signature: _BytesLike, data: _TextLike, digest: _TextLike) -> None: ...
def dump_publickey(type: int, pkey: PKey) -> bytes: ...
def load_publickey(type: int, buffer: Text | bytes) -> PKey: ...
def dump_crl(type: int, crl: CRL) -> bytes: ...
def load_crl(type: int, buffer: Text | bytes) -> CRL: ...
def load_pkcs7_data(type: int, buffer: Text | bytes) -> PKCS7: ...
def load_pkcs12(buffer: Text | bytes, passphrase: Optional[bytes] = ...) -> PKCS12: ...
def sign(pkey: PKey, data: Text | bytes, digest: Text | bytes) -> bytes: ...
def verify(cert: X509, signature: bytes, data: Text | bytes, digest: Text | bytes) -> None: ...
0