diff --git a/sdk/src/jumbf_io.rs b/sdk/src/jumbf_io.rs index bfe1ddd8a..5f68d5c41 100644 --- a/sdk/src/jumbf_io.rs +++ b/sdk/src/jumbf_io.rs @@ -282,7 +282,7 @@ pub fn load_jumbf_from_file>(in_path: P) -> Result> { } } -#[cfg(feature = "file_io")] +#[cfg(all(feature = "v1_api", feature = "file_io"))] pub(crate) fn object_locations(in_path: &Path) -> Result> { let ext = get_file_extension(in_path).ok_or(Error::UnsupportedType)?; diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 1da994a50..432b3aad1 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -121,6 +121,7 @@ pub use manifest::{Manifest, SignatureInfo}; pub use manifest_assertion::{ManifestAssertion, ManifestAssertionKind}; #[cfg(feature = "v1_api")] pub use manifest_store::ManifestStore; +#[cfg(feature = "v1_api")] pub use manifest_store_report::ManifestStoreReport; pub use reader::Reader; pub use resource_store::{ResourceRef, ResourceStore}; diff --git a/sdk/src/manifest_store.rs b/sdk/src/manifest_store.rs index f6cdc0c1d..877203629 100644 --- a/sdk/src/manifest_store.rs +++ b/sdk/src/manifest_store.rs @@ -268,7 +268,6 @@ impl ManifestStore { } /// Generate a Store from a format string and bytes. - #[cfg(feature = "v1_api")] #[deprecated(since = "0.38.0", note = "Please use Reader::from_stream() instead")] #[cfg(feature = "v1_api")] #[async_generic] diff --git a/sdk/src/reader.rs b/sdk/src/reader.rs index a50c98731..969c2bead 100644 --- a/sdk/src/reader.rs +++ b/sdk/src/reader.rs @@ -33,11 +33,12 @@ use crate::{ claim::ClaimAssetData, error::{Error, Result}, jumbf::labels::{manifest_label_from_uri, to_absolute_uri, to_relative_uri}, + manifest_store_report::ManifestStoreReport, settings::get_settings_value, store::Store, validation_results::{ValidationResults, ValidationState}, validation_status::ValidationStatus, - Manifest, ManifestStoreReport, + Manifest, }; /// A reader for the manifest store. diff --git a/sdk/src/store.rs b/sdk/src/store.rs index 5800b8744..f6d37ef7b 100644 --- a/sdk/src/store.rs +++ b/sdk/src/store.rs @@ -11,15 +11,14 @@ // specific language governing permissions and limitations under // each license. +#[cfg(all(feature = "v1_api", feature = "file_io"))] +use std::fs; +#[cfg(feature = "file_io")] +use std::path::{Path, PathBuf}; use std::{ collections::HashMap, io::{Cursor, Read, Seek}, }; -#[cfg(feature = "file_io")] -use std::{ - fs, - path::{Path, PathBuf}, -}; use async_generic::async_generic; use async_recursion::async_recursion; @@ -38,7 +37,7 @@ use crate::jumbf_io::save_jumbf_to_memory; use crate::jumbf_io::{ get_file_extension, get_supported_file_extension, load_jumbf_from_file, save_jumbf_to_file, }; -#[cfg(feature = "file_io")] +#[cfg(all(feature = "v1_api", feature = "file_io"))] use crate::jumbf_io::{object_locations, remove_jumbf_from_file}; use crate::{ assertion::{ @@ -308,6 +307,7 @@ impl Store { /// may be updated to reflect is position in the manifest Store /// if there are conflicting label names. The function /// will return the label of the claim used + #[cfg(all(feature = "v1_api", feature = "file_io"))] pub fn commit_update_manifest(&mut self, mut claim: Claim) -> Result { claim.set_update_manifest(true); @@ -767,11 +767,13 @@ impl Store { } /// Convert this claims store to a JUMBF box. + #[allow(unused)] // used in tests pub fn to_jumbf(&self, signer: &dyn Signer) -> Result> { self.to_jumbf_internal(signer.reserve_size()) } /// Convert this claims store to a JUMBF box. + #[cfg(feature = "v1_api")] pub fn to_jumbf_async(&self, signer: &dyn AsyncSigner) -> Result> { self.to_jumbf_internal(signer.reserve_size()) } @@ -1540,7 +1542,7 @@ impl Store { } // generate a list of AssetHashes based on the location of objects in the file - #[cfg(feature = "file_io")] + #[cfg(all(feature = "v1_api", feature = "file_io"))] fn generate_data_hashes( asset_path: &Path, alg: &str, @@ -1742,7 +1744,7 @@ impl Store { } // move or copy data from source to dest - #[cfg(feature = "file_io")] + #[cfg(all(feature = "v1_api", feature = "file_io"))] fn move_or_copy(source: &Path, dest: &Path) -> Result<()> { // copy temp file to asset std::fs::rename(source, dest) @@ -1752,7 +1754,7 @@ impl Store { } // copy output and possibly the external manifest to final destination - #[cfg(feature = "file_io")] + #[cfg(all(feature = "v1_api", feature = "file_io"))] fn copy_c2pa_to_output(source: &Path, dest: &Path, remote_type: RemoteManifest) -> Result<()> { match remote_type { RemoteManifest::NoRemote => Store::move_or_copy(source, dest)?, @@ -2588,7 +2590,7 @@ impl Store { } /// Embed the claims store as jumbf into an asset. Updates XMP with provenance record. - #[cfg(feature = "file_io")] + #[cfg(all(feature = "v1_api", feature = "file_io"))] pub fn save_to_asset( &mut self, asset_path: &Path, @@ -2642,7 +2644,7 @@ impl Store { } /// Embed the claims store as jumbf into an asset using an async signer. Updates XMP with provenance record. - #[cfg(feature = "file_io")] + #[cfg(all(feature = "v1_api", feature = "file_io"))] pub async fn save_to_asset_async( &mut self, asset_path: &Path, @@ -2995,7 +2997,7 @@ impl Store { )) } - #[cfg(feature = "file_io")] + #[cfg(all(feature = "v1_api", feature = "file_io"))] fn start_save( &mut self, asset_path: &Path, @@ -3302,6 +3304,7 @@ impl Store { } /// Return Store from in memory asset + #[cfg(any(feature = "file_io", feature = "v1_api"))] fn load_cai_from_memory( asset_type: &str, data: &[u8], @@ -3383,7 +3386,7 @@ impl Store { /// /// in_path - path to source file /// validation_log - optional vec to contain addition info about the asset - #[cfg(feature = "file_io")] + #[cfg(all(feature = "v1_api", feature = "file_io"))] fn load_cai_from_file( in_path: &Path, validation_log: &mut impl StatusTracker, @@ -3401,7 +3404,7 @@ impl Store { /// asset_path: path to input asset /// verify: determines whether to verify the contents of the provenance claim. Must be set true to use validation_log /// validation_log: If present all found errors are logged and returned, otherwise first error causes exit and is returned - #[cfg(feature = "file_io")] + #[cfg(all(feature = "v1_api", feature = "file_io"))] pub fn load_from_asset( asset_path: &Path, verify: bool, @@ -3423,6 +3426,7 @@ impl Store { }) } + #[cfg(feature = "v1_api")] pub fn get_store_from_memory( asset_type: &str, data: &[u8], @@ -3438,6 +3442,7 @@ impl Store { /// Returns embedded remote manifest URL if available /// asset_type: extensions or mime type of the data /// data: byte array containing the asset + #[allow(unused)] // we don't use this anywhere now, but we should! pub fn get_remote_manifest_url(asset_type: &str, data: &[u8]) -> Option { let mut buf_reader = Cursor::new(data); @@ -3466,6 +3471,7 @@ impl Store { /// data: reference to bytes of the the file /// verify: if true will run verification checks when loading /// validation_log: If present all found errors are logged and returned, otherwise first error causes exit and is returned + #[cfg(feature = "v1_api")] pub fn load_from_memory( asset_type: &str, data: &[u8], @@ -3532,7 +3538,7 @@ impl Store { let mut init_seg_data = Vec::new(); init_segment.read_to_end(&mut init_seg_data)?; - Store::get_store_from_memory(asset_type, &init_seg_data, validation_log).and_then(|store| { + Self::load_cai_from_memory(asset_type, &init_seg_data, validation_log).and_then(|store| { // verify the store if verify { // verify store and claims @@ -3553,6 +3559,7 @@ impl Store { /// stream: reference to initial segment asset /// fragment: reference to fragment asset /// validation_log: If present all found errors are logged and returned, otherwise first error causes exit and is returned + #[allow(unused)] // todo: we don't use this anywhere now, but we should! #[async_generic()] pub fn load_fragment_from_stream( format: &str, @@ -3617,6 +3624,7 @@ impl Store { /// fragment: reference to bytes of the fragment to validate /// verify: if true will run verification checks when loading /// validation_log: If present all found errors are logged and returned, otherwise first error causes exit and is returned + #[cfg(feature = "v1_api")] pub async fn load_fragment_from_memory_async( asset_type: &str, init_segment: &[u8], @@ -4255,7 +4263,7 @@ pub mod tests { assert_eq!(claim2_label, c3.unwrap().label()); // Do we generate JUMBF - let jumbf_bytes = store.to_jumbf_async(&signer).unwrap(); + let jumbf_bytes = store.to_jumbf_internal(signer.reserve_size()).unwrap(); assert!(!jumbf_bytes.is_empty()); // write to new file