Application-layer authenticated encryption for secrets at rest (AES-256-GCM). Master key held outside the database in an OS-protected file; sealed values carry nonce + key_id + algo_version for rotation. Decrypt once, hold plaintext only in process memory.
| Tier | infrastructure |
| Role | unclassified (baselined) |
| Path | crates/infrastructure/secrets |
| Edition | 2021 |
| Targets | infrastructure_secrets |
| Public items | 13 across 0 modules |
| Tests | 14 |
What it is for
Application-layer authenticated encryption for secrets at rest.
Why this exists (Gate 1.5 consensus, sprint-02): the ecosystem's prior at-rest secret mechanism was pgcrypto pgp_sym_encrypt with the master key held in a Postgres session GUC (app.encryption_key). Both consensus reviewers flagged that pattern for camera credentials: fragile on pooled connections, one leaked master key exposes every row, privileged SQL can invoke decrypt_credential, and rotation means re-encrypting every row. This crate moves the boundary into Rust:
- AES-256-GCM (AEAD) — confidentiality + integrity; tampering is detected.
- Master key outside the database, loaded from an OS-protected file (mode
0400/0600; group/other-readable keys are rejected). Callers may instead supply key bytes from a TPM-sealed blob or a systemd credential.
- Sealed values carry `key_id` + `algo_version` so keys can be rotated and
old ciphertext still decrypts. Store ciphertext/nonce as BYTEA, key_id as TEXT, algo_version as INT.
- Decrypt once in the consumer (e.g. a camera supervisor) and hold the
plaintext only in process memory — never persist a credential-bearing URL.
The key material and decrypted plaintext are zeroized on drop.
Capabilities
crate root
Application-layer authenticated encryption for secrets at rest.
| Item |
|---|
pub const ALGO_AES_256_GCM: u16 |
pub const KEY_LEN: usize |
pub const NONCE_LEN: usize |
Sealed
Application-layer authenticated encryption for secrets at rest.
| Item |
|---|
pub struct Sealed |
SecretCipher
Application-layer authenticated encryption for secrets at rest.
| Item |
|---|
pub struct SecretCipher |
SecretCipher :: fn from_key_bytes(key : u8; KEY_LEN, key_id : impl Into <String>) -> Self |
SecretCipher :: fn from_key_file(path : impl AsRef <Path>, key_id : impl Into <String>,) -> Result <Self, SecretError> |
SecretCipher :: fn key_id(& self) -> & str |
SecretCipher :: fn encrypt(& self, plaintext : & u8) -> Result <Sealed, SecretError> |
SecretCipher :: fn encrypt_str(& self, plaintext : & str) -> Result <Sealed, SecretError> |
SecretCipher :: fn decrypt(& self, sealed : & Sealed) -> Result <Zeroizing <Vec <u8>>, SecretError> |
SecretCipher :: fn decrypt_str(& self, sealed : & Sealed) -> Result <Zeroizing <String>, SecretError> |
SecretError
Application-layer authenticated encryption for secrets at rest.
| Item |
|---|
pub enum SecretError |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub const ALGO_AES_256_GCM: u16 | AEAD algorithm identifier stamped into every Sealed value |
pub const KEY_LEN: usize | Length of an AES-256 key, in bytes. |
pub const NONCE_LEN: usize | Length of the AES-GCM nonce, in bytes (96-bit). |
pub enum SecretError | Errors from sealing / unsealing secrets. |
pub struct Sealed | A sealed secret: everything needed to decrypt except the master key |
pub struct SecretCipher | Seals and unseals secrets with a single AES-256 master key |
SecretCipher :: fn from_key_bytes(key : u8; KEY_LEN, key_id : impl Into <String>) -> Self | Build a cipher from raw key bytes plus a key_id label (used to stamp sealed values and to check the right key is present on decrypt). |
SecretCipher :: fn from_key_file(path : impl AsRef <Path>, key_id : impl Into <String>,) -> Result <Self, SecretError> | Load the master key from an OS-protected file |
SecretCipher :: fn key_id(& self) -> & str | The label identifying this cipher's master key. |
SecretCipher :: fn encrypt(& self, plaintext : & u8) -> Result <Sealed, SecretError> | Encrypt plaintext, producing a Sealed value with a fresh random nonce and this cipher's key_id/algo_version. |
SecretCipher :: fn encrypt_str(& self, plaintext : & str) -> Result <Sealed, SecretError> | Convenience: seal a UTF-8 string. |
SecretCipher :: fn decrypt(& self, sealed : & Sealed) -> Result <Zeroizing <Vec <u8>>, SecretError> | Decrypt a Sealed value |
SecretCipher :: fn decrypt_str(& self, sealed : & Sealed) -> Result <Zeroizing <String>, SecretError> | Convenience: decrypt to a UTF-8 string (zeroized on drop) |
No pub use re-exports: every item above is declared in this crate.
Boundary
Depends on no other workspace tier.
Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-gmail, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, … (82 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | infrastructure |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/infrastructure/secrets |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
aes-gcm | ^0.10 | aes, alloc, getrandom | no | always |
thiserror | ^2 | — | no | always |
zeroize | ^1 | derive | no | always |
Development. None.
Build. None.
Depended on by. 1 workspace crate.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_operations_camera_registry["operations-camera-registry"] -->|uses| SELF SELF["infrastructure-secrets"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | infrastructure_secrets | `src/lib.rs` |
Error model
| Error type | Named by |
|---|---|
SecretError | declared, no public signature returns it |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
1 workspace crate depends on this one: operations-camera-registry.
Verification
| Kind | Count |
|---|---|
| Unit tests | 14 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 6 | 0 | 4 |
What the tests establish, by name:
ciphertext_is_not_plaintext—src/lib.rsempty_and_large_plaintext_round_trip—src/lib.rskey_id_mismatch_is_reported—src/lib.rsnonces_are_unique_per_encryption—src/lib.rsparse_key_accepts_hex_with_newline—src/lib.rsparse_key_accepts_raw_32_bytes—src/lib.rsparse_key_rejects_non_hex_of_right_length—src/lib.rsparse_key_rejects_wrong_length—src/lib.rsround_trips_a_secret—src/lib.rssealed_value_carries_key_id_and_algo—src/lib.rstampered_ciphertext_fails_authentication—src/lib.rstampered_nonce_fails_authentication—src/lib.rsunknown_algo_version_is_rejected—src/lib.rswrong_key_cannot_decrypt—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 13 | 13 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 13
"No rustdoc detected" : 0
Metrics
| Metric | Value |
|---|---|
| Rust source files | 1 |
| Source lines | 398 |
| Code lines | 283 |
| Public API items | 13 |
| Public modules | 0 |
| Tests | 14 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 3 |
| Workspace reverse dependencies | 1 |
pie showData
title Public API by kind
"constant" : 3
"enum" : 1
"method" : 7
"struct" : 2
pie showData
title Rust source composition
"Code" : 283
"Blank or comment" : 115
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.