rustls_cert_file_reader/
format.rs

1//! The certificate file formats.
2
3use std::str::FromStr;
4
5/// Format of the certificate/key file.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum Format {
8    /// PEM format.
9    PEM,
10    /// DER format
11    /// PKCS8 specifically, other formats are not supported via this DER.
12    DER,
13}
14
15/// Error for the format parsing.
16#[derive(Debug, thiserror::Error)]
17#[error("unknown format: {0}")]
18pub struct FormatParseError(pub String);
19
20impl FromStr for Format {
21    type Err = FormatParseError;
22
23    fn from_str(s: &str) -> Result<Self, Self::Err> {
24        Ok(match s {
25            "pem" => Self::PEM,
26            "der" => Self::DER,
27            other => return Err(FormatParseError(other.to_owned())),
28        })
29    }
30}