1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2026 WritersLogic. All rights reserved.
// Licensed under the Apache License, Version 2.0 or the MIT license,
// at your option.
use std::fmt;
#[derive(Debug)]
pub enum Error {
/// No `-----BEGIN/END C2PA MANIFEST-----` block was located.
NotFound,
/// More than one manifest block was found. Per the specification the asset
/// shall then be treated as if no manifests were located.
MultipleBlocks,
/// The block is present but the reference between the delimiters is empty.
EmptyReference,
/// The reference is neither a resolvable URI nor a `data:` URI.
MalformedReference(String),
/// The text uses bare CR (0x0D) line endings, which are unsupported by the
/// structured-text binding method because they make line boundaries
/// ambiguous. Convert to LF or CRLF before embedding or validating.
BareCarriageReturn,
/// A `data:application/c2pa;base64,` reference could not be Base64-decoded.
ManifestDecode(crate::codec::DecodeError),
/// The exclusion ranges of a data hash assertion are malformed: negative,
/// out of order, overlapping, or extending past the end of the asset.
/// Corresponds to `assertion.dataHash.malformed`.
MalformedExclusion,
/// The recomputed data hash did not match the value in the assertion.
/// Corresponds to `assertion.dataHash.mismatch`.
HashMismatch,
/// A hash algorithm identifier outside the C2PA allowed list was requested.
/// Corresponds to `algorithm.unsupported`.
UnsupportedAlgorithm(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotFound => write!(f, "no manifest block found"),
Self::MultipleBlocks => write!(f, "multiple manifest blocks found"),
Self::EmptyReference => write!(f, "empty manifest reference"),
Self::MalformedReference(s) => write!(f, "malformed manifest reference: {s}"),
Self::BareCarriageReturn => {
write!(
f,
"bare CR line endings are not supported; convert to LF or CRLF"
)
}
Self::ManifestDecode(e) => write!(f, "manifest data URI is not valid base64: {e}"),
Self::MalformedExclusion => write!(f, "data hash exclusion range is malformed"),
Self::HashMismatch => write!(f, "data hash does not match the asset content"),
Self::UnsupportedAlgorithm(a) => write!(f, "unsupported hash algorithm: {a}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::ManifestDecode(e) => Some(e),
_ => None,
}
}
}