feat(aead): a context exposes its parts as an AadPiece tree, not only its bytes - #318
Open
coderdan wants to merge 1 commit into
Open
feat(aead): a context exposes its parts as an AadPiece tree, not only its bytes#318coderdan wants to merge 1 commit into
AadPiece tree, not only its bytes#318coderdan wants to merge 1 commit into
Conversation
…ly its bytes
`IntoAad` hands a consumer the final, PAE-framed byte string of a context
and nothing else — right for the AEAD, useless for a consumer that has to
name what the bytes were built from: a key service logging the field a
data key was issued for, an audit trail, a structured binding built from
the same parts as the AAD. Recovering the parts from the bytes means
parsing PAE heuristically, which is neither injective nor a contract.
`IntoAadPiece` is the second view: the same context as an `AadPiece` tree
(`Text`, `Bytes`, `Unsigned`/`Signed` with their width, `List`) that
encodes through `IntoAad` to exactly the bytes the value does. Every
built-in context type implements both, one for one: `&str`/`String` are
`Text`; slices, arrays, `Vec<u8>`, `Cow<[u8]>`, an `Aad` and `()` are
`Bytes`; the integers keep their width; `(A, B)` is the two-element
`List`, `Option` the one- or zero-element one; `NonEmpty<T>` is
transparent. `Display` renders `("users/email", 7u64)` as
`(users/email, 7)`; `leaves()` walks the parts in encoding order for a
consumer building its own rendering or binding.
Additive. No encoding changes: quickcheck pins
`x.into_aad_piece().into_aad() == x.into_aad()` for every built-in.
Closes #317.
Claude-Session: https://claude.ai/code/session_019VRX1tXygj5bew3YhyK1B6
Contributor
🧬 Mutation testing (cargo-mutants,
|
| caught | missed | unviable | timeout |
|---|---|---|---|
| 6 | 0 | 16 | 0 |
✅ Every mutant in the changed lines was caught by a test.
Contributor
✅ No CRAP threshold violations589 function(s) analyzed · threshold 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #317.
What
AadPiece<'a>:Text,Bytes,Unsigned { value, width },Signed { value, width },List(Vec<AadPiece>). Encodes throughIntoAadto the bytes of the value it was built from (Listis the PAE of its parts).Displayfor humans —("users/email", 7u64)shows as(users/email, 7)— andleaves()walks the parts in encoding order for a consumer that renders or binds them itself.into_owned()detaches the borrow.IntoAadPiece<'a>:into_aad_piece(self) -> AadPiece<'a>, implemented for every typeIntoAadis, one for one:&str/String→Text; slices, arrays,Vec<u8>,Cow<[u8]>, anAad,()→Bytes; the ten integers with their width;(A, B)→ two-elementList;Option<T>→ one- or zero-elementList;NonEmpty<T>transparent;AadPieceitself.Additive. No encoding changes. A blanket
IntoAad for T: IntoAadPieceis ruled out by coherence with the existing concrete impls, so the two traits stay separate and the contract between them is pinned by quickcheck for every built-in:x.into_aad_piece().into_aad() == x.into_aad().Why
stack-encrypt now sends every leaf's context to ZeroKMS as the data key's
descriptor(cipherstash-suite#2180), which ZeroKMS HMACs into the key tag and logs per retrieval. A&strcontext is readable there; a composite —nonempty!("users/email").with(record_id)— is one PAE blob, so the log showsb64:AgAAAAAAAAALAAAA…. With the parts in hand the descriptor rendersusers/email/7, and the next ZeroKMS's structured binding ({label, value}per part) maps one to one onto the leaves — from the same value that built the AAD, so the two commit to identical bytes.Labels for tuple positions are a follow-up (a
Labelled<T>wrapper), noted in #317.https://claude.ai/code/session_019VRX1tXygj5bew3YhyK1B6