Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/Crypto/Cipher/AES.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Optional, Tuple, Union, overload
from typing import Optional, Tuple, Union, overload
from typing_extensions import Literal

Buffer=bytes|bytearray|memoryview
Expand All @@ -16,6 +16,7 @@ from Crypto.Cipher._mode_siv import SivMode
from Crypto.Cipher._mode_ocb import OcbMode
from Crypto.Cipher._mode_kw import KWMode
from Crypto.Cipher._mode_kwp import KWPMode
from Crypto.Util.Counter import CounterParams

MODE_ECB: Literal[1]
MODE_CBC: Literal[2]
Expand Down Expand Up @@ -91,7 +92,7 @@ def new(key: Buffer,
mode: Literal[6],
nonce : Optional[Buffer] = ...,
initial_value : Union[int, Buffer] = ...,
counter : Dict = ...,
counter : Optional[CounterParams] = ...,
use_aesni : bool = ...) -> \
CtrMode: ...

Expand Down
12 changes: 3 additions & 9 deletions lib/Crypto/Cipher/_mode_ocb.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from types import ModuleType
from typing import Union, Any, Optional, Tuple, Dict, overload
from typing import Union, Any, Optional, Tuple, Dict

Buffer = Union[bytes, bytearray, memoryview]

Expand All @@ -15,14 +15,8 @@ class OcbMode(object):

def update(self, assoc_data: Buffer) -> OcbMode: ...

@overload
def encrypt(self, plaintext: Buffer) -> bytes: ...
@overload
def encrypt(self, plaintext: Buffer, output: Union[bytearray, memoryview]) -> None: ...
@overload
def decrypt(self, plaintext: Buffer) -> bytes: ...
@overload
def decrypt(self, plaintext: Buffer, output: Union[bytearray, memoryview]) -> None: ...
def encrypt(self, plaintext: Optional[Buffer] = ...) -> bytes: ...
def decrypt(self, plaintext: Optional[Buffer] = ...) -> bytes: ...

def digest(self) -> bytes: ...
def hexdigest(self) -> str: ...
Expand Down
1 change: 1 addition & 0 deletions lib/Crypto/Hash/Poly1305.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Poly1305_MAC(object):
block_size: int
digest_size: int
oid: str
nonce: bytes

