Skip to content

Commit c6b6a59

Browse files
authored
refactor: Rename Metadata to AssertionMetadata (#1261)
1 parent 5f8ccf5 commit c6b6a59

File tree

11 files changed

+72
-68
lines changed

11 files changed

+72
-68
lines changed

sdk/src/assertions/actions.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use serde_cbor::Value;
1919

2020
use crate::{
2121
assertion::{Assertion, AssertionBase, AssertionCbor},
22-
assertions::{labels, region_of_interest::RegionOfInterest, Actor, Metadata},
22+
assertions::{labels, region_of_interest::RegionOfInterest, Actor, AssertionMetadata},
2323
error::Result,
2424
resource_store::UriOrResource,
2525
utils::cbor_types::DateT,
@@ -521,7 +521,7 @@ pub struct Actions {
521521

522522
/// Additional information about the assertion.
523523
#[serde(skip_serializing_if = "Option::is_none")]
524-
pub metadata: Option<Metadata>,
524+
pub metadata: Option<AssertionMetadata>,
525525
}
526526

527527
impl Actions {
@@ -580,8 +580,8 @@ impl Actions {
580580
&mut self.actions
581581
}
582582

583-
/// Returns the assertion's [`Metadata`], if it exists.
584-
pub fn metadata(&self) -> Option<&Metadata> {
583+
/// Returns the assertion's [`AssertionMetadata`], if it exists.
584+
pub fn metadata(&self) -> Option<&AssertionMetadata> {
585585
self.metadata.as_ref()
586586
}
587587

@@ -597,8 +597,8 @@ impl Actions {
597597
self
598598
}
599599

600-
/// Sets [`Metadata`] for the action.
601-
pub fn add_metadata(mut self, metadata: Metadata) -> Self {
600+
/// Sets [`AssertionMetadata`] for the action.
601+
pub fn add_metadata(mut self, metadata: AssertionMetadata) -> Self {
602602
self.metadata = Some(metadata);
603603
self
604604
}
@@ -657,7 +657,7 @@ pub mod tests {
657657
use crate::{
658658
assertion::AssertionData,
659659
assertions::{
660-
metadata::{c2pa_source::GENERATOR_REE, DataSource, ReviewRating},
660+
assertion_metadata::{c2pa_source::GENERATOR_REE, DataSource, ReviewRating},
661661
region_of_interest::{Range, RangeType, Time, TimeType},
662662
},
663663
hashed_uri::HashedUri,
@@ -723,7 +723,7 @@ pub mod tests {
723723
}),
724724
)
725725
.add_metadata(
726-
Metadata::new()
726+
AssertionMetadata::new()
727727
.add_review(ReviewRating::new("foo", Some("bar".to_owned()), 3))
728728
.set_reference(make_hashed_uri1())
729729
.set_data_source(DataSource::new(GENERATOR_REE)),

sdk/src/assertions/metadata.rs renamed to sdk/src/assertions/assertion_metadata.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ use crate::{
2626

2727
const ASSERTION_CREATION_VERSION: usize = 1;
2828

29-
/// The Metadata structure can be used as part of other assertions or on its own to reference others
29+
/// The AssertionMetadata structure can be used as part of other assertions or on its own to reference others
3030
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
3131
#[cfg_attr(feature = "json_schema", derive(JsonSchema))]
32-
pub struct Metadata {
32+
pub struct AssertionMetadata {
3333
#[serde(rename = "reviewRatings", skip_serializing_if = "Option::is_none")]
3434
reviews: Option<Vec<ReviewRating>>,
3535
#[serde(rename = "dateTime", skip_serializing_if = "Option::is_none")]
@@ -42,7 +42,7 @@ pub struct Metadata {
4242
region_of_interest: Option<RegionOfInterest>,
4343
}
4444

45-
impl Metadata {
45+
impl AssertionMetadata {
4646
/// Label prefix for an assertion metadata assertion.
4747
///
4848
/// See <https://c2pa.org/specifications/specifications/2.2/specs/C2PA_Specification.html#_metadata_about_assertions>.
@@ -123,21 +123,21 @@ impl Metadata {
123123
}
124124
}
125125

126-
impl Default for Metadata {
126+
impl Default for AssertionMetadata {
127127
fn default() -> Self {
128128
Self::new()
129129
}
130130
}
131131

132-
impl std::fmt::Display for Metadata {
132+
impl std::fmt::Display for AssertionMetadata {
133133
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
134134
f.write_str(&serde_json::to_string_pretty(self).unwrap_or_default())
135135
}
136136
}
137137

138-
impl AssertionCbor for Metadata {}
138+
impl AssertionCbor for AssertionMetadata {}
139139

140-
impl AssertionBase for Metadata {
140+
impl AssertionBase for AssertionMetadata {
141141
const LABEL: &'static str = Self::LABEL;
142142
const VERSION: Option<usize> = Some(ASSERTION_CREATION_VERSION);
143143

@@ -312,26 +312,25 @@ pub mod tests {
312312
#[test]
313313
fn assertion_metadata() {
314314
let review = ReviewRating::new("foo", Some("bar".to_owned()), 3);
315-
let original =
316-
Metadata::new()
317-
.add_review(review)
318-
.set_region_of_interest(RegionOfInterest {
319-
region: vec![Range {
320-
range_type: RangeType::Temporal,
321-
time: Some(Time {
322-
time_type: TimeType::Npt,
323-
start: None,
324-
end: None,
325-
}),
326-
..Default::default()
327-
}],
315+
let original = AssertionMetadata::new()
316+
.add_review(review)
317+
.set_region_of_interest(RegionOfInterest {
318+
region: vec![Range {
319+
range_type: RangeType::Temporal,
320+
time: Some(Time {
321+
time_type: TimeType::Npt,
322+
start: None,
323+
end: None,
324+
}),
328325
..Default::default()
329-
});
326+
}],
327+
..Default::default()
328+
});
330329
println!("{:}", &original);
331330
let assertion = original.to_assertion().expect("build_assertion");
332331
assert_eq!(assertion.mime_type(), "application/cbor");
333-
assert_eq!(assertion.label(), Metadata::LABEL);
334-
let result = Metadata::from_assertion(&assertion).expect("extract_assertion");
332+
assert_eq!(assertion.label(), AssertionMetadata::LABEL);
333+
let result = AssertionMetadata::from_assertion(&assertion).expect("extract_assertion");
335334
println!("{:?}", serde_json::to_string(&result));
336335
assert_eq!(original.date_time, result.date_time);
337336
assert_eq!(original.reviews, result.reviews);

sdk/src/assertions/asset_types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use schemars::JsonSchema;
1616
use serde::{Deserialize, Serialize};
1717

18-
use super::{labels, AssetType, Metadata};
18+
use super::{labels, AssertionMetadata, AssetType};
1919
use crate::{
2020
assertion::{Assertion, AssertionBase, AssertionCbor},
2121
error::Result,
@@ -101,7 +101,7 @@ const ASSERTION_CREATION_VERSION: usize = 1;
101101
#[cfg_attr(feature = "json_schema", derive(JsonSchema))]
102102
pub struct AssetTypes {
103103
types: Vec<AssetType>,
104-
metadata: Option<Metadata>,
104+
metadata: Option<AssertionMetadata>,
105105
}
106106

107107
#[allow(dead_code)]
@@ -125,12 +125,12 @@ impl AssetTypes {
125125
&self.types
126126
}
127127

128-
pub fn set_metadata(mut self, md: Metadata) -> Self {
128+
pub fn set_metadata(mut self, md: AssertionMetadata) -> Self {
129129
self.metadata = Some(md);
130130
self
131131
}
132132

133-
pub fn metadata(&self) -> Option<&Metadata> {
133+
pub fn metadata(&self) -> Option<&AssertionMetadata> {
134134
self.metadata.as_ref()
135135
}
136136
}

sdk/src/assertions/ingredient.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
1818
use super::AssetType;
1919
use crate::{
2020
assertion::{Assertion, AssertionBase, AssertionDecodeError, AssertionDecodeErrorCause},
21-
assertions::{labels, Metadata, ReviewRating},
21+
assertions::{labels, AssertionMetadata, ReviewRating},
2222
cbor_types::map_cbor_to_type,
2323
error::Result,
2424
hashed_uri::HashedUri,
@@ -56,7 +56,7 @@ pub struct Ingredient {
5656
pub validation_status: Option<Vec<ValidationStatus>>,
5757
pub relationship: Relationship,
5858
pub thumbnail: Option<HashedUri>,
59-
pub metadata: Option<Metadata>,
59+
pub metadata: Option<AssertionMetadata>,
6060
pub data: Option<HashedUri>,
6161
pub description: Option<String>,
6262
pub informational_uri: Option<String>,
@@ -220,7 +220,7 @@ impl Ingredient {
220220

221221
pub fn add_reviews(mut self, reviews: Option<Vec<ReviewRating>>) -> Self {
222222
if let Some(reviews) = reviews {
223-
let metadata = Metadata::new().set_reviews(reviews);
223+
let metadata = AssertionMetadata::new().set_reviews(reviews);
224224
self.metadata = Some(metadata);
225225
};
226226
self
@@ -641,7 +641,8 @@ impl AssertionBase for Ingredient {
641641
let thumbnail: Option<HashedUri> = map_cbor_to_type("thumbnail", &ingredient_value);
642642
let validation_status: Option<Vec<ValidationStatus>> =
643643
map_cbor_to_type("validationStatus", &ingredient_value);
644-
let metadata: Option<Metadata> = map_cbor_to_type("metadata", &ingredient_value);
644+
let metadata: Option<AssertionMetadata> =
645+
map_cbor_to_type("metadata", &ingredient_value);
645646

646647
Ingredient {
647648
title: Some(title),
@@ -707,7 +708,8 @@ impl AssertionBase for Ingredient {
707708
map_cbor_to_type("description", &ingredient_value);
708709
let informational_uri: Option<String> =
709710
map_cbor_to_type("informational_URI", &ingredient_value);
710-
let metadata: Option<Metadata> = map_cbor_to_type("metadata", &ingredient_value);
711+
let metadata: Option<AssertionMetadata> =
712+
map_cbor_to_type("metadata", &ingredient_value);
711713

712714
Ingredient {
713715
title: Some(title),
@@ -774,7 +776,8 @@ impl AssertionBase for Ingredient {
774776
map_cbor_to_type("description", &ingredient_value);
775777
let informational_uri: Option<String> =
776778
map_cbor_to_type("informationalURI", &ingredient_value);
777-
let metadata: Option<Metadata> = map_cbor_to_type("metadata", &ingredient_value);
779+
let metadata: Option<AssertionMetadata> =
780+
map_cbor_to_type("metadata", &ingredient_value);
778781

779782
Ingredient {
780783
title,
@@ -972,7 +975,7 @@ pub mod tests {
972975

973976
let review_rating = ReviewRating::new("Content bindings validated", None, 5);
974977

975-
let metadata = Metadata::new()
978+
let metadata = AssertionMetadata::new()
976979
.set_date_time("2021-06-28T16:49:32.874Z".to_owned())
977980
.add_review(review_rating);
978981

sdk/src/assertions/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ pub use ingredient::Relationship;
4747

4848
pub mod labels;
4949

50-
mod metadata;
51-
pub use metadata::{
52-
c2pa_source, Actor, AssetType, DataBox, DataSource, Metadata, ReviewCode, ReviewRating,
50+
mod assertion_metadata;
51+
pub use assertion_metadata::{
52+
c2pa_source, Actor, AssertionMetadata, AssetType, DataBox, DataSource, ReviewCode, ReviewRating,
5353
};
5454

5555
mod schema_org;

sdk/src/assertions/region_of_interest.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! A set of structs to define a region of interest within an
2-
//! [`Action`][crate::assertions::Action] or [`Metadata`].
2+
//! [`Action`][crate::assertions::Action] or [`AssertionMetadata`].
33
44
#[cfg(feature = "json_schema")]
55
use schemars::JsonSchema;
66
use serde::{Deserialize, Serialize};
77
use serde_with::skip_serializing_none;
88

9-
use super::Metadata;
9+
use super::AssertionMetadata;
1010

1111
/// An x, y coordinate used for specifying vertices in polygons.
1212
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -234,7 +234,7 @@ pub enum Role {
234234
/// A region of interest within an asset describing the change.
235235
///
236236
/// This struct can be used from [`Action::changes`][crate::assertions::Action::changes] or
237-
/// [`Metadata::region_of_interest`][crate::assertions::Metadata::region_of_interest].
237+
/// [`AssertionMetadata::region_of_interest`][crate::assertions::AssertionMetadata::region_of_interest].
238238
#[skip_serializing_none]
239239
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
240240
#[cfg_attr(feature = "json_schema", derive(JsonSchema))]
@@ -259,5 +259,5 @@ pub struct RegionOfInterest {
259259
// If we didn't have a box, `Metadata` would recursively use `RegionOfInterest` causing an infinite size error.
260260
//
261261
/// Additional information about the asset.
262-
pub metadata: Option<Box<Metadata>>,
262+
pub metadata: Option<Box<AssertionMetadata>>,
263263
}

sdk/src/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use zip::{write::SimpleFileOptions, ZipArchive, ZipWriter};
2929
use crate::{
3030
assertion::AssertionDecodeError,
3131
assertions::{
32-
c2pa_action, labels, Action, ActionTemplate, Actions, BmffHash, BoxHash, CreativeWork,
33-
DataHash, EmbeddedData, Exif, Metadata, SoftwareAgent, Thumbnail, User, UserCbor,
32+
c2pa_action, labels, Action, ActionTemplate, Actions, AssertionMetadata, BmffHash, BoxHash,
33+
CreativeWork, DataHash, EmbeddedData, Exif, SoftwareAgent, Thumbnail, User, UserCbor,
3434
},
3535
cbor_types::value_cbor_to_type,
3636
claim::Claim,
@@ -70,7 +70,7 @@ pub struct ManifestDefinition {
7070
pub claim_generator_info: Vec<ClaimGeneratorInfo>,
7171

7272
/// Optional manifest metadata. This will be deprecated in the future; not recommended to use.
73-
pub metadata: Option<Vec<Metadata>>,
73+
pub metadata: Option<Vec<AssertionMetadata>>,
7474

7575
/// A human-readable title, generally source filename.
7676
pub title: Option<String>,

sdk/src/claim.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{
3232
assertions::{
3333
self, c2pa_action,
3434
labels::{self, ACTIONS, ASSERTION_STORE, BMFF_HASH, CLAIM_THUMBNAIL, DATABOX_STORE},
35-
Actions, AssetType, BmffHash, BoxHash, DataBox, DataHash, Ingredient, Metadata,
35+
Actions, AssertionMetadata, AssetType, BmffHash, BoxHash, DataBox, DataHash, Ingredient,
3636
Relationship, V2_DEPRECATED_ACTIONS,
3737
},
3838
asset_io::CAIRead,
@@ -308,7 +308,7 @@ pub struct Claim {
308308

309309
claim_generator_hints: Option<HashMap<String, Value>>,
310310

311-
metadata: Option<Vec<Metadata>>,
311+
metadata: Option<Vec<AssertionMetadata>>,
312312

313313
data_boxes: Vec<(HashedUri, DataBox)>, /* list of the data boxes and their hashed URIs found for this manifest */
314314

@@ -622,7 +622,8 @@ impl Claim {
622622
map_cbor_to_type(REDACTED_ASSERTIONS_F, &claim_value);
623623
let alg: Option<String> = map_cbor_to_type(ALG_F, &claim_value);
624624
let alg_soft: Option<String> = map_cbor_to_type(ALG_SOFT_F, &claim_value);
625-
let metadata: Option<Vec<Metadata>> = map_cbor_to_type(METADATA_F, &claim_value);
625+
let metadata: Option<Vec<AssertionMetadata>> =
626+
map_cbor_to_type(METADATA_F, &claim_value);
626627

627628
Ok(Claim {
628629
remote_manifest: RemoteManifest::NoRemote,
@@ -710,7 +711,8 @@ impl Claim {
710711
map_cbor_to_type(REDACTED_ASSERTIONS_F, &claim_value);
711712
let alg: Option<String> = map_cbor_to_type(ALG_F, &claim_value);
712713
let alg_soft: Option<String> = map_cbor_to_type(ALG_SOFT_F, &claim_value);
713-
let metadata: Option<Vec<Metadata>> = map_cbor_to_type(METADATA_F, &claim_value);
714+
let metadata: Option<Vec<AssertionMetadata>> =
715+
map_cbor_to_type(METADATA_F, &claim_value);
714716

715717
// create merged list of created and gathered assertions for processing compatibility
716718
// created are added first with highest priority than gathered
@@ -1135,15 +1137,15 @@ impl Claim {
11351137
self.claim_generator_info.as_deref()
11361138
}
11371139

1138-
pub fn add_claim_metadata(&mut self, md: Metadata) -> &mut Self {
1140+
pub fn add_claim_metadata(&mut self, md: AssertionMetadata) -> &mut Self {
11391141
match self.metadata.as_mut() {
11401142
Some(md_vec) => md_vec.push(md),
11411143
None => self.metadata = Some([md].to_vec()),
11421144
}
11431145
self
11441146
}
11451147

1146-
pub fn metadata(&self) -> Option<&[Metadata]> {
1148+
pub fn metadata(&self) -> Option<&[AssertionMetadata]> {
11471149
self.metadata.as_deref()
11481150
}
11491151

0 commit comments

Comments
 (0)