Skip to main content

vitaminc_aead/
container.rs

1/// The ciphertext tree [`encrypt`](crate::encrypt) produces and
2/// [`decrypt`](crate::decrypt) consumes.
3///
4/// The shape mirrors the structure of the plaintext that was encrypted: a
5/// scalar yields [`Single`](CipherText::Single), while non-empty sequences
6/// and maps yield [`Sequence`](CipherText::Sequence) and
7/// [`Map`](CipherText::Map). Empty composites use the authenticated marker
8/// variants [`EmptySequence`](CipherText::EmptySequence) and
9/// [`EmptyMap`](CipherText::EmptyMap), since they contain no element
10/// ciphertexts to authenticate the supplied AAD. Nested structures are
11/// represented recursively. An absent value (`Option::None`, a host null)
12/// is a null leaf, a `Single` like any other scalar: the plain null, or a
13/// typed null padded to its type's length (see
14/// [`tags::TYPED_NULL`](crate::tags::TYPED_NULL)).
15///
16/// The two parameters:
17///
18/// - `Leaf` is the sealed leaf the cipher produces
19///   ([`Cipher::Leaf`](crate::Cipher::Leaf)) — e.g. [`LocalCipherText`](crate::LocalCipherText)
20///   for a local AES cipher, or an envelope leaf that additionally carries
21///   a wrapped data key.
22/// - `P` is the passthrough payload. For the sink-based path it is a
23///   [`PassthroughFrame`](crate::PassthroughFrame): [`Node`](crate::Node)
24///   is this tree with that payload.
25///
26/// Only the `Leaf` type carries a byte-level format commitment (and should
27/// implement `serde` where ciphertexts are persisted). The container itself
28/// has no canonical byte representation: hosts project it onto their native
29/// structures (a JS object tree, the Go binding's transport codec), with
30/// leaves as opaque byte strings.
31#[derive(Debug)]
32pub enum CipherText<Leaf, P> {
33    /// A single sealed value.
34    Single(Leaf),
35    /// A sequence of ciphertexts produced from a sequence-shaped plaintext.
36    Sequence(Vec<CipherText<Leaf, P>>),
37    /// An empty sequence, authenticated under domain-separated AAD
38    /// ([`Context::for_empty_sequence`](crate::Context::for_empty_sequence))
39    /// by a marker leaf.
40    EmptySequence(Leaf),
41    /// A map of (cleartext key, ciphertext value) pairs produced from a
42    /// map-shaped plaintext. Keys are stored in the clear but are bound into
43    /// each value's AAD via [`Context::for_map_entry`](crate::Context::for_map_entry),
44    /// so they cannot be swapped or renamed undetected (passthrough entries
45    /// excepted).
46    Map(Vec<(String, CipherText<Leaf, P>)>),
47    /// An empty map, authenticated under domain-separated AAD
48    /// ([`Context::for_empty_map`](crate::Context::for_empty_map)) by a
49    /// marker leaf.
50    EmptyMap(Leaf),
51    /// A subtree passed through the container **unencrypted and
52    /// unauthenticated**. Non-sensitive data only — see
53    /// [`Sink::passthrough`](crate::Sink::passthrough).
54    Passthrough(P),
55}