A LongTermStore that encrypts the values inner stores, with keys from keys (#2449, #2453; spec docs/superpowers/specs/2026-11-22-checkpoint-encryption-design.md, "The long-term store"). The long-term store is a separate SPI, so wrapping the checkpointer with EncryptingCheckpointer does not cover it. It works over any store - it is LongTermStoreContract that checks it - so give it, over the same keys, to everything that takes the store, on every instance:
val memories = EncryptingLongTermStore(postgres.longTermStore(), keys)
StoreFileBackend(memories) // its files are encrypted with no more wiring
'''What is encrypted''': each item's value, and the outcome the store records with a change until C4's guard forgets it. Each is sealed on its own with AES-256-GCM under a subkey of its namespace, bound to its key id, its tenant, its namespace and its item key - an outcome to its effect key too - so one moved to another item, namespace or tenant does not open. The key is the namespace's tenant's (EncryptionKeySource.current).
'''What stays in plain''', because the store looks items up, lists and bounds by it: item keys, namespaces and their tenants, updated timestamps, effect keys and fencing tokens, the id of the key that sealed a value, and the size of every value.
'''Reads.''' A value that cannot be opened is a Left (EncryptionError) of the whole call - a list or a search never leaves the item out, and never returns what is stored in its place. An item stored in plain is refused (EncryptionError.NotEncrypted) unless EncryptionSettings.plaintextReads is on.
'''search''' cannot be the store's own, which would match ciphertext: this store reads the namespace through inner.list, opens each value in key order and matches it as the shipped stores do - the query, case-insensitively, as a substring of the key or of any string in the value - stopping one hit past limit. Its results are those of an unencrypted InMemoryLongTermStore or Postgres store over the same items; the cost is the whole namespace read into memory, which the store's limits bound, and a decryption per item reached. A store with another search of its own loses it under this wrapper.
'''modify''' runs in inner's transaction, fenced and made idempotent by inner exactly as without encryption: an applied key is answered with its recorded outcome, opened, and the change is not run. Otherwise the change sees the plaintext of its namespace, and what it decides is checked against limits, sealed and handed to inner. The item being changed is opened before the change is asked, so an item that cannot be opened cannot be overwritten or deleted through this store, only through inner.
'''Limits.''' limits are in the caller's terms - bytes of what was written, as inner counts them unencrypted - and are checked here, in the transaction, with the store's own messages: they are the largest that always fit inner's once sealed, so inner never refuses first. To offer exactly some limits, open inner with EncryptingLongTermStore.storageLimits of them. Counting a namespace's bytes reads its items' sizes, so a write reads its namespace once more than inner does.
Attributes
- Companion
- object
- Source
- EncryptingLongTermStore.scala
- Graph
-
- Supertypes
