c2pa-rs

A fork of https://github.com/contentauth/c2pa-rs/
git clone git://archive.git.mtrnord.blog/mtrnords-photography-manager/c2pa-rs.git
Log | Files | Refs | README

lib.rs (5484B)


      1 // Copyright 2022 Adobe. All rights reserved.
      2 // This file is licensed to you under the Apache License,
      3 // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
      4 // or the MIT license (http://opensource.org/licenses/MIT),
      5 // at your option.
      6 
      7 // Unless required by applicable law or agreed to in writing,
      8 // this software is distributed on an "AS IS" BASIS, WITHOUT
      9 // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
     10 // implied. See the LICENSE-MIT and LICENSE-APACHE files for the
     11 // specific language governing permissions and limitations under
     12 // each license.
     13 
     14 #![deny(warnings)]
     15 #![deny(clippy::expect_used)]
     16 #![deny(clippy::panic)]
     17 #![deny(clippy::unwrap_used)]
     18 #![warn(clippy::missing_const_for_fn)]
     19 #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg, doc_cfg_hide))]
     20 
     21 //! This library supports reading, creating and embedding C2PA data
     22 //! with a variety of asset types.
     23 //!
     24 //! We have a new experimental Builder/Reader API that will eventually replace
     25 //! the existing methods of reading and writing C2PA data.
     26 //! The new API focuses on stream support and can do more with fewer methods.
     27 //! It will be supported in all language bindings and build environments.
     28 //! To try these out, you need to enable the `unstable_api` feature.
     29 //!
     30 //! To read with file based methods, you must add the `file_io` dependency to your Cargo.toml.
     31 //! For example:
     32 //!
     33 //! ```text
     34 //! c2pa = {version="0.32.0", features=["file_io"]}
     35 //! ```
     36 //!
     37 //! # Example: Reading a ManifestStore
     38 //!
     39 //! ```
     40 //! # use c2pa::Result;
     41 //! use c2pa::{assertions::Actions, Reader};
     42 //!
     43 //! # fn main() -> Result<()> {
     44 //! let stream = std::fs::File::open("tests/fixtures/C.jpg")?;
     45 //! let reader = Reader::from_stream("image/jpeg", stream)?;
     46 //! println!("{}", reader.json());
     47 //!
     48 //! if let Some(manifest) = reader.active_manifest() {
     49 //!     let actions: Actions = manifest.find_assertion(Actions::LABEL)?;
     50 //!     for action in actions.actions {
     51 //!         println!("{}\n", action.action());
     52 //!     }
     53 //! }
     54 //! # Ok(())
     55 //! # }
     56 //! ```
     57 //!
     58 //! # Example: Adding a Manifest to a file
     59 //!
     60 //! ```
     61 //! # use c2pa::Result;
     62 //! use std::path::PathBuf;
     63 //!
     64 //! use c2pa::{create_signer, Builder, SigningAlg};
     65 //! use serde::Serialize;
     66 //! use tempfile::tempdir;
     67 //!
     68 //! #[derive(Serialize)]
     69 //! struct Test {
     70 //!     my_tag: usize,
     71 //! }
     72 //!
     73 //! # fn main() -> Result<()> {
     74 //! let mut builder = Builder::from_json(r#"{"title": "Test"}"#)?;
     75 //! builder.add_assertion("org.contentauth.test", &Test { my_tag: 42 })?;
     76 //!
     77 //! // Create a ps256 signer using certs and key files
     78 //! let signer = create_signer::from_files(
     79 //!     "tests/fixtures/certs/ps256.pub",
     80 //!     "tests/fixtures/certs/ps256.pem",
     81 //!     SigningAlg::Ps256,
     82 //!     None,
     83 //! )?;
     84 //!
     85 //! // embed a manifest using the signer
     86 //! std::fs::remove_file("../target/tmp/lib_sign.jpg"); // ensure the file does not exist
     87 //! builder.sign_file(
     88 //!     &*signer,
     89 //!     "tests/fixtures/C.jpg",
     90 //!     "../target/tmp/lib_sign.jpg",
     91 //! )?;
     92 //! # Ok(())
     93 //! # }
     94 //! ```
     95 
     96 /// The internal name of the C2PA SDK
     97 pub const NAME: &str = "c2pa-rs";
     98 
     99 /// The version of this C2PA SDK
    100 pub const VERSION: &str = env!("CARGO_PKG_VERSION");
    101 
    102 // Public modules
    103 pub mod assertions;
    104 pub mod cose_sign;
    105 #[cfg(feature = "openssl_sign")]
    106 pub mod create_signer;
    107 pub mod jumbf_io;
    108 pub mod settings;
    109 pub mod validation_status;
    110 #[cfg(target_arch = "wasm32")]
    111 pub mod wasm;
    112 
    113 // Public exports
    114 #[cfg(feature = "v1_api")]
    115 pub use asset_io::{CAIRead, CAIReadWrite};
    116 #[cfg(feature = "unstable_api")]
    117 pub use builder::{Builder, ManifestDefinition};
    118 pub use callback_signer::{CallbackFunc, CallbackSigner};
    119 pub use claim_generator_info::ClaimGeneratorInfo;
    120 pub use error::{Error, Result};
    121 pub use hash_utils::{hash_stream_by_alg, HashRange};
    122 pub use ingredient::Ingredient;
    123 #[cfg(feature = "file_io")]
    124 pub use ingredient::{DefaultOptions, IngredientOptions};
    125 pub use manifest::Manifest;
    126 pub use manifest_assertion::{ManifestAssertion, ManifestAssertionKind};
    127 #[cfg(feature = "v1_api")]
    128 pub use manifest_store::ManifestStore;
    129 #[cfg(feature = "v1_api")]
    130 pub use manifest_store_report::ManifestStoreReport;
    131 #[cfg(feature = "unstable_api")]
    132 pub use reader::Reader;
    133 pub use resource_store::{ResourceRef, ResourceStore};
    134 pub use signer::{AsyncSigner, RemoteSigner, Signer};
    135 pub use signing_alg::SigningAlg;
    136 pub use utils::mime::format_from_path;
    137 
    138 // Internal modules
    139 #[allow(dead_code, clippy::enum_variant_names)]
    140 pub(crate) mod asn1;
    141 pub(crate) mod assertion;
    142 pub(crate) mod asset_handlers;
    143 pub(crate) mod asset_io;
    144 #[cfg(feature = "unstable_api")]
    145 pub(crate) mod builder;
    146 pub(crate) mod callback_signer;
    147 pub(crate) mod claim;
    148 pub(crate) mod claim_generator_info;
    149 pub(crate) mod cose_validator;
    150 pub(crate) mod error;
    151 pub(crate) mod hashed_uri;
    152 pub(crate) mod ingredient;
    153 #[allow(dead_code)]
    154 pub(crate) mod jumbf;
    155 pub(crate) mod manifest;
    156 pub(crate) mod manifest_assertion;
    157 pub(crate) mod manifest_store;
    158 pub(crate) mod manifest_store_report;
    159 pub(crate) mod ocsp_utils;
    160 #[cfg(feature = "openssl")]
    161 pub(crate) mod openssl;
    162 #[allow(dead_code)]
    163 // TODO: Remove this when the feature is released (used in tests only for some builds now)
    164 pub(crate) mod reader;
    165 pub(crate) mod resource_store;
    166 pub(crate) mod salt;
    167 pub(crate) mod signer;
    168 pub(crate) mod signing_alg;
    169 pub(crate) mod status_tracker;
    170 pub(crate) mod store;
    171 pub(crate) mod time_stamp;
    172 pub(crate) mod trust_handler;
    173 pub(crate) mod utils;
    174 pub(crate) use utils::{cbor_types, hash_utils};
    175 pub(crate) mod validator;