Skip to main content

weirdnet_tls/
error.rs

1use std::time::SystemTime;
2
3/// Errors from this crate.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6    /// The configuration is not usable.
7    #[error("config: {0}")]
8    Config(String),
9    /// A certificate or key could not be read or made.
10    #[error("certificate: {0}")]
11    Cert(String),
12    /// The ACME CA refused or failed a request.
13    #[error("acme: {0}")]
14    Acme(String),
15    /// A challenge answer could not be published.
16    #[error("challenge: {0}")]
17    Challenge(String),
18    /// The certificate store failed.
19    #[error("store: {0}")]
20    Store(String),
21    /// A forced renewal came too soon after the last issue; try again after the time given.
22    #[error("the last certificate was issued too recently to force a renewal")]
23    TooSoon(SystemTime),
24    /// An I/O error.
25    #[error(transparent)]
26    Io(#[from] std::io::Error),
27}
28
29/// `Result` with [`Error`].
30pub type Result<T, E = Error> = std::result::Result<T, E>;
31
32impl From<instant_acme::Error> for Error {
33    fn from(e: instant_acme::Error) -> Self {
34        Error::Acme(e.to_string())
35    }
36}
37
38impl From<rcgen::Error> for Error {
39    fn from(e: rcgen::Error) -> Self {
40        Error::Cert(e.to_string())
41    }
42}
43
44impl From<serde_json::Error> for Error {
45    fn from(e: serde_json::Error) -> Self {
46        Error::Store(e.to_string())
47    }
48}