Skip to main content

imferno_core/scm/
codes.rs

1//! Typed validation-code catalogue for SMPTE ST 2067-9:2018 (Sidecar Composition Map).
2
3use crate::diagnostics::codes::ValidationCode;
4use crate::diagnostics::{Category, Severity};
5
6/// Validation codes for ST 2067-9:2018 Sidecar Composition Map constraints.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, strum::EnumIter)]
8pub enum St2067_9_2018 {
9    /// SCM XML document is not well-formed or cannot be parsed (§6.1).
10    MalformedXml,
11    /// A sidecar asset is referenced by a Virtual Track in a CPL, violating §5.
12    SidecarAssetReferencedByVirtualTrack,
13    /// The same SidecarAsset Id appears more than once within an SCM document (§7.2.3).
14    DuplicateAssetId,
15    /// A `Signer` element is present but no `Signature` element (§7.2.4).
16    SignerWithoutSignature,
17    /// A `Signature` element is present but no `Signer` element (§7.2.5).
18    SignatureWithoutSigner,
19    /// A SidecarAsset Id is not present in the package AssetMap (§7.3.1).
20    SidecarAssetNotFound,
21    /// A CPLId within an AssociatedCPLList does not reference a known CPL (§7.3.1.1).
22    CplNotFound,
23    /// The same CPLId appears more than once within a single AssociatedCPLList (§7.3.1.1).
24    DuplicateCplId,
25}
26
27impl ValidationCode for St2067_9_2018 {
28    fn code(&self) -> &'static str {
29        match self {
30            Self::MalformedXml => "ST2067-9:2018:6.1/MalformedXml",
31            Self::SidecarAssetReferencedByVirtualTrack => {
32                "ST2067-9:2018:5/SidecarAssetReferencedByVirtualTrack"
33            }
34            Self::DuplicateAssetId => "ST2067-9:2018:7.2.3/DuplicateAssetId",
35            Self::SignerWithoutSignature => "ST2067-9:2018:7.2.4/SignerWithoutSignature",
36            Self::SignatureWithoutSigner => "ST2067-9:2018:7.2.5/SignatureWithoutSigner",
37            Self::SidecarAssetNotFound => "ST2067-9:2018:7.3.1/SidecarAssetNotFound",
38            Self::CplNotFound => "ST2067-9:2018:7.3.1.1/CplNotFound",
39            Self::DuplicateCplId => "ST2067-9:2018:7.3.1.1/DuplicateCplId",
40        }
41    }
42
43    fn description(&self) -> &'static str {
44        match self {
45            Self::MalformedXml =>
46                "SidecarCompositionMap document is not well-formed XML (§6.1).",
47            Self::SidecarAssetReferencedByVirtualTrack =>
48                "A sidecar asset shall not be referenced by any Virtual Track in a CPL (§5).",
49            Self::DuplicateAssetId =>
50                "Duplicate SidecarAsset Id within SidecarAssetList (§7.2.3).",
51            Self::SignerWithoutSignature =>
52                "Signer element is present but the required Signature element is absent (§7.2.4).",
53            Self::SignatureWithoutSigner =>
54                "Signature element is present but the required Signer element is absent (§7.2.5).",
55            Self::SidecarAssetNotFound =>
56                "SidecarAsset Id is not present in the package AssetMap (§7.3.1).",
57            Self::CplNotFound =>
58                "CPLId in AssociatedCPLList does not reference a known CPL in this package (§7.3.1.1).",
59            Self::DuplicateCplId =>
60                "Duplicate CPLId within a single AssociatedCPLList (§7.3.1.1).",
61        }
62    }
63
64    fn default_severity(&self) -> Severity {
65        match self {
66            Self::MalformedXml => Severity::Critical,
67            _ => Severity::Error,
68        }
69    }
70
71    fn category(&self) -> Category {
72        Category::Reference
73    }
74
75    fn example(&self) -> Option<&'static str> {
76        Some(match self {
77            Self::MalformedXml =>
78                "SCM_<uuid>.xml ends mid-element or has mismatched tags.",
79            Self::SidecarAssetReferencedByVirtualTrack =>
80                "A CPL <Resource><TrackFileId> points at a sidecar asset declared in an SCM document.",
81            Self::DuplicateAssetId =>
82                "Two <SidecarAsset> entries in one SCM share the same <Id>urn:uuid:abc…</Id>.",
83            Self::SignerWithoutSignature =>
84                "<Signer>…</Signer> appears but no sibling <Signature> follows.",
85            Self::SignatureWithoutSigner =>
86                "<Signature>…</Signature> appears without a preceding <Signer>.",
87            Self::SidecarAssetNotFound =>
88                "<SidecarAsset><Id>urn:uuid:abc…</Id> references a UUID that is not present in ASSETMAP.xml.",
89            Self::CplNotFound =>
90                "<AssociatedCPLList><CPLId>urn:uuid:xyz…</CPLId> points at a CPL that isn't in the package.",
91            Self::DuplicateCplId =>
92                "An <AssociatedCPLList> contains the same <CPLId>urn:uuid:xyz…</CPLId> twice.",
93        })
94    }
95}
96
97impl St2067_9_2018 {
98    pub const ALL: &'static [Self] = &[
99        Self::MalformedXml,
100        Self::SidecarAssetReferencedByVirtualTrack,
101        Self::DuplicateAssetId,
102        Self::SignerWithoutSignature,
103        Self::SignatureWithoutSigner,
104        Self::SidecarAssetNotFound,
105        Self::CplNotFound,
106        Self::DuplicateCplId,
107    ];
108}
109
110impl From<St2067_9_2018> for String {
111    fn from(c: St2067_9_2018) -> String {
112        c.code().to_string()
113    }
114}