diff --git a/stubs/pywin32/_win32typing.pyi b/stubs/pywin32/_win32typing.pyi index 4e61a1565645..01c52b59d9c0 100644 --- a/stubs/pywin32/_win32typing.pyi +++ b/stubs/pywin32/_win32typing.pyi @@ -1,8 +1,8 @@ # Not available at runtime. Contains type definitions that are otherwise not exposed and not part of a specific module. -from _typeshed import Incomplete, Unused -from collections.abc import Iterable, Sequence +from _typeshed import Incomplete, ReadableBuffer, Unused +from collections.abc import Callable, Iterable, Sequence from typing import Literal, SupportsIndex, TypeAlias, TypedDict, final, overload, type_check_only -from typing_extensions import Never, Required, Self, deprecated, disjoint_base +from typing_extensions import Never, NotRequired, Required, Self, deprecated, disjoint_base from win32.lib.pywintypes import TimeType @@ -775,6 +775,112 @@ class PyCTL_CONTEXT: class PyCTL_USAGE: ... +@type_check_only +class OIDInfo(TypedDict): + OID: str + Name: str | None + GroupId: int + Value: int + ExtraInfo: bytes + +@type_check_only +class ProveParam(TypedDict): + Param: int + Flags: int + Data: Incomplete + +@type_check_only +class ProveInfo(TypedDict): + ContainerName: str | None + ProvName: str | None + ProvType: int + Flags: int + KeySpec: int + ProvParam: tuple[ProveParam, ...] + +@type_check_only +class KeyIdentifierProperty(TypedDict): + PropId: int + Data: ProveInfo | bytes + +@type_check_only +class KeyIdentifier(TypedDict): + KeyIdentifier: bytes + Props: tuple[KeyIdentifierProperty] + +@type_check_only +class QueryObject(TypedDict): + MsgAndCertEncodingType: int + ContentType: int + FormatType: int + CertStore: PyCERTSTORE | None + Msg: PyCRYPTMSG | None + Context: PyCERT_CONTEXT | PyCTL_CONTEXT | int | None + +@type_check_only +class DecryptMessagePara(TypedDict): + CertStores: Iterable[PyCERTSTORE] + MsgAndCertEncodingType: NotRequired[int] + Flags: NotRequired[int] + +@type_check_only +class VerifyMessagePara(TypedDict): + MsgAndCertEncodingType: NotRequired[int] + CryptProv: NotRequired[PyCRYPTPROV | None] + GetSignerCertificate: NotRequired[Callable[..., Incomplete] | None] + GetArg: NotRequired[Callable[..., Incomplete] | None] + +@type_check_only +class DecodeMessage(TypedDict): + MsgType: int + InnerContentType: int + Decoded: bytes | None + XchgCert: PyCERT_CONTEXT | None + SignerCert: PyCERT_CONTEXT | None + +@type_check_only +class AlgorithmIdentifier(TypedDict): + ObjId: str + Parameters: ReadableBuffer | None + +@type_check_only +class EncryptMessagePara(TypedDict): + ContentEncryptionAlgorithm: AlgorithmIdentifier + CryptProv: NotRequired[PyCRYPTPROV | None] + EncryptionAuxInfo: NotRequired[None] + Flags: NotRequired[int] + InnerContentType: NotRequired[int] + MsgEncodingType: NotRequired[int] + +@type_check_only +class SignMessagePara(TypedDict): + SigningCert: PyCERT_CONTEXT + HashAlgorithm: AlgorithmIdentifier + HashAuxInfo: NotRequired[None] + MsgCert: NotRequired[Iterable[PyCERT_CONTEXT] | None] + MsgCrl: NotRequired[None] + AuthAttr: NotRequired[Iterable[dict[str, Incomplete]] | None] + UnauthAttr: NotRequired[Iterable[dict[str, Incomplete]] | None] + Flags: NotRequired[int] + InnerContentType: NotRequired[int] + MsgEncodingType: NotRequired[int] + +@type_check_only +class VerifyMessageSignature(TypedDict): + SignerCert: PyCERT_CONTEXT + Decoded: bytes | None + +@type_check_only +class DecryptAndVerifyMessageSignature(TypedDict): + Decrypted: bytes + XchgCert: PyCERT_CONTEXT + SignerCert: PyCERT_CONTEXT + +@type_check_only +class CryptBitBlob(TypedDict): + Data: ReadableBuffer + UnusedBits: int + @final class PyConsoleScreenBuffer: def __new__(self, Handle) -> Self: ... diff --git a/stubs/pywin32/win32/win32crypt.pyi b/stubs/pywin32/win32/win32crypt.pyi index 3bde0ede1ac6..b4fbf288f672 100644 --- a/stubs/pywin32/win32/win32crypt.pyi +++ b/stubs/pywin32/win32/win32crypt.pyi @@ -1,107 +1,173 @@ -from _typeshed import Incomplete +from _typeshed import Incomplete, ReadableBuffer +from collections.abc import Iterable, Sequence +from typing import Literal, overload import _win32typing def CryptProtectData( - DataIn, - DataDescr: str | None = ..., - OptionalEntropy: Incomplete | None = ..., - Reserved: Incomplete | None = ..., - PromptStruct: _win32typing.PyCRYPTPROTECT_PROMPTSTRUCT | None = ..., - Flags: int = ..., -): ... + DataIn: ReadableBuffer, + DataDescr: str | None = None, + OptionalEntropy: bytes | None = None, + Reserved: None = None, + PromptStruct: ( + tuple[int] + | tuple[int, int | _win32typing.PyHANDLE | None] + | tuple[int, int | _win32typing.PyHANDLE | None, str | None] + | None + ) = None, + Flags: int = 0, +) -> bytes: ... def CryptUnprotectData( - DataIn, - OptionalEntropy: Incomplete | None = ..., - Reserved: Incomplete | None = ..., - PromptStruct: _win32typing.PyCRYPTPROTECT_PROMPTSTRUCT | None = ..., - Flags: int = ..., -) -> tuple[Incomplete, Incomplete]: ... -def CryptEnumProviders() -> list[tuple[str, Incomplete]]: ... -def CryptEnumProviderTypes() -> list[tuple[str, Incomplete]]: ... -def CryptGetDefaultProvider(ProvType, Flags) -> str: ... -def CryptSetProviderEx(ProvName: str, ProvType, Flags) -> None: ... -def CryptAcquireContext(Container: str, Provider: str, ProvType, Flags) -> _win32typing.PyCRYPTPROV: ... -def CryptFindLocalizedName(CryptName: str) -> str: ... -def CertEnumSystemStore(Flags, SystemStoreLocationPara: Incomplete | None = ...) -> list[Incomplete]: ... -def CertEnumSystemStoreLocation(Flags: int = ...) -> list[Incomplete]: ... -def CertEnumPhysicalStore(SystemStore: str, Flags) -> list[Incomplete]: ... -def CertRegisterSystemStore(SystemStore: str, Flags) -> None: ... -def CertUnregisterSystemStore(SystemStore: str, Flags) -> None: ... + DataIn: ReadableBuffer, + OptionalEntropy: bytes | None = None, + Reserved: None = None, + PromptStruct: ( + tuple[int] + | tuple[int, int | _win32typing.PyHANDLE | None] + | tuple[int, int | _win32typing.PyHANDLE | None, str | None] + | None + ) = None, + Flags: int = 0, +) -> tuple[str, bytes]: ... +def CryptEnumProviders() -> list[tuple[str, int]]: ... +def CryptEnumProviderTypes() -> list[tuple[str | None, int]]: ... +def CryptGetDefaultProvider(ProvType: int, Flags: int) -> str: ... +def CryptSetProviderEx(ProvName: str | None, ProvType: int, Flags: int) -> None: ... +def CryptAcquireContext( + Container: str | None, Provider: str | None, ProvType: int, Flags: int +) -> _win32typing.PyCRYPTPROV | None: ... +def CryptFindLocalizedName(CryptName: str) -> str | None: ... +def CertEnumSystemStore( + Flags: int, SystemStoreLocationPara: str | Sequence[int | _win32typing.PyHANDLE | None | str] | None = None +) -> list[str]: ... +def CertEnumSystemStoreLocation(Flags: int = 0) -> list[str]: ... +def CertEnumPhysicalStore(SystemStore: str, Flags: int) -> list[str]: ... +def CertRegisterSystemStore(SystemStore: str | Sequence[int | _win32typing.PyHANDLE | None | str], Flags: int) -> None: ... +def CertUnregisterSystemStore(SystemStore: str, Flags: int) -> None: ... def CertOpenStore( - StoreProvider, MsgAndCertEncodingType, CryptProv: _win32typing.PyCRYPTPROV, Flags, Para: Incomplete | None -) -> _win32typing.PyCERTSTORE: ... -def CertOpenSystemStore(SubsystemProtocol: str, Prov: _win32typing.PyCRYPTPROV | None = ...) -> _win32typing.PyCERTSTORE: ... -def CryptFindOIDInfo(KeyType, Key, GroupId: int = ...): ... -def CertAlgIdToOID(AlgId) -> str: ... -def CertOIDToAlgId(ObjId: str): ... -def CryptGetKeyIdentifierProperty(KeyIdentifier: str, PropId=..., Flags: int = ..., ComputerName: str | None = ...): ... + StoreProvider: int, + MsgAndCertEncodingType: int, + CryptProv: _win32typing.PyCRYPTPROV | None, + Flags: int, + Para: str | Sequence[int | _win32typing.PyHANDLE | None | str] | None, +) -> _win32typing.PyCERTSTORE | None: ... +def CertOpenSystemStore(SubsystemProtocol: str, Prov: _win32typing.PyCRYPTPROV | None = None) -> _win32typing.PyCERTSTORE: ... + +@overload +def CryptFindOIDInfo(KeyType: Literal[1], Key: bytes, GroupId: int = 0) -> _win32typing.OIDInfo: ... +@overload +def CryptFindOIDInfo(KeyType: Literal[2], Key: str, GroupId: int = 0) -> _win32typing.OIDInfo: ... +@overload +def CryptFindOIDInfo(KeyType: Literal[3], Key: int, GroupId: int = 0) -> _win32typing.OIDInfo: ... +@overload +def CryptFindOIDInfo(KeyType: Literal[4], Key: tuple[int, int], GroupId: int = 0) -> _win32typing.OIDInfo: ... + +def CertAlgIdToOID(AlgId: int) -> bytes | None: ... +def CertOIDToAlgId(ObjId: str) -> int: ... +def CryptGetKeyIdentifierProperty( + KeyIdentifier: ReadableBuffer, PropId: int = 2, Flags: int = 0, ComputerName: str | None = None +) -> _win32typing.ProveInfo: ... def CryptEnumKeyIdentifierProperties( - KeyIdentifier: str | None = ..., PropId: int = ..., Flags: int = ..., ComputerName: str | None = ... -): ... -def CryptEnumOIDInfo(GroupId: int = ...): ... + KeyIdentifier: ReadableBuffer | None = None, PropId: int = 0, Flags: int = 0, ComputerName: str | None = None +) -> list[_win32typing.KeyIdentifier]: ... +def CryptEnumOIDInfo(GroupId: int = 0) -> list[_win32typing.OIDInfo]: ... def CertAddSerializedElementToStore( - CertStore: _win32typing.PyCERTSTORE, Element, AddDisposition, ContextTypeFlags=..., Flags: int = ... -) -> _win32typing.PyCERT_CONTEXT: ... -def CryptQueryObject(ObjectType, Object, ExpectedContentTypeFlags=..., ExpectedFormatTypeFlags=..., Flags: int = ...): ... + CertStore: _win32typing.PyCERTSTORE | None, + Element: ReadableBuffer, + AddDisposition: int, + ContextTypeFlags: int = 2, + Flags: int = 0, +) -> _win32typing.PyCERT_CONTEXT | _win32typing.PyCTL_CONTEXT | None: ... + +@overload +def CryptQueryObject( + ObjectType: Literal[1], + Object: ReadableBuffer, + ExpectedContentTypeFlags: int = 0x00003FFE, + ExpectedFormatTypeFlags: int = 0x0000000E, + Flags: int = 0, +) -> _win32typing.QueryObject: ... +@overload +def CryptQueryObject( + ObjectType: Literal[2], + Object: str, + ExpectedContentTypeFlags: int = 0x00003FFE, + ExpectedFormatTypeFlags: int = 0x0000000E, + Flags: int = 0, +) -> _win32typing.QueryObject: ... + def CryptDecodeMessage( - EncodedBlob, - DecryptPara, - VerifyPara: Incomplete | None = ..., - MsgTypeFlags=..., - SignerIndex: int = ..., - PrevInnerContentType: int = ..., - ReturnData: bool = ..., -): ... + EncodedBlob: ReadableBuffer, + DecryptPara: _win32typing.DecryptMessagePara, + VerifyPara: _win32typing.VerifyMessagePara | None = None, + MsgTypeFlags: int = -1, + SignerIndex: int = 0, + PrevInnerContentType: int = 0, + ReturnData: bool | Literal[0, 1] = True, +) -> _win32typing.DecodeMessage: ... def CryptEncryptMessage( - EncryptPara: _win32typing.PyCRYPT_ENCRYPT_MESSAGE_PARA, RecipientCert: tuple[_win32typing.PyCERT_CONTEXT, ...], ToBeEncrypted -): ... + EncryptPara: _win32typing.EncryptMessagePara, + RecipientCert: Iterable[_win32typing.PyCERT_CONTEXT] | None, + ToBeEncrypted: ReadableBuffer, +) -> bytes: ... def CryptDecryptMessage( - DecryptPara: _win32typing.PyCRYPT_DECRYPT_MESSAGE_PARA, EncryptedBlob -) -> tuple[Incomplete, _win32typing.PyCERT_CONTEXT]: ... + DecryptPara: _win32typing.DecryptMessagePara, EncryptedBlob: ReadableBuffer +) -> tuple[bytes, _win32typing.PyCERT_CONTEXT]: ... def CryptSignAndEncryptMessage( - SignPara: _win32typing.PyCRYPT_SIGN_MESSAGE_PARA, - EncryptPara: _win32typing.PyCRYPT_ENCRYPT_MESSAGE_PARA, - RecipientCert: tuple[_win32typing.PyCERT_CONTEXT, ...], - ToBeSignedAndEncrypted, -): ... + SignPara: _win32typing.SignMessagePara, + EncryptPara: _win32typing.EncryptMessagePara, + RecipientCert: Iterable[_win32typing.PyCERT_CONTEXT] | None, + ToBeSignedAndEncrypted: ReadableBuffer, +) -> bytes: ... def CryptVerifyMessageSignature( - SignedBlob, SignerIndex: int = ..., VerifyPara: _win32typing.PyCRYPT_VERIFY_MESSAGE_PARA | None = ..., ReturnData: bool = ... -) -> tuple[_win32typing.PyCERT_CONTEXT, Incomplete]: ... + SignedBlob: ReadableBuffer, + SignerIndex: int = 0, + VerifyPara: _win32typing.VerifyMessagePara | None = None, + ReturnData: bool | Literal[0, 1] = False, +) -> _win32typing.VerifyMessageSignature: ... def CryptGetMessageCertificates( - SignedBlob, MsgAndCertEncodingType=..., CryptProv: _win32typing.PyCRYPTPROV | None = ..., Flags: int = ... + SignedBlob: ReadableBuffer, + MsgAndCertEncodingType: int = ..., + CryptProv: _win32typing.PyCRYPTPROV | None = None, + Flags: int = 0, ) -> _win32typing.PyCERTSTORE: ... -def CryptGetMessageSignerCount(SignedBlob, MsgEncodingType=...): ... +def CryptGetMessageSignerCount(SignedBlob: ReadableBuffer, MsgEncodingType: int = ...) -> int: ... def CryptSignMessage( - SignPara: _win32typing.PyCRYPT_SIGN_MESSAGE_PARA, ToBeSigned: tuple[Incomplete, ...], DetachedSignature: bool = ... -): ... + SignPara: _win32typing.SignMessagePara, ToBeSigned: Iterable[Incomplete], DetachedSignature: bool | Literal[0, 1] = False +) -> bytes: ... def CryptVerifyDetachedMessageSignature( - SignerIndex, - DetachedSignBlob, - ToBeSigned: tuple[Incomplete, ...], - VerifyPara: _win32typing.PyCRYPT_VERIFY_MESSAGE_PARA | None = ..., + SignerIndex: int, + DetachedSignBlob: ReadableBuffer, + ToBeSigned: Iterable[Incomplete], + VerifyPara: _win32typing.VerifyMessagePara | None = None, ) -> _win32typing.PyCERT_CONTEXT: ... def CryptDecryptAndVerifyMessageSignature( - EncryptedBlob, - DecryptPara: _win32typing.PyCRYPT_DECRYPT_MESSAGE_PARA, - VerifyPara: _win32typing.PyCRYPT_VERIFY_MESSAGE_PARA | None = ..., - SignerIndex: int = ..., -): ... + EncryptedBlob: ReadableBuffer, + DecryptPara: _win32typing.DecryptMessagePara, + VerifyPara: _win32typing.VerifyMessagePara | None = None, + SignerIndex: int = 0, +) -> _win32typing.DecryptAndVerifyMessageSignature: ... def CryptEncodeObjectEx( - StructType, StructInfo=..., Flags: int = ..., CertEncodingType=..., EncodePara: Incomplete | None = ... + StructType: int | bytes, + StructInfo: Iterable[int | bytes] | _win32typing.CryptBitBlob, + Flags: int = 0, + CertEncodingType: int = ..., + EncodePara: None = None, +) -> bytes: ... +def CryptDecodeObjectEx( + StructType: int | bytes, Encoded: ReadableBuffer, Flags: int = 0, CertEncodingType: int = ..., DecodePara: None = None ): ... -def CryptDecodeObjectEx(StructType, Encoded, Flags: int = ..., CertEncodingType=..., DecodePara: Incomplete | None = ...): ... -def CertNameToStr(Name, StrType, CertEncodingType): ... +def CertNameToStr(Name: ReadableBuffer, StrType: int = 1, CertEncodingType: int = 0x00000001) -> str: ... def CryptFormatObject( - StructType, - Encoded, - FormatStrType: int = ..., - CertEncodingType=..., - FormatType: int = ..., - FormatStruct: Incomplete | None = ..., -): ... -def PFXImportCertStore(PFX, Password, Flags) -> _win32typing.PyCERTSTORE: ... -def PFXVerifyPassword(PFX, Password, Flags): ... -def PFXIsPFXBlob(PFX): ... -def CryptBinaryToString(Binary, Flags): ... -def CryptStringToBinary(String, Flags) -> tuple[Incomplete, Incomplete, Incomplete]: ... + StructType: int | bytes, + Encoded: ReadableBuffer, + FormatStrType: int = 0, + CertEncodingType: int = 0x00000001, + FormatType: int = 0, + FormatStruct: None = None, +) -> str: ... +def PFXImportCertStore(PFX: ReadableBuffer, Password: str | None, Flags: int) -> _win32typing.PyCERTSTORE: ... +def PFXVerifyPassword(PFX: ReadableBuffer, Password: str | None, Flags: int) -> bool: ... +def PFXIsPFXBlob(PFX: ReadableBuffer) -> bool: ... +def CryptBinaryToString(Binary: ReadableBuffer, Flags: int) -> str: ... +def CryptStringToBinary(String: str, Flags: int) -> tuple[bytes, int, int]: ...