-
Notifications
You must be signed in to change notification settings - Fork 82
feat: impl Soft Binding assertion definition #1147
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
Open
ok-nick
wants to merge
6
commits into
main
Choose a base branch
from
ok-nick/soft-binding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0afb90b
feat: impl Soft Binding assertion definition
ok-nick 826b4a1
Merge branch 'main' into ok-nick/soft-binding
ok-nick d189d86
fix: remove `AssertionJson` impl for `SoftBinding`
ok-nick 160426c
fix: use usize for timespan
ok-nick de7c6d5
docs: clarify `alg_params` field string type
ok-nick ca3db74
Merge branch 'main' into ok-nick/soft-binding
scouten-adobe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::labels; | ||
use crate::{ | ||
assertion::{Assertion, AssertionBase, AssertionCbor, AssertionJson}, | ||
assertions::region_of_interest::RegionOfInterest, | ||
cbor_types::UriT, | ||
Result, | ||
}; | ||
|
||
const ASSERTION_CREATION_VERSION: usize = 1; | ||
|
||
/// The data structure used to store one or more soft bindings across some or all of the asset's content. | ||
/// | ||
/// https://c2pa.org/specifications/specifications/2.2/specs/C2PA_Specification.html#soft_binding_assertion | ||
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)] | ||
pub struct SoftBinding { | ||
/// A string identifying the soft binding algorithm and version of that algorithm used to compute the value, | ||
/// taken from the [C2PA soft binding algorithm list](https://github.com/c2pa-org/softbinding-algorithm-list). | ||
/// | ||
/// If this field is absent, the algorithm is taken from the `alg_soft` value of the enclosing structure. | ||
/// If both are present, the field in this structure is used. If no value is present in any of these places, | ||
/// this structure is invalid; there is no default. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub alg: Option<String>, | ||
|
||
/// A list of details about the soft binding. | ||
pub blocks: Vec<SoftBindingBlockMap>, | ||
|
||
/// Zero-filled bytes used for filling up space. | ||
#[serde(with = "serde_bytes")] | ||
pub pad: Vec<u8>, | ||
|
||
/// Zero-filled bytes used for filling up space. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub pad2: Option<serde_bytes::ByteBuf>, | ||
|
||
/// A human-readable description of what this hash covers. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub name: Option<String>, | ||
|
||
/// CBOR byte string describing parameters of the soft binding algorithm. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub alg_params: Option<String>, | ||
|
||
/// A file or http(s) URL to where the bytes that are being hashed lived. | ||
/// | ||
/// This is useful for cases where the data lives in a different file chunk or side-car | ||
/// than the claim. | ||
#[deprecated] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub url: Option<UriT>, | ||
} | ||
|
||
/// Details about the soft binding, including the referenced value and scope. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq)] | ||
pub struct SoftBindingBlockMap { | ||
/// The scope of the soft binding where it is applicable. | ||
pub scope: SoftBindingScopeMap, | ||
|
||
/// In algorithm specific format, the value of the soft binding computed over this block of digital content. | ||
pub value: String, | ||
} | ||
|
||
/// Soft binding scope, specifying specifically where in an asset the soft binding is applicable. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq)] | ||
pub struct SoftBindingScopeMap { | ||
/// In algorithm specific format, the part of the digital content over which the soft binding value has been computed. | ||
#[deprecated] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub extent: Option<String>, | ||
|
||
/// For temporal assets, the timespan in which the soft binding is applicable. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub timespan: Option<SoftBindingTimespanMap>, | ||
|
||
/// Region of interest in regard to the soft binding. | ||
pub region: RegionOfInterest, | ||
} | ||
|
||
/// Soft binding timespan for temporal assets. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq)] | ||
pub struct SoftBindingTimespanMap { | ||
/// Start of the time range (as milliseconds from media start) over which the soft binding value has been computed. | ||
pub start: u32, | ||
ok-nick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// End of the time range (as milliseconds from media start) over which the soft binding value has been computed. | ||
pub end: u32, | ||
} | ||
|
||
impl SoftBinding { | ||
pub const LABEL: &'static str = labels::SOFT_BINDING; | ||
} | ||
|
||
impl AssertionBase for SoftBinding { | ||
const LABEL: &'static str = Self::LABEL; | ||
const VERSION: Option<usize> = Some(ASSERTION_CREATION_VERSION); | ||
|
||
fn to_assertion(&self) -> Result<Assertion> { | ||
Self::to_cbor_assertion(self) | ||
} | ||
|
||
fn from_assertion(assertion: &Assertion) -> Result<Self> { | ||
Self::from_cbor_assertion(assertion) | ||
} | ||
} | ||
|
||
impl AssertionJson for SoftBinding {} | ||
impl AssertionCbor for SoftBinding {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.