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

error.rs (8229B)


      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(missing_docs)] (we'll turn this on once fully documented)
     15 
     16 use thiserror::Error;
     17 
     18 /// `Error` enumerates errors returned by most C2PA toolkit operations.
     19 #[derive(Debug, Error)]
     20 #[non_exhaustive]
     21 pub enum Error {
     22     // --- c2pa errors ---
     23     /// Could not find a claim with this label.
     24     #[error("claim missing: label = {label}")]
     25     ClaimMissing { label: String },
     26 
     27     /// An assertion has an unsupported version
     28     #[error("Unsupported Assertion version")]
     29     AssertionUnsupportedVersion,
     30 
     31     /// An assertion could not be found at the expected URL.
     32     #[error("assertion missing: url = {url}")]
     33     AssertionMissing { url: String },
     34 
     35     /// The attempt to serialize the assertion (typically to JSON or CBOR) failed.
     36     #[error("unable to encode assertion data")]
     37     AssertionEncoding,
     38 
     39     #[error(transparent)]
     40     AssertionDecoding(#[from] crate::assertion::AssertionDecodeError),
     41 
     42     #[error("assertion could not be redacted")]
     43     AssertionInvalidRedaction,
     44 
     45     #[error("could not find the assertion to redact")]
     46     AssertionRedactionNotFound,
     47 
     48     #[error("bad parameter: {0}")]
     49     BadParam(String),
     50 
     51     #[error("required feature missing")]
     52     MissingFeature(String),
     53 
     54     #[error("feature implementation incomplete")]
     55     NotImplemented(String),
     56 
     57     /// The attempt to serialize the claim to CBOR failed.
     58     #[error("claim could not be converted to CBOR")]
     59     ClaimEncoding,
     60 
     61     /// The attempt to deserialize the claim from CBOR failed.
     62     #[error("claim could not be converted from CBOR")]
     63     ClaimDecoding,
     64 
     65     #[error("claim already signed, no further changes allowed")]
     66     ClaimAlreadySigned,
     67 
     68     #[error("attempt to add new claim without signing last claim")]
     69     ClaimUnsigned,
     70 
     71     #[error("missing signature box link")]
     72     ClaimMissingSignatureBox,
     73 
     74     #[error("identity required required with copyright assertion")]
     75     ClaimMissingIdentity,
     76 
     77     #[error("incompatible claim version")]
     78     ClaimVersion,
     79 
     80     #[error("invalid claim content")]
     81     ClaimInvalidContent,
     82 
     83     #[error("claim missing hard binding")]
     84     ClaimMissingHardBinding,
     85 
     86     #[error("claim contains self redactions")]
     87     ClaimSelfRedact,
     88 
     89     #[error("claim contains disallowed redactions")]
     90     ClaimDisallowedRedaction,
     91 
     92     #[error("update manifest is invalid")]
     93     UpdateManifestInvalid,
     94 
     95     #[error("more than one manifest store detected")]
     96     TooManyManifestStores,
     97 
     98     /// The COSE Sign1 structure can not be parsed.
     99     #[error("COSE Sign1 structure can not be parsed: {coset_error}")]
    100     InvalidCoseSignature {
    101         coset_error: coset::CoseError, /* NOTE: We can not use #[transparent] here because
    102                                         * coset::CoseError does not implement std::Error::error
    103                                         * and can't because coset is nostd. */
    104     },
    105 
    106     /// The COSE signature uses an algorithm that is not supported by this crate.
    107     #[error("COSE signature algorithm is not supported")]
    108     CoseSignatureAlgorithmNotSupported,
    109 
    110     #[error("COSE could not find verification key")]
    111     CoseMissingKey,
    112 
    113     /// The COSE signature did not contain a signing certificate.
    114     #[error("could not find signing certificate chain in COSE signature")]
    115     CoseX5ChainMissing,
    116 
    117     #[error("COSE error parsing certificate")]
    118     CoseInvalidCert,
    119 
    120     #[error("COSE signature invalid")]
    121     CoseSignature,
    122 
    123     #[error("COSE verifier failure")]
    124     CoseVerifier,
    125 
    126     #[error("COSE certificate has expired")]
    127     CoseCertExpiration,
    128 
    129     #[error("COSE certificate has been revoked")]
    130     CoseCertRevoked,
    131 
    132     #[error("COSE certificate not trusted")]
    133     CoseCertUntrusted,
    134 
    135     /// Unable to parse the time stamp from this signature.
    136     #[error("COSE time stamp could not be parsed")]
    137     CoseInvalidTimeStamp,
    138 
    139     #[error("COSE time stamp had expired cert")]
    140     CoseTimeStampValidity,
    141 
    142     /// The time stamp in the signature did not match the signed data.
    143     #[error("COSE time stamp does not match data")]
    144     CoseTimeStampMismatch,
    145 
    146     /// Unable to generate a trusted time stamp.
    147     #[error("could not generate a trusted time stamp")]
    148     CoseTimeStampGeneration,
    149 
    150     #[error("COSE TimeStamp Authority failure")]
    151     CoseTimeStampAuthority,
    152 
    153     #[error("COSE Signature too big for JUMBF box")]
    154     CoseSigboxTooSmall,
    155 
    156     #[error("COSE Signer does not contain signing certificate")]
    157     CoseNoCerts,
    158 
    159     #[error("WASM verifier error")]
    160     WasmVerifier,
    161 
    162     #[error("WASM RSA-PSS key import error: {0}")]
    163     WasmRsaKeyImport(String),
    164 
    165     #[error("WASM RSA-PSS verification error")]
    166     WasmRsaVerification,
    167 
    168     #[error("WASM crypto key error")]
    169     WasmKey,
    170 
    171     #[error("WASM not called from window or worker global scope")]
    172     WasmInvalidContext,
    173 
    174     #[error("WASM could not load crypto library")]
    175     WasmNoCrypto,
    176 
    177     /// Unable to generate valid JUMBF for a claim.
    178     #[error("could not create valid JUMBF for claim")]
    179     JumbfCreationError,
    180 
    181     #[error("thread receive error")]
    182     ThreadReceiveError,
    183 
    184     #[error("no JUMBF data found")]
    185     JumbfNotFound,
    186 
    187     #[error("required JUMBF box not found")]
    188     JumbfBoxNotFound,
    189 
    190     #[error("could not fetch the remote manifest")]
    191     RemoteManifestFetch(String),
    192 
    193     #[error("must fetch remote manifests from url")]
    194     RemoteManifestUrl(String),
    195 
    196     #[error("stopped because of logged error")]
    197     LogStop,
    198 
    199     #[error("not found")]
    200     NotFound,
    201 
    202     #[error("type is unsupported")]
    203     UnsupportedType,
    204 
    205     #[error("embedding error")]
    206     EmbeddingError,
    207 
    208     // Working claim errors
    209     #[error("ingredient file not found")]
    210     IngredientNotFound,
    211 
    212     #[error("file not found: {0}")]
    213     FileNotFound(String),
    214 
    215     #[error("resource not found: {0}")]
    216     ResourceNotFound(String),
    217 
    218     #[error("XMP read error")]
    219     XmpReadError(String),
    220 
    221     #[error("XMP write error")]
    222     XmpWriteError(String),
    223 
    224     #[error("XMP is not supported")]
    225     XmpNotSupported,
    226 
    227     #[error("C2PA provenance not found in XMP")]
    228     ProvenanceMissing,
    229 
    230     #[error("hash verification( {0} )")]
    231     HashMismatch(String),
    232 
    233     #[error("claim verification failure: {0}")]
    234     ClaimVerification(String),
    235 
    236     #[error("PDF read error")]
    237     PdfReadError,
    238 
    239     #[error(transparent)]
    240     InvalidClaim(#[from] crate::store::InvalidClaimError),
    241 
    242     #[error("asset could not be parsed: {0}")]
    243     InvalidAsset(String),
    244 
    245     #[error(transparent)]
    246     JumbfParseError(#[from] crate::jumbf::boxes::JumbfParseError),
    247 
    248     #[error("The Verifiable Content structure is not valid")]
    249     VerifiableCredentialInvalid,
    250 
    251     /// Could not parse ECDSA signature. (Only appears when using WASM web crypto.)
    252     #[error("could not parse ECDSA signature")]
    253     InvalidEcdsaSignature,
    254 
    255     #[error("missing data box")]
    256     MissingDataBox,
    257 
    258     #[error("could not generate XML")]
    259     XmlWriteError,
    260 
    261     #[error("unknown algorithm")]
    262     UnknownAlgorithm,
    263 
    264     // --- third-party errors ---
    265     #[error(transparent)]
    266     IoError(#[from] std::io::Error),
    267 
    268     #[error(transparent)]
    269     JsonError(#[from] serde_json::Error),
    270 
    271     #[error(transparent)]
    272     #[cfg(all(not(target_arch = "wasm32"), feature = "add_thumbnails"))]
    273     ImageError(#[from] image::ImageError),
    274 
    275     #[error(transparent)]
    276     CborError(#[from] serde_cbor::Error),
    277 
    278     #[error(transparent)]
    279     #[cfg(feature = "openssl")]
    280     OpenSslError(#[from] openssl::error::ErrorStack),
    281 
    282     #[error(transparent)]
    283     OtherError(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
    284 
    285     #[error("prerelease content detected")]
    286     PrereleaseError,
    287 }
    288 
    289 /// A specialized `Result` type for C2PA toolkit operations.
    290 pub type Result<T> = std::result::Result<T, Error>;