1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5 NotFound,
7 NotSfnt,
9 Collection,
11 Woff,
13 InvalidFont(String),
15 InvalidTable(String),
17 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}