|
1 | | -from _typeshed import Incomplete |
2 | | -from typing_extensions import Final, Self |
| 1 | +from _typeshed import SupportsKeysAndGetItem, Unused |
| 2 | +from typing_extensions import Final, Literal, Self, TypeAlias |
3 | 3 |
|
4 | 4 | from .jks import TrustedCertEntry |
5 | 5 | from .util import AbstractKeystore, AbstractKeystoreEntry |
6 | 6 |
|
| 7 | +_BksType: TypeAlias = Literal["bks", "uber"] |
| 8 | +_CertType: TypeAlias = Literal["X.509"] |
| 9 | +_EntryFormat: TypeAlias = Literal["PKCS8", "PKCS#8", "X.509", "X509", "RAW"] |
| 10 | +_BksVersion: TypeAlias = Literal[1, 2] |
| 11 | + |
7 | 12 | ENTRY_TYPE_CERTIFICATE: Final = 1 |
8 | 13 | ENTRY_TYPE_KEY: Final = 2 |
9 | 14 | ENTRY_TYPE_SECRET: Final = 3 |
10 | 15 | ENTRY_TYPE_SEALED: Final = 4 |
| 16 | + |
11 | 17 | KEY_TYPE_PRIVATE: Final = 0 |
12 | 18 | KEY_TYPE_PUBLIC: Final = 1 |
13 | 19 | KEY_TYPE_SECRET: Final = 2 |
| 20 | +_KeyType: TypeAlias = Literal[0, 1, 2] |
14 | 21 |
|
15 | 22 | class AbstractBksEntry(AbstractKeystoreEntry): |
16 | | - cert_chain: Incomplete |
17 | | - def __init__(self, **kwargs) -> None: ... |
| 23 | + store_type: _BksType | None |
| 24 | + cert_chain: list[tuple[_CertType, bytes]] |
| 25 | + def __init__( |
| 26 | + self, |
| 27 | + *, |
| 28 | + cert_chain: list[tuple[_CertType, bytes]] = ..., |
| 29 | + encrypted: bytes | None = None, |
| 30 | + store_type: _BksType | None = None, |
| 31 | + alias: str, |
| 32 | + timestamp: int, |
| 33 | + **kwargs: Unused, |
| 34 | + ) -> None: ... |
18 | 35 |
|
19 | | -class BksTrustedCertEntry(TrustedCertEntry): ... |
| 36 | +class BksTrustedCertEntry(TrustedCertEntry): |
| 37 | + store_type: _BksType | None # type: ignore[assignment] |
20 | 38 |
|
21 | 39 | class BksKeyEntry(AbstractBksEntry): |
22 | | - type: Incomplete |
23 | | - format: Incomplete |
24 | | - algorithm: Incomplete |
25 | | - encoded: Incomplete |
26 | | - pkey_pkcs8: Incomplete |
27 | | - pkey: Incomplete |
28 | | - algorithm_oid: Incomplete |
29 | | - public_key_info: Incomplete |
30 | | - public_key: Incomplete |
31 | | - key: Incomplete |
32 | | - key_size: Incomplete |
33 | | - def __init__(self, type, format, algorithm, encoded, **kwargs) -> None: ... |
34 | | - def is_decrypted(self): ... |
35 | | - def decrypt(self, key_password) -> None: ... |
| 40 | + type: _KeyType |
| 41 | + format: _EntryFormat |
| 42 | + algorithm: str |
| 43 | + encoded: bytes |
| 44 | + # type == KEY_TYPE_PRIVATE |
| 45 | + pkey_pkcs8: bytes |
| 46 | + pkey: bytes |
| 47 | + algorithm_oid: tuple[int, ...] |
| 48 | + # type == KEY_TYPE_PUBLIC |
| 49 | + public_key_info: bytes |
| 50 | + public_key: bytes |
| 51 | + # type == KEY_TYPE_SECRET |
| 52 | + key: bytes |
| 53 | + key_size: int |
| 54 | + def __init__( |
| 55 | + self, |
| 56 | + type: _KeyType, |
| 57 | + format: _EntryFormat, |
| 58 | + algorithm: str, |
| 59 | + encoded: bytes, |
| 60 | + *, |
| 61 | + cert_chain: list[tuple[_CertType, bytes]] = ..., |
| 62 | + encrypted: bytes | None = None, |
| 63 | + store_type: _BksType | None = None, |
| 64 | + alias: str, |
| 65 | + timestamp: int, |
| 66 | + **kwargs: Unused, |
| 67 | + ) -> None: ... |
36 | 68 | @classmethod |
37 | | - def type2str(cls, t): ... |
| 69 | + def type2str(cls, t: _KeyType) -> Literal["PRIVATE", "PUBLIC", "SECRET"]: ... |
| 70 | + def is_decrypted(self) -> Literal[True]: ... |
38 | 71 |
|
39 | 72 | class BksSecretKeyEntry(AbstractBksEntry): |
40 | | - key: Incomplete |
41 | | - def __init__(self, **kwargs) -> None: ... |
42 | | - def is_decrypted(self): ... |
43 | | - def decrypt(self, key_password) -> None: ... |
| 73 | + key: bytes |
| 74 | + def is_decrypted(self) -> Literal[True]: ... |
44 | 75 |
|
45 | 76 | class BksSealedKeyEntry(AbstractBksEntry): |
46 | | - def __init__(self, **kwargs) -> None: ... |
47 | | - def __getattr__(self, name): ... |
48 | | - def is_decrypted(self): ... |
49 | | - def decrypt(self, key_password) -> None: ... |
| 77 | + # Properties provided by __getattr__ |
| 78 | + nested: BksKeyEntry | None |
| 79 | + # __getattr__ proxies all attributes of nested BksKeyEntry after decrypting |
| 80 | + type: _KeyType |
| 81 | + format: _EntryFormat |
| 82 | + algorithm: str |
| 83 | + encoded: bytes |
| 84 | + # if type == KEY_TYPE_PRIVATE |
| 85 | + pkey_pkcs8: bytes |
| 86 | + pkey: bytes |
| 87 | + algorithm_oid: tuple[int, ...] |
| 88 | + # if type == KEY_TYPE_PUBLIC |
| 89 | + public_key_info: bytes |
| 90 | + public_key: bytes |
| 91 | + # if type == KEY_TYPE_SECRET |
| 92 | + key: bytes |
| 93 | + key_size: int |
50 | 94 |
|
51 | 95 | class BksKeyStore(AbstractKeystore): |
52 | | - version: Incomplete |
53 | | - def __init__(self, store_type, entries, version: int = 2) -> None: ... |
| 96 | + store_type: Literal["bks"] |
| 97 | + entries: dict[str, BksTrustedCertEntry | BksKeyEntry | BksSealedKeyEntry | BksSecretKeyEntry] # type: ignore[assignment] |
| 98 | + version: _BksVersion |
| 99 | + def __init__( |
| 100 | + self, |
| 101 | + store_type: Literal["bks"], |
| 102 | + entries: SupportsKeysAndGetItem[str, BksTrustedCertEntry | BksKeyEntry | BksSealedKeyEntry | BksSecretKeyEntry], |
| 103 | + version: _BksVersion = 2, |
| 104 | + ) -> None: ... |
54 | 105 | @property |
55 | | - def certs(self): ... |
| 106 | + def certs(self) -> dict[str, BksTrustedCertEntry]: ... |
56 | 107 | @property |
57 | | - def secret_keys(self): ... |
| 108 | + def plain_keys(self) -> dict[str, BksKeyEntry]: ... |
58 | 109 | @property |
59 | | - def sealed_keys(self): ... |
| 110 | + def sealed_keys(self) -> dict[str, BksSealedKeyEntry]: ... |
60 | 111 | @property |
61 | | - def plain_keys(self): ... |
| 112 | + def secret_keys(self) -> dict[str, BksSecretKeyEntry]: ... |
62 | 113 | @classmethod |
63 | | - def loads(cls, data, store_password, try_decrypt_keys: bool = True) -> Self: ... |
| 114 | + def loads(cls, data: bytes, store_password: str, try_decrypt_keys: bool = True) -> Self: ... |
64 | 115 |
|
65 | 116 | class UberKeyStore(BksKeyStore): |
66 | | - @classmethod |
67 | | - def loads(cls, data, store_password, try_decrypt_keys: bool = True) -> Self: ... |
68 | | - version: Incomplete |
69 | | - def __init__(self, store_type, entries, version: int = 1) -> None: ... |
| 117 | + store_type: Literal["uber"] # type: ignore[assignment] |
| 118 | + version: Literal[1] |
| 119 | + def __init__( |
| 120 | + self, |
| 121 | + store_type: Literal["uber"], |
| 122 | + entries: SupportsKeysAndGetItem[str, BksTrustedCertEntry | BksKeyEntry | BksSealedKeyEntry | BksSecretKeyEntry], |
| 123 | + version: Literal[1] = 1, |
| 124 | + ) -> None: ... |
0 commit comments