Skip to content

Fix to pyOpenSSL stubs to pass stubtest #5657

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 44 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 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
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
c46a01c
Merge remote-tracking branch 'upstream/master'
Jun 16, 2021
3f280c3
Merge remote-tracking branch 'upstream/master'
Jun 17, 2021
552aac4
Merge branch 'master' into openssl
Jun 17, 2021
0364062
Trying to enable all tests
Jun 17, 2021
4ea40bd
Fixed stubs according to stubtest
Jun 17, 2021
026bb5a
Fixed stubs according to stubtest
Jun 17, 2021
81f044a
Fixed stubs according to stubtest
Jun 17, 2021
79603ef
Excluded stubtest for OpenSSL.crypto, as the respective fix to mypy i…
Jun 17, 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
3 changes: 0 additions & 3 deletions stubs/pyOpenSSL/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
OpenSSL.SSL.Connection.__init__
OpenSSL.SSL.Context.load_verify_locations
OpenSSL.SSL.Context.set_verify
OpenSSL.crypto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stubtest complains that OpenSSL.crypto doesn't exist. If you don't want to figure out what's going on with that, you can leave OpenSSL.crypto in the allowlist for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems I've figured out what's going on and proposed a fix:
python/mypy#10663

8 changes: 4 additions & 4 deletions stubs/pyOpenSSL/OpenSSL/SSL.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from socket import socket
import socket
from typing import Callable, Sequence

from OpenSSL.crypto import X509
Expand All @@ -13,14 +13,14 @@ OP_NO_TLSv1_3: int
VERIFY_PEER: int

class Connection:
def __init__(self, context: Context, _socket: socket | None) -> None: ...
def __init__(self, context: Context, socket: socket.socket | None = ...) -> 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: str | None, capath: str | None) -> None: ...
def load_verify_locations(self, cafile: str | None, capath: str | None = ...) -> None: ...
def set_options(self, options: int) -> None: ...
def set_verify(self, mode: int, callback: Callable[[Connection, X509, int, int, int], bool]) -> None: ...
def set_verify(self, mode: int, callback: Callable[[Connection, X509, int, int, int], bool] | None = ...) -> None: ...
12 changes: 6 additions & 6 deletions stubs/pyOpenSSL/OpenSSL/crypto.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Callable, Iterable, List, Sequence, Set, Text, Tuple, Union
from typing import Any, Callable, Iterable, List, Sequence, Set, Text, Tuple, Union

from cryptography.hazmat.primitives.asymmetric.dsa import DSAPrivateKey, DSAPublicKey
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey
Expand All @@ -15,7 +15,7 @@ TYPE_RSA: int
TYPE_DSA: int

class _EllipticCurve:
name: Text
def __init__(self, lib: Any | None, nid: int, name: str) -> None: ...

class Error(Exception): ...

Expand Down Expand Up @@ -53,7 +53,7 @@ class X509:
def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ...
def digest(self, digest_name: bytes) -> bytes: ...
@classmethod
def from_cryptography(cls, crypto_key: Certificate) -> X509: ...
def from_cryptography(cls, crypto_cert: Certificate) -> X509: ...
def get_extension(self, index: int) -> X509Extension: ...
def get_extension_count(self) -> int: ...
def get_issuer(self) -> X509Name: ...
Expand Down Expand Up @@ -129,12 +129,12 @@ 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: Text | bytes, capath: Text | bytes) -> None: ...
def load_locations(self, cafile: Text | bytes, capath: Text | bytes | None = ...) -> None: ...
def set_flags(self, flags: int) -> None: ...
def set_time(self, vfy_time: datetime) -> None: ...

class X509StoreContext:
def __init__(self, store: X509Store, certificate: X509, chain: Sequence[X509] | None) -> None: ...
def __init__(self, store: X509Store, certificate: X509, chain: Sequence[X509] | None = ...) -> None: ...
def get_verified_chain(self) -> List[X509]: ...
def set_store(self, store: X509Store) -> None: ...
def verify_certificate(self) -> None: ...
Expand Down Expand Up @@ -187,7 +187,7 @@ def get_elliptic_curves() -> Set[_EllipticCurve]: ...
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 dump_certificate_request(type: int, req: X509Req) -> bytes: ...
def load_certificate_request(type: int, buffer: bytes) -> X509Req: ...
def dump_privatekey(
type: int, pkey: PKey, cipher: bytes | None = ..., passphrase: bytes | Callable[[], bytes] | None = ...
Expand Down