def __init__(self,
r : int,
Expand Down
25 changes: 19 additions & 6 deletions lib/Crypto/Protocol/KDF.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from types import ModuleType
from typing import Optional, Callable, Tuple, Union, Dict, Any, overload
from typing import Optional, Callable, List, Union, Dict, Any, overload
from typing_extensions import Literal

Buffer=bytes|bytearray|memoryview

RNG = Callable[[int], bytes]
PRF = Callable[[bytes, bytes], bytes]

def PBKDF1(password: str, salt: bytes, dkLen: int, count: Optional[int]=1000, hashAlgo: Optional[ModuleType]=None) -> bytes: ...
def PBKDF2(password: str, salt: bytes, dkLen: Optional[int]=16, count: Optional[int]=1000, prf: Optional[RNG]=None, hmac_hash_module: Optional[ModuleType]=None) -> bytes: ...
def PBKDF1(password: Union[str, Buffer], salt: Buffer, dkLen: int, count: Optional[int]=1000, hashAlgo: Optional[ModuleType]=None) -> bytes: ...
def PBKDF2(password: Union[str, Buffer], salt: Union[str, Buffer], dkLen: Optional[int]=16, count: Optional[int]=1000, prf: Optional[RNG]=None, hmac_hash_module: Optional[ModuleType]=None) -> bytes: ...

class _S2V(object):
def __init__(self, key: bytes, ciphermod: ModuleType, cipher_params: Optional[Dict[Any, Any]]=None) -> None: ...
Expand All @@ -20,9 +20,15 @@ class _S2V(object):

def _HKDF_extract(salt: Buffer, ikm: Buffer, hashmod: ModuleType) -> bytes: ...
def _HKDF_expand(prk: Buffer, info: Buffer, L: int, hashmod) -> bytes : ...
def HKDF(master: bytes, key_len: int, salt: bytes, hashmod: ModuleType, num_keys: Optional[int]=1, context: Optional[bytes]=None) -> Union[bytes, Tuple[bytes, ...]]: ...
@overload
def HKDF(master: Buffer, key_len: int, salt: Buffer, hashmod: ModuleType, num_keys: Literal[1]=1, context: Optional[Buffer]=None) -> bytes: ...
@overload
def HKDF(master: Buffer, key_len: int, salt: Buffer, hashmod: ModuleType, num_keys: int, context: Optional[Buffer]=None) -> Union[bytes, List[bytes]]: ...

def scrypt(password: str, salt: str, key_len: int, N: int, r: int, p: int, num_keys: Optional[int]=1) -> Union[bytes, Tuple[bytes, ...]]: ...
@overload
def scrypt(password: Union[str, Buffer], salt: Union[str, Buffer], key_len: int, N: int, r: int, p: int, num_keys: Literal[1]=1) -> bytes: ...
@overload
def scrypt(password: Union[str, Buffer], salt: Union[str, Buffer], key_len: int, N: int, r: int, p: int, num_keys: int) -> Union[bytes, List[bytes]]: ...

def _bcrypt_decode(data: bytes) -> bytes: ...
def _bcrypt_hash(password:bytes , cost: int, salt: bytes, constant:bytes, invert:bool) -> bytes: ...
Expand All @@ -36,9 +42,16 @@ def SP800_108_Counter(master: Buffer,
num_keys: Literal[None] = None,
label: Buffer = b'', context: Buffer = b'') -> bytes: ...

@overload
def SP800_108_Counter(master: Buffer,
key_len: int,
prf: PRF,
num_keys: Literal[1],
label: Buffer = b'', context: Buffer = b'') -> bytes: ...

@overload
def SP800_108_Counter(master: Buffer,
key_len: int,
prf: PRF,
num_keys: int,
label: Buffer = b'', context: Buffer = b'') -> Tuple[bytes]: ...
label: Buffer = b'', context: Buffer = b'') -> Union[bytes, List[bytes]]: ...
2 changes: 1 addition & 1 deletion lib/Crypto/Signature/eddsa.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Hash(Protocol):
def digest(self) -> bytes: ...

class XOF(Protocol):
def read(self, len: int) -> bytes: ...
def read(self, length: int) -> bytes: ...

def import_public_key(encoded: bytes) -> EccKey: ...
def import_private_key(encoded: bytes) -> EccKey: ...
Expand Down
8 changes: 6 additions & 2 deletions lib/Crypto/Signature/pss.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ from typing_extensions import Protocol

from Crypto.PublicKey.RSA import RsaKey

Buffer = Union[bytes, bytearray, memoryview]

class Hash(Protocol):
digest_size: int
def digest(self) -> bytes: ...
def update(self, bytes) -> None: ...
def update(self, data: Buffer) -> None: ...
def new(self) -> Hash: ...


class HashModule(Protocol):
digest_size: int
@staticmethod
def new(data: Optional[bytes]) -> Hash: ...
def new() -> Hash: ...


MaskFunction = Callable[[bytes, int, Union[Hash, HashModule]], bytes]
Expand Down
19 changes: 15 additions & 4 deletions lib/Crypto/Util/Counter.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from typing import Optional, Union, Dict
from typing import Union
from typing_extensions import TypedDict

def new(nbits: int, prefix: Optional[bytes]=..., suffix: Optional[bytes]=..., initial_value: Optional[int]=1,
little_endian: Optional[bool]=False, allow_wraparound: Optional[bool]=False) -> \
Dict[str, Union[int, bytes, bool]]: ...
Buffer = Union[bytes, bytearray, memoryview]
CounterBuffer = Union[bytes, bytearray]

class CounterParams(TypedDict):
counter_len: int
prefix: CounterBuffer
suffix: Buffer
initial_value: int
little_endian: bool

def new(nbits: int, prefix: CounterBuffer=..., suffix: Buffer=..., initial_value: int=1,
little_endian: bool=False, allow_wraparound: bool=False) -> \
CounterParams: ...
Loading