memory.sharing.crypto¶
memory.sharing.crypto ¶
Thin, safe wrappers over the age encryption scheme (via pyrage).
We deliberately do NOT hand-roll any crypto primitive. All encryption is
delegated to pyrage — the maintained Python binding for the Rust age
implementation (rage). age natively supports encrypting one ciphertext to
multiple recipients (each recipient's copy of the ephemeral file key is wrapped
to their X25519 public key in a header stanza), so per-unit multi-recipient
encryption needs no custom content-key/wrap layer — we use age's native
recipient list directly.
Only two operations are exposed:
- :func:
encrypt— encrypt bytes to a list of recipient public keys. - :func:
decrypt— decrypt bytes with a single private key/identity.
:class:DecryptError (re-exported from pyrage) is raised when a ciphertext
was not encrypted to the supplied key — bundle consumers catch it to skip units
their key cannot open.
encrypt ¶
Encrypt plaintext to every recipient in recipient_pubkeys.
Each key is an age X25519 recipient string (age1...). Any recipient
holding the matching private key can :func:decrypt the result. Returns the
binary age ciphertext.
Raises :class:ValueError if no recipients are given (encrypting to nobody
would produce an unopenable blob) or if a recipient string is malformed
(surfaced as :class:pyrage.RecipientError).
Source code in memory/sharing/crypto.py
decrypt ¶
Decrypt ciphertext with private_key.
private_key may be an AGE-SECRET-KEY-... string or a pre-parsed
:class:pyrage.x25519.Identity. Raises :class:DecryptError if the
ciphertext was not encrypted to this key.