@@ -51,7 +51,7 @@ use crate::{
5151 hash_utils:: { hash256, HashRange } ,
5252 patch:: patch_bytes,
5353 } ,
54- validation_status, AsyncSigner , ManifestStoreReport , Signer ,
54+ validation_status, AsyncSigner , ManifestStoreReport , RemoteSigner , Signer ,
5555} ;
5656#[ cfg( feature = "file_io" ) ]
5757use crate :: {
@@ -1659,22 +1659,10 @@ impl Store {
16591659 Ok ( composed)
16601660 }
16611661
1662- /// Returns a finalized, signed manifest. The manfiest are only supported
1663- /// for cases when the client has provided a data hash content hash binding. Note,
1664- /// this function will not work for cases like BMFF where the position
1665- /// of the content is also encoded. This function is not compatible with
1666- /// BMFF hash binding. If a BMFF data hash or box hash is detected that is
1667- /// an error. The DataHash placeholder assertion will be adjusted to the contain
1668- /// the correct values. If the asset_reader value is supplied it will also perform
1669- /// the hash calulations, otherwise the function uses the caller supplied values.
1670- /// It is an error if `get_data_hashed_manifest_placeholder` was not called first
1671- /// as this call inserts the DataHash placeholder assertion to reserve space for the
1672- /// actual hash values not required when using BoxHashes.
1673- pub fn get_data_hashed_embeddable_manifest (
1662+ fn prep_embeddable_store (
16741663 & mut self ,
1664+ reserve_size : usize ,
16751665 dh : & DataHash ,
1676- signer : & dyn Signer ,
1677- format : & str ,
16781666 asset_reader : Option < & mut dyn CAIRead > ,
16791667 ) -> Result < Vec < u8 > > {
16801668 let pc = self . provenance_claim_mut ( ) . ok_or ( Error :: ClaimEncoding ) ?;
@@ -1705,23 +1693,23 @@ impl Store {
17051693 // update the placeholder hash
17061694 pc. update_data_hash ( adusted_dh) ?;
17071695
1708- // reborrow immuttable
1709- let pc = self . provenance_claim ( ) . ok_or ( Error :: ClaimEncoding ) ?;
1710- let mut jumbf_bytes = self . to_jumbf_internal ( signer. reserve_size ( ) ) ?;
1711-
1712- // sign contents
1713- let sig = self . sign_claim ( pc, signer, signer. reserve_size ( ) ) ?;
1714-
1715- let sig_placeholder = Store :: sign_claim_placeholder ( pc, signer. reserve_size ( ) ) ;
1696+ self . to_jumbf_internal ( reserve_size)
1697+ }
17161698
1699+ fn finish_embeddable_store (
1700+ & mut self ,
1701+ sig : & [ u8 ] ,
1702+ sig_placeholder : & [ u8 ] ,
1703+ jumbf_bytes : & mut Vec < u8 > ,
1704+ format : & str ,
1705+ ) -> Result < Vec < u8 > > {
17171706 if sig_placeholder. len ( ) != sig. len ( ) {
17181707 return Err ( Error :: CoseSigboxTooSmall ) ;
17191708 }
17201709
1721- patch_bytes ( & mut jumbf_bytes, & sig_placeholder, & sig)
1722- . map_err ( |_| Error :: JumbfCreationError ) ?;
1710+ patch_bytes ( jumbf_bytes, sig_placeholder, sig) . map_err ( |_| Error :: JumbfCreationError ) ?;
17231711
1724- self . get_composed_manifest ( & jumbf_bytes, format)
1712+ self . get_composed_manifest ( jumbf_bytes, format)
17251713 }
17261714
17271715 /// Returns a finalized, signed manifest. The manfiest are only supported
@@ -1735,60 +1723,86 @@ impl Store {
17351723 /// It is an error if `get_data_hashed_manifest_placeholder` was not called first
17361724 /// as this call inserts the DataHash placeholder assertion to reserve space for the
17371725 /// actual hash values not required when using BoxHashes.
1738- pub async fn get_data_hashed_embeddable_manifest_async (
1726+ pub fn get_data_hashed_embeddable_manifest (
17391727 & mut self ,
17401728 dh : & DataHash ,
1741- signer : & dyn AsyncSigner ,
1729+ signer : & dyn Signer ,
17421730 format : & str ,
17431731 asset_reader : Option < & mut dyn CAIRead > ,
17441732 ) -> Result < Vec < u8 > > {
1745- let pc = self . provenance_claim_mut ( ) . ok_or ( Error :: ClaimEncoding ) ?;
1746-
1747- // make sure there are data hashes present before generating
1748- if pc. hash_assertions ( ) . is_empty ( ) {
1749- return Err ( Error :: BadParam (
1750- "Claim must have hash binding assertion" . to_string ( ) ,
1751- ) ) ;
1752- }
1733+ let mut jumbf_bytes =
1734+ self . prep_embeddable_store ( signer. reserve_size ( ) , dh, asset_reader) ?;
17531735
1754- // don't allow BMFF assertions to be present
1755- if !pc. bmff_hash_assertions ( ) . is_empty ( ) {
1756- return Err ( Error :: BadParam (
1757- "BMFF assertions not supported in embeddable manifests" . to_string ( ) ,
1758- ) ) ;
1759- }
1760-
1761- let mut adusted_dh = DataHash :: new ( "jumbf manifest" , pc. alg ( ) ) ;
1762- adusted_dh. exclusions = dh. exclusions . clone ( ) ;
1763- adusted_dh. hash = dh. hash . clone ( ) ;
1736+ // sign contents
1737+ let pc = self . provenance_claim ( ) . ok_or ( Error :: ClaimEncoding ) ?;
1738+ let sig = self . sign_claim ( pc, signer, signer. reserve_size ( ) ) ?;
17641739
1765- if let Some ( reader) = asset_reader {
1766- // calc hashes
1767- adusted_dh. gen_hash_from_stream ( reader) ?;
1768- }
1740+ let sig_placeholder = Store :: sign_claim_placeholder ( pc, signer. reserve_size ( ) ) ;
17691741
1770- // update the placeholder hash
1771- pc . update_data_hash ( adusted_dh ) ? ;
1742+ self . finish_embeddable_store ( & sig , & sig_placeholder , & mut jumbf_bytes , format )
1743+ }
17721744
1773- // reborrow immuttable
1774- let pc = self . provenance_claim ( ) . ok_or ( Error :: ClaimEncoding ) ?;
1775- let mut jumbf_bytes = self . to_jumbf_internal ( signer. reserve_size ( ) ) ?;
1745+ /// Returns a finalized, signed manifest. The manfiest are only supported
1746+ /// for cases when the client has provided a data hash content hash binding. Note,
1747+ /// this function will not work for cases like BMFF where the position
1748+ /// of the content is also encoded. This function is not compatible with
1749+ /// BMFF hash binding. If a BMFF data hash or box hash is detected that is
1750+ /// an error. The DataHash placeholder assertion will be adjusted to the contain
1751+ /// the correct values. If the asset_reader value is supplied it will also perform
1752+ /// the hash calulations, otherwise the function uses the caller supplied values.
1753+ /// It is an error if `get_data_hashed_manifest_placeholder` was not called first
1754+ /// as this call inserts the DataHash placeholder assertion to reserve space for the
1755+ /// actual hash values not required when using BoxHashes.
1756+ pub async fn get_data_hashed_embeddable_manifest_async (
1757+ & mut self ,
1758+ dh : & DataHash ,
1759+ signer : & dyn AsyncSigner ,
1760+ format : & str ,
1761+ asset_reader : Option < & mut dyn CAIRead > ,
1762+ ) -> Result < Vec < u8 > > {
1763+ let mut jumbf_bytes =
1764+ self . prep_embeddable_store ( signer. reserve_size ( ) , dh, asset_reader) ?;
17761765
17771766 // sign contents
1767+ let pc = self . provenance_claim ( ) . ok_or ( Error :: ClaimEncoding ) ?;
17781768 let sig = self
17791769 . sign_claim_async ( pc, signer, signer. reserve_size ( ) )
17801770 . await ?;
17811771
17821772 let sig_placeholder = Store :: sign_claim_placeholder ( pc, signer. reserve_size ( ) ) ;
17831773
1784- if sig_placeholder. len ( ) != sig. len ( ) {
1785- return Err ( Error :: CoseSigboxTooSmall ) ;
1786- }
1774+ self . finish_embeddable_store ( & sig, & sig_placeholder, & mut jumbf_bytes, format)
1775+ }
17871776
1788- patch_bytes ( & mut jumbf_bytes, & sig_placeholder, & sig)
1789- . map_err ( |_| Error :: JumbfCreationError ) ?;
1777+ /// Returns a finalized, signed manifest. The manfiest are only supported
1778+ /// for cases when the client has provided a data hash content hash binding. Note,
1779+ /// this function will not work for cases like BMFF where the position
1780+ /// of the content is also encoded. This function is not compatible with
1781+ /// BMFF hash binding. If a BMFF data hash or box hash is detected that is
1782+ /// an error. The DataHash placeholder assertion will be adjusted to the contain
1783+ /// the correct values. If the asset_reader value is supplied it will also perform
1784+ /// the hash calulations, otherwise the function uses the caller supplied values.
1785+ /// It is an error if `get_data_hashed_manifest_placeholder` was not called first
1786+ /// as this call inserts the DataHash placeholder assertion to reserve space for the
1787+ /// actual hash values not required when using BoxHashes.
1788+ pub async fn get_data_hashed_embeddable_manifest_remote (
1789+ & mut self ,
1790+ dh : & DataHash ,
1791+ signer : & dyn RemoteSigner ,
1792+ format : & str ,
1793+ asset_reader : Option < & mut dyn CAIRead > ,
1794+ ) -> Result < Vec < u8 > > {
1795+ let mut jumbf_bytes =
1796+ self . prep_embeddable_store ( signer. reserve_size ( ) , dh, asset_reader) ?;
1797+
1798+ // sign contents
1799+ let pc = self . provenance_claim ( ) . ok_or ( Error :: ClaimEncoding ) ?;
1800+ let claim_bytes = pc. data ( ) ?;
1801+ let sig = signer. sign_remote ( & claim_bytes) . await ?;
1802+
1803+ let sig_placeholder = Store :: sign_claim_placeholder ( pc, signer. reserve_size ( ) ) ;
17901804
1791- self . get_composed_manifest ( & jumbf_bytes, format)
1805+ self . finish_embeddable_store ( & sig , & sig_placeholder , & mut jumbf_bytes, format)
17921806 }
17931807
17941808 /// Returns a finalized, signed manifest. The client is required to have
0 commit comments