Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Jan 27, 2023
1 parent b7b1b4d commit a5a91a1
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 110 deletions.
2 changes: 1 addition & 1 deletion examples/report_arf_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ fn main() {
.unwrap();

// Print ARF feedback to stdout
println!("{}", feedback);
println!("{feedback}");
}
2 changes: 1 addition & 1 deletion examples/report_dmarc_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ fn main() {
.unwrap();

// Print report to stdout
println!("{}", report);
println!("{report}");
}
2 changes: 1 addition & 1 deletion src/arc/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ mod test {
.selector(s)
.headers(["From", "To", "Subject", "DKIM-Signature"])
.seal(&message, &auth_results, &arc_result)
.unwrap_or_else(|err| panic!("Got {:?} for {}", err, raw_message));
.unwrap_or_else(|err| panic!("Got {err:?} for {raw_message}"));
format!(
"{}{}{}",
arc.to_header(),
Expand Down
2 changes: 1 addition & 1 deletion src/arc/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mod test {
{
#[cfg(any(test, feature = "test"))]
resolver.txt_add(
format!("{}.", key),
format!("{key}."),
DomainKey::parse(value).unwrap(),
Instant::now() + Duration::new(3200, 0),
);
Expand Down
42 changes: 17 additions & 25 deletions src/common/auth_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'x> AuthenticationResults<'x> {
}

if dkim.is_atps {
write!(self.auth_results, " header.from={}", header_from).ok();
write!(self.auth_results, " header.from={header_from}").ok();
}
}

Expand All @@ -84,10 +84,10 @@ impl<'x> AuthenticationResults<'x> {
spf.result.as_spf_result(
&mut self.auth_results,
self.hostname,
&format!("postmaster@{}", ehlo_domain),
&format!("postmaster@{ehlo_domain}"),
ip_addr,
);
write!(self.auth_results, " smtp.helo={}", ehlo_domain).ok();
write!(self.auth_results, " smtp.helo={ehlo_domain}").ok();
self
}

Expand All @@ -101,7 +101,7 @@ impl<'x> AuthenticationResults<'x> {
let (mail_from, addr) = if !from.is_empty() {
(Cow::from(from), from)
} else {
(format!("postmaster@{}", ehlo_domain).into(), "<>")
(format!("postmaster@{ehlo_domain}").into(), "<>")
};
self.auth_results.push_str(";\r\n\tspf=");
spf.result.as_spf_result(
Expand All @@ -110,14 +110,14 @@ impl<'x> AuthenticationResults<'x> {
mail_from.as_ref(),
ip_addr,
);
write!(self.auth_results, " smtp.mailfrom={}", addr).ok();
write!(self.auth_results, " smtp.mailfrom={addr}").ok();
self
}

pub fn with_arc_result(mut self, arc: &ArcOutput, remote_ip: IpAddr) -> Self {
self.auth_results.push_str(";\r\n\tarc=");
arc.result.as_auth_result(&mut self.auth_results);
write!(self.auth_results, " smtp.remote-ip={}", remote_ip).ok();
write!(self.auth_results, " smtp.remote-ip={remote_ip}").ok();
self
}

Expand All @@ -144,7 +144,7 @@ impl<'x> AuthenticationResults<'x> {
pub fn with_iprev_result(mut self, iprev: &IprevOutput, remote_ip: IpAddr) -> Self {
self.auth_results.push_str(";\r\n\tiprev=");
iprev.result.as_auth_result(&mut self.auth_results);
write!(self.auth_results, " policy.iprev={}", remote_ip).ok();
write!(self.auth_results, " policy.iprev={remote_ip}").ok();
self
}
}
Expand Down Expand Up @@ -189,16 +189,15 @@ impl ReceivedSpf {
let mail_from = if !mail_from.is_empty() {
Cow::from(mail_from)
} else {
format!("postmaster@{}", helo).into()
format!("postmaster@{helo}").into()
};

spf.result
.as_spf_result(&mut received_spf, hostname, mail_from.as_ref(), ip_addr);

write!(
received_spf,
"\r\n\treceiver={}; client-ip={}; envelope-from=\"{}\"; helo={};",
hostname, ip_addr, mail_from, helo
"\r\n\treceiver={hostname}; client-ip={ip_addr}; envelope-from=\"{mail_from}\"; helo={helo};",
)
.ok();

Expand All @@ -211,38 +210,31 @@ impl SpfResult {
match &self {
SpfResult::Pass => write!(
header,
"pass ({}: domain of {} designates {} as permitted sender)",
hostname, mail_from, ip_addr
"pass ({hostname}: domain of {mail_from} designates {ip_addr} as permitted sender)",
),
SpfResult::Fail => write!(
header,
"fail ({}: domain of {} does not designate {} as permitted sender)",
hostname, mail_from, ip_addr
"fail ({hostname}: domain of {mail_from} does not designate {ip_addr} as permitted sender)",
),
SpfResult::SoftFail => write!(
header,
"softfail ({}: domain of {} reports soft fail for {})",
hostname, mail_from, ip_addr
"softfail ({hostname}: domain of {mail_from} reports soft fail for {ip_addr})",
),
SpfResult::Neutral => write!(
header,
"neutral ({}: domain of {} reports neutral for {})",
hostname, mail_from, ip_addr
"neutral ({hostname}: domain of {mail_from} reports neutral for {ip_addr})",
),
SpfResult::TempError => write!(
header,
"temperror ({}: temporary dns error validating {})",
hostname, mail_from
"temperror ({hostname}: temporary dns error validating {mail_from})",
),
SpfResult::PermError => write!(
header,
"permerror ({}: unable to verify SPF record for {})",
hostname, mail_from,
"permerror ({hostname}: unable to verify SPF record for {mail_from})",
),
SpfResult::None => write!(
header,
"none ({}: no SPF records found for {})",
hostname, mail_from
"none ({hostname}: no SPF records found for {mail_from})",
),
}
.ok();
Expand Down Expand Up @@ -343,7 +335,7 @@ impl AsAuthResult for Error {
Error::DnsError(_) => "dns error",
Error::DnsRecordNotFound(_) => "dns record not found",
Error::ArcInvalidInstance(i) => {
write!(header, "invalid ARC instance {})", i).ok();
write!(header, "invalid ARC instance {i})").ok();
return;
}
Error::ArcInvalidCV => "invalid ARC cv",
Expand Down
2 changes: 1 addition & 1 deletion src/dkim/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Signature {
for &ch in self.i.as_bytes().iter() {
match ch {
0..=0x20 | b';' | 0x7f..=u8::MAX => {
writer.write_len(format!("={:02X}", ch).as_bytes(), &mut bw);
writer.write_len(format!("={ch:02X}").as_bytes(), &mut bw);
}
_ => {
writer.write_len(&[ch], &mut bw);
Expand Down
28 changes: 14 additions & 14 deletions src/dkim/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,20 +605,20 @@ mod test {
),
] {
let result = Signature::parse(signature.as_bytes()).unwrap();
assert_eq!(result.v, expected_result.v, "{:?}", signature);
assert_eq!(result.a, expected_result.a, "{:?}", signature);
assert_eq!(result.d, expected_result.d, "{:?}", signature);
assert_eq!(result.s, expected_result.s, "{:?}", signature);
assert_eq!(result.i, expected_result.i, "{:?}", signature);
assert_eq!(result.b, expected_result.b, "{:?}", signature);
assert_eq!(result.bh, expected_result.bh, "{:?}", signature);
assert_eq!(result.h, expected_result.h, "{:?}", signature);
assert_eq!(result.z, expected_result.z, "{:?}", signature);
assert_eq!(result.l, expected_result.l, "{:?}", signature);
assert_eq!(result.x, expected_result.x, "{:?}", signature);
assert_eq!(result.t, expected_result.t, "{:?}", signature);
assert_eq!(result.ch, expected_result.ch, "{:?}", signature);
assert_eq!(result.cb, expected_result.cb, "{:?}", signature);
assert_eq!(result.v, expected_result.v, "{signature:?}");
assert_eq!(result.a, expected_result.a, "{signature:?}");
assert_eq!(result.d, expected_result.d, "{signature:?}");
assert_eq!(result.s, expected_result.s, "{signature:?}");
assert_eq!(result.i, expected_result.i, "{signature:?}");
assert_eq!(result.b, expected_result.b, "{signature:?}");
assert_eq!(result.bh, expected_result.bh, "{signature:?}");
assert_eq!(result.h, expected_result.h, "{signature:?}");
assert_eq!(result.z, expected_result.z, "{signature:?}");
assert_eq!(result.l, expected_result.l, "{signature:?}");
assert_eq!(result.x, expected_result.x, "{signature:?}");
assert_eq!(result.t, expected_result.t, "{signature:?}");
assert_eq!(result.ch, expected_result.ch, "{signature:?}");
assert_eq!(result.cb, expected_result.cb, "{signature:?}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/dkim/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ mod test {
DkimResult::Fail(hdr) | DkimResult::PermError(hdr) | DkimResult::Neutral(hdr),
Err(err),
) if hdr == err => (),
(result, expect) => panic!("Expected {:?} but got {:?}.", expect, result),
(result, expect) => panic!("Expected {expect:?} but got {result:?}."),
}

dkim.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion src/dkim/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ mod test {
{
#[cfg(any(test, feature = "test"))]
resolver.txt_add(
format!("{}.", key),
format!("{key}."),
DomainKey::parse(value).unwrap(),
Instant::now() + Duration::new(3200, 0),
);
Expand Down
5 changes: 2 additions & 3 deletions src/dmarc/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,9 @@ mod test {
] {
assert_eq!(
Dmarc::parse(record.as_bytes())
.unwrap_or_else(|err| panic!("{:?} : {:?}", record, err)),
.unwrap_or_else(|err| panic!("{record:?} : {err:?}")),
expected_result,
"{}",
record
"{record}"
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/dmarc/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ impl Resolver {
let has_dkim_pass = dkim_output.iter().any(|o| o.result == DkimResult::Pass);
if spf_output.result == SpfResult::Pass || has_dkim_pass {
// Check SPF alignment
let from_subdomain = format!(".{}", from_domain);
let from_subdomain = format!(".{from_domain}");
if spf_output.result == SpfResult::Pass {
output.spf_result = if mail_from_domain == from_domain {
DmarcResult::Pass
} else if dmarc.aspf == Alignment::Relaxed
&& mail_from_domain.ends_with(&from_subdomain)
|| from_domain.ends_with(&format!(".{}", mail_from_domain))
|| from_domain.ends_with(&format!(".{mail_from_domain}"))
{
output.policy = dmarc.sp;
DmarcResult::Pass
Expand Down
30 changes: 15 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ impl Display for Error {
Error::ParseError => write!(f, "Parse error"),
Error::MissingParameters => write!(f, "Missing parameters"),
Error::NoHeadersFound => write!(f, "No headers found"),
Error::CryptoError(err) => write!(f, "Cryptography layer error: {}", err),
Error::Io(e) => write!(f, "I/O error: {}", e),
Error::CryptoError(err) => write!(f, "Cryptography layer error: {err}"),
Error::Io(e) => write!(f, "I/O error: {e}"),
Error::Base64 => write!(f, "Base64 encode or decode error."),
Error::UnsupportedVersion => write!(f, "Unsupported version in DKIM Signature"),
Error::UnsupportedAlgorithm => write!(f, "Unsupported algorithm in DKIM Signature"),
Expand All @@ -499,15 +499,15 @@ impl Display for Error {
Error::SignatureExpired => write!(f, "Signature expired"),
Error::FailedAuidMatch => write!(f, "AUID does not match domain name"),
Error::ArcInvalidInstance(i) => {
write!(f, "Invalid 'i={}' value found in ARC header", i)
write!(f, "Invalid 'i={i}' value found in ARC header")
}
Error::ArcInvalidCV => write!(f, "Invalid 'cv=' value found in ARC header"),
Error::ArcHasHeaderTag => write!(f, "Invalid 'h=' tag present in ARC-Seal"),
Error::ArcBrokenChain => write!(f, "Broken or missing ARC chain"),
Error::ArcChainTooLong => write!(f, "Too many ARC headers"),
Error::InvalidRecordType => write!(f, "Invalid record"),
Error::DnsError(err) => write!(f, "DNS resolution error: {}", err),
Error::DnsRecordNotFound(code) => write!(f, "DNS record not found: {}", code),
Error::DnsError(err) => write!(f, "DNS resolution error: {err}"),
Error::DnsRecordNotFound(code) => write!(f, "DNS record not found: {code}"),
Error::NotAligned => write!(f, "Policy not aligned"),
}
}
Expand All @@ -531,9 +531,9 @@ impl Display for IprevResult {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
IprevResult::Pass => f.write_str("pass"),
IprevResult::Fail(err) => write!(f, "fail; {}", err),
IprevResult::TempError(err) => write!(f, "temp error; {}", err),
IprevResult::PermError(err) => write!(f, "perm error; {}", err),
IprevResult::Fail(err) => write!(f, "fail; {err}"),
IprevResult::TempError(err) => write!(f, "temp error; {err}"),
IprevResult::PermError(err) => write!(f, "perm error; {err}"),
IprevResult::None => f.write_str("none"),
}
}
Expand All @@ -543,10 +543,10 @@ impl Display for DkimResult {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DkimResult::Pass => f.write_str("pass"),
DkimResult::Fail(err) => write!(f, "fail; {}", err),
DkimResult::Neutral(err) => write!(f, "neutral; {}", err),
DkimResult::TempError(err) => write!(f, "temp error; {}", err),
DkimResult::PermError(err) => write!(f, "perm error; {}", err),
DkimResult::Fail(err) => write!(f, "fail; {err}"),
DkimResult::Neutral(err) => write!(f, "neutral; {err}"),
DkimResult::TempError(err) => write!(f, "temp error; {err}"),
DkimResult::PermError(err) => write!(f, "perm error; {err}"),
DkimResult::None => f.write_str("none"),
}
}
Expand All @@ -556,9 +556,9 @@ impl Display for DmarcResult {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DmarcResult::Pass => f.write_str("pass"),
DmarcResult::Fail(err) => write!(f, "fail; {}", err),
DmarcResult::TempError(err) => write!(f, "temp error; {}", err),
DmarcResult::PermError(err) => write!(f, "perm error; {}", err),
DmarcResult::Fail(err) => write!(f, "fail; {err}"),
DmarcResult::TempError(err) => write!(f, "temp error; {err}"),
DmarcResult::PermError(err) => write!(f, "perm error; {err}"),
DmarcResult::None => f.write_str("none"),
}
}
Expand Down
Loading

0 comments on commit a5a91a1

Please sign in to comment.