Expand description
Persistent salt+file_id cache for deterministic re-encryption.
During decrypt, the file’s salt and file_id are recorded. During
encrypt, the cached values are reused so that decrypt→encrypt on the
same plaintext produces byte-identical output.
§Architecture
§Read Path (encrypt) — Zero-copy via mmap + rkyv
SaltCacheReader memory-maps the cache file and uses rkyv’s zero-copy
deserialization to access the archived HashMap<String, CachedEntry>
directly. No heap allocation or full deserialization is required for
lookups.
§Write Path (decrypt) — mpsc + rkyv
SaltCacheSender is a Sync handle that wraps an mpsc::Sender.
Rayon worker threads send (path, entry) pairs through the channel.
After all parallel work completes, SaltCacheSaver collects the
entries, merges with any existing on-disk cache, and serializes the
result via rkyv.
§Key Format
Cache keys are repo-relative path bytes with forward slashes (b'/'),
computed by the caller via crate::crypt::cache_key. Using raw bytes
(Vec<u8>) avoids UTF-8 validation overhead and string allocation.
§Persistence
Serialized via rkyv to <repo>/.git/git-simple-encrypt-salt-cache.
The binary format is opaque and not meant for human consumption. Writes
are performed atomically to prevent corruption.
§Lifecycle
- Decrypt: Create sender → workers send entries → saver persists (atomically)
- Encrypt: Create reader (mmap, read-only) → workers look up cached values. No write is performed during encryption.
- On error: Cache is saved with whatever entries were captured before the failure, preserving partial progress.
- Stale entries: Entries for files that no longer exist are harmless (looked up by key, simply not found) and do not affect correctness.
Structs§
- Archived
Cached Entry - An archived
CachedEntry - Cache
Ref - Borrowed reference to a salt-cache writer + the repo-relative key for a single file.
- Cached
Entry - A cached header entry for deterministic re-encryption.
- Cached
Entry Resolver - The resolver for an archived
CachedEntry - Salt
Cache Reader - Read-only salt cache backed by memory-mapped file + rkyv zero-copy access.
- Salt
Cache Saver - Receiver that collects and persists cache entries to disk.
- Salt
Cache Sender - Thread-safe sender for cache entries, safe to share across rayon workers.
Functions§
- create_
writer - Create a paired sender/saver for collecting cache entries.