Skip to content

Commit

Permalink
Fix typing for PBES and PKCS8
Browse files Browse the repository at this point in the history
  • Loading branch information
Legrandin committed Jan 8, 2024
1 parent a14a222 commit 22b854b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 9 additions & 6 deletions lib/Crypto/IO/PKCS8.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from typing import Dict, Tuple, Optional, Union, Callable
from typing import Tuple, Optional, Union, Callable
from typing_extensions import NotRequired

from Crypto.Util.asn1 import DerObject
from Crypto.IO._PBES import ProtParams


def wrap(private_key: bytes,
key_oid: str,
passphrase: Union[bytes, str] = ...,
protection: str = ...,
prot_params: Dict = ...,
key_params: Optional[DerObject] = ...,
randfunc: Optional[Callable[[int],str]] = ...) -> bytes: ...
passphrase: Union[bytes, str] = ...,
protection: str = ...,
prot_params: Optional[ProtParams] = ...,
key_params: Optional[DerObject] = ...,
randfunc: Optional[Callable[[int], str]] = ...) -> bytes: ...


def unwrap(p8_private_key: bytes, passphrase: Optional[Union[bytes, str]] = ...) -> Tuple[str, bytes, Optional[bytes]]: ...
15 changes: 11 additions & 4 deletions lib/Crypto/IO/_PBES.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Dict, Optional, Callable
from typing import Optional, Callable, TypedDict
from typing_extensions import NotRequired

class PbesError(ValueError):
...
Expand All @@ -7,13 +8,19 @@ class PBES1(object):
@staticmethod
def decrypt(data: bytes, passphrase: bytes) -> bytes: ...

class ProtParams(TypedDict):
iteration_count: NotRequired[int]
salt_size: NotRequired[int]
block_size: NotRequired[int]
parallelization: NotRequired[int]

class PBES2(object):
@staticmethod
def encrypt(data: bytes,
passphrase: bytes,
protection: str,
prot_params: Optional[Dict] = ...,
randfunc: Optional[Callable[[int],bytes]] = ...) -> bytes: ...
protection: str,
prot_params: Optional[ProtParams] = ...,
randfunc: Optional[Callable[[int],bytes]] = ...) -> bytes: ...

@staticmethod
def decrypt(data:bytes, passphrase: bytes) -> bytes: ...

0 comments on commit 22b854b

Please sign in to comment.