Skip to main content

c2pa_fonts/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5    /// No `C2PA` table is present in the font.
6    NotFound,
7    /// The font is not a supported SFNT (TrueType/OpenType) file.
8    NotSfnt,
9    /// Font collections (`ttcf`) are not supported.
10    Collection,
11    /// WOFF/WOFF2 wrapped fonts are not supported; decompress to SFNT first.
12    Woff,
13    /// The SFNT structure could not be parsed.
14    InvalidFont(String),
15    /// The `C2PA` table could not be parsed or violates the spec.
16    InvalidTable(String),
17    /// Hard-binding or delegated (c2pa-rs) validation failed.
18    Validation(String),
19    Io(std::io::Error),
20}
21
22impl fmt::Display for Error {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            Self::NotFound => write!(f, "no C2PA table found in font"),
26            Self::NotSfnt => write!(f, "not a supported SFNT (TrueType/OpenType) font"),
27            Self::Collection => write!(f, "font collections (ttcf) are not supported"),
28            Self::Woff => write!(
29                f,
30                "WOFF/WOFF2 fonts are not supported; decompress to SFNT first"
31            ),
32            Self::InvalidFont(s) => write!(f, "invalid font: {s}"),
33            Self::InvalidTable(s) => write!(f, "invalid C2PA table: {s}"),
34            Self::Validation(s) => write!(f, "validation failed: {s}"),
35            Self::Io(e) => write!(f, "I/O error: {e}"),
36        }
37    }
38}
39
40impl std::error::Error for Error {}
41
42impl From<std::io::Error> for Error {
43    fn from(e: std::io::Error) -> Self {
44        Self::Io(e)
45    }
46}