nyms.keys#
Key management for a single user or a small team: where the project’s secret lives.
The key is the “additional information” of GDPR Art. 4(5): whoever holds it and the mapping
store can re-identify. So it never sits next to the pseudonymised text, and never inside the
mapping store’s directory. Resolution order of resolve_key():
the environment variable (
NYMS_KEY, hex or base64), for CI and scripted use;a per-project key file under the user’s config dir (
~/.config/nyms/keys/<project>.key, mode 0600), created with 32 random bytes on first use;a passphrase, when one is given, derived with scrypt (stdlib) and a per-project salt stored next to the key file.
Replacements this seam allows: the keyring package (OS keychain), config2py’s layered
resolution, age recipients, an external KMS. Each is one key= argument to the
facade. Rotation is a new project (keyed-hash surrogates change with the key by construction;
counter surrogates survive it, since they live in the store).
>>> import tempfile, os
>>> d = tempfile.mkdtemp()
>>> k1 = resolve_key('demo', key_dir=d, env_var=None)
>>> len(k1), k1 == resolve_key('demo', key_dir=d, env_var=None)
(32, True)
>>> derive_key('correct horse', salt=b'salt' * 4) == derive_key('correct horse', salt=b'salt' * 4)
True
Functions
|
|
|
|
|
A key from its hex or base64 text form. |
|
scrypt key derivation (stdlib). |
|
|
|
The project's key, by the resolution order in the module docstring. |
- nyms.keys.data_dir()[source]#
$XDG_DATA_HOME/nymsor~/.local/share/nyms: where mapping stores live by default.- Return type:
- nyms.keys.decode_key(text)[source]#
A key from its hex or base64 text form.
>>> decode_key('00' * 32) == bytes(32) True
- Return type: