-
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 18 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,23 +60,36 @@ 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. | ||
/// | ||
/// The default value is true. | ||
/// | ||
/// <div class="warning"> | ||
/// This setting is only applicable if the crate is compiled with the `add_thumbnails` feature. | ||
/// </div> | ||
pub enabled: bool, | ||
/// Whether to ignore thumbnail generation errors. | ||
/// | ||
/// This may occur, for instance, if the thumbnail media type or color layout isn't | ||
/// supported. | ||
/// | ||
/// The default value is true. | ||
pub ignore_errors: bool, | ||
/// The size of the longest edge of the thumbnail. | ||
/// | ||
/// This function will resize the input to preserve aspect ratio. | ||
/// | ||
/// The default value is 1024. | ||
pub long_edge: u32, | ||
/// Format of the thumbnail. | ||
/// | ||
/// If this field isn't specified, the thumbnail format will correspond to the | ||
/// input format. | ||
/// | ||
/// The default value is None. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub format: Option<ThumbnailFormat>, | ||
/// Whether or not to prefer a smaller sized media format for the thumbnail. | ||
|
@@ -85,11 +100,15 @@ pub(crate) struct ThumbnailSettings { | |
/// | ||
/// For instance, if the source input type is a PNG, but it doesn't have an alpha channel, | ||
/// the image will be converted to a JPEG of smaller size. | ||
/// | ||
/// The default value is true. | ||
pub prefer_smallest_format: bool, | ||
/// The output quality of the thumbnail. | ||
/// | ||
/// This setting contains sensible defaults for things like quality, compression, and | ||
/// algorithms for various formats. | ||
/// | ||
/// The default value is [`ThumbnailQuality::Medium`]. | ||
pub quality: ThumbnailQuality, | ||
} | ||
|
||
|
@@ -118,55 +137,57 @@ 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. | ||
/// | ||
/// This option will attempt to following the [LLVM "triples"] conventions. For more information, | ||
/// see [`ClaimGeneratorInfoOperatingSystem::Other`]. | ||
/// | ||
/// [LLVM "triples"]: https://clang.llvm.org/docs/CrossCompilation.html#target-triple | ||
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, | ||
} | ||
} | ||
/// It is recommended to follow the [LLVM "triples"] conventions to define the operating system, | ||
/// with the format `<arch><sub>-<vendor>-<sys>-<env>`. For instance: | ||
/// - `x86_64-unknown-linux-gnu` | ||
/// - `x86_64-pc-windows-msvc` | ||
/// - `arm64-apple-darwin` | ||
/// | ||
/// [LLVM "triples"]: https://clang.llvm.org/docs/CrossCompilation.html#target-triple | ||
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 +199,12 @@ 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 => { | ||
format!("{}-unknown-{}", consts::ARCH, consts::OS) | ||
} | ||
ClaimGeneratorInfoOperatingSystem::Other(name) => name, | ||
}) | ||
}, | ||
other: value | ||
.other | ||
|
@@ -198,6 +220,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 +244,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 +279,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 +345,34 @@ 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? | ||
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. | ||
#[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. | ||
#[doc(hidden)] | ||
// TODO: ActionSettings indirectly depends on ActionParameters which contains a serde_cbor::Value and | ||
// schemars can't generate a schema for cbor values. It also doesn't feel right to change our API for | ||
// the sake of json schemas. | ||
#[serde(skip)] | ||
pub(crate) actions: Option<Vec<ActionSettings>>, | ||
/// 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> | ||
|
@@ -389,9 +412,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 +427,38 @@ 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. | ||
pub certificate_status_should_override: Option<bool>, | ||
// TODO: this setting affects fetching and generation of the assertion; needs clarification | ||
/// Whether to create [`CertificateStatus`] assertions for manifests to store certificate revocation | ||
/// status. The assertion can be fetched for the active manifest or for all manifests (including | ||
/// ingredients). | ||
/// | ||
/// The default is to not fetch them at all. | ||
/// | ||
/// See more information in the spec here: | ||
/// <https://spec.c2pa.org/specifications/specifications/2.2/specs/C2PA_Specification.html#certificate_status_assertion> | ||
/// | ||
/// [`CertificateStatus`]: crate::assertions::CertificateStatus | ||
pub(crate) certificate_status_fetch: Option<OcspFetchScope>, | ||
// TODO: this setting affects fetching and generation of the assertion; needs clarification | ||
/// Whether to only use [`CertificateStatus`] assertions to check certificate revocation status. If there | ||
/// is a stapled OCSP in the COSE claim of the manifest, it will be ignored. If [`Verify::ocsp_fetch`] is | ||
/// enabled, it will also be ignored. | ||
/// | ||
/// The default value is false. | ||
ok-nick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// [`CertificateStatus`]: crate::assertions::CertificateStatus | ||
/// [`Verify::ocsp_fetch`]: crate::settings::Verify::ocsp_fetch | ||
pub(crate) 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(crate) enum OcspFetchScope { | ||
/// 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?