oxabl_cache_crypto/
error.rs1use std::fmt;
2use std::io;
3
4use oxabl_cache_format::FormatError;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum Error {
10 Format(FormatError),
12 Random,
14 KeyCommitment,
16 Authentication,
19 SegmentId,
21 Signature,
23 Compression(&'static str),
25 Limit(&'static str),
27 Io(io::ErrorKind),
29 SignerNotAccepted,
31 RosterVersionAhead,
33 Mismatch(&'static str),
35 Roster(&'static str),
37 IdentityNotInRoster,
39 Keyring(&'static str),
41 Identity(&'static str),
43}
44
45impl fmt::Display for Error {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 match self {
48 Self::Format(e) => write!(f, "format: {e}"),
49 Self::Random => f.write_str("random generator failed"),
50 Self::KeyCommitment => f.write_str("key commitment mismatch"),
51 Self::Authentication => f.write_str("authentication failed"),
52 Self::SegmentId => f.write_str("segment id mismatch"),
53 Self::Signature => f.write_str("signature invalid"),
54 Self::Compression(what) => write!(f, "compression: {what}"),
55 Self::Limit(what) => write!(f, "limit exceeded: {what}"),
56 Self::Io(kind) => write!(f, "i/o: {kind}"),
57 Self::SignerNotAccepted => f.write_str("signer not accepted"),
58 Self::RosterVersionAhead => f.write_str("record is ahead of the roster"),
59 Self::Mismatch(what) => write!(f, "mismatch: {what}"),
60 Self::Roster(what) => write!(f, "roster: {what}"),
61 Self::IdentityNotInRoster => f.write_str("identity is not in the roster"),
62 Self::Keyring(what) => write!(f, "keyring: {what}"),
63 Self::Identity(what) => write!(f, "identity: {what}"),
64 }
65 }
66}
67
68impl std::error::Error for Error {}
69
70impl From<FormatError> for Error {
71 fn from(e: FormatError) -> Self {
72 Self::Format(e)
73 }
74}
75
76impl From<io::Error> for Error {
77 fn from(e: io::Error) -> Self {
78 Self::Io(e.kind())
79 }
80}
81
82pub type Result<T> = std::result::Result<T, Error>;