Marco Ricci commited on 2024-09-12 21:23:13
Zeige 5 geänderte Dateien mit 77 Einfügungen und 40 Löschungen.
This includes formatting, typos and missing/wrong links. Most of these are in non-public documentation parts which don't get rendered by default.
... | ... |
@@ -176,9 +176,11 @@ class SSH_AGENTC(enum.Enum): # noqa: N801 |
176 | 176 |
|
177 | 177 |
Attributes: |
178 | 178 |
REQUEST_IDENTITIES: |
179 |
- List identities. Expecting `SSH_AGENT.IDENTITIES_ANSWER`. |
|
179 |
+ List identities. Expecting [`SSH_AGENT.IDENTITIES_ANSWER`] |
|
180 |
+ [derivepassphrase._types.SSH_AGENT]. |
|
180 | 181 |
SIGN_REQUEST: |
181 |
- Sign data. Expecting `SSH_AGENT.SIGN_RESPONSE`. |
|
182 |
+ Sign data. Expecting [`SSH_AGENT.SIGN_RESPONSE`] |
|
183 |
+ [derivepassphrase._types.SSH_AGENT]. |
|
182 | 184 |
|
183 | 185 |
""" |
184 | 186 |
|
... | ... |
@@ -195,9 +197,11 @@ class SSH_AGENT(enum.Enum): # noqa: N801 |
195 | 197 |
SUCCESS: |
196 | 198 |
Generic success code. |
197 | 199 |
IDENTITIES_ANSWER: |
198 |
- Successful answer to `SSH_AGENTC.REQUEST_IDENTITIES`. |
|
200 |
+ Successful answer to [`SSH_AGENTC.REQUEST_IDENTITIES`] |
|
201 |
+ [derivepassphrase._types.SSH_AGENTC]. |
|
199 | 202 |
SIGN_RESPONSE: |
200 |
- Successful answer to `SSH_AGENTC.SIGN_REQUEST`. |
|
203 |
+ Successful answer to [`SSH_AGENTC.SIGN_REQUEST`] |
|
204 |
+ [derivepassphrase._types.SSH_AGENTC]. |
|
201 | 205 |
|
202 | 206 |
""" |
203 | 207 |
|
... | ... |
@@ -393,7 +393,7 @@ def _load_config() -> _types.VaultConfig: |
393 | 393 |
|
394 | 394 |
Returns: |
395 | 395 |
The vault settings. See |
396 |
- [`derivepassphrase.types.VaultConfig`][] for details. |
|
396 |
+ [`derivepassphrase._types.VaultConfig`][] for details. |
|
397 | 397 |
|
398 | 398 |
Raises: |
399 | 399 |
OSError: |
... | ... |
@@ -423,7 +423,7 @@ def _migrate_and_load_old_config() -> ( |
423 | 423 |
|
424 | 424 |
Returns: |
425 | 425 |
The vault settings, and an optional exception encountered during |
426 |
- migration. See [`derivepassphrase.types.VaultConfig`][] for |
|
426 |
+ migration. See [`derivepassphrase._types.VaultConfig`][] for |
|
427 | 427 |
details on the former. |
428 | 428 |
|
429 | 429 |
Raises: |
... | ... |
@@ -485,7 +485,7 @@ def _get_suitable_ssh_keys( |
485 | 485 |
"""Yield all SSH keys suitable for passphrase derivation. |
486 | 486 |
|
487 | 487 |
Suitable SSH keys are queried from the running SSH agent (see |
488 |
- [`ssh_agent.SSHAgentClient.list_keys`][]). |
|
488 |
+ [`derivepassphrase.ssh_agent.SSHAgentClient.list_keys`][]). |
|
489 | 489 |
|
490 | 490 |
Args: |
491 | 491 |
conn: |
... | ... |
@@ -521,7 +521,7 @@ def _get_suitable_ssh_keys( |
521 | 521 |
SSH agent. |
522 | 522 |
RuntimeError: |
523 | 523 |
There was an error communicating with the SSH agent. |
524 |
- SSHAgentFailedError: |
|
524 |
+ ssh_agent.SSHAgentFailedError: |
|
525 | 525 |
The agent failed to supply a list of loaded keys. |
526 | 526 |
|
527 | 527 |
""" |
... | ... |
@@ -629,8 +629,9 @@ def _select_ssh_key( |
629 | 629 |
"""Interactively select an SSH key for passphrase derivation. |
630 | 630 |
|
631 | 631 |
Suitable SSH keys are queried from the running SSH agent (see |
632 |
- [`ssh_agent.SSHAgentClient.list_keys`][]), then the user is |
|
633 |
- prompted interactively (see [`click.prompt`][]) for a selection. |
|
632 |
+ [`derivepassphrase.ssh_agent.SSHAgentClient.list_keys`][]), then the |
|
633 |
+ user is prompted interactively (see [`click.prompt`][]) for |
|
634 |
+ a selection. |
|
634 | 635 |
|
635 | 636 |
Args: |
636 | 637 |
conn: |
... | ... |
@@ -17,10 +17,11 @@ __all__ = () |
17 | 17 |
|
18 | 18 |
|
19 | 19 |
def get_vault_key() -> bytes: |
20 |
- """Automatically determine the vault master key/password. |
|
20 |
+ """Automatically determine the vault(1) master key/password. |
|
21 | 21 |
|
22 | 22 |
Query the `VAULT_KEY`, `LOGNAME`, `USER` and `USERNAME` environment |
23 |
- variables, in that order. This is the same algorithm as vault uses. |
|
23 |
+ variables, in that order. This is the same algorithm that vault |
|
24 |
+ uses. |
|
24 | 25 |
|
25 | 26 |
Returns: |
26 | 27 |
The master key/password. This is generally used as input to |
... | ... |
@@ -46,10 +47,10 @@ def get_vault_key() -> bytes: |
46 | 47 |
|
47 | 48 |
|
48 | 49 |
def get_vault_path() -> str | bytes | os.PathLike: |
49 |
- """Automatically determine the vault configuration path. |
|
50 |
+ """Automatically determine the vault(1) configuration path. |
|
50 | 51 |
|
51 | 52 |
Query the `VAULT_PATH` environment variable, or default to |
52 |
- `~/.vault`. This is the same algorithm as vault uses. If not |
|
53 |
+ `~/.vault`. This is the same algorithm that vault uses. If not |
|
53 | 54 |
absolute, then `VAULT_PATH` is relative to the home directory. |
54 | 55 |
|
55 | 56 |
Returns: |
... | ... |
@@ -285,21 +285,21 @@ class Sequin: |
285 | 285 |
take `k` numbers from the base `base` sequence (or bail if not |
286 | 286 |
possible). If the resulting number `v` is out of range for |
287 | 287 |
base `n`, then push `v - n` onto the rejection queue for |
288 |
- base `r` = `base` ** `k` - `n`, and attempt to generate the |
|
289 |
- requested base `n` integer from the sequence of base `r` numbers |
|
290 |
- next. (This recursion is not attempted if `r` = 1.) Otherwise, |
|
291 |
- return the number. |
|
288 |
+ base `r` (where `r = base ** k - n`), and attempt to generate |
|
289 |
+ the requested base `n` integer from the sequence of base `r` |
|
290 |
+ numbers next. (This recursion is not attempted if `r` = 1.) |
|
291 |
+ Otherwise, return the number. |
|
292 | 292 |
|
293 | 293 |
Args: |
294 | 294 |
n: |
295 |
- Generate numbers in the range 0, ..., `n` - 1. |
|
295 |
+ Generate numbers in the range 0, ..., `n - 1`. |
|
296 | 296 |
(Inclusive.) Must be larger than 0. |
297 | 297 |
base: |
298 | 298 |
Use the base `base` sequence as a source for |
299 | 299 |
pseudorandom numbers. |
300 | 300 |
|
301 | 301 |
Returns: |
302 |
- A pseudorandom number in the range 0, ..., `n` - 1 if |
|
302 |
+ A pseudorandom number in the range 0, ..., `n - 1` if |
|
303 | 303 |
possible, or `n` if the stream is exhausted. |
304 | 304 |
|
305 | 305 |
Raises: |
... | ... |
@@ -377,7 +377,11 @@ class Sequin: |
377 | 377 |
return v |
378 | 378 |
|
379 | 379 |
def _stash(self, value: int, /, *, base: int = 2) -> None: |
380 |
- """Stash `value` on the base `base` sequence.""" |
|
380 |
+ """Stash `value` on the base `base` sequence. |
|
381 |
+ |
|
382 |
+ Sets up the base `base` sequence if it does not yet exist. |
|
383 |
+ |
|
384 |
+ """ |
|
381 | 385 |
if base not in self.bases: |
382 | 386 |
self.bases[base] = collections.deque() |
383 | 387 |
self.bases[base].append(value) |
... | ... |
@@ -10,6 +10,7 @@ import base64 |
10 | 10 |
import collections |
11 | 11 |
import hashlib |
12 | 12 |
import math |
13 |
+import types |
|
13 | 14 |
from collections.abc import Callable |
14 | 15 |
from typing import TypeAlias |
15 | 16 |
|
... | ... |
@@ -20,24 +21,6 @@ from derivepassphrase import sequin, ssh_agent |
20 | 21 |
__author__ = 'Marco Ricci <software@the13thletter.info>' |
21 | 22 |
|
22 | 23 |
|
23 |
-_CHARSETS = collections.OrderedDict([ |
|
24 |
- ('lower', b'abcdefghijklmnopqrstuvwxyz'), |
|
25 |
- ('upper', b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), |
|
26 |
- ('alpha', b''), # Placeholder. |
|
27 |
- ('number', b'0123456789'), |
|
28 |
- ('alphanum', b''), # Placeholder. |
|
29 |
- ('space', b' '), |
|
30 |
- ('dash', b'-_'), |
|
31 |
- ('symbol', b'!"#$%&\'()*+,./:;<=>?@[\\]^{|}~-_'), |
|
32 |
- ('all', b''), # Placeholder. |
|
33 |
-]) |
|
34 |
-_CHARSETS['alpha'] = _CHARSETS['lower'] + _CHARSETS['upper'] |
|
35 |
-_CHARSETS['alphanum'] = _CHARSETS['alpha'] + _CHARSETS['number'] |
|
36 |
-_CHARSETS['all'] = ( |
|
37 |
- _CHARSETS['alphanum'] + _CHARSETS['space'] + _CHARSETS['symbol'] |
|
38 |
-) |
|
39 |
- |
|
40 |
- |
|
41 | 24 |
class Vault: |
42 | 25 |
"""A work-alike of James Coglan's vault. |
43 | 26 |
|
... | ... |
@@ -63,7 +46,51 @@ class Vault: |
63 | 46 |
|
64 | 47 |
_UUID = b'e87eb0f4-34cb-46b9-93ad-766c5ab063e7' |
65 | 48 |
"""A tag used by vault in the bit stream generation.""" |
66 |
- _CHARSETS = _CHARSETS |
|
49 |
+ _CHARSETS = types.MappingProxyType( |
|
50 |
+ collections.OrderedDict([ |
|
51 |
+ ('lower', b'abcdefghijklmnopqrstuvwxyz'), |
|
52 |
+ ('upper', b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), |
|
53 |
+ ( |
|
54 |
+ 'alpha', |
|
55 |
+ ( |
|
56 |
+ # _CHARSETS['lower'] |
|
57 |
+ b'abcdefghijklmnopqrstuvwxyz' |
|
58 |
+ # _CHARSETS['upper'] |
|
59 |
+ b'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
60 |
+ ), |
|
61 |
+ ), |
|
62 |
+ ('number', b'0123456789'), |
|
63 |
+ ( |
|
64 |
+ 'alphanum', |
|
65 |
+ ( |
|
66 |
+ # _CHARSETS['lower'] |
|
67 |
+ b'abcdefghijklmnopqrstuvwxyz' |
|
68 |
+ # _CHARSETS['upper'] |
|
69 |
+ b'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
70 |
+ # _CHARSETS['number'] |
|
71 |
+ b'0123456789' |
|
72 |
+ ), |
|
73 |
+ ), |
|
74 |
+ ('space', b' '), |
|
75 |
+ ('dash', b'-_'), |
|
76 |
+ ('symbol', b'!"#$%&\'()*+,./:;<=>?@[\\]^{|}~-_'), |
|
77 |
+ ( |
|
78 |
+ 'all', |
|
79 |
+ ( |
|
80 |
+ # _CHARSETS['lower'] |
|
81 |
+ b'abcdefghijklmnopqrstuvwxyz' |
|
82 |
+ # _CHARSETS['upper'] |
|
83 |
+ b'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
84 |
+ # _CHARSETS['number'] |
|
85 |
+ b'0123456789' |
|
86 |
+ # _CHARSETS['space'] |
|
87 |
+ b' ' |
|
88 |
+ # _CHARSETS['symbol'] |
|
89 |
+ b'!"#$%&\'()*+,./:;<=>?@[\\]^{|}~-_' |
|
90 |
+ ), |
|
91 |
+ ), |
|
92 |
+ ]) |
|
93 |
+ ) |
|
67 | 94 |
""" |
68 | 95 |
Known character sets from which to draw passphrase characters. |
69 | 96 |
Relies on a certain, fixed order for their definition and their |
70 | 97 |