use super::{Canonicalization, DkimSigner, Done, NeedDomain, NeedHeaders, NeedSelector, Signature};
use crate::common::crypto::{HashAlgorithm, SigningKey};
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
}
}