capsule_core/crypto/provenance/action.rs
1//! The closed lifecycle-action set (SSoT: [Authorization — The Closed Action Set]).
2//!
3//! Every lifecycle transition is an [`AssetManifest`](super::manifest::AssetManifest) whose
4//! `action` is one of these. A value outside the set is a **structural error**, never a
5//! "future value to ignore" — adding a value bumps `protocol_version` and old albums never
6//! see it. Deserializing an unknown action string fails (closed-enum rejection).
7//!
8//! [Authorization — The Closed Action Set]: https://docs/design/authorization/#the-closed-action-set
9
10use serde::{Deserialize, Serialize};
11
12/// The seven authorized lifecycle actions.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
14#[serde(rename_all = "kebab-case")]
15pub enum Action {
16 /// First write of an asset; `prior_provenance_hash` is null.
17 Create,
18 /// Replace the original bytes (e.g. re-encryption under a new AMK epoch).
19 Replace,
20 /// Soft-delete; the asset enters trash with a retention window.
21 Delete,
22 /// Edit to the encrypted metadata blob or sidecar fields.
23 MetadataUpdate,
24 /// Add a thumbnail, preview, or embedding.
25 DerivativeAdd,
26 /// Replace an existing derivative — the only authorized path; silent overwrite rejected.
27 DerivativeReplace,
28 /// Recover a soft-deleted asset from trash within its retention window.
29 TrashRestore,
30}
31
32impl Action {
33 /// Whether this action is the first link in an asset's chain (`prior_provenance_hash`
34 /// must be null iff this is true).
35 pub fn is_create(self) -> bool {
36 matches!(self, Action::Create)
37 }
38
39 /// Whether this action mints a new encrypted metadata blob and its manifest therefore
40 /// commits to `metadata_blob_hash`: `create | replace | metadata-update` carry the field,
41 /// the other four (`delete | derivative-add | derivative-replace | trash-restore`) omit it
42 /// (SSoT: [Provenance — Asset Manifest]). The presence-by-action rule is enforced at
43 /// [`structural_ok`](super::manifest::AssetManifest::structural_ok).
44 ///
45 /// [Provenance — Asset Manifest]: https://docs/design/cryptography/provenance/#asset-manifest
46 pub fn binds_metadata_blob(self) -> bool {
47 matches!(
48 self,
49 Action::Create | Action::Replace | Action::MetadataUpdate
50 )
51 }
52}
53
54/// The role of a derivative (SSoT: [Provenance — Derivative Provenance]).
55///
56/// [Provenance — Derivative Provenance]: https://docs/design/cryptography/provenance/#derivative-provenance
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
58#[serde(rename_all = "kebab-case")]
59pub enum DerivativeRole {
60 /// A small thumbnail image.
61 Thumbnail,
62 /// A larger preview image.
63 Preview,
64 /// An ML embedding vector.
65 Embedding,
66}
67
68#[cfg(test)]
69mod tests;