c2pa_ml/asset_type.rs
1//! The C2PA asset type values for AI/ML assets, from Table 11 ("Asset type
2//! values") of the [C2PA Technical Specification].
3//!
4//! The core specification defines no dedicated *embedding* method for model
5//! container formats; instead a C2PA Manifest embedded in a model uses the
6//! [asset type assertion] (`c2pa.asset-type`) to declare what the asset is. This
7//! module exposes the canonical `c2pa.types.model.*` strings so a claim
8//! generator can populate that assertion consistently with how this crate
9//! embedded the manifest.
10//!
11//! [C2PA Technical Specification]: https://spec.c2pa.org/specifications/specifications/2.4/specs/C2PA_Specification.html
12//! [asset type assertion]: https://spec.c2pa.org/specifications/specifications/2.4/specs/C2PA_Specification.html#_asset_type
13
14/// A C2PA model asset type (a value of the asset type assertion's `type` field).
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub enum ModelType {
17 /// `c2pa.types.model` — a model not described by any other value.
18 Generic,
19 /// `c2pa.types.model.onnx` — an ONNX model.
20 Onnx,
21 /// `c2pa.types.model.pytorch` — a PyTorch model.
22 PyTorch,
23 /// `c2pa.types.model.tensorflow` — a TensorFlow model.
24 TensorFlow,
25 /// `c2pa.types.model.jax` — a JAX model.
26 Jax,
27 /// `c2pa.types.model.keras` — a Keras model.
28 Keras,
29 /// `c2pa.types.model.mxnet` — an MXNet model.
30 MxNet,
31 /// `c2pa.types.model.openvino` — an OpenVINO model.
32 OpenVino,
33}
34
35impl ModelType {
36 /// The specification string for this model type.
37 pub fn as_str(self) -> &'static str {
38 match self {
39 ModelType::Generic => "c2pa.types.model",
40 ModelType::Onnx => "c2pa.types.model.onnx",
41 ModelType::PyTorch => "c2pa.types.model.pytorch",
42 ModelType::TensorFlow => "c2pa.types.model.tensorflow",
43 ModelType::Jax => "c2pa.types.model.jax",
44 ModelType::Keras => "c2pa.types.model.keras",
45 ModelType::MxNet => "c2pa.types.model.mxnet",
46 ModelType::OpenVino => "c2pa.types.model.openvino",
47 }
48 }
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn known_strings() {
57 assert_eq!(ModelType::Generic.as_str(), "c2pa.types.model");
58 assert_eq!(ModelType::Onnx.as_str(), "c2pa.types.model.onnx");
59 assert_eq!(ModelType::PyTorch.as_str(), "c2pa.types.model.pytorch");
60 }
61}