3fe3634dc06a5339cfd939ba01062d4778f4f064
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py   1) # SPDX-FileCopyrightText: 2024 Marco Ricci <software@the13thletter.info>
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py    2) #
src/derivepassphrase/types.py    3) # SPDX-License-Identifier: MIT
src/derivepassphrase/types.py    4) 
Marco Ricci Update documentation to use...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py   5) """Types used by derivepassphrase."""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py    6) 
src/derivepassphrase/types.py    7) from __future__ import annotations
src/derivepassphrase/types.py    8) 
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py   9) import enum
Marco Ricci Allow all textual strings,...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  10) from typing import Literal, NamedTuple, TypeGuard
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   11) 
Marco Ricci Support Python 3.10 and PyP...

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   12) from typing_extensions import (
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   13)     Any,
src/derivepassphrase/types.py   14)     NotRequired,
src/derivepassphrase/types.py   15)     Required,
src/derivepassphrase/types.py   16)     TypedDict,
Marco Ricci Support Python 3.10 and PyP...

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   17) )
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   18) 
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py  19) __all__ = (
src/derivepassphrase/_types.py  20)     'SSH_AGENT',
src/derivepassphrase/_types.py  21)     'SSH_AGENTC',
src/derivepassphrase/_types.py  22)     'KeyCommentPair',
src/derivepassphrase/_types.py  23)     'VaultConfig',
src/derivepassphrase/_types.py  24)     'is_vault_config',
src/derivepassphrase/_types.py  25) )
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   26) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   27) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   28) class VaultConfigGlobalSettings(TypedDict, total=False):
src/derivepassphrase/types.py   29)     r"""Configuration for vault: global settings.
src/derivepassphrase/types.py   30) 
src/derivepassphrase/types.py   31)     Attributes:
src/derivepassphrase/types.py   32)         key:
src/derivepassphrase/types.py   33)             The base64-encoded ssh public key to use, overriding the
src/derivepassphrase/types.py   34)             master passphrase. Optional.
src/derivepassphrase/types.py   35)         phrase:
src/derivepassphrase/types.py   36)             The master passphrase. Optional.
Marco Ricci Allow all textual strings,...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  37)         unicode_normalization_form:
src/derivepassphrase/_types.py  38)             The preferred Unicode normalization form; we warn the user
src/derivepassphrase/_types.py  39)             if textual passphrases do not match their normalized forms.
src/derivepassphrase/_types.py  40)             Optional, and a `derivepassphrase` extension.
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   41) 
src/derivepassphrase/types.py   42)     """
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   43) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   44)     key: NotRequired[str]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py  45)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   46)     phrase: NotRequired[str]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py  47)     """"""
Marco Ricci Allow all textual strings,...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py  48)     unicode_normalization_form: NotRequired[
src/derivepassphrase/_types.py  49)         Literal['NFC', 'NFD', 'NFKC', 'NFKD']
src/derivepassphrase/_types.py  50)     ]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py  51)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   52) 
src/derivepassphrase/types.py   53) 
src/derivepassphrase/types.py   54) class VaultConfigServicesSettings(VaultConfigGlobalSettings, total=False):
src/derivepassphrase/types.py   55)     r"""Configuration for vault: services settings.
src/derivepassphrase/types.py   56) 
src/derivepassphrase/types.py   57)     Attributes:
src/derivepassphrase/types.py   58)         notes:
src/derivepassphrase/types.py   59)             Optional notes for this service, to display to the user when
src/derivepassphrase/types.py   60)             generating the passphrase.
src/derivepassphrase/types.py   61)         length:
src/derivepassphrase/types.py   62)             Desired passphrase length.
src/derivepassphrase/types.py   63)         repeat:
src/derivepassphrase/types.py   64)             The maximum number of immediate character repetitions
src/derivepassphrase/types.py   65)             allowed in the passphrase.  Disabled if set to 0.
src/derivepassphrase/types.py   66)         lower:
src/derivepassphrase/types.py   67)             Optional constraint on ASCII lowercase characters.  If
src/derivepassphrase/types.py   68)             positive, include this many lowercase characters
src/derivepassphrase/types.py   69)             somewhere in the passphrase.  If 0, avoid lowercase
src/derivepassphrase/types.py   70)             characters altogether.
src/derivepassphrase/types.py   71)         upper:
src/derivepassphrase/types.py   72)             Same as `lower`, but for ASCII uppercase characters.
src/derivepassphrase/types.py   73)         number:
src/derivepassphrase/types.py   74)             Same as `lower`, but for ASCII digits.
src/derivepassphrase/types.py   75)         space:
src/derivepassphrase/types.py   76)             Same as `lower`, but for the space character.
src/derivepassphrase/types.py   77)         dash:
src/derivepassphrase/types.py   78)             Same as `lower`, but for the hyphen-minus and underscore
src/derivepassphrase/types.py   79)             characters.
src/derivepassphrase/types.py   80)         symbol:
src/derivepassphrase/types.py   81)             Same as `lower`, but for all other hitherto unlisted
src/derivepassphrase/types.py   82)             ASCII printable characters (except backquote).
src/derivepassphrase/types.py   83) 
src/derivepassphrase/types.py   84)     """
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py   85) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   86)     notes: NotRequired[str]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py  87)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   88)     length: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py  89)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   90)     repeat: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py  91)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   92)     lower: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py  93)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   94)     upper: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py  95)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   96)     number: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py  97)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py   98)     space: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py  99)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  100)     dash: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 101)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  102)     symbol: NotRequired[int]
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 103)     """"""
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  104) 
src/derivepassphrase/types.py  105) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py  106) _VaultConfig = TypedDict(
src/derivepassphrase/types.py  107)     '_VaultConfig',
src/derivepassphrase/types.py  108)     {'global': NotRequired[VaultConfigGlobalSettings]},
src/derivepassphrase/types.py  109)     total=False,
src/derivepassphrase/types.py  110) )
src/derivepassphrase/types.py  111) 
src/derivepassphrase/types.py  112) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  113) class VaultConfig(TypedDict, _VaultConfig, total=False):
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 114)     r"""Configuration for vault.  For typing purposes.
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  115) 
src/derivepassphrase/types.py  116)     Usually stored as JSON.
src/derivepassphrase/types.py  117) 
src/derivepassphrase/types.py  118)     Attributes:
src/derivepassphrase/types.py  119)         global (NotRequired[VaultConfigGlobalSettings]):
src/derivepassphrase/types.py  120)             Global settings.
src/derivepassphrase/types.py  121)         services (Required[dict[str, VaultConfigServicesSettings]]):
src/derivepassphrase/types.py  122)             Service-specific settings.
src/derivepassphrase/types.py  123) 
src/derivepassphrase/types.py  124)     """
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py  125) 
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  126)     services: Required[dict[str, VaultConfigServicesSettings]]
src/derivepassphrase/types.py  127) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

