-
Notifications
You must be signed in to change notification settings - Fork 99
feat: add settings structs to the public API #1447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 12 commits
550319b
2d710cb
10aed0e
992ec27
17927f5
be43767
f752fb5
40591e7
a89476f
b3e6cb4
aee4a00
2ae744f
3cfa107
3b2cb72
9fb4585
4efca84
62f34dd
7d93444
2791e68
585c9bc
f3d9ff4
c2dd7f8
d5816e6
2e221f4
9d80172
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,10 @@ use crate::{ | |
/// | ||
/// These formats are a combination of types supported in [image-rs](https://docs.rs/image/latest/image/enum.ImageFormat.html) | ||
/// and types defined by the [IANA registry media type](https://www.iana.org/assignments/media-types/media-types.xhtml) (as defined in the spec). | ||
#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))] | ||
#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
#[serde(rename_all = "lowercase")] | ||
pub(crate) enum ThumbnailFormat { | ||
pub enum ThumbnailFormat { | ||
/// An image in PNG format. | ||
Png, | ||
/// An image in JPEG format. | ||
|
@@ -46,9 +47,10 @@ pub(crate) enum ThumbnailFormat { | |
Tiff, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we support TIFF thumbnails> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's naturally supported by the |
||
} | ||
/// Quality of the thumbnail. | ||
#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))] | ||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
#[serde(rename_all = "lowercase")] | ||
pub(crate) enum ThumbnailQuality { | ||
pub enum ThumbnailQuality { | ||
/// Low quality. | ||
Low, | ||
/// Medium quality. | ||
|
@@ -58,8 +60,9 @@ pub(crate) enum ThumbnailQuality { | |
} | ||
|
||
/// Settings for controlling automatic thumbnail generation. | ||
#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))] | ||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
pub(crate) struct ThumbnailSettings { | ||
pub struct ThumbnailSettings { | ||
/// Whether or not to automatically generate thumbnails. | ||
pub enabled: bool, | ||
/// Whether to ignore thumbnail generation errors. | ||
|
@@ -118,55 +121,44 @@ impl SettingsValidate for ThumbnailSettings { | |
} | ||
|
||
/// Settings for the auto actions (e.g. created, opened, placed). | ||
#[allow(unused)] | ||
#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))] | ||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
pub(crate) struct AutoActionSettings { | ||
pub struct AutoActionSettings { | ||
/// Whether to enable this auto action or not. | ||
pub enabled: bool, | ||
/// The default source type for the auto action. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub source_type: Option<DigitalSourceType>, | ||
} | ||
|
||
/// Settings for how to specify the claim generator info's operating system. | ||
#[allow(unused)] | ||
#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))] | ||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
pub(crate) struct ClaimGeneratorInfoOSSettings { | ||
/// Whether or not to infer the operating system. | ||
pub infer: bool, | ||
#[serde(untagged, rename_all = "lowercase")] | ||
pub enum ClaimGeneratorInfoOperatingSystem { | ||
gpeacock marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Whether or not to automatically infer the operating system. | ||
Auto, | ||
/// The name of the operating system. | ||
/// | ||
/// Note this field overrides [ClaimGeneratorInfoOSSettings::infer]. | ||
pub name: Option<String>, | ||
} | ||
|
||
impl Default for ClaimGeneratorInfoOSSettings { | ||
fn default() -> Self { | ||
Self { | ||
infer: true, | ||
name: None, | ||
} | ||
} | ||
Other(String), | ||
} | ||
|
||
/// Settings for the claim generator info. | ||
#[allow(unused)] | ||
#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))] | ||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
pub(crate) struct ClaimGeneratorInfoSettings { | ||
pub struct ClaimGeneratorInfoSettings { | ||
/// A human readable string naming the claim_generator. | ||
pub name: String, | ||
/// A human readable string of the product's version. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub version: Option<String>, | ||
/// Reference to an icon. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub icon: Option<ResourceRef>, | ||
pub(crate) icon: Option<ResourceRef>, | ||
/// Settings for the claim generator info's operating system field. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub operating_system: Option<ClaimGeneratorInfoOSSettings>, | ||
pub operating_system: Option<ClaimGeneratorInfoOperatingSystem>, | ||
ok-nick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Any other values that are not part of the standard. | ||
#[serde(flatten)] | ||
pub other: HashMap<String, toml::Value>, | ||
pub other: HashMap<String, serde_json::Value>, | ||
} | ||
|
||
impl TryFrom<ClaimGeneratorInfoSettings> for ClaimGeneratorInfo { | ||
|
@@ -178,11 +170,10 @@ impl TryFrom<ClaimGeneratorInfoSettings> for ClaimGeneratorInfo { | |
version: value.version, | ||
icon: value.icon.map(UriOrResource::ResourceRef), | ||
operating_system: { | ||
ok-nick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let os = value.operating_system.unwrap_or_default(); | ||
match os.infer { | ||
true => Some(consts::OS.to_owned()), | ||
false => os.name, | ||
} | ||
value.operating_system.map(|os| match os { | ||
ClaimGeneratorInfoOperatingSystem::Auto => consts::OS.to_owned(), | ||
ClaimGeneratorInfoOperatingSystem::Other(name) => name, | ||
}) | ||
}, | ||
other: value | ||
.other | ||
|
@@ -198,6 +189,7 @@ impl TryFrom<ClaimGeneratorInfoSettings> for ClaimGeneratorInfo { | |
} | ||
|
||
/// Settings for an action template. | ||
#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))] | ||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
pub(crate) struct ActionTemplateSettings { | ||
ok-nick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// The label associated with this action. See ([c2pa_action][crate::assertions::actions::c2pa_action]). | ||
|
@@ -221,7 +213,7 @@ pub(crate) struct ActionTemplateSettings { | |
pub description: Option<String>, | ||
/// Additional parameters for the template | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub template_parameters: Option<HashMap<String, toml::Value>>, | ||
pub template_parameters: Option<HashMap<String, serde_json::Value>>, | ||
} | ||
|
||
impl TryFrom<ActionTemplateSettings> for ActionTemplate { | ||
|
@@ -256,7 +248,6 @@ impl TryFrom<ActionTemplateSettings> for ActionTemplate { | |
} | ||
|
||
/// Settings for an action. | ||
#[allow(unused)] | ||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
pub(crate) struct ActionSettings { | ||
/// The label associated with this action. See ([`c2pa_action`]). | ||
|
@@ -323,33 +314,33 @@ impl TryFrom<ActionSettings> for Action { | |
/// | ||
/// The reason this setting exists only for an [Actions][crate::assertions::Actions] assertion | ||
/// is because of its mandations and reusable fields. | ||
#[allow(unused)] | ||
#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))] | ||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
pub(crate) struct ActionsSettings { | ||
pub struct ActionsSettings { | ||
/// Whether or not to set the [Actions::all_actions_included][crate::assertions::Actions::all_actions_included] | ||
/// field. | ||
pub all_actions_included: bool, | ||
ok-nick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
/// Templates to be added to the [Actions::templates][crate::assertions::Actions::templates] field. | ||
#[doc(hidden)] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub templates: Option<Vec<ActionTemplateSettings>>, | ||
// TODO: should we define a new struct for "Action" too, like ActionTemplateSettings? | ||
/// Actions to be added to the [Actions::actions][crate::assertions::Actions::actions] field. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub actions: Option<Vec<ActionSettings>>, | ||
/// Whether to automatically generate a c2pa.created [Action][crate::assertions::Action] | ||
/// assertion or error that it doesn't already exist. | ||
pub(crate) templates: Option<Vec<ActionTemplateSettings>>, | ||
ok-nick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// /// Actions to be added to the [Actions::actions][crate::assertions::Actions::actions] field. | ||
// #[doc(hidden)] | ||
// #[serde(skip_serializing_if = "Option::is_none")] | ||
// pub(crate) actions: Option<Vec<ActionSettings>>, | ||
ok-nick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// | ||
/// Whether to automatically generate a c2pa.created [Action] assertion or error that it doesn't already exist. | ||
/// | ||
/// For more information about the mandatory conditions for a c2pa.created action assertion, see here: | ||
/// <https://spec.c2pa.org/specifications/specifications/2.2/specs/C2PA_Specification.html#_mandatory_presence_of_at_least_one_actions_assertion> | ||
pub auto_created_action: AutoActionSettings, | ||
ok-nick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Whether to automatically generate a c2pa.opened [Action][crate::assertions::Action] | ||
/// assertion or error that it doesn't already exist. | ||
/// Whether to automatically generate a c2pa.opened [Action] assertion or error that it doesn't already exist. | ||
/// | ||
/// For more information about the mandatory conditions for a c2pa.opened action assertion, see here: | ||
/// <https://spec.c2pa.org/specifications/specifications/2.2/specs/C2PA_Specification.html#_mandatory_presence_of_at_least_one_actions_assertion> | ||
pub auto_opened_action: AutoActionSettings, | ||
/// Whether to automatically generate a c2pa.placed [Action][crate::assertions::Action] | ||
/// assertion or error that it doesn't already exist. | ||
/// Whether to automatically generate a c2pa.placed [Action] assertion or error that it doesn't already exist. | ||
/// | ||
/// For more information about the mandatory conditions for a c2pa.placed action assertion, see: | ||
/// <https://spec.c2pa.org/specifications/specifications/2.2/specs/C2PA_Specification.html#_relationship> | ||
|
@@ -361,7 +352,6 @@ impl Default for ActionsSettings { | |
ActionsSettings { | ||
all_actions_included: true, | ||
templates: None, | ||
actions: None, | ||
auto_created_action: AutoActionSettings { | ||
enabled: true, | ||
source_type: Some(DigitalSourceType::Empty), | ||
|
@@ -389,9 +379,9 @@ impl SettingsValidate for ActionsSettings { | |
|
||
// TODO: do more validation on URL fields, cert fields, etc. | ||
/// Settings for the [Builder][crate::Builder]. | ||
#[allow(unused)] | ||
#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))] | ||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)] | ||
pub(crate) struct BuilderSettings { | ||
pub struct BuilderSettings { | ||
/// Claim generator info that is automatically added to the builder. | ||
/// | ||
/// Note that this information will prepend any claim generator info | ||
|
@@ -404,18 +394,21 @@ pub(crate) struct BuilderSettings { | |
/// | ||
/// For more information on the reasoning behind this field see [ActionsSettings]. | ||
pub actions: ActionsSettings, | ||
|
||
// Certificate statuses will be fetched for either all the manifest labels, or just the active manifest. | ||
pub certificate_status_fetch: Option<OcspFetch>, | ||
|
||
// Whether or not existing OCSP responses should be overridden by new values. | ||
// REVIEW NOTE: should this be in builder settings or core? | ||
/// Certificate statuses will be fetched for either all the manifest labels, or just the active manifest. | ||
ok-nick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
pub certificate_status_fetch: Option<OcspFetchScope>, | ||
/// Whether or not existing OCSP responses should be overridden by new values. | ||
pub certificate_status_should_override: Option<bool>, | ||
} | ||
|
||
/// The scope of which manifests to fetch for OCSP. | ||
#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))] | ||
#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
#[serde(rename_all = "lowercase")] | ||
pub(crate) enum OcspFetch { | ||
pub enum OcspFetchScope { | ||
ok-nick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
/// Fetch OCSP for all manifests. | ||
All, | ||
/// Fetch OCSP for the active manifest only. | ||
Active, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this meant to be used in the settings file? Without an "off" choice then the presence of OCSPFetchScope will mean we are fetching responses. I do not thing fetching should ever default to on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we fetching OCSP responses for every certificate as a default!
certificate_status_fetch = "all"
certificate_status_should_override = true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, that's interesting. @scouten-adobe any input on this?