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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use crate::common::crypto::{HashAlgorithm, SigningKey};
use super::{Canonicalization, DkimSigner, Done, NeedDomain, NeedHeaders, NeedSelector, Signature};
impl<T: SigningKey> DkimSigner<T> {
pub fn from_key(key: T) -> DkimSigner<T, NeedDomain> {
DkimSigner {
_state: Default::default(),
template: Signature {
v: 1,
a: key.algorithm(),
..Default::default()
},
key,
}
}
}
impl<T: SigningKey> DkimSigner<T, NeedDomain> {
pub fn domain(mut self, domain: impl Into<String>) -> DkimSigner<T, NeedSelector> {
self.template.d = domain.into();
DkimSigner {
_state: Default::default(),
key: self.key,
template: self.template,
}
}
}
impl<T: SigningKey> DkimSigner<T, NeedSelector> {
pub fn selector(mut self, selector: impl Into<String>) -> DkimSigner<T, NeedHeaders> {
self.template.s = selector.into();
DkimSigner {
_state: Default::default(),
key: self.key,
template: self.template,
}
}
}
impl<T: SigningKey> DkimSigner<T, NeedHeaders> {
pub fn headers(
mut self,
headers: impl IntoIterator<Item = impl Into<String>>,
) -> DkimSigner<T, Done> {
self.template.h = headers.into_iter().map(|h| h.into()).collect();
DkimSigner {
_state: Default::default(),
key: self.key,
template: self.template,
}
}
}
impl<T: SigningKey> DkimSigner<T, Done> {
pub fn atps(mut self, atps: impl Into<String>) -> Self {
self.template.atps = Some(atps.into());
self
}
pub fn atpsh(mut self, atpsh: HashAlgorithm) -> Self {
self.template.atpsh = atpsh.into();
self
}
pub fn agent_user_identifier(mut self, auid: impl Into<String>) -> Self {
self.template.i = auid.into();
self
}
pub fn expiration(mut self, expiration: u64) -> Self {
self.template.x = expiration;
self
}
pub fn body_length(mut self, body_length: bool) -> Self {
self.template.l = u64::from(body_length);
self
}
pub fn reporting(mut self, reporting: bool) -> Self {
self.template.r = reporting;
self
}
pub fn header_canonicalization(mut self, ch: Canonicalization) -> Self {
self.template.ch = ch;
self
}
pub fn body_canonicalization(mut self, cb: Canonicalization) -> Self {
self.template.cb = cb;
self
}
}