Skip to content

Commit

Permalink
Merge branch 'nonce_typing'
Browse files Browse the repository at this point in the history
  • Loading branch information
Legrandin committed Jan 27, 2023
2 parents 7ff4746 + 37315bc commit 454cf15
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 95 deletions.
28 changes: 14 additions & 14 deletions lib/Crypto/Cipher/AES.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@ def new(key: ByteString,
@overload
def new(key: ByteString,
mode: Literal[2],
iv : ByteString = ...,
iv : Optional[ByteString] = ...,
use_aesni : bool = ...) -> \
CbcMode: ...

@overload
def new(key: ByteString,
mode: Literal[2],
IV : ByteString = ...,
IV : Optional[ByteString] = ...,
use_aesni : bool = ...) -> \
CbcMode: ...

# MODE_CFB
@overload
def new(key: ByteString,
mode: Literal[3],
iv : ByteString = ...,
iv : Optional[ByteString] = ...,
segment_size : int = ...,
use_aesni : bool = ...) -> \
CfbMode: ...

@overload
def new(key: ByteString,
mode: Literal[3],
IV : ByteString = ...,
IV : Optional[ByteString] = ...,
segment_size : int = ...,
use_aesni : bool = ...) -> \
CfbMode: ...
Expand All @@ -68,22 +68,22 @@ def new(key: ByteString,
@overload
def new(key: ByteString,
mode: Literal[5],
iv : ByteString = ...,
iv : Optional[ByteString] = ...,
use_aesni : bool = ...) -> \
OfbMode: ...

@overload
def new(key: ByteString,
mode: Literal[5],
IV : ByteString = ...,
IV : Optional[ByteString] = ...,
use_aesni : bool = ...) -> \
OfbMode: ...

# MODE_CTR
@overload
def new(key: ByteString,
mode: Literal[6],
nonce : ByteString = ...,
nonce : Optional[ByteString] = ...,
initial_value : Union[int, ByteString] = ...,
counter : Dict = ...,
use_aesni : bool = ...) -> \
Expand All @@ -93,22 +93,22 @@ def new(key: ByteString,
@overload
def new(key: ByteString,
mode: Literal[7],
iv : ByteString = ...,
iv : Optional[ByteString] = ...,
use_aesni : bool = ...) -> \
OpenPgpMode: ...

@overload
def new(key: ByteString,
mode: Literal[7],
IV : ByteString = ...,
IV : Optional[ByteString] = ...,
use_aesni : bool = ...) -> \
OpenPgpMode: ...

# MODE_CCM
@overload
def new(key: ByteString,
mode: Literal[8],
nonce : ByteString = ...,
nonce : Optional[ByteString] = ...,
mac_len : int = ...,
assoc_len : int = ...,
use_aesni : bool = ...) -> \
Expand All @@ -118,7 +118,7 @@ def new(key: ByteString,
@overload
def new(key: ByteString,
mode: Literal[9],
nonce : ByteString = ...,
nonce : Optional[ByteString] = ...,
mac_len : int = ...,
use_aesni : bool = ...) -> \
EaxMode: ...
Expand All @@ -127,15 +127,15 @@ def new(key: ByteString,
@overload
def new(key: ByteString,
mode: Literal[10],
nonce : ByteString = ...,
nonce : Optional[ByteString] = ...,
use_aesni : bool = ...) -> \
SivMode: ...

# MODE_SIV
@overload
def new(key: ByteString,
mode: Literal[11],
nonce : ByteString = ...,
nonce : Optional[ByteString] = ...,
mac_len : int = ...,
use_aesni : bool = ...) -> \
GcmMode: ...
Expand All @@ -144,7 +144,7 @@ def new(key: ByteString,
@overload
def new(key: ByteString,
mode: Literal[12],
nonce : ByteString = ...,
nonce : Optional[ByteString] = ...,
mac_len : int = ...,
use_aesni : bool = ...) -> \
OcbMode: ...
Expand Down
14 changes: 6 additions & 8 deletions lib/Crypto/Cipher/ARC2.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Dict, Iterable
from typing import Union, Dict, Iterable, Optional, ByteString

from Crypto.Cipher._mode_ecb import EcbMode
from Crypto.Cipher._mode_cbc import CbcMode
Expand All @@ -18,16 +18,14 @@ MODE_CTR: ARC2Mode
MODE_OPENPGP: ARC2Mode
MODE_EAX: ARC2Mode

Buffer = Union[bytes, bytearray, memoryview]

def new(key: Buffer,
def new(key: ByteString,
mode: ARC2Mode,
iv : Buffer = ...,
IV : Buffer = ...,
nonce : Buffer = ...,
iv : Optional[ByteString] = ...,
IV : Optional[ByteString] = ...,
nonce : Optional[ByteString] = ...,
segment_size : int = ...,
mac_len : int = ...,
initial_value : Union[int, Buffer] = ...,
initial_value : Union[int, ByteString] = ...,
counter : Dict = ...) -> \
Union[EcbMode, CbcMode, CfbMode, OfbMode, CtrMode, OpenPgpMode]: ...

Expand Down
12 changes: 5 additions & 7 deletions lib/Crypto/Cipher/ARC4.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from typing import Any, Union, Iterable

Buffer = Union[bytes, bytearray, memoryview]
from typing import Any, Union, Iterable, ByteString

class ARC4Cipher:
block_size: int
key_size: int

def __init__(self, key: Buffer, *args: Any, **kwargs: Any) -> None: ...
def encrypt(self, plaintext: Buffer) -> bytes: ...
def decrypt(self, ciphertext: Buffer) -> bytes: ...
def __init__(self, key: ByteString, *args: Any, **kwargs: Any) -> None: ...
def encrypt(self, plaintext: ByteString) -> bytes: ...
def decrypt(self, ciphertext: ByteString) -> bytes: ...

def new(key: Buffer, drop : int = ...) -> ARC4Cipher: ...
def new(key: ByteString, drop : int = ...) -> ARC4Cipher: ...

block_size: int
key_size: Iterable[int]
14 changes: 6 additions & 8 deletions lib/Crypto/Cipher/Blowfish.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Dict, Iterable
from typing import Union, Dict, Iterable, ByteString, Optional

from Crypto.Cipher._mode_ecb import EcbMode
from Crypto.Cipher._mode_cbc import CbcMode
Expand All @@ -18,16 +18,14 @@ MODE_CTR: BlowfishMode
MODE_OPENPGP: BlowfishMode
MODE_EAX: BlowfishMode

Buffer = Union[bytes, bytearray, memoryview]

def new(key: Buffer,
def new(key: ByteString,
mode: BlowfishMode,
iv : Buffer = ...,
IV : Buffer = ...,
nonce : Buffer = ...,
iv : Optional[ByteString] = ...,
IV : Optional[ByteString] = ...,
nonce : Optional[ByteString] = ...,
segment_size : int = ...,
mac_len : int = ...,
initial_value : Union[int, Buffer] = ...,
initial_value : Union[int, ByteString] = ...,
counter : Dict = ...) -> \
Union[EcbMode, CbcMode, CfbMode, OfbMode, CtrMode, OpenPgpMode]: ...

Expand Down
14 changes: 6 additions & 8 deletions lib/Crypto/Cipher/CAST.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Dict, Iterable
from typing import Union, Dict, Iterable, Optional, ByteString

from Crypto.Cipher._mode_ecb import EcbMode
from Crypto.Cipher._mode_cbc import CbcMode
Expand All @@ -18,16 +18,14 @@ MODE_CTR: CASTMode
MODE_OPENPGP: CASTMode
MODE_EAX: CASTMode

Buffer = Union[bytes, bytearray, memoryview]

def new(key: Buffer,
def new(key: ByteString,
mode: CASTMode,
iv : Buffer = ...,
IV : Buffer = ...,
nonce : Buffer = ...,
iv : Optional[ByteString] = ...,
IV : Optional[ByteString] = ...,
nonce : Optional[ByteString] = ...,
segment_size : int = ...,
mac_len : int = ...,
initial_value : Union[int, Buffer] = ...,
initial_value : Union[int, ByteString] = ...,
counter : Dict = ...) -> \
Union[EcbMode, CbcMode, CfbMode, OfbMode, CtrMode, OpenPgpMode]: ...

Expand Down
18 changes: 8 additions & 10 deletions lib/Crypto/Cipher/ChaCha20.pyi
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
from typing import Union, overload
from typing import Union, overload, ByteString, Optional

Buffer = Union[bytes, bytearray, memoryview]

def _HChaCha20(key: Buffer, nonce: Buffer) -> bytearray: ...
def _HChaCha20(key: ByteString, nonce: ByteString) -> bytearray: ...

class ChaCha20Cipher:
block_size: int
nonce: bytes

def __init__(self, key: Buffer, nonce: Buffer) -> None: ...
def __init__(self, key: ByteString, nonce: ByteString) -> None: ...
@overload
def encrypt(self, plaintext: Buffer) -> bytes: ...
def encrypt(self, plaintext: ByteString) -> bytes: ...
@overload
def encrypt(self, plaintext: Buffer, output: Union[bytearray, memoryview]) -> None: ...
def encrypt(self, plaintext: ByteString, output: Union[bytearray, memoryview]) -> None: ...
@overload
def decrypt(self, plaintext: Buffer) -> bytes: ...
def decrypt(self, plaintext: ByteString) -> bytes: ...
@overload
def decrypt(self, plaintext: Buffer, output: Union[bytearray, memoryview]) -> None: ...
def decrypt(self, plaintext: ByteString, output: Union[bytearray, memoryview]) -> None: ...
def seek(self, position: int) -> None: ...

def new(key: Buffer, nonce: Buffer = ...) -> ChaCha20Cipher: ...
def new(key: ByteString, nonce: Optional[ByteString] = ...) -> ChaCha20Cipher: ...

block_size: int
key_size: int
24 changes: 11 additions & 13 deletions lib/Crypto/Cipher/ChaCha20_Poly1305.pyi
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
from typing import Union, Tuple, overload

Buffer = Union[bytes, bytearray, memoryview]
from typing import Union, Tuple, overload, ByteString, Optional

class ChaCha20Poly1305Cipher:
nonce: bytes

def __init__(self, key: Buffer, nonce: Buffer) -> None: ...
def update(self, data: Buffer) -> None: ...
def __init__(self, key: ByteString, nonce: ByteString) -> None: ...
def update(self, data: ByteString) -> None: ...
@overload
def encrypt(self, plaintext: Buffer) -> bytes: ...
def encrypt(self, plaintext: ByteString) -> bytes: ...
@overload
def encrypt(self, plaintext: Buffer, output: Union[bytearray, memoryview]) -> None: ...
def encrypt(self, plaintext: ByteString, output: Union[bytearray, memoryview]) -> None: ...
@overload
def decrypt(self, plaintext: Buffer) -> bytes: ...
def decrypt(self, plaintext: ByteString) -> bytes: ...
@overload
def decrypt(self, plaintext: Buffer, output: Union[bytearray, memoryview]) -> None: ...
def decrypt(self, plaintext: ByteString, output: Union[bytearray, memoryview]) -> None: ...
def digest(self) -> bytes: ...
def hexdigest(self) -> str: ...
def verify(self, received_mac_tag: Buffer) -> None: ...
def verify(self, received_mac_tag: ByteString) -> None: ...
def hexverify(self, received_mac_tag: str) -> None: ...
def encrypt_and_digest(self, plaintext: Buffer) -> Tuple[bytes, bytes]: ...
def decrypt_and_verify(self, ciphertext: Buffer, received_mac_tag: Buffer) -> bytes: ...
def encrypt_and_digest(self, plaintext: ByteString) -> Tuple[bytes, bytes]: ...
def decrypt_and_verify(self, ciphertext: ByteString, received_mac_tag: ByteString) -> bytes: ...

def new(key: Buffer, nonce: Buffer = ...) -> ChaCha20Poly1305Cipher: ...
def new(key: ByteString, nonce: Optional[ByteString] = ...) -> ChaCha20Poly1305Cipher: ...

block_size: int
key_size: int
14 changes: 6 additions & 8 deletions lib/Crypto/Cipher/DES.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Dict, Iterable
from typing import Union, Dict, Iterable, ByteString, Optional

from Crypto.Cipher._mode_ecb import EcbMode
from Crypto.Cipher._mode_cbc import CbcMode
Expand All @@ -18,16 +18,14 @@ MODE_CTR: DESMode
MODE_OPENPGP: DESMode
MODE_EAX: DESMode

Buffer = Union[bytes, bytearray, memoryview]

def new(key: Buffer,
def new(key: ByteString,
mode: DESMode,
iv : Buffer = ...,
IV : Buffer = ...,
nonce : Buffer = ...,
iv : Optional[ByteString] = ...,
IV : Optional[ByteString] = ...,
nonce : Optional[ByteString] = ...,
segment_size : int = ...,
mac_len : int = ...,
initial_value : Union[int, Buffer] = ...,
initial_value : Union[int, ByteString] = ...,
counter : Dict = ...) -> \
Union[EcbMode, CbcMode, CfbMode, OfbMode, CtrMode, OpenPgpMode]: ...

Expand Down
14 changes: 6 additions & 8 deletions lib/Crypto/Cipher/DES3.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Dict, Tuple
from typing import Union, Dict, Tuple, ByteString, Optional

from Crypto.Cipher._mode_ecb import EcbMode
from Crypto.Cipher._mode_cbc import CbcMode
Expand All @@ -20,16 +20,14 @@ MODE_CTR: DES3Mode
MODE_OPENPGP: DES3Mode
MODE_EAX: DES3Mode

Buffer = Union[bytes, bytearray, memoryview]

def new(key: Buffer,
def new(key: ByteString,
mode: DES3Mode,
iv : Buffer = ...,
IV : Buffer = ...,
nonce : Buffer = ...,
iv : Optional[ByteString] = ...,
IV : Optional[ByteString] = ...,
nonce : Optional[ByteString] = ...,
segment_size : int = ...,
mac_len : int = ...,
initial_value : Union[int, Buffer] = ...,
initial_value : Union[int, ByteString] = ...,
counter : Dict = ...) -> \
Union[EcbMode, CbcMode, CfbMode, OfbMode, CtrMode, OpenPgpMode]: ...

Expand Down
19 changes: 8 additions & 11 deletions lib/Crypto/Cipher/Salsa20.pyi
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
from typing import Union, Tuple, Optional, overload


Buffer = Union[bytes, bytearray, memoryview]
from typing import Union, Tuple, Optional, overload, ByteString, Optional

class Salsa20Cipher:
nonce: bytes
block_size: int
key_size: int

def __init__(self,
key: Buffer,
nonce: Buffer) -> None: ...
key: ByteString,
nonce: ByteString) -> None: ...
@overload
def encrypt(self, plaintext: Buffer) -> bytes: ...
def encrypt(self, plaintext: ByteString) -> bytes: ...
@overload
def encrypt(self, plaintext: Buffer, output: Union[bytearray, memoryview]) -> None: ...
def encrypt(self, plaintext: ByteString, output: Union[bytearray, memoryview]) -> None: ...
@overload
def decrypt(self, plaintext: Buffer) -> bytes: ...
def decrypt(self, plaintext: ByteString) -> bytes: ...
@overload
def decrypt(self, plaintext: Buffer, output: Union[bytearray, memoryview]) -> None: ...
def decrypt(self, plaintext: ByteString, output: Union[bytearray, memoryview]) -> None: ...

def new(key: Buffer, nonce: Optional[Buffer] = ...) -> Salsa20Cipher: ...
def new(key: ByteString, nonce: Optional[ByteString] = ...) -> Salsa20Cipher: ...

block_size: int
key_size: Tuple[int, int]
Expand Down

0 comments on commit 454cf15

Please sign in to comment.