From 84897db9e86c10b753ae2f64996a207887a2d141 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 20:57:39 +0300 Subject: [PATCH 01/33] Stubs for pyaudio added --- stubs/pyaudio/__init__.pyi | 166 +++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 stubs/pyaudio/__init__.pyi diff --git a/stubs/pyaudio/__init__.pyi b/stubs/pyaudio/__init__.pyi new file mode 100644 index 000000000000..b085bf2f6dcd --- /dev/null +++ b/stubs/pyaudio/__init__.pyi @@ -0,0 +1,166 @@ +from typing import Callable, ClassVar, Final, Literal, Mapping, Optional, Sequence, Tuple, Union + +paFloat32: Final[int] = ... +paInt32: Final[int] = ... +paInt24: Final[int] = ... +paInt16: Final[int] = ... +paInt8: Final[int] = ... +paUInt8: Final[int] = ... +paCustomFormat: Final[int] = ... + +paInDevelopment: Final[int] = ... +paDirectSound: Final[int] = ... +paMME: Final[int] = ... +paASIO: Final[int] = ... +paSoundManager: Final[int] = ... +paCoreAudio: Final[int] = ... +paOSS: Final[int] = ... +paALSA: Final[int] = ... +paAL: Final[int] = ... +paBeOS: Final[int] = ... +paWDMKS: Final[int] = ... +paJACK: Final[int] = ... +paWASAPI: Final[int] = ... +paNoDevice: Final[int] = ... + +paNoError: Final[int] = ... +paNotInitialized: Final[int] = ... +paUnanticipatedHostError: Final[int] = ... +paInvalidChannelCount: Final[int] = ... +paInvalidSampleRate: Final[int] = ... +paInvalidDevice: Final[int] = ... +paInvalidFlag: Final[int] = ... +paSampleFormatNotSupported: Final[int] = ... +paBadIODeviceCombination: Final[int] = ... +paInsufficientMemory: Final[int] = ... +paBufferTooBig: Final[int] = ... +paBufferTooSmall: Final[int] = ... +paNullCallback: Final[int] = ... +paBadStreamPtr: Final[int] = ... +paTimedOut: Final[int] = ... +paInternalError: Final[int] = ... +paDeviceUnavailable: Final[int] = ... +paIncompatibleHostApiSpecificStreamInfo: Final[int] = ... +paStreamIsStopped: Final[int] = ... +paStreamIsNotStopped: Final[int] = ... +paInputOverflowed: Final[int] = ... +paOutputUnderflowed: Final[int] = ... +paHostApiNotFound: Final[int] = ... +paInvalidHostApi: Final[int] = ... +paCanNotReadFromACallbackStream: Final[int] = ... +paCanNotWriteToACallbackStream: Final[int] = ... +paCanNotReadFromAnOutputOnlyStream: Final[int] = ... +paCanNotWriteToAnInputOnlyStream: Final[int] = ... +paIncompatibleStreamHostApi: Final[int] = ... + +paContinue: Final[int] = ... +paComplete: Final[int] = ... +paAbort: Final[int] = ... + +paInputUnderflow: Final[int] = ... +paInputOverflow: Final[int] = ... +paOutputUnderflow: Final[int] = ... +paOutputOverflow: Final[int] = ... +paPrimingOutput: Final[int] = ... + +paMacCoreStreamInfo: 'PaMacCoreStreamInfo' + +# Auxiliary types +ChannelMap = Sequence[int] +PaHostApiInfo = Mapping[str, Union[str, int]] +PaDeviceInfo = Mapping[str, Union[str, int, float]] +StreamCallback = Callable[[Optional[bytes], int, Mapping[str, float], int], Tuple[Optional[bytes], int]] +Width = Literal[1, 2, 3, 4] + +def get_format_from_width(width: Width, unsigned: bool = ...) -> int: ... +def get_portaudio_version() -> int: ... +def get_portaudio_version_text() -> str: ... +def get_sample_size(format: int) -> int: ... + +class Stream: + def __init__(self, + PA_manager: 'PyAudio', + rate: int, + channels: int, + format: int, + input: bool = ..., + output: bool = ..., + input_device_index: Optional[int] = ..., + output_device_index: Optional[int] = ..., + frames_per_buffer: int = ..., + start: bool = ..., + input_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., + output_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., + stream_callback: Optional[StreamCallback] = ...) -> None: ... + + def close(self) -> None: ... + def get_cpu_load(self) -> float: ... + def get_input_latency(self) -> float: ... + def get_output_latency(self) -> float: ... + def get_read_available(self) -> int: ... + def get_time(self) -> float: ... + def get_write_available(self) -> int: ... + def is_active(self) -> bool: ... + def is_stopped(self) -> bool: ... + def read(self, num_frames: int, exception_on_overflow: bool = ...) -> bytes: ... + def start_stream(self) -> None: ... + def stop_stream(self) -> None: ... + def write(self, + frames: Sequence[bytes], + num_frames: Optional[int] = ..., + exception_on_underflow: bool = ...) -> None: ... + +class PyAudio: + def __init__(self) -> None: ... + def close(self, stream: Stream) -> None: ... + def get_default_host_api_info(self) -> PaHostApiInfo: ... + def get_default_input_device_info(self) -> PaDeviceInfo: ... + def get_default_output_device_info(self) -> PaDeviceInfo: ... + def get_device_count(self) -> int: ... + def get_device_info_by_host_api_device_index(self, + host_api_index: int, + host_api_device_index: int) -> PaDeviceInfo: ... + def get_device_info_by_index(self, device_index: int) -> PaDeviceInfo: ... + def get_format_from_width(self, width: Width, unsigned: bool = ...) -> int: ... + def get_host_api_count(self) -> int: ... + def get_host_api_info_by_index(self, host_api_index: int) -> PaHostApiInfo: ... + def get_host_api_info_by_type(self, host_api_type: int) -> PaHostApiInfo: ... + def get_sample_size(self, format: int) -> int: ... + def is_format_supported(self, rate: int, + input_device: Optional[int] = ..., + input_channels: Optional[int] = ..., + input_format: Optional[int] = ..., + output_device: Optional[int] = ..., + output_channels: Optional[int] = ..., + output_format: Optional[int] = ...) -> bool: ... + def open(self, + rate: int, + channels: int, + format: int, + input: bool = ..., + output: bool = ..., + input_device_index: Optional[int] = ..., + output_device_index: Optional[int] = ..., + frames_per_buffer: int = ..., + start: bool = ..., + input_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., + output_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., + stream_callback: Optional[StreamCallback] = ...) -> Stream: ... + def terminate(self) -> None: ... + +class PaMacCoreStreamInfo: + paMacCoreChangeDeviceParameters: Final[ClassVar[int]] = ... + paMacCoreFailIfConversionRequired: Final[ClassVar[int]] = ... + paMacCoreConversionQualityMin: Final[ClassVar[int]] = ... + paMacCoreConversionQualityMedium: Final[ClassVar[int]] = ... + paMacCoreConversionQualityLow: Final[ClassVar[int]] = ... + paMacCoreConversionQualityHigh: Final[ClassVar[int]] = ... + paMacCoreConversionQualityMax: Final[ClassVar[int]] = ... + paMacCorePlayNice: Final[ClassVar[int]] = ... + paMacCorePro: Final[ClassVar[int]] = ... + paMacCoreMinimizeCPUButPlayNice: Final[ClassVar[int]] = ... + paMacCoreMinimizeCPU: Final[ClassVar[int]] = ... + + def __init__(self, flags: Optional[int] = ..., channel_map: Optional[ChannelMap] = ...) -> None: ... + def get_flags(self) -> int: ... + def get_channel_map(self) -> Optional[ChannelMap]: ... From f7a40e838dff1ad71bbfebba8d2a12b041f98a88 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 21:05:56 +0300 Subject: [PATCH 02/33] Fixed for new format --- stubs/pyaudio/METADATA.toml | 2 + stubs/pyaudio/{__init__.pyi => pyaudio.pyi} | 332 ++++++++++---------- 2 files changed, 168 insertions(+), 166 deletions(-) create mode 100644 stubs/pyaudio/METADATA.toml rename stubs/pyaudio/{__init__.pyi => pyaudio.pyi} (97%) diff --git a/stubs/pyaudio/METADATA.toml b/stubs/pyaudio/METADATA.toml new file mode 100644 index 000000000000..4295107b9036 --- /dev/null +++ b/stubs/pyaudio/METADATA.toml @@ -0,0 +1,2 @@ +version = "0.1" +python2 = false diff --git a/stubs/pyaudio/__init__.pyi b/stubs/pyaudio/pyaudio.pyi similarity index 97% rename from stubs/pyaudio/__init__.pyi rename to stubs/pyaudio/pyaudio.pyi index b085bf2f6dcd..d6db11b4906d 100644 --- a/stubs/pyaudio/__init__.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -1,166 +1,166 @@ -from typing import Callable, ClassVar, Final, Literal, Mapping, Optional, Sequence, Tuple, Union - -paFloat32: Final[int] = ... -paInt32: Final[int] = ... -paInt24: Final[int] = ... -paInt16: Final[int] = ... -paInt8: Final[int] = ... -paUInt8: Final[int] = ... -paCustomFormat: Final[int] = ... - -paInDevelopment: Final[int] = ... -paDirectSound: Final[int] = ... -paMME: Final[int] = ... -paASIO: Final[int] = ... -paSoundManager: Final[int] = ... -paCoreAudio: Final[int] = ... -paOSS: Final[int] = ... -paALSA: Final[int] = ... -paAL: Final[int] = ... -paBeOS: Final[int] = ... -paWDMKS: Final[int] = ... -paJACK: Final[int] = ... -paWASAPI: Final[int] = ... -paNoDevice: Final[int] = ... - -paNoError: Final[int] = ... -paNotInitialized: Final[int] = ... -paUnanticipatedHostError: Final[int] = ... -paInvalidChannelCount: Final[int] = ... -paInvalidSampleRate: Final[int] = ... -paInvalidDevice: Final[int] = ... -paInvalidFlag: Final[int] = ... -paSampleFormatNotSupported: Final[int] = ... -paBadIODeviceCombination: Final[int] = ... -paInsufficientMemory: Final[int] = ... -paBufferTooBig: Final[int] = ... -paBufferTooSmall: Final[int] = ... -paNullCallback: Final[int] = ... -paBadStreamPtr: Final[int] = ... -paTimedOut: Final[int] = ... -paInternalError: Final[int] = ... -paDeviceUnavailable: Final[int] = ... -paIncompatibleHostApiSpecificStreamInfo: Final[int] = ... -paStreamIsStopped: Final[int] = ... -paStreamIsNotStopped: Final[int] = ... -paInputOverflowed: Final[int] = ... -paOutputUnderflowed: Final[int] = ... -paHostApiNotFound: Final[int] = ... -paInvalidHostApi: Final[int] = ... -paCanNotReadFromACallbackStream: Final[int] = ... -paCanNotWriteToACallbackStream: Final[int] = ... -paCanNotReadFromAnOutputOnlyStream: Final[int] = ... -paCanNotWriteToAnInputOnlyStream: Final[int] = ... -paIncompatibleStreamHostApi: Final[int] = ... - -paContinue: Final[int] = ... -paComplete: Final[int] = ... -paAbort: Final[int] = ... - -paInputUnderflow: Final[int] = ... -paInputOverflow: Final[int] = ... -paOutputUnderflow: Final[int] = ... -paOutputOverflow: Final[int] = ... -paPrimingOutput: Final[int] = ... - -paMacCoreStreamInfo: 'PaMacCoreStreamInfo' - -# Auxiliary types -ChannelMap = Sequence[int] -PaHostApiInfo = Mapping[str, Union[str, int]] -PaDeviceInfo = Mapping[str, Union[str, int, float]] -StreamCallback = Callable[[Optional[bytes], int, Mapping[str, float], int], Tuple[Optional[bytes], int]] -Width = Literal[1, 2, 3, 4] - -def get_format_from_width(width: Width, unsigned: bool = ...) -> int: ... -def get_portaudio_version() -> int: ... -def get_portaudio_version_text() -> str: ... -def get_sample_size(format: int) -> int: ... - -class Stream: - def __init__(self, - PA_manager: 'PyAudio', - rate: int, - channels: int, - format: int, - input: bool = ..., - output: bool = ..., - input_device_index: Optional[int] = ..., - output_device_index: Optional[int] = ..., - frames_per_buffer: int = ..., - start: bool = ..., - input_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., - output_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., - stream_callback: Optional[StreamCallback] = ...) -> None: ... - - def close(self) -> None: ... - def get_cpu_load(self) -> float: ... - def get_input_latency(self) -> float: ... - def get_output_latency(self) -> float: ... - def get_read_available(self) -> int: ... - def get_time(self) -> float: ... - def get_write_available(self) -> int: ... - def is_active(self) -> bool: ... - def is_stopped(self) -> bool: ... - def read(self, num_frames: int, exception_on_overflow: bool = ...) -> bytes: ... - def start_stream(self) -> None: ... - def stop_stream(self) -> None: ... - def write(self, - frames: Sequence[bytes], - num_frames: Optional[int] = ..., - exception_on_underflow: bool = ...) -> None: ... - -class PyAudio: - def __init__(self) -> None: ... - def close(self, stream: Stream) -> None: ... - def get_default_host_api_info(self) -> PaHostApiInfo: ... - def get_default_input_device_info(self) -> PaDeviceInfo: ... - def get_default_output_device_info(self) -> PaDeviceInfo: ... - def get_device_count(self) -> int: ... - def get_device_info_by_host_api_device_index(self, - host_api_index: int, - host_api_device_index: int) -> PaDeviceInfo: ... - def get_device_info_by_index(self, device_index: int) -> PaDeviceInfo: ... - def get_format_from_width(self, width: Width, unsigned: bool = ...) -> int: ... - def get_host_api_count(self) -> int: ... - def get_host_api_info_by_index(self, host_api_index: int) -> PaHostApiInfo: ... - def get_host_api_info_by_type(self, host_api_type: int) -> PaHostApiInfo: ... - def get_sample_size(self, format: int) -> int: ... - def is_format_supported(self, rate: int, - input_device: Optional[int] = ..., - input_channels: Optional[int] = ..., - input_format: Optional[int] = ..., - output_device: Optional[int] = ..., - output_channels: Optional[int] = ..., - output_format: Optional[int] = ...) -> bool: ... - def open(self, - rate: int, - channels: int, - format: int, - input: bool = ..., - output: bool = ..., - input_device_index: Optional[int] = ..., - output_device_index: Optional[int] = ..., - frames_per_buffer: int = ..., - start: bool = ..., - input_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., - output_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., - stream_callback: Optional[StreamCallback] = ...) -> Stream: ... - def terminate(self) -> None: ... - -class PaMacCoreStreamInfo: - paMacCoreChangeDeviceParameters: Final[ClassVar[int]] = ... - paMacCoreFailIfConversionRequired: Final[ClassVar[int]] = ... - paMacCoreConversionQualityMin: Final[ClassVar[int]] = ... - paMacCoreConversionQualityMedium: Final[ClassVar[int]] = ... - paMacCoreConversionQualityLow: Final[ClassVar[int]] = ... - paMacCoreConversionQualityHigh: Final[ClassVar[int]] = ... - paMacCoreConversionQualityMax: Final[ClassVar[int]] = ... - paMacCorePlayNice: Final[ClassVar[int]] = ... - paMacCorePro: Final[ClassVar[int]] = ... - paMacCoreMinimizeCPUButPlayNice: Final[ClassVar[int]] = ... - paMacCoreMinimizeCPU: Final[ClassVar[int]] = ... - - def __init__(self, flags: Optional[int] = ..., channel_map: Optional[ChannelMap] = ...) -> None: ... - def get_flags(self) -> int: ... - def get_channel_map(self) -> Optional[ChannelMap]: ... +from typing import Callable, ClassVar, Final, Literal, Mapping, Optional, Sequence, Tuple, Union + +paFloat32: Final[int] = ... +paInt32: Final[int] = ... +paInt24: Final[int] = ... +paInt16: Final[int] = ... +paInt8: Final[int] = ... +paUInt8: Final[int] = ... +paCustomFormat: Final[int] = ... + +paInDevelopment: Final[int] = ... +paDirectSound: Final[int] = ... +paMME: Final[int] = ... +paASIO: Final[int] = ... +paSoundManager: Final[int] = ... +paCoreAudio: Final[int] = ... +paOSS: Final[int] = ... +paALSA: Final[int] = ... +paAL: Final[int] = ... +paBeOS: Final[int] = ... +paWDMKS: Final[int] = ... +paJACK: Final[int] = ... +paWASAPI: Final[int] = ... +paNoDevice: Final[int] = ... + +paNoError: Final[int] = ... +paNotInitialized: Final[int] = ... +paUnanticipatedHostError: Final[int] = ... +paInvalidChannelCount: Final[int] = ... +paInvalidSampleRate: Final[int] = ... +paInvalidDevice: Final[int] = ... +paInvalidFlag: Final[int] = ... +paSampleFormatNotSupported: Final[int] = ... +paBadIODeviceCombination: Final[int] = ... +paInsufficientMemory: Final[int] = ... +paBufferTooBig: Final[int] = ... +paBufferTooSmall: Final[int] = ... +paNullCallback: Final[int] = ... +paBadStreamPtr: Final[int] = ... +paTimedOut: Final[int] = ... +paInternalError: Final[int] = ... +paDeviceUnavailable: Final[int] = ... +paIncompatibleHostApiSpecificStreamInfo: Final[int] = ... +paStreamIsStopped: Final[int] = ... +paStreamIsNotStopped: Final[int] = ... +paInputOverflowed: Final[int] = ... +paOutputUnderflowed: Final[int] = ... +paHostApiNotFound: Final[int] = ... +paInvalidHostApi: Final[int] = ... +paCanNotReadFromACallbackStream: Final[int] = ... +paCanNotWriteToACallbackStream: Final[int] = ... +paCanNotReadFromAnOutputOnlyStream: Final[int] = ... +paCanNotWriteToAnInputOnlyStream: Final[int] = ... +paIncompatibleStreamHostApi: Final[int] = ... + +paContinue: Final[int] = ... +paComplete: Final[int] = ... +paAbort: Final[int] = ... + +paInputUnderflow: Final[int] = ... +paInputOverflow: Final[int] = ... +paOutputUnderflow: Final[int] = ... +paOutputOverflow: Final[int] = ... +paPrimingOutput: Final[int] = ... + +paMacCoreStreamInfo: 'PaMacCoreStreamInfo' + +# Auxiliary types +ChannelMap = Sequence[int] +PaHostApiInfo = Mapping[str, Union[str, int]] +PaDeviceInfo = Mapping[str, Union[str, int, float]] +StreamCallback = Callable[[Optional[bytes], int, Mapping[str, float], int], Tuple[Optional[bytes], int]] +Width = Literal[1, 2, 3, 4] + +def get_format_from_width(width: Width, unsigned: bool = ...) -> int: ... +def get_portaudio_version() -> int: ... +def get_portaudio_version_text() -> str: ... +def get_sample_size(format: int) -> int: ... + +class Stream: + def __init__(self, + PA_manager: 'PyAudio', + rate: int, + channels: int, + format: int, + input: bool = ..., + output: bool = ..., + input_device_index: Optional[int] = ..., + output_device_index: Optional[int] = ..., + frames_per_buffer: int = ..., + start: bool = ..., + input_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., + output_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., + stream_callback: Optional[StreamCallback] = ...) -> None: ... + + def close(self) -> None: ... + def get_cpu_load(self) -> float: ... + def get_input_latency(self) -> float: ... + def get_output_latency(self) -> float: ... + def get_read_available(self) -> int: ... + def get_time(self) -> float: ... + def get_write_available(self) -> int: ... + def is_active(self) -> bool: ... + def is_stopped(self) -> bool: ... + def read(self, num_frames: int, exception_on_overflow: bool = ...) -> bytes: ... + def start_stream(self) -> None: ... + def stop_stream(self) -> None: ... + def write(self, + frames: Sequence[bytes], + num_frames: Optional[int] = ..., + exception_on_underflow: bool = ...) -> None: ... + +class PyAudio: + def __init__(self) -> None: ... + def close(self, stream: Stream) -> None: ... + def get_default_host_api_info(self) -> PaHostApiInfo: ... + def get_default_input_device_info(self) -> PaDeviceInfo: ... + def get_default_output_device_info(self) -> PaDeviceInfo: ... + def get_device_count(self) -> int: ... + def get_device_info_by_host_api_device_index(self, + host_api_index: int, + host_api_device_index: int) -> PaDeviceInfo: ... + def get_device_info_by_index(self, device_index: int) -> PaDeviceInfo: ... + def get_format_from_width(self, width: Width, unsigned: bool = ...) -> int: ... + def get_host_api_count(self) -> int: ... + def get_host_api_info_by_index(self, host_api_index: int) -> PaHostApiInfo: ... + def get_host_api_info_by_type(self, host_api_type: int) -> PaHostApiInfo: ... + def get_sample_size(self, format: int) -> int: ... + def is_format_supported(self, rate: int, + input_device: Optional[int] = ..., + input_channels: Optional[int] = ..., + input_format: Optional[int] = ..., + output_device: Optional[int] = ..., + output_channels: Optional[int] = ..., + output_format: Optional[int] = ...) -> bool: ... + def open(self, + rate: int, + channels: int, + format: int, + input: bool = ..., + output: bool = ..., + input_device_index: Optional[int] = ..., + output_device_index: Optional[int] = ..., + frames_per_buffer: int = ..., + start: bool = ..., + input_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., + output_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., + stream_callback: Optional[StreamCallback] = ...) -> Stream: ... + def terminate(self) -> None: ... + +class PaMacCoreStreamInfo: + paMacCoreChangeDeviceParameters: Final[ClassVar[int]] = ... + paMacCoreFailIfConversionRequired: Final[ClassVar[int]] = ... + paMacCoreConversionQualityMin: Final[ClassVar[int]] = ... + paMacCoreConversionQualityMedium: Final[ClassVar[int]] = ... + paMacCoreConversionQualityLow: Final[ClassVar[int]] = ... + paMacCoreConversionQualityHigh: Final[ClassVar[int]] = ... + paMacCoreConversionQualityMax: Final[ClassVar[int]] = ... + paMacCorePlayNice: Final[ClassVar[int]] = ... + paMacCorePro: Final[ClassVar[int]] = ... + paMacCoreMinimizeCPUButPlayNice: Final[ClassVar[int]] = ... + paMacCoreMinimizeCPU: Final[ClassVar[int]] = ... + + def __init__(self, flags: Optional[int] = ..., channel_map: Optional[ChannelMap] = ...) -> None: ... + def get_flags(self) -> int: ... + def get_channel_map(self) -> Optional[ChannelMap]: ... From 3204ff50ccb454bc71db8f6dd2af86251af25e85 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 21:09:00 +0300 Subject: [PATCH 03/33] Trying to backport for Python 3.6 --- stubs/pyaudio/pyaudio.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index d6db11b4906d..c2665bf95a15 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -1,4 +1,5 @@ -from typing import Callable, ClassVar, Final, Literal, Mapping, Optional, Sequence, Tuple, Union +from typing import Callable, ClassVar, Mapping, Optional, Sequence, Tuple, Union +from typing_extensions import Final, Literal paFloat32: Final[int] = ... paInt32: Final[int] = ... From e2b25526689b1a60d8d042d9c2a9234422b0f4ea Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 21:21:13 +0300 Subject: [PATCH 04/33] Fixed according to build checks --- stubs/pyaudio/pyaudio.pyi | 80 +++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index c2665bf95a15..22c7ad504b01 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -64,7 +64,7 @@ paOutputUnderflow: Final[int] = ... paOutputOverflow: Final[int] = ... paPrimingOutput: Final[int] = ... -paMacCoreStreamInfo: 'PaMacCoreStreamInfo' +paMacCoreStreamInfo: PaMacCoreStreamInfo # Auxiliary types ChannelMap = Sequence[int] @@ -79,20 +79,21 @@ def get_portaudio_version_text() -> str: ... def get_sample_size(format: int) -> int: ... class Stream: - def __init__(self, - PA_manager: 'PyAudio', - rate: int, - channels: int, - format: int, - input: bool = ..., - output: bool = ..., - input_device_index: Optional[int] = ..., - output_device_index: Optional[int] = ..., - frames_per_buffer: int = ..., - start: bool = ..., - input_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., - output_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., - stream_callback: Optional[StreamCallback] = ...) -> None: ... + def __init__( + self, + PA_manager: PyAudio, + rate: int, + channels: int, + format: int, + input: bool = ..., + output: bool = ..., + input_device_index: Optional[int] = ..., + output_device_index: Optional[int] = ..., + frames_per_buffer: int = ..., + start: bool = ..., + input_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., + output_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., + stream_callback: Optional[StreamCallback] = ...) -> None: ... def close(self) -> None: ... def get_cpu_load(self) -> float: ... @@ -106,10 +107,7 @@ class Stream: def read(self, num_frames: int, exception_on_overflow: bool = ...) -> bytes: ... def start_stream(self) -> None: ... def stop_stream(self) -> None: ... - def write(self, - frames: Sequence[bytes], - num_frames: Optional[int] = ..., - exception_on_underflow: bool = ...) -> None: ... + def write(self, frames: Sequence[bytes], num_frames: Optional[int] = ..., exception_on_underflow: bool = ...) -> None: ... class PyAudio: def __init__(self) -> None: ... @@ -127,26 +125,29 @@ class PyAudio: def get_host_api_info_by_index(self, host_api_index: int) -> PaHostApiInfo: ... def get_host_api_info_by_type(self, host_api_type: int) -> PaHostApiInfo: ... def get_sample_size(self, format: int) -> int: ... - def is_format_supported(self, rate: int, - input_device: Optional[int] = ..., - input_channels: Optional[int] = ..., - input_format: Optional[int] = ..., - output_device: Optional[int] = ..., - output_channels: Optional[int] = ..., - output_format: Optional[int] = ...) -> bool: ... - def open(self, - rate: int, - channels: int, - format: int, - input: bool = ..., - output: bool = ..., - input_device_index: Optional[int] = ..., - output_device_index: Optional[int] = ..., - frames_per_buffer: int = ..., - start: bool = ..., - input_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., - output_host_api_specific_stream_info: Optional['PaMacCoreStreamInfo'] = ..., - stream_callback: Optional[StreamCallback] = ...) -> Stream: ... + def is_format_supported( + self, + rate: int, + input_device: Optional[int] = ..., + input_channels: Optional[int] = ..., + input_format: Optional[int] = ..., + output_device: Optional[int] = ..., + output_channels: Optional[int] = ..., + output_format: Optional[int] = ...) -> bool: ... + def open( + self, + rate: int, + channels: int, + format: int, + input: bool = ..., + output: bool = ..., + input_device_index: Optional[int] = ..., + output_device_index: Optional[int] = ..., + frames_per_buffer: int = ..., + start: bool = ..., + input_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., + output_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., + stream_callback: Optional[StreamCallback] = ...) -> Stream: ... def terminate(self) -> None: ... class PaMacCoreStreamInfo: @@ -161,7 +162,6 @@ class PaMacCoreStreamInfo: paMacCorePro: Final[ClassVar[int]] = ... paMacCoreMinimizeCPUButPlayNice: Final[ClassVar[int]] = ... paMacCoreMinimizeCPU: Final[ClassVar[int]] = ... - def __init__(self, flags: Optional[int] = ..., channel_map: Optional[ChannelMap] = ...) -> None: ... def get_flags(self) -> int: ... def get_channel_map(self) -> Optional[ChannelMap]: ... From c5d7d62faa9c20146daede61f6b8e2507c664478 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 21:25:14 +0300 Subject: [PATCH 05/33] Fixed according to build checks --- stubs/pyaudio/pyaudio.pyi | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index 22c7ad504b01..39acc09497ed 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -93,7 +93,8 @@ class Stream: start: bool = ..., input_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., output_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., - stream_callback: Optional[StreamCallback] = ...) -> None: ... + stream_callback: Optional[StreamCallback] = ..., + ) -> None: ... def close(self) -> None: ... def get_cpu_load(self) -> float: ... @@ -116,9 +117,7 @@ class PyAudio: def get_default_input_device_info(self) -> PaDeviceInfo: ... def get_default_output_device_info(self) -> PaDeviceInfo: ... def get_device_count(self) -> int: ... - def get_device_info_by_host_api_device_index(self, - host_api_index: int, - host_api_device_index: int) -> PaDeviceInfo: ... + def get_device_info_by_host_api_device_index(self, host_api_index: int, host_api_device_index: int) -> PaDeviceInfo: ... def get_device_info_by_index(self, device_index: int) -> PaDeviceInfo: ... def get_format_from_width(self, width: Width, unsigned: bool = ...) -> int: ... def get_host_api_count(self) -> int: ... @@ -133,7 +132,8 @@ class PyAudio: input_format: Optional[int] = ..., output_device: Optional[int] = ..., output_channels: Optional[int] = ..., - output_format: Optional[int] = ...) -> bool: ... + output_format: Optional[int] = ..., + ) -> bool: ... def open( self, rate: int, @@ -147,7 +147,8 @@ class PyAudio: start: bool = ..., input_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., output_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., - stream_callback: Optional[StreamCallback] = ...) -> Stream: ... + stream_callback: Optional[StreamCallback] = ..., + ) -> Stream: ... def terminate(self) -> None: ... class PaMacCoreStreamInfo: From 15241365762d45d5b6ab8155572a57d837fec3c8 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 21:31:11 +0300 Subject: [PATCH 06/33] Fixed according to build checks --- stubs/pyaudio/pyaudio.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index 39acc09497ed..f38efa16a026 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -95,7 +95,6 @@ class Stream: output_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., stream_callback: Optional[StreamCallback] = ..., ) -> None: ... - def close(self) -> None: ... def get_cpu_load(self) -> float: ... def get_input_latency(self) -> float: ... From 42c500fef62642e1d122297833a41aa5ca617341 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 21:37:55 +0300 Subject: [PATCH 07/33] Avoiding Literal as causing too much trouble in actual use --- stubs/pyaudio/pyaudio.pyi | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index f38efa16a026..c269651ea73f 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -1,5 +1,5 @@ from typing import Callable, ClassVar, Mapping, Optional, Sequence, Tuple, Union -from typing_extensions import Final, Literal +from typing_extensions import Final paFloat32: Final[int] = ... paInt32: Final[int] = ... @@ -71,9 +71,8 @@ ChannelMap = Sequence[int] PaHostApiInfo = Mapping[str, Union[str, int]] PaDeviceInfo = Mapping[str, Union[str, int, float]] StreamCallback = Callable[[Optional[bytes], int, Mapping[str, float], int], Tuple[Optional[bytes], int]] -Width = Literal[1, 2, 3, 4] -def get_format_from_width(width: Width, unsigned: bool = ...) -> int: ... +def get_format_from_width(width: int, unsigned: bool = ...) -> int: ... def get_portaudio_version() -> int: ... def get_portaudio_version_text() -> str: ... def get_sample_size(format: int) -> int: ... @@ -118,7 +117,7 @@ class PyAudio: def get_device_count(self) -> int: ... def get_device_info_by_host_api_device_index(self, host_api_index: int, host_api_device_index: int) -> PaDeviceInfo: ... def get_device_info_by_index(self, device_index: int) -> PaDeviceInfo: ... - def get_format_from_width(self, width: Width, unsigned: bool = ...) -> int: ... + def get_format_from_width(self, width: int, unsigned: bool = ...) -> int: ... def get_host_api_count(self) -> int: ... def get_host_api_info_by_index(self, host_api_index: int) -> PaHostApiInfo: ... def get_host_api_info_by_type(self, host_api_type: int) -> PaHostApiInfo: ... From 3be6149de51436a498f55183c38b0adc89cce471 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 21:41:02 +0300 Subject: [PATCH 08/33] Trying Python 2 compatibility --- stubs/pyaudio/METADATA.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/pyaudio/METADATA.toml b/stubs/pyaudio/METADATA.toml index 4295107b9036..31f638bf33df 100644 --- a/stubs/pyaudio/METADATA.toml +++ b/stubs/pyaudio/METADATA.toml @@ -1,2 +1,2 @@ version = "0.1" -python2 = false +python2 = true From 6f8d9285152cbfca1cbc1456c0cc5d9e201c3e98 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 21:44:25 +0300 Subject: [PATCH 09/33] Fixed error in annotation --- stubs/pyaudio/pyaudio.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index c269651ea73f..3c5292017da6 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -106,7 +106,7 @@ class Stream: def read(self, num_frames: int, exception_on_overflow: bool = ...) -> bytes: ... def start_stream(self) -> None: ... def stop_stream(self) -> None: ... - def write(self, frames: Sequence[bytes], num_frames: Optional[int] = ..., exception_on_underflow: bool = ...) -> None: ... + def write(self, frames: bytes, num_frames: Optional[int] = ..., exception_on_underflow: bool = ...) -> None: ... class PyAudio: def __init__(self) -> None: ... From 03e4dcab99d1f86b821a75067150c81ac2f1617f Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 22:10:47 +0300 Subject: [PATCH 10/33] Empty commit to trigger timed out build check --- stubs/pyaudio/pyaudio.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index 3c5292017da6..0aad9685c3b3 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -164,3 +164,4 @@ class PaMacCoreStreamInfo: def __init__(self, flags: Optional[int] = ..., channel_map: Optional[ChannelMap] = ...) -> None: ... def get_flags(self) -> int: ... def get_channel_map(self) -> Optional[ChannelMap]: ... + From 605c18da2a3345d35329d7b0936a6ef50f9a8c86 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Sun, 28 Feb 2021 22:10:54 +0300 Subject: [PATCH 11/33] Revert "Empty commit to trigger timed out build check" This reverts commit 03e4dcab99d1f86b821a75067150c81ac2f1617f. --- stubs/pyaudio/pyaudio.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index 0aad9685c3b3..3c5292017da6 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -164,4 +164,3 @@ class PaMacCoreStreamInfo: def __init__(self, flags: Optional[int] = ..., channel_map: Optional[ChannelMap] = ...) -> None: ... def get_flags(self) -> int: ... def get_channel_map(self) -> Optional[ChannelMap]: ... - From e4a364dd2fa184277e7df936c9cb762a744ba2da Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Tue, 23 Mar 2021 15:39:10 +0300 Subject: [PATCH 12/33] Added _ before auxiliary type names --- stubs/pyaudio/pyaudio.pyi | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/stubs/pyaudio/pyaudio.pyi b/stubs/pyaudio/pyaudio.pyi index 3c5292017da6..58176455c6c6 100644 --- a/stubs/pyaudio/pyaudio.pyi +++ b/stubs/pyaudio/pyaudio.pyi @@ -67,10 +67,10 @@ paPrimingOutput: Final[int] = ... paMacCoreStreamInfo: PaMacCoreStreamInfo # Auxiliary types -ChannelMap = Sequence[int] -PaHostApiInfo = Mapping[str, Union[str, int]] -PaDeviceInfo = Mapping[str, Union[str, int, float]] -StreamCallback = Callable[[Optional[bytes], int, Mapping[str, float], int], Tuple[Optional[bytes], int]] +_ChannelMap = Sequence[int] +_PaHostApiInfo = Mapping[str, Union[str, int]] +_PaDeviceInfo = Mapping[str, Union[str, int, float]] +_StreamCallback = Callable[[Optional[bytes], int, Mapping[str, float], int], Tuple[Optional[bytes], int]] def get_format_from_width(width: int, unsigned: bool = ...) -> int: ... def get_portaudio_version() -> int: ... @@ -92,7 +92,7 @@ class Stream: start: bool = ..., input_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., output_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., - stream_callback: Optional[StreamCallback] = ..., + stream_callback: Optional[_StreamCallback] = ..., ) -> None: ... def close(self) -> None: ... def get_cpu_load(self) -> float: ... @@ -111,16 +111,16 @@ class Stream: class PyAudio: def __init__(self) -> None: ... def close(self, stream: Stream) -> None: ... - def get_default_host_api_info(self) -> PaHostApiInfo: ... - def get_default_input_device_info(self) -> PaDeviceInfo: ... - def get_default_output_device_info(self) -> PaDeviceInfo: ... + def get_default_host_api_info(self) -> _PaHostApiInfo: ... + def get_default_input_device_info(self) -> _PaDeviceInfo: ... + def get_default_output_device_info(self) -> _PaDeviceInfo: ... def get_device_count(self) -> int: ... - def get_device_info_by_host_api_device_index(self, host_api_index: int, host_api_device_index: int) -> PaDeviceInfo: ... - def get_device_info_by_index(self, device_index: int) -> PaDeviceInfo: ... + def get_device_info_by_host_api_device_index(self, host_api_index: int, host_api_device_index: int) -> _PaDeviceInfo: ... + def get_device_info_by_index(self, device_index: int) -> _PaDeviceInfo: ... def get_format_from_width(self, width: int, unsigned: bool = ...) -> int: ... def get_host_api_count(self) -> int: ... - def get_host_api_info_by_index(self, host_api_index: int) -> PaHostApiInfo: ... - def get_host_api_info_by_type(self, host_api_type: int) -> PaHostApiInfo: ... + def get_host_api_info_by_index(self, host_api_index: int) -> _PaHostApiInfo: ... + def get_host_api_info_by_type(self, host_api_type: int) -> _PaHostApiInfo: ... def get_sample_size(self, format: int) -> int: ... def is_format_supported( self, @@ -145,7 +145,7 @@ class PyAudio: start: bool = ..., input_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., output_host_api_specific_stream_info: Optional[PaMacCoreStreamInfo] = ..., - stream_callback: Optional[StreamCallback] = ..., + stream_callback: Optional[_StreamCallback] = ..., ) -> Stream: ... def terminate(self) -> None: ... @@ -161,6 +161,6 @@ class PaMacCoreStreamInfo: paMacCorePro: Final[ClassVar[int]] = ... paMacCoreMinimizeCPUButPlayNice: Final[ClassVar[int]] = ... paMacCoreMinimizeCPU: Final[ClassVar[int]] = ... - def __init__(self, flags: Optional[int] = ..., channel_map: Optional[ChannelMap] = ...) -> None: ... + def __init__(self, flags: Optional[int] = ..., channel_map: Optional[_ChannelMap] = ...) -> None: ... def get_flags(self) -> int: ... - def get_channel_map(self) -> Optional[ChannelMap]: ... + def get_channel_map(self) -> Optional[_ChannelMap]: ... From d2a5e1c4622aad6a046831b05666bb080c8e5d4c Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Tue, 23 Mar 2021 15:39:34 +0300 Subject: [PATCH 13/33] Provided the actual version number --- stubs/pyaudio/METADATA.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/pyaudio/METADATA.toml b/stubs/pyaudio/METADATA.toml index 31f638bf33df..0ddb3dae7a99 100644 --- a/stubs/pyaudio/METADATA.toml +++ b/stubs/pyaudio/METADATA.toml @@ -1,2 +1,2 @@ -version = "0.1" +version = "0.2.11" python2 = true From 1821870bbeb445f8949ad94c81d48fa625a5eedf Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Tue, 23 Mar 2021 15:41:24 +0300 Subject: [PATCH 14/33] Fixed AssertionError: Unsupported Python version 0.2.11 --- stubs/pyaudio/METADATA.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/pyaudio/METADATA.toml b/stubs/pyaudio/METADATA.toml index 0ddb3dae7a99..0291bda1316a 100644 --- a/stubs/pyaudio/METADATA.toml +++ b/stubs/pyaudio/METADATA.toml @@ -1,2 +1,2 @@ -version = "0.2.11" +version = "0.2" python2 = true From 80d773effa9a9025f0967e339d67760a1fd1515a Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 00:08:55 +0300 Subject: [PATCH 15/33] Added missing OpenSSL stubs --- stubs/openssl-python/OpenSSL/SSL.pyi | 26 +++++++++++++++++++++++++ stubs/openssl-python/OpenSSL/crypto.pyi | 10 ++++++++++ 2 files changed, 36 insertions(+) create mode 100644 stubs/openssl-python/OpenSSL/SSL.pyi diff --git a/stubs/openssl-python/OpenSSL/SSL.pyi b/stubs/openssl-python/OpenSSL/SSL.pyi new file mode 100644 index 000000000000..d9700585f6a8 --- /dev/null +++ b/stubs/openssl-python/OpenSSL/SSL.pyi @@ -0,0 +1,26 @@ +from socket import socket +from typing import Callable, Optional, Sequence, Union + +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 = ... + +class Connection: + def __init__(self, context: Context, _socket: Optional[socket] = ...) -> None: ... + def connect(self, addr: Union[str, bytes, Sequence[Union[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 set_options(self, options: int) -> None: ... + def set_verify(self, mode: int, callback: Callable[[Connection, X509, int, int, int], bool]) -> None: ... diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index 5e9e3e69dfd7..d7ce82f58ffb 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -3,6 +3,7 @@ from datetime import datetime from typing import Callable, Iterable, List, Optional, Set, Text, Tuple, Union from cryptography.hazmat.primitives.asymmetric import dsa, rsa +from cryptography.x509 import Certificate, CertificateRevocationList, CertificateSigningRequest FILETYPE_PEM: int FILETYPE_ASN1: int @@ -73,6 +74,9 @@ class X509Req: def get_extensions(self) -> List[X509Extension]: ... def sign(self, pkey: PKey, digest: str) -> None: ... def verify(self, pkey: PKey) -> bool: ... + @classmethod + def from_cryptography(cls, crypto_req: CertificateSigningRequest) -> X509Req: ... + def to_cryptography(self) -> CertificateSigningRequest: ... class X509: def __init__(self) -> None: ... @@ -100,6 +104,9 @@ class X509: def get_extension_count(self) -> int: ... def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ... def get_extension(self, index: int) -> X509Extension: ... + @classmethod + def from_cryptography(cls, crypto_key: Certificate) -> X509: ... + def to_cryptography(self) -> Certificate: ... class X509StoreFlags: CRL_CHECK: int @@ -157,6 +164,9 @@ class CRL: def set_nextUpdate(self, when: str) -> None: ... def sign(self, issuer_cert: X509, issuer_key: PKey, digest: str) -> None: ... def export(self, cert: X509, key: PKey, type: int = ..., days: int = ..., digest: str = ...) -> bytes: ... + @classmethod + def from_cryptography(cls, crypto_crl: CertificateRevocationList) -> CRL: ... + def to_cryptography(self) -> CertificateRevocationList: ... class PKCS7: def type_is_signed(self) -> bool: ... From 0419f5845f0046d90e1ca098dcf2145e0234930e Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 00:09:55 +0300 Subject: [PATCH 16/33] Improved imports --- stubs/openssl-python/OpenSSL/crypto.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index d7ce82f58ffb..dbc418ed0883 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -2,7 +2,8 @@ import sys from datetime import datetime from typing import Callable, Iterable, List, Optional, Set, Text, Tuple, Union -from cryptography.hazmat.primitives.asymmetric import dsa, rsa +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 FILETYPE_PEM: int @@ -13,7 +14,7 @@ TYPE_DSA: int class Error(Exception): ... -_Key = Union[rsa.RSAPublicKey, rsa.RSAPrivateKey, dsa.DSAPublicKey, dsa.DSAPrivateKey] +_Key = Union[DSAPrivateKey, DSAPublicKey, RSAPrivateKey, RSAPublicKey] class PKey: def __init__(self) -> None: ... From b3549739fb3c964b6ff0f6c531d9cbbe490e681e Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 00:16:58 +0300 Subject: [PATCH 17/33] Fixed _StrLike and _BytesLike annotations, as well as passphrase callback annotations --- stubs/openssl-python/OpenSSL/crypto.pyi | 98 +++++++++++++------------ 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index dbc418ed0883..df3fb8060f19 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -30,12 +30,16 @@ class _EllipticCurve: name: Text def get_elliptic_curves() -> Set[_EllipticCurve]: ... -def get_elliptic_curve(name: str) -> _EllipticCurve: ... +def get_elliptic_curve(name: _StrLike) -> _EllipticCurve: ... if sys.version_info >= (3, 0): + _BytesLike = bytes _StrLike = str + _TextLike = Union[_BytesLike, _StrLike] else: + _BytesLike = str _StrLike = Union[str, unicode] + _TextLike = _StrLike class X509Name: def __init__(self, name: X509Name) -> None: ... @@ -53,16 +57,16 @@ class X509Name: OU: _StrLike CN: _StrLike def hash(self) -> int: ... - def der(self) -> bytes: ... + def der(self) -> _BytesLike: ... def get_components(self) -> List[Tuple[str, str]]: ... class X509Extension: def __init__( - self, type_name: bytes, critical: bool, value: bytes, subject: Optional[X509] = ..., issuer: Optional[X509] = ... + self, type_name: _BytesLike, critical: bool, value: _BytesLike, subject: Optional[X509] = ..., issuer: Optional[X509] = ... ) -> None: ... def get_critical(self) -> bool: ... - def get_short_name(self) -> str: ... - def get_data(self) -> str: ... + def get_short_name(self) -> _BytesLike: ... + def get_data(self) -> _BytesLike: ... class X509Req: def __init__(self) -> None: ... @@ -73,7 +77,7 @@ class X509Req: def get_subject(self) -> X509Name: ... def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ... def get_extensions(self) -> List[X509Extension]: ... - def sign(self, pkey: PKey, digest: str) -> None: ... + def sign(self, pkey: PKey, digest: _TextLike) -> None: ... def verify(self, pkey: PKey) -> bool: ... @classmethod def from_cryptography(cls, crypto_req: CertificateSigningRequest) -> X509Req: ... @@ -85,19 +89,19 @@ class X509: def get_version(self) -> int: ... def get_pubkey(self) -> PKey: ... def set_pubkey(self, pkey: PKey) -> None: ... - def sign(self, pkey: PKey, digest: str) -> None: ... - def get_signature_algorithm(self) -> str: ... - def digest(self, digest_name: str) -> str: ... - def subject_name_hash(self) -> str: ... + def sign(self, pkey: PKey, digest: _TextLike) -> None: ... + def get_signature_algorithm(self) -> _BytesLike: ... + def digest(self, digest_name: _BytesLike) -> _BytesLike: ... + def subject_name_hash(self) -> _BytesLike: ... def set_serial_number(self, serial: int) -> None: ... def get_serial_number(self) -> int: ... def gmtime_adj_notAfter(self, amount: int) -> None: ... def gmtime_adj_notBefore(self, amount: int) -> None: ... def has_expired(self) -> bool: ... - def get_notBefore(self) -> str: ... - def set_notBefore(self, when: str) -> None: ... - def get_notAfter(self) -> str: ... - def set_notAfter(self, when: str) -> None: ... + def get_notBefore(self) -> Optional[_BytesLike]: ... + def set_notBefore(self, when: _BytesLike) -> None: ... + def get_notAfter(self) -> Optional[_BytesLike]: ... + def set_notAfter(self, when: _BytesLike) -> None: ... def get_issuer(self) -> X509Name: ... def set_issuer(self, issuer: X509Name) -> None: ... def get_subject(self) -> X509Name: ... @@ -131,29 +135,29 @@ class X509Store: class X509StoreContextError(Exception): certificate: X509 - def __init__(self, message: str, certificate: X509) -> None: ... + def __init__(self, message: _TextLike, certificate: X509) -> None: ... class X509StoreContext: def __init__(self, store: X509Store, certificate: X509) -> None: ... def set_store(self, store: X509Store) -> None: ... def verify_certificate(self) -> None: ... -def load_certificate(type: int, buffer: _StrLike) -> X509: ... -def dump_certificate(type: int, cert: X509) -> bytes: ... -def dump_publickey(type: int, pkey: PKey) -> bytes: ... +def load_certificate(type: int, buffer: _BytesLike) -> X509: ... +def dump_certificate(type: int, cert: X509) -> _BytesLike: ... +def dump_publickey(type: int, pkey: PKey) -> _BytesLike: ... def dump_privatekey( - type: int, pkey: PKey, cipher: Optional[str] = ..., passphrase: Optional[Union[str, Callable[[int], int]]] = ... -) -> bytes: ... + type: int, pkey: PKey, cipher: Optional[_BytesLike] = ..., passphrase: Union[_BytesLike, Callable[[], _BytesLike], None] = ... +) -> _BytesLike: ... class Revoked: def __init__(self) -> None: ... - def set_serial(self, hex_str: str) -> None: ... - def get_serial(self) -> str: ... - def set_reason(self, reason: str) -> None: ... - def get_reason(self) -> str: ... - def all_reasons(self) -> List[str]: ... - def set_rev_date(self, when: str) -> None: ... - def get_rev_date(self) -> str: ... + def set_serial(self, hex_str: _BytesLike) -> None: ... + def get_serial(self) -> _BytesLike: ... + def set_reason(self, reason: Optional[_BytesLike]) -> None: ... + def get_reason(self) -> Optional[_BytesLike]: ... + def all_reasons(self) -> List[_BytesLike]: ... + def set_rev_date(self, when: _BytesLike) -> None: ... + def get_rev_date(self) -> _BytesLike: ... class CRL: def __init__(self) -> None: ... @@ -161,10 +165,10 @@ class CRL: def add_revoked(self, revoked: Revoked) -> None: ... def get_issuer(self) -> X509Name: ... def set_version(self, version: int) -> None: ... - def set_lastUpdate(self, when: str) -> None: ... - def set_nextUpdate(self, when: str) -> None: ... - def sign(self, issuer_cert: X509, issuer_key: PKey, digest: str) -> None: ... - def export(self, cert: X509, key: PKey, type: int = ..., days: int = ..., digest: str = ...) -> bytes: ... + def set_lastUpdate(self, when: _BytesLike) -> None: ... + def set_nextUpdate(self, when: _BytesLike) -> None: ... + def sign(self, issuer_cert: X509, issuer_key: PKey, digest: _BytesLike) -> None: ... + def export(self, cert: X509, key: PKey, type: int = ..., days: int = ..., digest: _BytesLike = ...) -> _BytesLike: ... @classmethod def from_cryptography(cls, crypto_crl: CertificateRevocationList) -> CRL: ... def to_cryptography(self) -> CertificateRevocationList: ... @@ -174,7 +178,7 @@ class PKCS7: def type_is_enveloped(self) -> bool: ... def type_is_signedAndEnveloped(self) -> bool: ... def type_is_data(self) -> bool: ... - def get_type_name(self) -> str: ... + def get_type_name(self) -> _StrLike: ... class PKCS12: def __init__(self) -> None: ... @@ -184,25 +188,25 @@ class PKCS12: def set_privatekey(self, pkey: PKey) -> None: ... def get_ca_certificates(self) -> Tuple[X509, ...]: ... def set_ca_certificates(self, cacerts: Iterable[X509]) -> None: ... - def set_friendlyname(self, name: bytes) -> None: ... - def get_friendlyname(self) -> bytes: ... - def export(self, passphrase: Optional[str] = ..., iter: int = ..., maciter: int = ...) -> bytes: ... + def set_friendlyname(self, name: Optional[_BytesLike]) -> None: ... + def get_friendlyname(self) -> Optional[_BytesLike]: ... + def export(self, passphrase: Optional[_BytesLike] = ..., iter: int = ..., maciter: int = ...) -> _BytesLike: ... class NetscapeSPKI: def __init__(self) -> None: ... - def sign(self, pkey: PKey, digest: str) -> None: ... + def sign(self, pkey: PKey, digest: _BytesLike) -> None: ... def verify(self, key: PKey) -> bool: ... - def b64_encode(self) -> str: ... + def b64_encode(self) -> _BytesLike: ... def get_pubkey(self) -> PKey: ... def set_pubkey(self, pkey: PKey) -> None: ... -def load_publickey(type: int, buffer: _StrLike) -> PKey: ... -def load_privatekey(type: int, buffer: bytes, passphrase: Optional[Union[str, Callable[[int], int]]] = ...) -> PKey: ... -def dump_certificate_request(type: int, req: X509Req) -> bytes: ... -def load_certificate_request(type: int, buffer: _StrLike) -> X509Req: ... -def sign(pkey: PKey, data: _StrLike, digest: str) -> bytes: ... -def verify(cert: X509, signature: bytes, data: _StrLike, digest: str) -> None: ... -def dump_crl(type: int, crl: CRL) -> bytes: ... -def load_crl(type: int, buffer: _StrLike) -> CRL: ... -def load_pkcs7_data(type: int, buffer: _StrLike) -> PKCS7: ... -def load_pkcs12(buffer: _StrLike, passphrase: Optional[Union[str, Callable[[int], int]]] = ...) -> PKCS12: ... +def load_publickey(type: int, buffer: _TextLike) -> PKey: ... +def load_privatekey(type: int, buffer: _TextLike, passphrase: Union[_BytesLike, Callable[[], _BytesLike], None] = ...) -> PKey: ... +def dump_certificate_request(type: int, cert: X509Req) -> _BytesLike: ... +def load_certificate_request(type: int, buffer: _BytesLike) -> X509Req: ... +def sign(pkey: PKey, data: _TextLike, digest: _TextLike) -> _BytesLike: ... +def verify(cert: X509, signature: _BytesLike, data: _TextLike, digest: _TextLike) -> None: ... +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: ... From fe4aa2a2dfefc74cca997cc0fb25c577b618cfea Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 00:17:17 +0300 Subject: [PATCH 18/33] More annotation fixes --- stubs/openssl-python/OpenSSL/crypto.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index df3fb8060f19..53f3967fff6f 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -1,6 +1,6 @@ import sys from datetime import datetime -from typing import Callable, Iterable, List, Optional, Set, Text, Tuple, Union +from typing import Callable, Iterable, List, Optional, Sequence, Set, Text, Tuple, Union from cryptography.hazmat.primitives.asymmetric.dsa import DSAPrivateKey, DSAPublicKey from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey, RSAPublicKey @@ -138,7 +138,7 @@ class X509StoreContextError(Exception): def __init__(self, message: _TextLike, certificate: X509) -> None: ... class X509StoreContext: - def __init__(self, store: X509Store, certificate: X509) -> None: ... + def __init__(self, store: X509Store, certificate: X509, chain: Optional[Sequence[X509]]) -> None: ... def set_store(self, store: X509Store) -> None: ... def verify_certificate(self) -> None: ... @@ -187,7 +187,7 @@ class PKCS12: def get_privatekey(self) -> PKey: ... def set_privatekey(self, pkey: PKey) -> None: ... def get_ca_certificates(self) -> Tuple[X509, ...]: ... - def set_ca_certificates(self, cacerts: Iterable[X509]) -> None: ... + def set_ca_certificates(self, cacerts: Optional[Iterable[X509]]) -> None: ... def set_friendlyname(self, name: Optional[_BytesLike]) -> None: ... def get_friendlyname(self) -> Optional[_BytesLike]: ... def export(self, passphrase: Optional[_BytesLike] = ..., iter: int = ..., maciter: int = ...) -> _BytesLike: ... From 5e6fd2312f4e0c975f7519b061ef27b674147ed1 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 00:27:20 +0300 Subject: [PATCH 19/33] Reordering classes according to official documentation per https://www.pyopenssl.org/en/stable/api/crypto.html --- stubs/openssl-python/OpenSSL/crypto.pyi | 173 ++++++++++++------------ 1 file changed, 86 insertions(+), 87 deletions(-) diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index 53f3967fff6f..89733aa5643f 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -6,15 +6,28 @@ from cryptography.hazmat.primitives.asymmetric.dsa import DSAPrivateKey, DSAPubl 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] + FILETYPE_PEM: int FILETYPE_ASN1: int FILETYPE_TEXT: int + TYPE_RSA: int TYPE_DSA: int -class Error(Exception): ... +class _EllipticCurve: + name: Text -_Key = Union[DSAPrivateKey, DSAPublicKey, RSAPrivateKey, RSAPublicKey] +class Error(Exception): ... class PKey: def __init__(self) -> None: ... @@ -26,21 +39,6 @@ class PKey: def type(self) -> int: ... def bits(self) -> int: ... -class _EllipticCurve: - name: Text - -def get_elliptic_curves() -> Set[_EllipticCurve]: ... -def get_elliptic_curve(name: _StrLike) -> _EllipticCurve: ... - -if sys.version_info >= (3, 0): - _BytesLike = bytes - _StrLike = str - _TextLike = Union[_BytesLike, _StrLike] -else: - _BytesLike = str - _StrLike = Union[str, unicode] - _TextLike = _StrLike - class X509Name: def __init__(self, name: X509Name) -> None: ... countryName: _StrLike @@ -60,29 +58,6 @@ class X509Name: def der(self) -> _BytesLike: ... def get_components(self) -> List[Tuple[str, str]]: ... -class X509Extension: - def __init__( - self, type_name: _BytesLike, critical: bool, value: _BytesLike, subject: Optional[X509] = ..., issuer: Optional[X509] = ... - ) -> None: ... - def get_critical(self) -> bool: ... - def get_short_name(self) -> _BytesLike: ... - def get_data(self) -> _BytesLike: ... - -class X509Req: - def __init__(self) -> None: ... - def set_pubkey(self, pkey: PKey) -> None: ... - def get_pubkey(self) -> PKey: ... - def set_version(self, version: int) -> None: ... - def get_version(self) -> int: ... - def get_subject(self) -> X509Name: ... - def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ... - def get_extensions(self) -> List[X509Extension]: ... - def sign(self, pkey: PKey, digest: _TextLike) -> None: ... - def verify(self, pkey: PKey) -> bool: ... - @classmethod - def from_cryptography(cls, crypto_req: CertificateSigningRequest) -> X509Req: ... - def to_cryptography(self) -> CertificateSigningRequest: ... - class X509: def __init__(self) -> None: ... def set_version(self, version: int) -> None: ... @@ -113,51 +88,28 @@ class X509: def from_cryptography(cls, crypto_key: Certificate) -> X509: ... def to_cryptography(self) -> Certificate: ... -class X509StoreFlags: - CRL_CHECK: int - CRL_CHECK_ALL: int - IGNORE_CRITICAL: int - X509_STRICT: int - ALLOW_PROXY_CERTS: int - POLICY_CHECK: int - EXPLICIT_POLICY: int - INHIBIT_MAP: int - NOTIFY_POLICY: int - CHECK_SS_SIGNATURE: int - CB_ISSUER_CHECK: int - -class X509Store: +class X509Req: def __init__(self) -> None: ... - def add_cert(self, cert: X509) -> None: ... - def add_crl(self, crl: CRL) -> None: ... - def set_flags(self, flags: int) -> None: ... - def set_time(self, vfy_time: datetime) -> None: ... - -class X509StoreContextError(Exception): - certificate: X509 - def __init__(self, message: _TextLike, certificate: X509) -> None: ... - -class X509StoreContext: - def __init__(self, store: X509Store, certificate: X509, chain: Optional[Sequence[X509]]) -> None: ... - def set_store(self, store: X509Store) -> None: ... - def verify_certificate(self) -> None: ... - -def load_certificate(type: int, buffer: _BytesLike) -> X509: ... -def dump_certificate(type: int, cert: X509) -> _BytesLike: ... -def dump_publickey(type: int, pkey: PKey) -> _BytesLike: ... -def dump_privatekey( - type: int, pkey: PKey, cipher: Optional[_BytesLike] = ..., passphrase: Union[_BytesLike, Callable[[], _BytesLike], None] = ... -) -> _BytesLike: ... + def set_pubkey(self, pkey: PKey) -> None: ... + def get_pubkey(self) -> PKey: ... + def set_version(self, version: int) -> None: ... + def get_version(self) -> int: ... + def get_subject(self) -> X509Name: ... + def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ... + def get_extensions(self) -> List[X509Extension]: ... + def sign(self, pkey: PKey, digest: _TextLike) -> None: ... + def verify(self, pkey: PKey) -> bool: ... + @classmethod + def from_cryptography(cls, crypto_req: CertificateSigningRequest) -> X509Req: ... + def to_cryptography(self) -> CertificateSigningRequest: ... -class Revoked: - def __init__(self) -> None: ... - def set_serial(self, hex_str: _BytesLike) -> None: ... - def get_serial(self) -> _BytesLike: ... - def set_reason(self, reason: Optional[_BytesLike]) -> None: ... - def get_reason(self) -> Optional[_BytesLike]: ... - def all_reasons(self) -> List[_BytesLike]: ... - def set_rev_date(self, when: _BytesLike) -> None: ... - def get_rev_date(self) -> _BytesLike: ... +class X509Extension: + def __init__( + self, type_name: _BytesLike, critical: bool, value: _BytesLike, subject: Optional[X509] = ..., issuer: Optional[X509] = ... + ) -> None: ... + def get_critical(self) -> bool: ... + def get_short_name(self) -> _BytesLike: ... + def get_data(self) -> _BytesLike: ... class CRL: def __init__(self) -> None: ... @@ -173,6 +125,45 @@ class CRL: def from_cryptography(cls, crypto_crl: CertificateRevocationList) -> CRL: ... def to_cryptography(self) -> CertificateRevocationList: ... +class Revoked: + def __init__(self) -> None: ... + def set_serial(self, hex_str: _BytesLike) -> None: ... + def get_serial(self) -> _BytesLike: ... + def set_reason(self, reason: Optional[_BytesLike]) -> None: ... + def get_reason(self) -> Optional[_BytesLike]: ... + def all_reasons(self) -> List[_BytesLike]: ... + def set_rev_date(self, when: _BytesLike) -> None: ... + def get_rev_date(self) -> _BytesLike: ... + +class X509Store: + def __init__(self) -> None: ... + def add_cert(self, cert: X509) -> None: ... + def add_crl(self, crl: CRL) -> 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: Optional[Sequence[X509]]) -> None: ... + def set_store(self, store: X509Store) -> None: ... + def verify_certificate(self) -> None: ... + +class X509StoreContextError(Exception): + certificate: X509 + def __init__(self, message: _TextLike, certificate: X509) -> None: ... + +class X509StoreFlags: + CRL_CHECK: int + CRL_CHECK_ALL: int + IGNORE_CRITICAL: int + X509_STRICT: int + ALLOW_PROXY_CERTS: int + POLICY_CHECK: int + EXPLICIT_POLICY: int + INHIBIT_MAP: int + NOTIFY_POLICY: int + CHECK_SS_SIGNATURE: int + CB_ISSUER_CHECK: int + class PKCS7: def type_is_signed(self) -> bool: ... def type_is_enveloped(self) -> bool: ... @@ -200,13 +191,21 @@ class NetscapeSPKI: def get_pubkey(self) -> PKey: ... def set_pubkey(self, pkey: PKey) -> None: ... -def load_publickey(type: int, buffer: _TextLike) -> PKey: ... -def load_privatekey(type: int, buffer: _TextLike, passphrase: Union[_BytesLike, Callable[[], _BytesLike], None] = ...) -> PKey: ... +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 sign(pkey: PKey, data: _TextLike, digest: _TextLike) -> _BytesLike: ... -def verify(cert: X509, signature: _BytesLike, data: _TextLike, digest: _TextLike) -> None: ... +def dump_privatekey( + type: int, pkey: PKey, cipher: Optional[_BytesLike] = ..., passphrase: Union[_BytesLike, Callable[[], _BytesLike], None] = ... +) -> _BytesLike: ... +def load_privatekey(type: int, buffer: _TextLike, passphrase: Union[_BytesLike, Callable[[], _BytesLike], 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: ... From 4b9a50d04fee39d16b3e0969ea58ebd9ba2d0c4a Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 00:34:43 +0300 Subject: [PATCH 20/33] Added missing OpenSSL stubs --- stubs/openssl-python/OpenSSL/crypto.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index 89733aa5643f..04c82d29df31 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -139,11 +139,13 @@ 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 set_flags(self, flags: int) -> None: ... def set_time(self, vfy_time: datetime) -> None: ... class X509StoreContext: def __init__(self, store: X509Store, certificate: X509, chain: Optional[Sequence[X509]]) -> None: ... + def get_verified_chain(self) -> List[X509]: ... def set_store(self, store: X509Store) -> None: ... def verify_certificate(self) -> None: ... From 1ab37de3119207e0b9d14deb702310da5306aaf5 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 00:41:44 +0300 Subject: [PATCH 21/33] Reordering class fields according to official documentation per https://www.pyopenssl.org/en/stable/api/crypto.htmlAdded missing OpenSSL stubs --- stubs/openssl-python/OpenSSL/crypto.pyi | 123 +++++++++++++----------- 1 file changed, 65 insertions(+), 58 deletions(-) diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index 04c82d29df31..6913c60cbabd 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -31,109 +31,109 @@ class Error(Exception): ... class PKey: def __init__(self) -> None: ... - def to_cryptography_key(self) -> _Key: ... + def bits(self) -> int: ... + def check(self) -> bool: ... @classmethod def from_cryptography_key(cls, crypto_key: _Key) -> PKey: ... def generate_key(self, type: int, bits: int) -> None: ... - def check(self) -> bool: ... + def to_cryptography_key(self) -> _Key: ... def type(self) -> int: ... - def bits(self) -> int: ... class X509Name: - def __init__(self, name: X509Name) -> None: ... countryName: _StrLike - stateOrProvinceName: _StrLike - localityName: _StrLike - organizationName: _StrLike - organizationalUnitName: _StrLike - commonName: _StrLike - emailAddress: _StrLike C: _StrLike + stateOrProvinceName: _StrLike ST: _StrLike + localityName: _StrLike L: _StrLike + organizationName: _StrLike O: _StrLike + organizationalUnitName: _StrLike OU: _StrLike + commonName: _StrLike CN: _StrLike - def hash(self) -> int: ... + emailAddress: _StrLike + def __init__(self, name: X509Name) -> None: ... def der(self) -> _BytesLike: ... def get_components(self) -> List[Tuple[str, str]]: ... + def hash(self) -> int: ... class X509: def __init__(self) -> None: ... - def set_version(self, version: int) -> None: ... - def get_version(self) -> int: ... - def get_pubkey(self) -> PKey: ... - def set_pubkey(self, pkey: PKey) -> None: ... - def sign(self, pkey: PKey, digest: _TextLike) -> None: ... - def get_signature_algorithm(self) -> _BytesLike: ... + def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ... def digest(self, digest_name: _BytesLike) -> _BytesLike: ... - def subject_name_hash(self) -> _BytesLike: ... - def set_serial_number(self, serial: int) -> None: ... + @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_pubkey(self) -> PKey: ... def get_serial_number(self) -> int: ... + def get_signature_algorithm(self) -> _BytesLike: ... + 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 get_notBefore(self) -> Optional[_BytesLike]: ... - def set_notBefore(self, when: _BytesLike) -> None: ... - def get_notAfter(self) -> Optional[_BytesLike]: ... - def set_notAfter(self, when: _BytesLike) -> None: ... - def get_issuer(self) -> X509Name: ... def set_issuer(self, issuer: X509Name) -> None: ... - def get_subject(self) -> X509Name: ... + def set_notAfter(self, when: _BytesLike) -> None: ... + def set_notBefore(self, when: _BytesLike) -> None: ... + def set_pubkey(self, pkey: PKey) -> None: ... + def set_serial_number(self, serial: int) -> None: ... def set_subject(self, subject: X509Name) -> None: ... - def get_extension_count(self) -> int: ... - def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ... - def get_extension(self, index: int) -> X509Extension: ... - @classmethod - def from_cryptography(cls, crypto_key: Certificate) -> X509: ... + def set_version(self, version: int) -> None: ... + def sign(self, pkey: PKey, digest: _TextLike) -> None: ... + def subject_name_hash(self) -> _BytesLike: ... def to_cryptography(self) -> Certificate: ... class X509Req: def __init__(self) -> None: ... - def set_pubkey(self, pkey: PKey) -> None: ... - def get_pubkey(self) -> PKey: ... - def set_version(self, version: int) -> None: ... - def get_version(self) -> int: ... - def get_subject(self) -> X509Name: ... def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ... - def get_extensions(self) -> List[X509Extension]: ... - def sign(self, pkey: PKey, digest: _TextLike) -> None: ... - def verify(self, pkey: PKey) -> bool: ... @classmethod def from_cryptography(cls, crypto_req: CertificateSigningRequest) -> X509Req: ... + def get_extensions(self) -> List[X509Extension]: ... + def get_pubkey(self) -> PKey: ... + def get_subject(self) -> X509Name: ... + 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 to_cryptography(self) -> CertificateSigningRequest: ... + def verify(self, pkey: PKey) -> bool: ... class X509Extension: def __init__( self, type_name: _BytesLike, critical: bool, value: _BytesLike, subject: Optional[X509] = ..., issuer: Optional[X509] = ... ) -> None: ... def get_critical(self) -> bool: ... - def get_short_name(self) -> _BytesLike: ... def get_data(self) -> _BytesLike: ... + def get_short_name(self) -> _BytesLike: ... class CRL: def __init__(self) -> None: ... - def get_revoked(self) -> Tuple[Revoked, ...]: ... def add_revoked(self, revoked: Revoked) -> None: ... + def export(self, cert: X509, key: PKey, type: int = ..., days: int = ..., digest: _BytesLike = ...) -> _BytesLike: ... + @classmethod + def from_cryptography(cls, crypto_crl: CertificateRevocationList) -> CRL: ... def get_issuer(self) -> X509Name: ... - def set_version(self, version: int) -> None: ... + def get_revoked(self) -> Tuple[Revoked, ...]: ... def set_lastUpdate(self, when: _BytesLike) -> None: ... def set_nextUpdate(self, when: _BytesLike) -> None: ... + def set_version(self, version: int) -> None: ... def sign(self, issuer_cert: X509, issuer_key: PKey, digest: _BytesLike) -> None: ... - def export(self, cert: X509, key: PKey, type: int = ..., days: int = ..., digest: _BytesLike = ...) -> _BytesLike: ... - @classmethod - def from_cryptography(cls, crypto_crl: CertificateRevocationList) -> CRL: ... def to_cryptography(self) -> CertificateRevocationList: ... class Revoked: def __init__(self) -> None: ... - def set_serial(self, hex_str: _BytesLike) -> 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 get_reason(self) -> Optional[_BytesLike]: ... - def all_reasons(self) -> List[_BytesLike]: ... def set_rev_date(self, when: _BytesLike) -> None: ... - def get_rev_date(self) -> _BytesLike: ... + def set_serial(self, hex_str: _BytesLike) -> None: ... class X509Store: def __init__(self) -> None: ... @@ -167,47 +167,54 @@ class X509StoreFlags: CB_ISSUER_CHECK: int class PKCS7: - def type_is_signed(self) -> bool: ... + def get_type_name(self) -> _StrLike: ... + def type_is_data(self) -> bool: ... def type_is_enveloped(self) -> bool: ... + def type_is_signed(self) -> bool: ... def type_is_signedAndEnveloped(self) -> bool: ... - def type_is_data(self) -> bool: ... - def get_type_name(self) -> _StrLike: ... class PKCS12: def __init__(self) -> None: ... + def export(self, passphrase: Optional[_BytesLike] = ..., iter: int = ..., maciter: int = ...) -> _BytesLike: ... + def get_ca_certificates(self) -> Tuple[X509, ...]: ... def get_certificate(self) -> X509: ... - def set_certificate(self, cert: X509) -> None: ... + def get_friendlyname(self) -> Optional[_BytesLike]: ... def get_privatekey(self) -> PKey: ... - def set_privatekey(self, pkey: PKey) -> None: ... - def get_ca_certificates(self) -> Tuple[X509, ...]: ... 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 get_friendlyname(self) -> Optional[_BytesLike]: ... - def export(self, passphrase: Optional[_BytesLike] = ..., iter: int = ..., maciter: int = ...) -> _BytesLike: ... + def set_privatekey(self, pkey: PKey) -> None: ... class NetscapeSPKI: def __init__(self) -> None: ... - def sign(self, pkey: PKey, digest: _BytesLike) -> None: ... - def verify(self, key: PKey) -> bool: ... def b64_encode(self) -> _BytesLike: ... def get_pubkey(self) -> PKey: ... def set_pubkey(self, pkey: PKey) -> None: ... + def sign(self, pkey: PKey, digest: _BytesLike) -> 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 dump_privatekey( type: int, pkey: PKey, cipher: Optional[_BytesLike] = ..., passphrase: Union[_BytesLike, Callable[[], _BytesLike], None] = ... ) -> _BytesLike: ... def load_privatekey(type: int, buffer: _TextLike, passphrase: Union[_BytesLike, Callable[[], _BytesLike], 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: ... From 4798d01dc8b73d545451da7153ff6c4a24d3c834 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 00:49:14 +0300 Subject: [PATCH 22/33] Formatting fixes --- stubs/openssl-python/OpenSSL/crypto.pyi | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index 6913c60cbabd..4d750fcb0438 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -105,12 +105,27 @@ class X509Req: class X509Extension: def __init__( - self, type_name: _BytesLike, critical: bool, value: _BytesLike, subject: Optional[X509] = ..., issuer: Optional[X509] = ... + self, + type_name: _BytesLike, + critical: bool, + value: _BytesLike, + subject: Optional[X509] = ..., + issuer: Optional[X509] = ..., ) -> None: ... def get_critical(self) -> bool: ... def get_data(self) -> _BytesLike: ... def get_short_name(self) -> _BytesLike: ... +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: ... + class CRL: def __init__(self) -> None: ... def add_revoked(self, revoked: Revoked) -> None: ... @@ -125,16 +140,6 @@ class CRL: def sign(self, issuer_cert: X509, issuer_key: PKey, digest: _BytesLike) -> None: ... def to_cryptography(self) -> CertificateRevocationList: ... -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: ... - class X509Store: def __init__(self) -> None: ... def add_cert(self, cert: X509) -> None: ... @@ -195,26 +200,21 @@ class NetscapeSPKI: 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 dump_privatekey( type: int, pkey: PKey, cipher: Optional[_BytesLike] = ..., passphrase: Union[_BytesLike, Callable[[], _BytesLike], None] = ... ) -> _BytesLike: ... -def load_privatekey(type: int, buffer: _TextLike, passphrase: Union[_BytesLike, Callable[[], _BytesLike], None] = ...) -> PKey: ... - +def load_privatekey( + type: int, buffer: _TextLike, passphrase: Union[_BytesLike, Callable[[], _BytesLike], 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: ... From ab5ae9f4dad893569b216d28bacbdd898a82d2f7 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 00:51:41 +0300 Subject: [PATCH 23/33] Formatting fixes --- stubs/openssl-python/OpenSSL/crypto.pyi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index 4d750fcb0438..0e0d63215cb5 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -105,12 +105,12 @@ class X509Req: class X509Extension: def __init__( - self, - type_name: _BytesLike, - critical: bool, - value: _BytesLike, - subject: Optional[X509] = ..., - issuer: Optional[X509] = ..., + self, + type_name: _BytesLike, + critical: bool, + value: _BytesLike, + subject: Optional[X509] = ..., + issuer: Optional[X509] = ..., ) -> None: ... def get_critical(self) -> bool: ... def get_data(self) -> _BytesLike: ... From 037ccc25f05e7198c901c8f9b93d77835789db80 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 16:53:34 +0300 Subject: [PATCH 24/33] Updated per review by @srittau --- stubs/openssl-python/METADATA.toml | 2 +- stubs/openssl-python/OpenSSL/SSL.pyi | 24 ++--- stubs/openssl-python/OpenSSL/crypto.pyi | 138 +++++++++++------------- 3 files changed, 77 insertions(+), 87 deletions(-) diff --git a/stubs/openssl-python/METADATA.toml b/stubs/openssl-python/METADATA.toml index 557390f69830..f2e57a602bc3 100644 --- a/stubs/openssl-python/METADATA.toml +++ b/stubs/openssl-python/METADATA.toml @@ -1,4 +1,4 @@ version = "0.1" python2 = true -python3 = false +python3 = true requires = ["types-cryptography"] diff --git a/stubs/openssl-python/OpenSSL/SSL.pyi b/stubs/openssl-python/OpenSSL/SSL.pyi index d9700585f6a8..be75f73a52c3 100644 --- a/stubs/openssl-python/OpenSSL/SSL.pyi +++ b/stubs/openssl-python/OpenSSL/SSL.pyi @@ -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: ... diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index 0e0d63215cb5..4f5a4a531200 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -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 @@ -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: @@ -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: ... @@ -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: ... class X509StoreFlags: CRL_CHECK: int @@ -172,7 +162,7 @@ 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: ... @@ -180,41 +170,41 @@ class PKCS7: 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: ... From d8d2531207c24c191d0728e3f6f26924baa1f1c5 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 17:08:29 +0300 Subject: [PATCH 25/33] More fixes --- stubs/openssl-python/METADATA.toml | 2 +- stubs/openssl-python/OpenSSL/crypto.pyi | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/stubs/openssl-python/METADATA.toml b/stubs/openssl-python/METADATA.toml index f2e57a602bc3..5bc182eb7cd3 100644 --- a/stubs/openssl-python/METADATA.toml +++ b/stubs/openssl-python/METADATA.toml @@ -1,4 +1,4 @@ -version = "0.1" +version = "20.0" python2 = true python3 = true requires = ["types-cryptography"] diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index 4f5a4a531200..78b03450cc36 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -1,11 +1,11 @@ from datetime import datetime -from typing import Callable, Iterable, List, Optional, Sequence, Set, Text, Tuple +from typing import Callable, Iterable, List, Optional, Sequence, Set, Text, Tuple, Union 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 -_Key = DSAPrivateKey | DSAPublicKey | RSAPrivateKey | RSAPublicKey +_Key = Union[DSAPrivateKey, DSAPublicKey, RSAPrivateKey, RSAPublicKey] FILETYPE_PEM: int FILETYPE_ASN1: int @@ -95,12 +95,7 @@ class X509Req: class X509Extension: def __init__( - self, - type_name: bytes, - critical: bool, - value: bytes, - subject: Optional[X509] = ..., - issuer: Optional[X509] = ..., + self, type_name: bytes, critical: bool, value: bytes, subject: Optional[X509] = ..., issuer: Optional[X509] = ... ) -> None: ... def get_critical(self) -> bool: ... def get_data(self) -> bytes: ... @@ -197,9 +192,7 @@ def load_certificate_request(type: int, buffer: bytes) -> X509Req: ... def dump_privatekey( type: int, pkey: PKey, cipher: Optional[bytes] = ..., 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: Text | 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 dump_crl(type: int, crl: CRL) -> bytes: ... From 714d9d260b6f272b0f18bfe63b2153d92b8a6a80 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 17:11:55 +0300 Subject: [PATCH 26/33] Replaced Optional with | syntax --- stubs/openssl-python/OpenSSL/SSL.pyi | 6 +++--- stubs/openssl-python/OpenSSL/crypto.pyi | 26 ++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/stubs/openssl-python/OpenSSL/SSL.pyi b/stubs/openssl-python/OpenSSL/SSL.pyi index be75f73a52c3..78955f099d15 100644 --- a/stubs/openssl-python/OpenSSL/SSL.pyi +++ b/stubs/openssl-python/OpenSSL/SSL.pyi @@ -1,5 +1,5 @@ from socket import socket -from typing import Callable, Optional, Sequence +from typing import Callable, Sequence from OpenSSL.crypto import X509 @@ -13,7 +13,7 @@ OP_NO_TLSv1_3: int VERIFY_PEER: int class Connection: - def __init__(self, context: Context, _socket: Optional[socket]) -> None: ... + def __init__(self, context: Context, _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: ... @@ -21,6 +21,6 @@ class Connection: 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: 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: ... diff --git a/stubs/openssl-python/OpenSSL/crypto.pyi b/stubs/openssl-python/OpenSSL/crypto.pyi index 78b03450cc36..3bb1adb128b7 100644 --- a/stubs/openssl-python/OpenSSL/crypto.pyi +++ b/stubs/openssl-python/OpenSSL/crypto.pyi @@ -1,5 +1,5 @@ from datetime import datetime -from typing import Callable, Iterable, List, Optional, Sequence, Set, Text, Tuple, Union +from typing import 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 @@ -57,8 +57,8 @@ class X509: def get_extension(self, index: int) -> X509Extension: ... def get_extension_count(self) -> int: ... def get_issuer(self) -> X509Name: ... - def get_notAfter(self) -> Optional[bytes]: ... - def get_notBefore(self) -> Optional[bytes]: ... + def get_notAfter(self) -> bytes | None: ... + def get_notBefore(self) -> bytes | None: ... def get_pubkey(self) -> PKey: ... def get_serial_number(self) -> int: ... def get_signature_algorithm(self) -> bytes: ... @@ -95,7 +95,7 @@ class X509Req: class X509Extension: def __init__( - self, type_name: bytes, critical: bool, value: bytes, subject: Optional[X509] = ..., issuer: Optional[X509] = ... + self, type_name: bytes, critical: bool, value: bytes, subject: X509 | None = ..., issuer: X509 | None = ... ) -> None: ... def get_critical(self) -> bool: ... def get_data(self) -> bytes: ... @@ -104,10 +104,10 @@ class X509Extension: class Revoked: def __init__(self) -> None: ... def all_reasons(self) -> List[bytes]: ... - def get_reason(self) -> Optional[bytes]: ... + def get_reason(self) -> bytes | None: ... def get_rev_date(self) -> bytes: ... def get_serial(self) -> bytes: ... - def set_reason(self, reason: Optional[bytes]) -> None: ... + def set_reason(self, reason: bytes | None) -> None: ... def set_rev_date(self, when: bytes) -> None: ... def set_serial(self, hex_str: bytes) -> None: ... @@ -134,7 +134,7 @@ class X509Store: def set_time(self, vfy_time: datetime) -> None: ... class X509StoreContext: - def __init__(self, store: X509Store, certificate: X509, chain: Optional[Sequence[X509]]) -> 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: ... @@ -165,14 +165,14 @@ class PKCS7: class PKCS12: def __init__(self) -> None: ... - def export(self, passphrase: Optional[bytes] = ..., iter: int = ..., maciter: int = ...) -> bytes: ... + def export(self, passphrase: bytes | None = ..., iter: int = ..., maciter: int = ...) -> bytes: ... def get_ca_certificates(self) -> Tuple[X509, ...]: ... def get_certificate(self) -> X509: ... - def get_friendlyname(self) -> Optional[bytes]: ... + def get_friendlyname(self) -> bytes | None: ... def get_privatekey(self) -> PKey: ... - def set_ca_certificates(self, cacerts: Optional[Iterable[X509]]) -> None: ... + def set_ca_certificates(self, cacerts: Iterable[X509] | None) -> None: ... def set_certificate(self, cert: X509) -> None: ... - def set_friendlyname(self, name: Optional[bytes]) -> None: ... + def set_friendlyname(self, name: bytes | None) -> None: ... def set_privatekey(self, pkey: PKey) -> None: ... class NetscapeSPKI: @@ -190,7 +190,7 @@ 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[bytes] = ..., passphrase: bytes | Callable[[], bytes] | None = ... + type: int, pkey: PKey, cipher: bytes | None = ..., passphrase: bytes | Callable[[], bytes] | None = ... ) -> bytes: ... def load_privatekey(type: int, buffer: Text | bytes, passphrase: bytes | Callable[[], bytes] | None = ...) -> PKey: ... def dump_publickey(type: int, pkey: PKey) -> bytes: ... @@ -198,6 +198,6 @@ 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 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: ... From ec63bbf8e16054fec5e31d30799c5feb2b7f830a Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 16 Jun 2021 17:29:45 +0300 Subject: [PATCH 27/33] Reverted version for now --- stubs/openssl-python/METADATA.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/openssl-python/METADATA.toml b/stubs/openssl-python/METADATA.toml index 5bc182eb7cd3..f2e57a602bc3 100644 --- a/stubs/openssl-python/METADATA.toml +++ b/stubs/openssl-python/METADATA.toml @@ -1,4 +1,4 @@ -version = "20.0" +version = "0.1" python2 = true python3 = true requires = ["types-cryptography"] From f0b16bcd006e0344aa944025925b42d1173e7ea9 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 16 Jun 2021 16:44:37 +0200 Subject: [PATCH 28/33] Temporarily disable stubtest --- stubs/openssl-python/@tests/stubtest_allowlist.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 stubs/openssl-python/@tests/stubtest_allowlist.txt diff --git a/stubs/openssl-python/@tests/stubtest_allowlist.txt b/stubs/openssl-python/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..b84899f82079 --- /dev/null +++ b/stubs/openssl-python/@tests/stubtest_allowlist.txt @@ -0,0 +1,3 @@ +OpenSSL +OpenSSL.SSL +OpenSSL.crypto From 03640621604eee4af25a8937a5828f2dec5d82a1 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Thu, 17 Jun 2021 05:44:02 +0300 Subject: [PATCH 29/33] Trying to enable all tests --- stubs/pyOpenSSL/@tests/stubtest_allowlist.txt | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 stubs/pyOpenSSL/@tests/stubtest_allowlist.txt diff --git a/stubs/pyOpenSSL/@tests/stubtest_allowlist.txt b/stubs/pyOpenSSL/@tests/stubtest_allowlist.txt deleted file mode 100644 index b84899f82079..000000000000 --- a/stubs/pyOpenSSL/@tests/stubtest_allowlist.txt +++ /dev/null @@ -1,3 +0,0 @@ -OpenSSL -OpenSSL.SSL -OpenSSL.crypto From 4ea40bd07cfeba62e4fba138afd699f5376147de Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Thu, 17 Jun 2021 05:56:17 +0300 Subject: [PATCH 30/33] Fixed stubs according to stubtest --- stubs/pyOpenSSL/OpenSSL/SSL.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/pyOpenSSL/OpenSSL/SSL.pyi b/stubs/pyOpenSSL/OpenSSL/SSL.pyi index 78955f099d15..55476ed1c40f 100644 --- a/stubs/pyOpenSSL/OpenSSL/SSL.pyi +++ b/stubs/pyOpenSSL/OpenSSL/SSL.pyi @@ -1,4 +1,4 @@ -from socket import socket +import socket from typing import Callable, Sequence from OpenSSL.crypto import X509 @@ -13,7 +13,7 @@ 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: ... @@ -21,6 +21,6 @@ class Connection: 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: ... From 026bb5a0fbe0ab226a9a1afa9cd759c94359de62 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Thu, 17 Jun 2021 06:09:36 +0300 Subject: [PATCH 31/33] Fixed stubs according to stubtest --- stubs/pyOpenSSL/OpenSSL/SSL.pyi | 2 +- stubs/pyOpenSSL/OpenSSL/crypto.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/pyOpenSSL/OpenSSL/SSL.pyi b/stubs/pyOpenSSL/OpenSSL/SSL.pyi index 55476ed1c40f..9ede0ecbecc0 100644 --- a/stubs/pyOpenSSL/OpenSSL/SSL.pyi +++ b/stubs/pyOpenSSL/OpenSSL/SSL.pyi @@ -13,7 +13,7 @@ OP_NO_TLSv1_3: int VERIFY_PEER: int class Connection: - def __init__(self, context: Context, socket: 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: ... diff --git a/stubs/pyOpenSSL/OpenSSL/crypto.pyi b/stubs/pyOpenSSL/OpenSSL/crypto.pyi index 3bb1adb128b7..3e0ea36a5f13 100644 --- a/stubs/pyOpenSSL/OpenSSL/crypto.pyi +++ b/stubs/pyOpenSSL/OpenSSL/crypto.pyi @@ -134,7 +134,7 @@ class X509Store: 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: ... From 81f044aea9d1afae5f775458ab4c7a347c18d252 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Thu, 17 Jun 2021 21:30:06 +0300 Subject: [PATCH 32/33] Fixed stubs according to stubtest --- stubs/pyOpenSSL/OpenSSL/crypto.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stubs/pyOpenSSL/OpenSSL/crypto.pyi b/stubs/pyOpenSSL/OpenSSL/crypto.pyi index 3e0ea36a5f13..a0822311c342 100644 --- a/stubs/pyOpenSSL/OpenSSL/crypto.pyi +++ b/stubs/pyOpenSSL/OpenSSL/crypto.pyi @@ -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 @@ -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): ... @@ -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: ... @@ -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: ... + 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: ... @@ -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 = ... From 79603ef552de15907495d2a3c167638906e8e7c5 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Thu, 17 Jun 2021 23:37:18 +0300 Subject: [PATCH 33/33] Excluded stubtest for OpenSSL.crypto, as the respective fix to mypy is not going to be merged. See https://github.com/python/mypy/pull/10663. --- stubs/pyOpenSSL/@tests/stubtest_allowlist.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 stubs/pyOpenSSL/@tests/stubtest_allowlist.txt diff --git a/stubs/pyOpenSSL/@tests/stubtest_allowlist.txt b/stubs/pyOpenSSL/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..dd84546dff4f --- /dev/null +++ b/stubs/pyOpenSSL/@tests/stubtest_allowlist.txt @@ -0,0 +1 @@ +OpenSSL.crypto