commit e8f591d6f2ea23759ea1e632f678640fb038aa95 parent dffd14cbda0585c0319b61598b56283e5706b922 Author: Eric Scouten <scouten@adobe.com> Date: Fri, 5 Aug 2022 11:38:58 -0700 (IGNORE) Format `use` statements consistently (#99) No code changes made here; just reorganizating / reformatting. Diffstat:
56 files changed, 318 insertions(+), 296 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml @@ -163,7 +163,7 @@ jobs: - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: nightly override: true components: rustfmt diff --git a/make_test_images/src/make_test_images.rs b/make_test_images/src/make_test_images.rs @@ -12,20 +12,20 @@ // each license. //! Constructs a set of test images using a configuration script +use std::{ + fs, + path::{Path, PathBuf}, +}; + +use anyhow::{Context, Result}; use c2pa::{ assertions::{c2pa_action, Action, Actions, CreativeWork, SchemaDotOrgPerson}, create_signer, jumbf_io, Error, Ingredient, IngredientOptions, Manifest, ManifestStore, Signer, SigningAlg, }; - -use anyhow::{Context, Result}; use image::GenericImageView; use nom::AsBytes; use serde::Deserialize; -use std::{ - fs, - path::{Path, PathBuf}, -}; use twoway::find_bytes; const IMAGE_WIDTH: u32 = 2048; @@ -100,8 +100,7 @@ impl Default for Config { /// Generate a blake3 hash over the image in path using a fixed buffer fn blake3_hash(path: &Path) -> Result<String> { - use std::fs::File; - use std::io::Read; + use std::{fs::File, io::Read}; // Hash an input incrementally. let mut hasher = blake3::Hasher::new(); const BUFFER_LEN: usize = 1024 * 1024; diff --git a/rustfmt.toml b/rustfmt.toml @@ -1 +1,4 @@ edition = "2018" +group_imports = "StdExternalCrate" +imports_granularity = "Crate" +unstable_features = true diff --git a/sdk/examples/client/client.rs b/sdk/examples/client/client.rs @@ -13,13 +13,13 @@ //! Example C2PA client application -use anyhow::Result; +use std::path::PathBuf; +use anyhow::Result; use c2pa::{ assertions::{c2pa_action, labels, Action, Actions, CreativeWork, SchemaDotOrgPerson}, create_signer, Ingredient, Manifest, ManifestStore, SigningAlg, }; -use std::path::PathBuf; const GENERATOR: &str = "test_app/0.1"; const INDENT_SPACE: usize = 2; diff --git a/sdk/src/asn1/rfc3161.rs b/sdk/src/asn1/rfc3161.rs @@ -4,19 +4,18 @@ //! ASN.1 types defined by RFC 3161. -use { - crate::asn1::{rfc4210::PkiFreeText, rfc5652::ContentInfo}, - bcder::{ - decode::{Constructed, Malformed, Primitive, Source}, - encode::{self, PrimitiveContent, Values}, - ConstOid, Integer, OctetString, Oid, Tag, - }, - x509_certificate::{ - asn1time::GeneralizedTime, - rfc3280::GeneralName, - rfc5280::{AlgorithmIdentifier, Extensions}, - }, +use bcder::{ + decode::{Constructed, Malformed, Primitive, Source}, + encode::{self, PrimitiveContent, Values}, + ConstOid, Integer, OctetString, Oid, Tag, }; +use x509_certificate::{ + asn1time::GeneralizedTime, + rfc3280::GeneralName, + rfc5280::{AlgorithmIdentifier, Extensions}, +}; + +use crate::asn1::{rfc4210::PkiFreeText, rfc5652::ContentInfo}; /// Content-Type for Time-Stamp Token Info. /// diff --git a/sdk/src/asn1/rfc3281.rs b/sdk/src/asn1/rfc3281.rs @@ -2,13 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use { - bcder::{ - decode::{Constructed, Source, Unimplemented}, - BitString, Oid, - }, - x509_certificate::{asn1time::*, rfc3280::*, rfc5280::*}, +use bcder::{ + decode::{Constructed, Source, Unimplemented}, + BitString, Oid, }; +use x509_certificate::{asn1time::*, rfc3280::*, rfc5280::*}; /// Attribute certificate. /// diff --git a/sdk/src/asn1/rfc5652.rs b/sdk/src/asn1/rfc5652.rs @@ -12,22 +12,22 @@ Some RFC 5652 types are defined in the `x509-certificate` crate, which this crate relies on for certificate parsing functionality. */ -use { - crate::asn1::rfc3281::AttributeCertificate, - bcder::{ - decode::{Constructed, Malformed, Source, Unimplemented}, - encode, - encode::{PrimitiveContent, Values}, - BitString, Captured, ConstOid, Integer, Mode, OctetString, Oid, Tag, - }, - std::{ - fmt::{Debug, Formatter}, - io::Write, - ops::{Deref, DerefMut}, - }, - x509_certificate::{asn1time::*, rfc3280::*, rfc5280::*, rfc5652::*}, +use std::{ + fmt::{Debug, Formatter}, + io::Write, + ops::{Deref, DerefMut}, }; +use bcder::{ + decode::{Constructed, Malformed, Source, Unimplemented}, + encode, + encode::{PrimitiveContent, Values}, + BitString, Captured, ConstOid, Integer, Mode, OctetString, Oid, Tag, +}; +use x509_certificate::{asn1time::*, rfc3280::*, rfc5280::*, rfc5652::*}; + +use crate::asn1::rfc3281::AttributeCertificate; + /// The data content type. /// /// `id-data` in the specification. diff --git a/sdk/src/assertion.rs b/sdk/src/assertion.rs @@ -11,18 +11,18 @@ // specific language governing permissions and limitations under // each license. -use crate::{ - assertions::labels, - error::{Error, Result}, -}; use std::fmt; -use serde::de::DeserializeOwned; -use serde::{Deserialize, Serialize}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde_bytes::ByteBuf; use serde_json::Value; use thiserror::Error; +use crate::{ + assertions::labels, + error::{Error, Result}, +}; + /// Check to see if this a label whose string can vary, if so return the root of the label and version if available fn get_mutable_label(var_label: &str) -> (String, Option<usize>) { if var_label.starts_with(labels::SCHEMA_ORG) { @@ -611,7 +611,6 @@ pub mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::assertions::{Action, Actions}; #[test] diff --git a/sdk/src/assertions/actions.rs b/sdk/src/assertions/actions.rs @@ -11,6 +11,11 @@ // specific language governing permissions and limitations under // each license. +use std::collections::HashMap; + +use serde::{Deserialize, Serialize}; +use serde_json::Value; + use crate::{ assertion::{Assertion, AssertionBase, AssertionCbor}, assertions::{labels, Actor, Metadata}, @@ -18,10 +23,6 @@ use crate::{ Error, }; -use serde::{Deserialize, Serialize}; -use serde_json::Value; -use std::collections::HashMap; - /// Specification defined C2PA actions pub mod c2pa_action { /// Changes to tone, saturation, etc. @@ -308,10 +309,11 @@ pub mod tests { #![allow(clippy::unwrap_used)] use super::*; - - use crate::assertion::{Assertion, AssertionData}; - use crate::assertions::metadata::{c2pa_source::GENERATOR_REE, DataSource, ReviewRating}; - use crate::hashed_uri::HashedUri; + use crate::{ + assertion::{Assertion, AssertionData}, + assertions::metadata::{c2pa_source::GENERATOR_REE, DataSource, ReviewRating}, + hashed_uri::HashedUri, + }; fn make_hashed_uri1() -> HashedUri { HashedUri::new( diff --git a/sdk/src/assertions/creative_work.rs b/sdk/src/assertions/creative_work.rs @@ -11,15 +11,16 @@ // specific language governing permissions and limitations under // each license. +use std::ops::Deref; + use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use serde_json::json; use crate::{ assertion::{Assertion, AssertionBase, AssertionJson}, assertions::{labels, SchemaDotOrg, SchemaDotOrgPerson}, error::Result, }; -use serde_json::json; -use std::ops::Deref; const ASSERTION_CREATION_VERSION: usize = 1; const CW_AUTHOR: &str = "author"; diff --git a/sdk/src/assertions/data_hash.rs b/sdk/src/assertions/data_hash.rs @@ -247,7 +247,6 @@ pub mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::{ assertion::{Assertion, AssertionData}, utils::test::fixture_path, diff --git a/sdk/src/assertions/ingredient.rs b/sdk/src/assertions/ingredient.rs @@ -144,7 +144,6 @@ pub mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::assertion::{AssertionCbor, AssertionData}; #[test] diff --git a/sdk/src/assertions/metadata.rs b/sdk/src/assertions/metadata.rs @@ -11,6 +11,12 @@ // specific language governing permissions and limitations under // each license. +use std::collections::HashMap; + +use chrono::{SecondsFormat, Utc}; +use serde::{Deserialize, Serialize}; +use serde_json::Value; + use crate::{ assertion::{Assertion, AssertionBase, AssertionCbor}, assertions::labels, @@ -18,11 +24,6 @@ use crate::{ hashed_uri::HashedUri, }; -use chrono::{SecondsFormat, Utc}; -use serde::{Deserialize, Serialize}; -use serde_json::Value; -use std::collections::HashMap; - const ASSERTION_CREATION_VERSION: usize = 1; /// The Metadata structure can be used as part of other assertions or on its own to reference others diff --git a/sdk/src/assertions/schema_org.rs b/sdk/src/assertions/schema_org.rs @@ -11,7 +11,10 @@ // specific language governing permissions and limitations under // each license. +use std::collections::HashMap; + use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use serde_json::{json, Value}; use crate::{ assertion::{Assertion, AssertionBase, AssertionJson}, @@ -19,8 +22,6 @@ use crate::{ error::{Error, Result}, hashed_uri::HashedUri, }; -use serde_json::{json, Value}; -use std::collections::HashMap; const ASSERTION_CREATION_VERSION: usize = 1; diff --git a/sdk/src/assertions/thumbnail.rs b/sdk/src/assertions/thumbnail.rs @@ -11,6 +11,8 @@ // specific language governing permissions and limitations under // each license. +use serde::Serialize; + use crate::{ assertion::{ get_thumbnail_image_type, Assertion, AssertionBase, AssertionData, AssertionDecodeError, @@ -19,8 +21,6 @@ use crate::{ error::Result, }; -use serde::Serialize; - /// A Thumbnail assertion #[derive(Serialize)] pub struct Thumbnail { @@ -88,7 +88,6 @@ pub mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::assertions::labels; // a binary assertion ('deadbeefadbeadbe') diff --git a/sdk/src/assertions/user.rs b/sdk/src/assertions/user.rs @@ -11,11 +11,12 @@ // specific language governing permissions and limitations under // each license. +use serde::Serialize; + use crate::{ assertion::{Assertion, AssertionBase, AssertionData, AssertionDecodeError}, error::{Error, Result}, }; -use serde::Serialize; /// Helper class to create User assertion #[derive(Debug, Default, Serialize)] diff --git a/sdk/src/assertions/user_cbor.rs b/sdk/src/assertions/user_cbor.rs @@ -75,7 +75,6 @@ pub mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::assertion::Assertion; const LABEL: &str = "user_test_assertion"; diff --git a/sdk/src/asset_handlers/bmff_io.rs b/sdk/src/asset_handlers/bmff_io.rs @@ -11,24 +11,27 @@ // specific language governing permissions and limitations under // each license. -use std::collections::HashMap; -use std::convert::{From, TryFrom}; -use std::fs::{File, OpenOptions}; -use std::io::{Read, Seek, SeekFrom, Write}; -use std::path::Path; +use std::{ + collections::HashMap, + convert::{From, TryFrom}, + fs::{File, OpenOptions}, + io::{Read, Seek, SeekFrom, Write}, + path::Path, +}; +use atree::{Arena, Token}; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use conv::ValueFrom; use serde::{Deserialize, Serialize}; use serde_bytes::ByteBuf; - -use atree::{Arena, Token}; use tempfile::{Builder, NamedTempFile}; -use crate::assertions::ExclusionsMap; -use crate::asset_io::{AssetIO, AssetPatch, CAILoader, CAIRead, HashObjectPositions}; -use crate::error::{Error, Result}; -use crate::utils::hash_utils::{vec_compare, Exclusion}; +use crate::{ + assertions::ExclusionsMap, + asset_io::{AssetIO, AssetPatch, CAILoader, CAIRead, HashObjectPositions}, + error::{Error, Result}, + utils::hash_utils::{vec_compare, Exclusion}, +}; pub struct BmffIO { #[allow(dead_code)] diff --git a/sdk/src/asset_handlers/c2pa_io.rs b/sdk/src/asset_handlers/c2pa_io.rs @@ -11,10 +11,12 @@ // specific language governing permissions and limitations under // each license. -use crate::asset_io::{AssetIO, CAILoader, CAIRead, HashObjectPositions}; -use crate::error::{Error, Result}; -use std::fs::File; -use std::path::Path; +use std::{fs::File, path::Path}; + +use crate::{ + asset_io::{AssetIO, CAILoader, CAIRead, HashObjectPositions}, + error::{Error, Result}, +}; /// Supports working with ".c2pa" files containing only manifest store data pub struct C2paIO {} @@ -61,10 +63,9 @@ pub mod tests { #![allow(clippy::expect_used)] #![allow(clippy::unwrap_used)] - use super::{AssetIO, C2paIO}; - use tempfile::tempdir; + use super::{AssetIO, C2paIO}; use crate::{ status_tracker::OneShotStatusTracker, store::Store, diff --git a/sdk/src/asset_handlers/jpeg_io.rs b/sdk/src/asset_handlers/jpeg_io.rs @@ -11,18 +11,22 @@ // specific language governing permissions and limitations under // each license. -use std::fs::{read, File}; -use std::io::Cursor; -use std::path::*; +use std::{ + fs::{read, File}, + io::Cursor, + path::*, +}; use byteorder::{BigEndian, ReadBytesExt}; +use img_parts::{ + jpeg::{markers, Jpeg, JpegSegment}, + Bytes, DynImage, +}; -use img_parts::jpeg::{markers, Jpeg, JpegSegment}; -use img_parts::Bytes; -use img_parts::DynImage; - -use crate::asset_io::{AssetIO, CAILoader, CAIRead, HashBlockObjectType, HashObjectPositions}; -use crate::error::{wrap_io_err, Error, Result}; +use crate::{ + asset_io::{AssetIO, CAILoader, CAIRead, HashBlockObjectType, HashObjectPositions}, + error::{wrap_io_err, Error, Result}, +}; const XMP_SIGNATURE: &[u8] = b"http://ns.adobe.com/xap/1.0/"; const XMP_SIGNATURE_BUFFER_SIZE: usize = XMP_SIGNATURE.len() + 1; // skip null or space char at end @@ -397,9 +401,10 @@ impl AssetIO for JpegIO { pub mod tests { #![allow(clippy::unwrap_used)] - use super::*; use img_parts::Bytes; + use super::*; + #[test] fn test_extract_xmp() { let contents = Bytes::from_static(b"http://ns.adobe.com/xap/1.0/\0stuff"); diff --git a/sdk/src/asset_handlers/png_io.rs b/sdk/src/asset_handlers/png_io.rs @@ -11,15 +11,19 @@ // specific language governing permissions and limitations under // each license. -use std::fs::File; -use std::io::{Cursor, SeekFrom}; -use std::path::*; +use std::{ + fs::File, + io::{Cursor, SeekFrom}, + path::*, +}; use byteorder::{BigEndian, ReadBytesExt}; use conv::ValueFrom; -use crate::asset_io::{AssetIO, CAILoader, CAIRead, HashBlockObjectType, HashObjectPositions}; -use crate::error::{Error, Result}; +use crate::{ + asset_io::{AssetIO, CAILoader, CAIRead, HashBlockObjectType, HashObjectPositions}, + error::{Error, Result}, +}; const PNG_ID: [u8; 8] = [137, 80, 78, 71, 13, 10, 26, 10]; const CAI_CHUNK: [u8; 4] = *b"caBX"; diff --git a/sdk/src/asset_io.rs b/sdk/src/asset_io.rs @@ -11,10 +11,14 @@ // specific language governing permissions and limitations under // each license. -use std::io::{Read, Seek}; +use std::{ + fmt, + io::{Read, Seek}, + path::Path, +}; use crate::error::Result; -use std::{fmt, path::Path}; + #[derive(Clone, Debug, PartialEq)] pub enum HashBlockObjectType { Cai, diff --git a/sdk/src/claim.rs b/sdk/src/claim.rs @@ -11,32 +11,34 @@ // specific language governing permissions and limitations under // each license. +use std::{collections::HashMap, fmt, path::Path}; + use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_json::{json, Map, Value}; -use std::collections::HashMap; -use std::fmt; -use std::path::Path; use uuid::Uuid; -use crate::assertion::{ - get_thumbnail_image_type, get_thumbnail_instance, get_thumbnail_type, Assertion, AssertionBase, - AssertionData, -}; -use crate::assertions::{self, labels, BmffHash, DataHash}; -use crate::cose_validator::{get_signing_info, verify_cose, verify_cose_async}; -use crate::hashed_uri::HashedUri; -use crate::jumbf::{ - self, - boxes::{CAICBORAssertionBox, CAIJSONAssertionBox, CAIUUIDAssertionBox, JumbfEmbeddedFileBox}, +use crate::{ + assertion::{ + get_thumbnail_image_type, get_thumbnail_instance, get_thumbnail_type, Assertion, + AssertionBase, AssertionData, + }, + assertions::{self, labels, BmffHash, DataHash}, + cose_validator::{get_signing_info, verify_cose, verify_cose_async}, + error::{Error, Result}, + hashed_uri::HashedUri, + jumbf::{ + self, + boxes::{ + CAICBORAssertionBox, CAIJSONAssertionBox, CAIUUIDAssertionBox, JumbfEmbeddedFileBox, + }, + }, + salt::{SaltGenerator, NO_SALT}, + status_tracker::{log_item, OneShotStatusTracker, StatusTracker}, + utils::hash_utils::{hash_by_alg, vec_compare, verify_by_alg}, + validation_status, + validator::ValidationInfo, }; -use crate::salt::{SaltGenerator, NO_SALT}; -use crate::utils::hash_utils::{hash_by_alg, vec_compare, verify_by_alg}; - -use crate::error::{Error, Result}; -use crate::status_tracker::{log_item, OneShotStatusTracker, StatusTracker}; -use crate::validation_status; -use crate::validator::ValidationInfo; const BUILD_HASH_ALG: &str = "sha256"; diff --git a/sdk/src/cose_sign.rs b/sdk/src/cose_sign.rs @@ -337,7 +337,6 @@ mod tests { #![allow(clippy::unwrap_used)] use super::sign_claim; - use crate::{claim::Claim, openssl::RsaSigner, utils::test::temp_signer}; #[test] diff --git a/sdk/src/cose_validator.rs b/sdk/src/cose_validator.rs @@ -14,11 +14,16 @@ use ciborium::value::Value; use conv::*; use coset::{sig_structure_data, Label, TaggedCborSerializable}; - use x509_parser::{ - der_parser::ber::parse_ber_sequence, der_parser::oid, oid_registry::Oid, prelude::*, + der_parser::{ber::parse_ber_sequence, oid}, + oid_registry::Oid, + prelude::*, }; +#[cfg(not(target_arch = "wasm32"))] +use crate::validator::{get_validator, CoseValidator}; +#[cfg(target_arch = "wasm32")] +use crate::wasm::webcrypto_validator::validate_async; use crate::{ asn1::rfc3161::TstInfo, error::{Error, Result}, @@ -29,12 +34,6 @@ use crate::{ SigningAlg, }; -#[cfg(target_arch = "wasm32")] -use crate::wasm::webcrypto_validator::validate_async; - -#[cfg(not(target_arch = "wasm32"))] -use crate::validator::{get_validator, CoseValidator}; - const RSA_OID: Oid<'static> = oid!(1.2.840 .113549 .1 .1 .1); const EC_PUBLICKEY_OID: Oid<'static> = oid!(1.2.840 .10045 .2 .1); const ECDSA_WITH_SHA256_OID: Oid<'static> = oid!(1.2.840 .10045 .4 .3 .2); @@ -940,10 +939,9 @@ async fn validate_with_cert_async( pub mod tests { #![allow(clippy::unwrap_used)] - use super::*; - use sha2::digest::generic_array::sequence::Shorten; + use super::*; use crate::{status_tracker::DetailedStatusTracker, SigningAlg}; #[test] diff --git a/sdk/src/hashed_uri.rs b/sdk/src/hashed_uri.rs @@ -11,9 +11,10 @@ // specific language governing permissions and limitations under // each license. -use serde::{Deserialize, Serialize}; use std::fmt; +use serde::{Deserialize, Serialize}; + /// Hashed Uri stucture as defined by C2PA spec /// It is annotated to produce the correctly tagged cbor serialization #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] diff --git a/sdk/src/ingredient.rs b/sdk/src/ingredient.rs @@ -13,6 +13,11 @@ #![deny(missing_docs)] +use std::ops::Deref; + +use log::{debug, error}; +use serde::{Deserialize, Serialize}; + use crate::{ assertion::{get_thumbnail_image_type, Assertion, AssertionBase}, assertions::{self, labels, Metadata, Relationship, Thumbnail}, @@ -23,12 +28,8 @@ use crate::{ store::Store, validation_status::{self, ValidationStatus}, }; -use std::ops::Deref; - #[cfg(feature = "file_io")] use crate::{error::wrap_io_err, validation_status::status_for_store, xmp_inmemory_utils::XmpInfo}; -use log::{debug, error}; -use serde::{Deserialize, Serialize}; /// Function that is used by serde to determine whether or not we should serialize /// thumbnail data based on the "serialize_thumbnails" flag (serialization is disabled by default) @@ -386,8 +387,10 @@ impl Ingredient { #[cfg(feature = "file_io")] fn from_file_impl(path: &Path, options: &dyn IngredientOptions) -> Result<Self> { // these are declared inside this function in order to isolate them for wasm builds - use crate::jumbf_io; - use crate::status_tracker::{DetailedStatusTracker, StatusTracker}; + use crate::{ + jumbf_io, + status_tracker::{DetailedStatusTracker, StatusTracker}, + }; #[cfg(feature = "diagnostics")] let _t = crate::utils::time_it::TimeIt::new("Ingredient:from_file_with_options"); @@ -709,8 +712,8 @@ mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::assertions::Metadata; + #[test] fn test_ingredient_api() { let mut ingredient = Ingredient::new("title", "format", "instance_id"); @@ -753,7 +756,6 @@ mod tests_file_io { #![allow(clippy::unwrap_used)] use super::*; - use crate::utils::test::fixture_path; const NO_MANIFEST_JPEG: &str = "earth_apollo17.jpg"; diff --git a/sdk/src/jumbf/boxes.rs b/sdk/src/jumbf/boxes.rs @@ -2233,11 +2233,11 @@ pub mod tests { #![allow(clippy::expect_used)] #![allow(clippy::unwrap_used)] - use super::*; + use std::io::Cursor; use extfmt::*; - use std::io::Cursor; + use super::*; // base_len = size (u32) + type (u32) // desc_len = base + 16 (UUID type) + 1 (TOGGLE) diff --git a/sdk/src/jumbf_io.rs b/sdk/src/jumbf_io.rs @@ -11,18 +11,18 @@ // specific language governing permissions and limitations under // each license. -use crate::{ - asset_handlers::{bmff_io::BmffIO, c2pa_io::C2paIO, jpeg_io::JpegIO, png_io::PngIO}, - asset_io::{AssetIO, CAILoader, HashObjectPositions}, - error::{Error, Result}, -}; - use std::{ fs::{self, File}, io::Cursor, path::{Path, PathBuf}, }; +use crate::{ + asset_handlers::{bmff_io::BmffIO, c2pa_io::C2paIO, jpeg_io::JpegIO, png_io::PngIO}, + asset_io::{AssetIO, CAILoader, HashObjectPositions}, + error::{Error, Result}, +}; + static SUPPORTED_TYPES: [&str; 18] = [ "avif", "c2pa", // stand-alone manifest file diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs @@ -107,10 +107,9 @@ mod manifest_store_report; pub use manifest_store_report::ManifestStoreReport; mod signing_alg; -pub use signing_alg::{SigningAlg, UnknownAlgorithmError}; - #[cfg(feature = "file_io")] pub use ingredient::{DefaultOptions, IngredientOptions}; +pub use signing_alg::{SigningAlg, UnknownAlgorithmError}; #[cfg(feature = "file_io")] pub(crate) mod ocsp_utils; #[cfg(feature = "file_io")] @@ -144,9 +143,7 @@ pub(crate) mod store; pub(crate) mod time_stamp; pub(crate) mod utils; pub mod validation_status; -pub(crate) use utils::cbor_types; -pub(crate) use utils::hash_utils; -pub(crate) use utils::xmp_inmemory_utils; +pub(crate) use utils::{cbor_types, hash_utils, xmp_inmemory_utils}; pub(crate) mod validator; #[cfg(target_arch = "wasm32")] pub mod wasm; diff --git a/sdk/src/manifest.rs b/sdk/src/manifest.rs @@ -11,6 +11,17 @@ // specific language governing permissions and limitations under // each license. +use std::collections::HashMap; +#[cfg(feature = "file_io")] +use std::path::Path; + +use log::{debug, error, warn}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use serde_json::Value; +use uuid::Uuid; + +#[cfg(feature = "file_io")] +use crate::Signer; use crate::{ assertion::{AssertionBase, AssertionData}, assertions::{labels, Actions, CreativeWork, Thumbnail, User, UserCbor}, @@ -21,20 +32,9 @@ use crate::{ store::Store, Ingredient, ManifestAssertion, ManifestAssertionKind, }; - -#[cfg(feature = "file_io")] -use crate::Signer; #[cfg(all(feature = "async_signer", feature = "file_io"))] use crate::{AsyncSigner, RemoteSigner}; -use log::{debug, error, warn}; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use serde_json::Value; -use std::collections::HashMap; -#[cfg(feature = "file_io")] -use std::path::Path; -use uuid::Uuid; - /// Function that is used by serde to determine whether or not we should serialize /// thumbnail data based on the `serialize_thumbnails` flag. /// (Serialization is disabled by default.) @@ -738,12 +738,14 @@ pub(crate) mod tests { #![allow(clippy::expect_used)] #![allow(clippy::unwrap_used)] + #[cfg(feature = "file_io")] + use tempfile::tempdir; + use crate::{ assertions::{c2pa_action, Action, Actions}, utils::test::TEST_VC, Manifest, Result, }; - #[cfg(feature = "file_io")] use crate::{ status_tracker::{DetailedStatusTracker, StatusTracker}, @@ -754,9 +756,6 @@ pub(crate) mod tests { Ingredient, }; - #[cfg(feature = "file_io")] - use tempfile::tempdir; - // example of random data structure as an assertion #[derive(serde::Serialize)] struct MyStruct { @@ -881,8 +880,8 @@ pub(crate) mod tests { #[test] fn test_assertion_user_cbor() { - use crate::assertions::UserCbor; - use crate::Manifest; + use crate::{assertions::UserCbor, Manifest}; + const LABEL: &str = "org.cai.test"; const DATA: &str = r#"{ "l1":"some data", "l2":"some other data" }"#; let json: serde_json::Value = serde_json::from_str(DATA).unwrap(); diff --git a/sdk/src/manifest_assertion.rs b/sdk/src/manifest_assertion.rs @@ -1,11 +1,11 @@ +use serde::{de::DeserializeOwned, Deserialize, Serialize}; //, Deserializer, Serializer}; +use serde_json::Value; + use crate::{ assertion::{AssertionBase, AssertionDecodeError}, error::{Error, Result}, }; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; //, Deserializer, Serializer}; -use serde_json::Value; - /// Assertions in C2PA can be stored in several formats #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] pub enum ManifestAssertionKind { diff --git a/sdk/src/manifest_store.rs b/sdk/src/manifest_store.rs @@ -11,17 +11,18 @@ // specific language governing permissions and limitations under // each license. +use std::collections::HashMap; +#[cfg(feature = "file_io")] +use std::path::Path; + +use serde::Serialize; + use crate::{ status_tracker::{DetailedStatusTracker, StatusTracker}, store::Store, validation_status::{status_for_store, ValidationStatus}, Manifest, Result, }; -use serde::Serialize; -use std::collections::HashMap; - -#[cfg(feature = "file_io")] -use std::path::Path; #[derive(Serialize)] /// A Container for a set of Manifests and a ValidationStatus list @@ -215,12 +216,12 @@ mod tests { #![allow(clippy::expect_used)] #![allow(clippy::unwrap_used)] - use super::*; - use crate::{status_tracker::OneShotStatusTracker, utils::test::create_test_store}; - #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; + use super::*; + use crate::{status_tracker::OneShotStatusTracker, utils::test::create_test_store}; + #[cfg(target_arch = "wasm32")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); diff --git a/sdk/src/manifest_store_report.rs b/sdk/src/manifest_store_report.rs @@ -11,6 +11,13 @@ // specific language governing permissions and limitations under // each license. +use std::collections::HashMap; +#[cfg(feature = "file_io")] +use std::path::Path; + +use serde::{Deserialize, Serialize}; +use serde_json::Value; + use crate::{ assertion::AssertionData, claim::Claim, @@ -19,11 +26,6 @@ use crate::{ validation_status::ValidationStatus, Result, }; -use serde::{Deserialize, Serialize}; -use serde_json::Value; -use std::collections::HashMap; -#[cfg(feature = "file_io")] -use std::path::Path; /// Low level JSON based representation of Manifest Store - used for debugging #[non_exhaustive] diff --git a/sdk/src/ocsp_utils.rs b/sdk/src/ocsp_utils.rs @@ -11,14 +11,18 @@ // specific language governing permissions and limitations under // each license. -use crate::error::{Error, Result}; -use crate::openssl::check_chain_order_der; -use crate::status_tracker::{log_item, StatusTracker}; -use crate::validation_status; +use std::io::Read; + use chrono::{DateTime, NaiveDateTime, Utc}; use conv::ConvUtil; use openssl::ocsp::{self, OcspBasicResponse, OcspCertStatus, OcspRevokedStatus}; -use std::io::Read; + +use crate::{ + error::{Error, Result}, + openssl::check_chain_order_der, + status_tracker::{log_item, StatusTracker}, + validation_status, +}; const DATE_FMT: &str = "%b %d %H:%M:%S %Y %Z"; diff --git a/sdk/src/openssl/ec_signer.rs b/sdk/src/openssl/ec_signer.rs @@ -13,20 +13,23 @@ use std::{fs, path::Path}; -use crate::{ - error::{wrap_io_err, wrap_openssl_err, Error, Result}, - signer::ConfigurableSigner, - Signer, SigningAlg, +use openssl::{ + ec::EcKey, + hash::MessageDigest, + pkey::{PKey, Private}, + x509::X509, }; -use openssl::hash::MessageDigest; -use openssl::pkey::PKey; -use openssl::{ec::EcKey, pkey::Private, x509::X509}; use x509_parser::der_parser::{ self, der::{parse_der_integer, parse_der_sequence_defined_g}, }; use super::check_chain_order; +use crate::{ + error::{wrap_io_err, wrap_openssl_err, Error, Result}, + signer::ConfigurableSigner, + Signer, SigningAlg, +}; /// Implements `Signer` trait using OpenSSL's implementation of /// ECDSA encryption. @@ -207,7 +210,6 @@ mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::{openssl::temp_signer, utils::test::fixture_path, SigningAlg}; #[test] diff --git a/sdk/src/openssl/ec_validator.rs b/sdk/src/openssl/ec_validator.rs @@ -11,10 +11,9 @@ // specific language governing permissions and limitations under // each license. +use openssl::{ec::EcKey, hash::MessageDigest, pkey::PKey}; + use crate::{validator::CoseValidator, Error, Result, SigningAlg}; -use openssl::ec::EcKey; -use openssl::hash::MessageDigest; -use openssl::pkey::PKey; pub struct EcValidator { alg: SigningAlg, @@ -76,7 +75,6 @@ fn wrap_openssl_err(err: openssl::error::ErrorStack) -> Error { mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::{openssl::temp_signer, utils::test::fixture_path, Signer, SigningAlg}; #[test] diff --git a/sdk/src/openssl/ed_signer.rs b/sdk/src/openssl/ed_signer.rs @@ -18,9 +18,8 @@ use openssl::{ x509::X509, }; -use crate::{signer::ConfigurableSigner, Error, Result, Signer, SigningAlg}; - use super::check_chain_order; +use crate::{signer::ConfigurableSigner, Error, Result, Signer, SigningAlg}; /// Implements `Signer` trait using OpenSSL's implementation of /// Edwards Curve encryption. @@ -126,7 +125,6 @@ fn wrap_openssl_err(err: openssl::error::ErrorStack) -> Error { mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::{openssl::temp_signer, utils::test::fixture_path, SigningAlg}; #[test] diff --git a/sdk/src/openssl/ed_validator.rs b/sdk/src/openssl/ed_validator.rs @@ -43,7 +43,6 @@ mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::{openssl::temp_signer, utils::test::fixture_path, Signer, SigningAlg}; #[test] diff --git a/sdk/src/openssl/mod.rs b/sdk/src/openssl/mod.rs @@ -35,13 +35,12 @@ pub(crate) mod temp_signer; #[cfg(test)] pub(crate) mod temp_signer_async; +use openssl::x509::X509; #[cfg(test)] #[allow(unused_imports)] #[cfg(feature = "async_signer")] pub(crate) use temp_signer_async::AsyncSignerAdapter; -use openssl::x509::X509; - pub(crate) fn check_chain_order(certs: &[X509]) -> bool { if certs.len() > 1 { for (i, c) in certs.iter().enumerate() { diff --git a/sdk/src/openssl/rsa_signer.rs b/sdk/src/openssl/rsa_signer.rs @@ -11,11 +11,6 @@ // specific language governing permissions and limitations under // each license. -use crate::{ - ocsp_utils::{get_ocsp_response, OcspData}, - signer::ConfigurableSigner, - Error, Result, Signer, SigningAlg, -}; use std::{cell::Cell, fs, path::Path}; //use extfmt::Hexlify; @@ -27,6 +22,11 @@ use openssl::{ }; use super::check_chain_order; +use crate::{ + ocsp_utils::{get_ocsp_response, OcspData}, + signer::ConfigurableSigner, + Error, Result, Signer, SigningAlg, +}; /// Implements `Signer` trait using OpenSSL's implementation of /// SHA256 + RSA encryption. @@ -211,7 +211,6 @@ mod tests { #![allow(clippy::unwrap_used)] use super::*; - use crate::{ utils::test::{fixture_path, temp_signer}, Signer, SigningAlg, diff --git a/sdk/src/openssl/rsa_validator.rs b/sdk/src/openssl/rsa_validator.rs @@ -11,9 +11,10 @@ // specific language governing permissions and limitations under // each license. -use crate::{validator::CoseValidator, Error, Result, SigningAlg}; use openssl::{hash::MessageDigest, pkey::PKey, rsa::Rsa}; +use crate::{validator::CoseValidator, Error, Result, SigningAlg}; + pub struct RsaValidator { alg: SigningAlg, } diff --git a/sdk/src/status_tracker.rs b/sdk/src/status_tracker.rs @@ -11,10 +11,10 @@ // specific language governing permissions and limitations under // each license. -use crate::error::{Error, Result}; - use std::fmt; +use crate::error::{Error, Result}; + #[derive(Debug)] pub struct LogItem { pub label: String, // JUBMF label of the item if available, or other descriptive label diff --git a/sdk/src/store.rs b/sdk/src/store.rs @@ -11,19 +11,17 @@ // specific language governing permissions and limitations under // each license. -use crate::{ - assertion::{Assertion, AssertionBase, AssertionDecodeError, AssertionDecodeErrorCause}, - assertions::{labels, Ingredient, Relationship}, - claim::{Claim, ClaimAssertion, ClaimAssetData}, - error::{Error, Result}, - hash_utils::{hash_by_alg, vec_compare, verify_by_alg}, - jumbf::{self, boxes::*}, - jumbf_io::{get_cailoader_handler, load_jumbf_from_memory}, - status_tracker::{log_item, OneShotStatusTracker, StatusTracker}, - validation_status, - xmp_inmemory_utils::extract_provenance, -}; +use std::{collections::HashMap, io::Cursor}; +#[cfg(feature = "file_io")] +use std::{fs, path::Path}; + +#[cfg(feature = "file_io")] +use log::error; +#[cfg(all(feature = "xmp_write", feature = "file_io"))] +use crate::embedded_xmp; +#[cfg(feature = "async_signer")] +use crate::AsyncSigner; #[cfg(feature = "file_io")] use crate::{ assertion::AssertionData, @@ -41,18 +39,19 @@ use crate::{ }, Signer, }; - -#[cfg(all(feature = "xmp_write", feature = "file_io"))] -use crate::embedded_xmp; - -#[cfg(feature = "async_signer")] -use crate::AsyncSigner; -use crate::ManifestStoreReport; -#[cfg(feature = "file_io")] -use log::error; -use std::{collections::HashMap, io::Cursor}; -#[cfg(feature = "file_io")] -use std::{fs, path::Path}; +use crate::{ + assertion::{Assertion, AssertionBase, AssertionDecodeError, AssertionDecodeErrorCause}, + assertions::{labels, Ingredient, Relationship}, + claim::{Claim, ClaimAssertion, ClaimAssetData}, + error::{Error, Result}, + hash_utils::{hash_by_alg, vec_compare, verify_by_alg}, + jumbf::{self, boxes::*}, + jumbf_io::{get_cailoader_handler, load_jumbf_from_memory}, + status_tracker::{log_item, OneShotStatusTracker, StatusTracker}, + validation_status, + xmp_inmemory_utils::extract_provenance, + ManifestStoreReport, +}; /// A `Store` maintains a list of `Claim` structs. /// @@ -360,8 +359,7 @@ impl Store { signer: &dyn AsyncSigner, box_size: usize, ) -> Result<Vec<u8>> { - use crate::cose_sign::cose_sign_async; - use crate::cose_validator::verify_cose_async; + use crate::{cose_sign::cose_sign_async, cose_validator::verify_cose_async}; let claim_bytes = claim.data()?; @@ -1937,12 +1935,11 @@ pub mod tests { #![allow(clippy::panic)] #![allow(clippy::unwrap_used)] - use super::*; - use tempfile::tempdir; use thiserror::private::PathAsDisplay; use twoway::find_bytes; + use super::*; use crate::{ assertions::{Action, Actions, Ingredient, Uuid}, claim::{AssertionStoreJsonFormat, Claim}, diff --git a/sdk/src/time_stamp.rs b/sdk/src/time_stamp.rs @@ -11,23 +11,24 @@ // specific language governing permissions and limitations under // each license. -use crate::asn1::rfc5652::CertificateChoices::Certificate; -use crate::asn1::rfc5652::{SignedData, OID_ID_SIGNED_DATA}; -use serde::{Deserialize, Serialize}; use std::convert::TryFrom; -/// Generate TimeStamp signature according to https://datatracker.ietf.org/doc/html/rfc3161 -/// using the specified Time Authority -use crate::error::{Error, Result}; -use crate::hash_utils::vec_compare; - -use crate::asn1::rfc3161::{TimeStampResp, TstInfo, OID_CONTENT_TYPE_TST_INFO}; -use crate::SigningAlg; - use bcder::decode::Constructed; +use coset::{iana, sig_structure_data, HeaderBuilder, ProtectedHeader}; +use serde::{Deserialize, Serialize}; use x509_certificate::DigestAlgorithm::{self}; -use coset::{iana, sig_structure_data, HeaderBuilder, ProtectedHeader}; +/// Generate TimeStamp signature according to https://datatracker.ietf.org/doc/html/rfc3161 +/// using the specified Time Authority +use crate::error::{Error, Result}; +use crate::{ + asn1::{ + rfc3161::{TimeStampResp, TstInfo, OID_CONTENT_TYPE_TST_INFO}, + rfc5652::{CertificateChoices::Certificate, SignedData, OID_ID_SIGNED_DATA}, + }, + hash_utils::vec_compare, + SigningAlg, +}; #[allow(dead_code)] pub(crate) fn cose_countersign_data(data: &[u8], alg: SigningAlg) -> Vec<u8> { @@ -131,9 +132,10 @@ fn time_stamp_request_http( url: &str, request: &crate::asn1::rfc3161::TimeStampReq, ) -> Result<Vec<u8>> { - use bcder::encode::Values; use std::io::Read; + use bcder::encode::Values; + const HTTP_CONTENT_TYPE_REQUEST: &str = "application/timestamp-query"; const HTTP_CONTENT_TYPE_RESPONSE: &str = "application/timestamp-reply"; diff --git a/sdk/src/utils/cbor_types.rs b/sdk/src/utils/cbor_types.rs @@ -11,11 +11,14 @@ // specific language governing permissions and limitations under // each license. -use serde::de::{Deserialize, Deserializer}; -use serde::ser::{Serialize, Serializer}; +use std::fmt; + +use serde::{ + de::{Deserialize, Deserializer}, + ser::{Serialize, Serializer}, +}; use serde_bytes::ByteBuf; use serde_cbor::tags::Tagged; -use std::fmt; // New types for C2PA that will serialize to the correct // CBOR type specified in the C2PA spec. diff --git a/sdk/src/utils/hash_utils.rs b/sdk/src/utils/hash_utils.rs @@ -19,14 +19,11 @@ use std::{ }; use log::{debug, warn}; -use serde::{Deserialize, Serialize}; - // multihash versions use multibase::{decode, encode}; use multihash::{wrap, Code, Multihash, Sha2_256, Sha2_512, Sha3_256, Sha3_384, Sha3_512}; - use range_set::RangeSet; - +use serde::{Deserialize, Serialize}; // direct sha functions use sha2::{Digest, Sha256, Sha384, Sha512}; diff --git a/sdk/src/utils/patch.rs b/sdk/src/utils/patch.rs @@ -11,11 +11,12 @@ // specific language governing permissions and limitations under // each license. -use crate::error::{Error, Result}; use twoway::find_bytes; #[cfg(all(test, feature = "file_io"))] use crate::error::wrap_io_err; +use crate::error::{Error, Result}; + /** Patch a sequence bytes with a new set of bytes - the search_bytes are erased and replaced with replace_bytes This function only patches the first occurance diff --git a/sdk/src/utils/test.rs b/sdk/src/utils/test.rs @@ -13,6 +13,10 @@ #![allow(clippy::unwrap_used)] +use std::path::PathBuf; + +use tempfile::TempDir; + use crate::{ assertions::{labels, Action, Actions, Ingredient, ReviewRating, SchemaDotOrg, Thumbnail}, claim::Claim, @@ -20,7 +24,6 @@ use crate::{ store::Store, Result, }; - #[cfg(feature = "file_io")] use crate::{ create_signer, @@ -29,9 +32,6 @@ use crate::{ SigningAlg, }; -use std::path::PathBuf; -use tempfile::TempDir; - pub const TEST_SMALL_JPEG: &str = "earth_apollo17.jpg"; pub const TEST_VC: &str = r#"{ diff --git a/sdk/src/utils/thumbnail.rs b/sdk/src/utils/thumbnail.rs @@ -11,9 +11,10 @@ // specific language governing permissions and limitations under // each license. -use crate::Result; use image::ImageFormat; +use crate::Result; + /// utility to generate a thumbnail from a file at path /// returns Result (format, image_bits) if successful, otherwise Error pub fn make_thumbnail(path: &std::path::Path) -> Result<(String, Vec<u8>)> { diff --git a/sdk/src/utils/time_it.rs b/sdk/src/utils/time_it.rs @@ -11,9 +11,10 @@ // specific language governing permissions and limitations under // each license. -use log::info; use std::time::Instant; +use log::info; + // (Internal debugging tool.) // Measure and log the time from the creation of this struct until it is dropped. pub(crate) struct TimeIt { diff --git a/sdk/src/utils/xmp_inmemory_utils.rs b/sdk/src/utils/xmp_inmemory_utils.rs @@ -11,16 +11,18 @@ // specific language governing permissions and limitations under // each license. -use crate::{ - asset_io::CAIRead, jumbf_io::get_cailoader_handler, utils::hash_utils::vec_compare, Error, - Result, -}; +use std::io::Cursor; + use log::error; use quick_xml::{ events::{BytesEnd, BytesStart, Event}, Reader, Writer, }; -use std::io::Cursor; + +use crate::{ + asset_io::CAIRead, jumbf_io::get_cailoader_handler, utils::hash_utils::vec_compare, Error, + Result, +}; const RDF_DESCRIPTION: &[u8] = b"rdf:Description"; diff --git a/sdk/src/validator.rs b/sdk/src/validator.rs @@ -11,12 +11,12 @@ // specific language governing permissions and limitations under // each license. +use chrono::{DateTime, Utc}; + #[cfg(feature = "file_io")] use crate::openssl::{EcValidator, EdValidator, RsaValidator}; use crate::{Result, SigningAlg}; -use chrono::{DateTime, Utc}; - #[derive(Debug, Default)] pub struct ValidationInfo { pub alg: Option<SigningAlg>, // validation algorithm diff --git a/sdk/src/wasm/context.rs b/sdk/src/wasm/context.rs @@ -11,11 +11,11 @@ // specific language governing permissions and limitations under // each license. -use crate::{Error, Result}; -use wasm_bindgen::prelude::*; -use wasm_bindgen::{JsCast, JsValue}; +use wasm_bindgen::{prelude::*, JsCast, JsValue}; use web_sys::{SubtleCrypto, Window, WorkerGlobalScope}; +use crate::{Error, Result}; + // Adapted from gloo's implementation, since there doesn't seem to be a great way to do context checking using // wasm-bindgen/web-sys without using something like `js_sys::eval`. References: // - Issue: https://github.com/rustwasm/wasm-bindgen/issues/1046 diff --git a/sdk/src/wasm/webcrypto_validator.rs b/sdk/src/wasm/webcrypto_validator.rs @@ -319,13 +319,12 @@ pub async fn validate_async(alg: SigningAlg, sig: &[u8], data: &[u8], pkey: &[u8 pub mod tests { #![allow(clippy::unwrap_used)] - use super::*; - - use crate::SigningAlg; - #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; + use super::*; + use crate::SigningAlg; + #[cfg(target_arch = "wasm32")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); diff --git a/sdk/tests/integration.rs b/sdk/tests/integration.rs @@ -16,11 +16,12 @@ #[cfg(feature = "file_io")] mod integration_1 { + use std::path::PathBuf; + use c2pa::{ assertions::{c2pa_action, Action, Actions}, create_signer, Ingredient, Manifest, ManifestStore, Result, Signer, SigningAlg, }; - use std::path::PathBuf; use tempfile::tempdir; const GENERATOR: &str = "app";