rcssl/
error.rs

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
use openssl::error::ErrorStack;

pub type CertGenResult<T, E = CertGenError> = Result<T, E>;

#[derive(Debug, thiserror::Error)]
pub enum CertGenError {
    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),
    #[error("Invalid profile")]
    InvalidProfile,
    #[error("Invalid CA")]
    InvalidCA,
    #[error("Invalid certificate generation: {0}")]
    InvalidCertificateGeneration(String),
    #[error("Invalid key")]
    InvalidKey,
    #[error("Invalid directory")]
    InvalidDirectory,
    #[error("Invalid UTF-8")]
    InvalidUtf8(#[from] std::str::Utf8Error),
    #[error("Invalid PEM")]
    InvalidPem(#[from] ErrorStack),
    #[error("Generation error: {0}")]
    GenerationError(String),
}

impl From<rcgen::Error> for CertGenError {
    fn from(e: rcgen::Error) -> Self {
        CertGenError::InvalidCertificateGeneration(e.to_string())
    }
}