msg_auth_status/
error.rs

1//! Public errors
2
3/// Parsing Detail relating to an Error
4#[derive(Clone, Debug, PartialEq)]
5pub struct ParsingDetail<'hdr> {
6    /// Component
7    pub component: &'static str,
8    /// Span start
9    pub span_start: usize,
10    /// Span end
11    pub span_end: usize,
12    /// Source
13    pub source: &'hdr str,
14    /// Clipped span
15    pub clipped_span: &'hdr str,
16    /// Clipped remaining
17    pub clipped_remaining: &'hdr str,
18}
19
20/// Errors relating to parsing Authentication-Results Header
21#[derive(Clone, Debug, PartialEq)]
22pub enum AuthResultsError<'hdr> {
23    /// Could not find the ending for unknown method block beginning from
24    RunawayUnknownMethod(usize),
25    /// Detailed with ParsingDetail
26    ParsingDetailed(ParsingDetail<'hdr>),
27    /// No header
28    NoHeader,
29    /// Unknown parsing error
30    Parse,
31    /// Comment parsing error
32    ParseComment(CommentError<'hdr>),
33    /// Host parsing error
34    ParseHost(String),
35    /// Bug
36    ParsePtypeBugGating,
37    /// Bug
38    ParsePtypeBugInvalidProperty,
39    /// Bug
40    ParsePtypeBugPropertyGating,
41    /// Invalid associated ptype Encountered
42    ParsePtypeInvalidAssociatedPtype(ParsingDetail<'hdr>),
43    /// Invalid dkim method Result Code
44    InvalidDkimResult(String),
45    /// Invalid spf method Result Code
46    InvalidSpfResult(String),
47    /// Invalid iprev method Result Code
48    InvalidIpRevResult(String),
49    /// Was not a valid ptype/property per IANA and strict validation was used
50    InvalidProperty,
51    /// Invalid auth method Result code
52    InvalidSmtpAuthResult(String),
53    /// Invalid stage in result
54    InvalidResultStage,
55    /// Invalid version - Only 1 allowed
56    InvalidVersion,
57    /// No associated version found when required
58    NoAssociatedVersion,
59    /// No associated policy found when defined
60    NoAssociatedPolicy,
61    /// No assicited reason found when defined
62    NoAssociatedReason,
63    /// No hostname found that is required
64    NoHostname,
65    /// Err
66    ParsePtypeNoMethodResult,
67    /// Bug property keys not implemented for ptype
68    PropertiesNotImplemented,
69    /// Bug property values not implemented for ptype
70    PropertyValuesNotImplemented,
71    /// Run-away auth method property key
72    RunAwayAuthPropertyKey,
73    /// Run-away auth method property value
74    RunAwayAuthPropertyValue,
75    /// Run-away comment
76    RunAwayComment,
77    /// Run-away dkim method property key
78    RunAwayDkimPropertyKey,
79    /// Run-away dkim method property value
80    RunAwayDkimPropertyValue,
81    /// Run-away iprev method property key
82    RunAwayIpRevPropertyKey,
83    /// Run-away iprev method property value
84    RunAwayIpRevPropertyValue,
85    /// Run-away spf method property key
86    RunAwaySpfPropertyKey,
87    /// Run-away spf method property value
88    RunAwaySpfPropertyValue,
89    /// Unexpected forward slash
90    UnexpectedForwardSlash,
91    /// Bug
92    ParseCurrentPushNotImplemented,
93}
94
95/// DKIM-Signature header parsing Errors
96#[derive(Debug)]
97pub enum DkimSignatureError<'hdr> {
98    /// Detailed with ParsingDetail
99    ParsingDetailed(ParsingDetail<'hdr>),
100    /// No tags found at all
101    NoTagFound,
102    /// Encountered unexpected Equal '=' character when a tag was expected
103    UnexpectedEqual,
104    /// Error (from lexer) trying to parse value - Unmatched
105    ParseValueUnmatch,
106    /// Error (from parse conversion) trying to parse a valid value on tag
107    ParseValueInvalid(DkimTagValueError),
108    /// Missign Required v=
109    MissingVersion,
110    /// Msising Required a=
111    MissingAlgorithm,
112    /// Msising Required b=
113    MissingSignature,
114    /// Missing Required bh=
115    MissingBodyHash,
116    /// Missing Required d=
117    MissingResponsibleSdid,
118    /// Msising Required h=
119    MissingSignedHeaderFields,
120    /// Missing Required s=
121    MissingSelector,
122}
123
124/// Currently no error - may change in future
125#[derive(Debug, PartialEq)]
126pub enum DkimAlgorithmError {}
127
128/// Currently infallible may be changed in the future
129#[derive(Clone, Debug, PartialEq)]
130pub enum DkimCanonicalizationError {}
131
132/// Currently infallible, may change in the future
133#[derive(Debug, PartialEq)]
134pub enum DkimTimestampError {}
135
136/// Currently infallible, may change in the future
137#[derive(Debug, PartialEq)]
138pub enum DkimVersionError {}
139
140// Currently no errors - may change in the future
141//#[derive(Clone, Debug, PartialEq)]
142//pub enum DkimHeaderError {}
143
144/// DKIM Header tags values parsing error
145#[derive(Debug, PartialEq)]
146pub enum DkimTagValueError {
147    /// Tag value must appear only once per tag
148    Duplicate,
149    /// DKIM Timestamp parsing error
150    Timestamp(DkimTimestampError),
151    /// DKIM Canonizalition parsing error
152    Canonicalization(DkimCanonicalizationError),
153    /// DKIM Algorithm parsing error
154    Algorithm(DkimAlgorithmError),
155    /// DKIM Version parsing error
156    Version(DkimVersionError),
157}
158
159impl<'hdr> From<DkimTagValueError> for DkimSignatureError<'hdr> {
160    fn from(e: DkimTagValueError) -> Self {
161        Self::ParseValueInvalid(e)
162    }
163}
164
165impl From<DkimTimestampError> for DkimTagValueError {
166    fn from(e: DkimTimestampError) -> Self {
167        Self::Timestamp(e)
168    }
169}
170
171impl From<DkimCanonicalizationError> for DkimTagValueError {
172    fn from(e: DkimCanonicalizationError) -> Self {
173        Self::Canonicalization(e)
174    }
175}
176
177impl From<DkimAlgorithmError> for DkimTagValueError {
178    fn from(e: DkimAlgorithmError) -> Self {
179        Self::Algorithm(e)
180    }
181}
182
183impl From<DkimVersionError> for DkimTagValueError {
184    fn from(e: DkimVersionError) -> Self {
185        Self::Version(e)
186    }
187}
188
189/// Comment errors
190#[derive(Clone, Debug, PartialEq)]
191pub enum CommentError<'hdr> {
192    /// None found
193    RunAway,
194    /// Detailed with ParsingDetail
195    ParsingDetailed(ParsingDetail<'hdr>),
196}
197
198/// Quoted value parsing error
199#[derive(Clone, Debug, PartialEq)]
200pub enum QuotedError<'hdr> {
201    /// Bug
202    Bug,
203    /// None found
204    RunAway,
205    /// Detailed with ParsingDetail    
206    ParsingDetailed(ParsingDetail<'hdr>),
207}
208
209/// Addr-Spec parsing errors
210#[derive(Clone, Debug, PartialEq)]
211pub enum AddrSpecError<'hdr> {
212    /// Local part not found
213    NoAssociatedLocalPart,
214    /// Domain not found
215    NoAssociatedDomain,
216    /// None found
217    NoAssociatedAddrSpec,
218    /// Detailed with ParsingDetail
219    ParsingDetailed(ParsingDetail<'hdr>),
220    /// Parsing failed at comment
221    ParseComment(CommentError<'hdr>),
222    /// Parsing display name failed
223    ParseDisplayName(QuotedError<'hdr>),
224}
225
226/// Return-Path verifier errors
227#[derive(Debug, PartialEq)]
228pub enum ReturnPathVerifierError<'hdr> {
229    /// Bug encountered with attempted verify - selector didn't match error / success
230    BugSelectorFalse,
231    /// Encountered multiple Return-Path headers
232    MultipleNotAllowed,
233    /// Return-Path header not present
234    NoHeader,
235    /// Invalid Return Path
236    InvalidHeader(AddrSpecError<'hdr>),
237}