src/derivepassphrase/types.py  128) 
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 129) def is_vault_config(obj: Any) -> TypeGuard[VaultConfig]:  # noqa: ANN401,C901,PLR0911,PLR0912
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  130)     """Check if `obj` is a valid vault config, according to typing.
src/derivepassphrase/types.py  131) 
src/derivepassphrase/types.py  132)     Args:
src/derivepassphrase/types.py  133)         obj: The object to test.
src/derivepassphrase/types.py  134) 
src/derivepassphrase/types.py  135)     Returns:
src/derivepassphrase/types.py  136)         True if this is a vault config, false otherwise.
src/derivepassphrase/types.py  137) 
src/derivepassphrase/types.py  138)     """
src/derivepassphrase/types.py  139)     if not isinstance(obj, dict):
src/derivepassphrase/types.py  140)         return False
src/derivepassphrase/types.py  141)     if 'global' in obj:
src/derivepassphrase/types.py  142)         o_global = obj['global']
src/derivepassphrase/types.py  143)         if not isinstance(o_global, dict):
src/derivepassphrase/types.py  144)             return False
Marco Ricci Allow all textual strings,...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 145)         for key in ('key', 'phrase', 'unicode_normalization_form'):
Marco Ricci Move typing classes into se...

Marco Ricci authored 6 months ago

