Skip to main content

made_core/entities/
published_ceremony_definition.rs

1//! [`PublishedCeremonyDefinition`] — a definition fixed to a content
2//! identity.
3//!
4//! An agent can already write a definition and run it. What publication
5//! adds is that the thing it ran can be named later and shown to be the
6//! same thing: an immutable version with a digest an instance binds to
7//! and an auditor recomputes.
8//!
9//! Running an ad-hoc definition stays possible and is not the same act.
10//! Investigation should not need a published version; governed reuse
11//! should not accept an unpublished one.
12
13use crate::error::DomainError;
14use crate::value_objects::{CeremonyDefinitionDigest, CeremonyName, CeremonyVersion};
15
16use super::CeremonyDefinition;
17
18/// A definition and the digest that identifies its content.
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct PublishedCeremonyDefinition {
21    definition: CeremonyDefinition,
22    digest: CeremonyDefinitionDigest,
23}
24
25impl PublishedCeremonyDefinition {
26    /// Fix a definition to its content identity.
27    ///
28    /// Only a definition can be sealed, and a `CeremonyDefinition`
29    /// cannot exist while invalid — so an unpublishable draft can never
30    /// reach this constructor.
31    pub fn seal(definition: CeremonyDefinition) -> Result<Self, DomainError> {
32        let digest = definition.digest()?;
33        Ok(Self { definition, digest })
34    }
35
36    #[must_use]
37    pub fn definition(&self) -> &CeremonyDefinition {
38        &self.definition
39    }
40
41    #[must_use]
42    pub fn digest(&self) -> CeremonyDefinitionDigest {
43        self.digest
44    }
45
46    #[must_use]
47    pub fn name(&self) -> &CeremonyName {
48        self.definition.name()
49    }
50
51    #[must_use]
52    pub fn version(&self) -> &CeremonyVersion {
53        self.definition.version()
54    }
55
56    #[must_use]
57    pub fn into_definition(self) -> CeremonyDefinition {
58        self.definition
59    }
60}