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
76impl St2067_9_2018 {
77    pub const ALL: &'static [Self] = &[
78        Self::MalformedXml,
79        Self::SidecarAssetReferencedByVirtualTrack,
80        Self::DuplicateAssetId,
81        Self::SignerWithoutSignature,
82        Self::SignatureWithoutSigner,
83        Self::SidecarAssetNotFound,
84        Self::CplNotFound,
85        Self::DuplicateCplId,
86    ];
87}
88
89impl From<St2067_9_2018> for String {
90    fn from(c: St2067_9_2018) -> String {
91        c.code().to_string()
92    }
93}