Skip to content
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

pyOpenSSL: Adapt to changes in 22.0.0 #7080

Merged
merged 4 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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: 1 addition & 2 deletions stubs/pyOpenSSL/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
version = "21.0.*"
python2 = true
version = "22.0.*"
requires = ["types-cryptography"]
6 changes: 3 additions & 3 deletions stubs/pyOpenSSL/OpenSSL/SSL.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ class SysCallError(Error): ...

def SSLeay_version(type: int) -> str: ...

class Session(object): ...
class Session: ...

class Connection(object):
class Connection:
def __getattr__(self, name: str) -> Any: ... # incomplete
def __init__(self, context: Context, socket: socket.socket | None = ...) -> None: ...
def connect(self, addr: str | bytes | Sequence[str | int]) -> None: ...
Expand All @@ -134,7 +134,7 @@ class Connection(object):
def get_app_data(self) -> Any: ...
def set_app_data(self, data: Any) -> None: ...

class Context(object):
class Context:
def __getattr__(self, name: str) -> Any: ... # incomplete
def __init__(self, method: int) -> None: ...
def load_verify_locations(self, cafile: str | None, capath: str | None = ...) -> None: ...
Expand Down
60 changes: 30 additions & 30 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 Any, Callable, Iterable, Sequence, Text, Union
from typing import Any, Callable, Iterable, Sequence, Union

from cryptography.hazmat.primitives.asymmetric.dsa import DSAPrivateKey, DSAPublicKey
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey
Expand Down Expand Up @@ -30,19 +30,19 @@ class PKey:
def type(self) -> int: ...

class X509Name:
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
countryName: str
C: str
stateOrProvinceName: str
ST: str
localityName: str
L: str
organizationName: str
O: str
organizationalUnitName: str
OU: str
commonName: str
CN: str
emailAddress: str
def __init__(self, name: X509Name) -> None: ...
def der(self) -> bytes: ...
def get_components(self) -> list[tuple[bytes, bytes]]: ...
Expand All @@ -51,7 +51,7 @@ class X509Name:
class X509:
def __init__(self) -> None: ...
def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ...
def digest(self, digest_name: bytes) -> bytes: ...
def digest(self, digest_name: str) -> bytes: ...
@classmethod
def from_cryptography(cls, crypto_cert: Certificate) -> X509: ...
def get_extension(self, index: int) -> X509Extension: ...
Expand All @@ -74,7 +74,7 @@ class X509:
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: Text | bytes) -> None: ...
def sign(self, pkey: PKey, digest: str) -> None: ...
def subject_name_hash(self) -> bytes: ...
def to_cryptography(self) -> Certificate: ...

Expand All @@ -89,7 +89,7 @@ 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: Text | bytes) -> None: ...
def sign(self, pkey: PKey, digest: str) -> None: ...
def to_cryptography(self) -> CertificateSigningRequest: ...
def verify(self, pkey: PKey) -> bool: ...

Expand Down Expand Up @@ -129,7 +129,7 @@ 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 = ...) -> None: ...
def load_locations(self, cafile: str | bytes, capath: str | bytes | None = ...) -> None: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

cafile and capath should be annotated with _typeshed.StrOrBytesPath. They get passed to _path_bytes which calls os.fspath.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the suggestions

def set_flags(self, flags: int) -> None: ...
def set_time(self, vfy_time: datetime) -> None: ...

Expand All @@ -141,7 +141,7 @@ class X509StoreContext:

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

class X509StoreFlags:
CRL_CHECK: int
Expand All @@ -157,7 +157,7 @@ class X509StoreFlags:
CB_ISSUER_CHECK: int

class PKCS7:
def get_type_name(self) -> Text: ...
def get_type_name(self) -> str: ...
def type_is_data(self) -> bool: ...
def type_is_enveloped(self) -> bool: ...
def type_is_signed(self) -> bool: ...
Expand All @@ -180,24 +180,24 @@ class NetscapeSPKI:
def b64_encode(self) -> bytes: ...
def get_pubkey(self) -> PKey: ...
def set_pubkey(self, pkey: PKey) -> None: ...
def sign(self, pkey: PKey, digest: bytes) -> None: ...
def sign(self, pkey: PKey, digest: str) -> None: ...
def verify(self, key: PKey) -> bool: ...

def get_elliptic_curves() -> set[_EllipticCurve]: ...
def get_elliptic_curve(name: Text) -> _EllipticCurve: ...
def get_elliptic_curve(name: str) -> _EllipticCurve: ...
def dump_certificate(type: int, cert: X509) -> bytes: ...
def load_certificate(type: int, buffer: bytes) -> X509: ...
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 = ...
type: int, pkey: PKey, cipher: str | None = ..., passphrase: bytes | Callable[[], bytes] | None = ...
) -> bytes: ...
def load_privatekey(type: int, buffer: Text | bytes, passphrase: bytes | Callable[[], bytes] | None = ...) -> PKey: ...
def load_privatekey(type: int, buffer: str | bytes, passphrase: bytes | Callable[[], bytes] | None = ...) -> PKey: ...
def dump_publickey(type: int, pkey: PKey) -> bytes: ...
def load_publickey(type: int, buffer: Text | bytes) -> PKey: ...
def load_publickey(type: int, buffer: str | 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: bytes | None = ...) -> 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: ...
def load_crl(type: int, buffer: str | bytes) -> CRL: ...
def load_pkcs7_data(type: int, buffer: str | bytes) -> PKCS7: ...
def load_pkcs12(buffer: str | bytes, passphrase: bytes | None = ...) -> PKCS12: ...
def sign(pkey: PKey, data: str | bytes, digest: str) -> bytes: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Idea for future PR: Some arguments, such as data here, get passed to text_to_bytes_and_warn, which emits a DeprecationWarning if you pass a string. We should probably just change them to bytes in typeshed, so that the warning happens when type checking rather than at runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im curious, is this a standard thing done in the typing community?

This seems to force application maintainers into one of the following options if they use a deprecated type

  • They could add a # type: ignore which stops typing of more stuff than we want
  • They could not update to the newest version of these stubs and miss out on changes which fixed wrong typings
  • They could use the new type, which may or may not be possible depending on the project

Don’t seem very good options to me

Especially because DeprecationWarnings can be catched by unittests.

But i don’t have much experience with typing so maybe this is standard procedure in the community and its not a big deal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We currently don't have a good way to mark deprecated things. There's some discussion about this here: python/typing#1043

For now, we usually keep deprecated things in the spirit of avoiding false positives. This was just a random idea.

def verify(cert: X509, signature: bytes, data: str | bytes, digest: str) -> None: ...