src/derivepassphrase/types.py  146)             if key in o_global and not isinstance(o_global[key], str):
src/derivepassphrase/types.py  147)                 return False
src/derivepassphrase/types.py  148)         if 'key' in o_global and 'phrase' in o_global:
src/derivepassphrase/types.py  149)             return False
src/derivepassphrase/types.py  150)     if not isinstance(obj.get('services'), dict):
src/derivepassphrase/types.py  151)         return False
src/derivepassphrase/types.py  152)     for sv_name, service in obj['services'].items():
src/derivepassphrase/types.py  153)         if not isinstance(sv_name, str):
src/derivepassphrase/types.py  154)             return False
src/derivepassphrase/types.py  155)         if not isinstance(service, dict):
src/derivepassphrase/types.py  156)             return False
src/derivepassphrase/types.py  157)         for key, value in service.items():
src/derivepassphrase/types.py  158)             match key:
src/derivepassphrase/types.py  159)                 case 'notes' | 'phrase' | 'key':
src/derivepassphrase/types.py  160)                     if not isinstance(value, str):
src/derivepassphrase/types.py  161)                         return False
src/derivepassphrase/types.py  162)                 case 'length':
src/derivepassphrase/types.py  163)                     if not isinstance(value, int) or value < 1:
src/derivepassphrase/types.py  164)                         return False
src/derivepassphrase/types.py  165)                 case _:
src/derivepassphrase/types.py  166)                     if not isinstance(value, int) or value < 0:
src/derivepassphrase/types.py  167)                         return False
src/derivepassphrase/types.py  168)         if 'key' in service and 'phrase' in service:
src/derivepassphrase/types.py  169)             return False
src/derivepassphrase/types.py  170)     return True
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 171) 
src/derivepassphrase/_types.py 172) 
src/derivepassphrase/_types.py 173) class KeyCommentPair(NamedTuple):
src/derivepassphrase/_types.py 174)     """SSH key plus comment pair.  For typing purposes.
src/derivepassphrase/_types.py 175) 
src/derivepassphrase/_types.py 176)     Attributes:
src/derivepassphrase/_types.py 177)         key: SSH key.
src/derivepassphrase/_types.py 178)         comment: SSH key comment.
src/derivepassphrase/_types.py 179) 
src/derivepassphrase/_types.py 180)     """
src/derivepassphrase/_types.py 181) 
src/derivepassphrase/_types.py 182)     key: bytes | bytearray
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 183)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 184)     comment: bytes | bytearray
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 185)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 186) 
src/derivepassphrase/_types.py 187) 
src/derivepassphrase/_types.py 188) class SSH_AGENTC(enum.Enum):  # noqa: N801
src/derivepassphrase/_types.py 189)     """SSH agent protocol numbers: client requests.
src/derivepassphrase/_types.py 190) 
src/derivepassphrase/_types.py 191)     Attributes:
src/derivepassphrase/_types.py 192)         REQUEST_IDENTITIES:
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 193)             List identities.  Expecting
src/derivepassphrase/_types.py 194)             [`SSH_AGENT.IDENTITIES_ANSWER`][].
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 195)         SIGN_REQUEST:
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 196)             Sign data.  Expecting [`SSH_AGENT.SIGN_RESPONSE`][].
Marco Ricci Add principal support for u...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 197)         ADD_IDENTITY:
src/derivepassphrase/_types.py 198)             Add an (SSH2) identity.
src/derivepassphrase/_types.py 199)         REMOVE_IDENTITY:
src/derivepassphrase/_types.py 200)             Remove an (SSH2) identity.
src/derivepassphrase/_types.py 201)         ADD_ID_CONSTRAINED:
src/derivepassphrase/_types.py 202)             Add an (SSH2) identity, including key constraints.
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 203) 
src/derivepassphrase/_types.py 204)     """
src/derivepassphrase/_types.py 205) 
src/derivepassphrase/_types.py 206)     REQUEST_IDENTITIES: int = 11
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 207)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 208)     SIGN_REQUEST: int = 13
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 209)     """"""
Marco Ricci Add principal support for u...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 210)     ADD_IDENTITY: int = 17
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 211)     """"""
Marco Ricci Add principal support for u...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 212)     REMOVE_IDENTITY: int = 18
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 213)     """"""
Marco Ricci Add principal support for u...

Marco Ricci authored 3 months ago

src/derivepassphrase/_types.py 214)     ADD_ID_CONSTRAINED: int = 25
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 215)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 216) 
src/derivepassphrase/_types.py 217) 
src/derivepassphrase/_types.py 218) class SSH_AGENT(enum.Enum):  # noqa: N801
src/derivepassphrase/_types.py 219)     """SSH agent protocol numbers: server replies.
src/derivepassphrase/_types.py 220) 
src/derivepassphrase/_types.py 221)     Attributes:
Marco Ricci Add a specific error class...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 222)         FAILURE:
src/derivepassphrase/_types.py 223)             Generic failure code.
src/derivepassphrase/_types.py 224)         SUCCESS:
src/derivepassphrase/_types.py 225)             Generic success code.
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 226)         IDENTITIES_ANSWER:
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 227)             Successful answer to [`SSH_AGENTC.REQUEST_IDENTITIES`][].
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 228)         SIGN_RESPONSE:
Marco Ricci Generate nicer documentatio...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 229)             Successful answer to [`SSH_AGENTC.SIGN_REQUEST`][].
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 230) 
src/derivepassphrase/_types.py 231)     """
src/derivepassphrase/_types.py 232) 
Marco Ricci Add a specific error class...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 233)     FAILURE: int = 5
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 234)     """"""
Marco Ricci Add a specific error class...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 235)     SUCCESS: int = 6
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 236)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 237)     IDENTITIES_ANSWER: int = 12
Marco Ricci Enable cross-references on...

Marco Ricci authored 2 months ago

src/derivepassphrase/_types.py 238)     """"""
Marco Ricci Consolidate `types` submodu...

Marco Ricci authored 4 months ago

src/derivepassphrase/_types.py 239)     SIGN_RESPONSE: int = 14