msg_auth_status/dkim/
canonicalization.rs

1//! DKIM Canonicalization behaviour
2
3/// DKIM Canonicalization (per RFC)
4#[derive(Clone, Debug, Default, PartialEq)]
5pub enum DkimCanonicalization<'hdr> {
6    /// simple/simple & simple algorithm tolerates almost no modification    
7    #[default]
8    Simple,
9    /// relaxed/simple & relaxed algorithm tolerates common modifications such
10    /// as whitespace replacement and header field line rewrapping.
11    Relaxed,
12    /// Unknown RFC does not define
13    Unknown(&'hdr str),
14}
15
16use crate::error::DkimCanonicalizationError;
17
18impl<'hdr> TryFrom<&'hdr str> for DkimCanonicalization<'hdr> {
19    type Error = DkimCanonicalizationError;
20
21    fn try_from(hdr: &'hdr str) -> Result<Self, Self::Error> {
22        let ret = match hdr {
23            "simple" => Self::Simple,
24            "simple/simple" => Self::Simple,
25            "relaxed" => Self::Relaxed,
26            "relaxed/relaxed" => Self::Relaxed,
27            "relaxed/simple" => Self::Relaxed,
28            _ => Self::Unknown(hdr),
29        };
30        Ok(ret)
31    }
32}