Make clippy happy

- Applied many of the `clippy` suggestions.
This commit is contained in:
Malte Meiboom
2026-04-27 13:42:47 +02:00
parent 799f6eb588
commit 4e28e636a1
6 changed files with 44 additions and 43 deletions
+26 -31
View File
@@ -46,10 +46,7 @@ pub fn get_local_trust_root(cert_store: &CertStore) -> anyhow::Result<Cert> {
Ok(mut parser) => {
match parser.next() {
Some(Ok(cert)) => {
match Cert::from_bytes(cert.as_bytes()) {
Ok(c) => Some(c),
Err(_) => None,
}
Cert::from_bytes(cert.as_bytes()).ok()
},
Some(Err(_))
| None => None
@@ -89,7 +86,7 @@ pub fn get_local_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
for (fpr, some_userid) in bindings {
if let Some(userid) = some_userid {
let paths = n.authenticate(userid, &fpr, wot::FULLY_TRUSTED);
if paths.len() > 0 {
if !paths.is_empty() {
log::debug!("{} authenticated!!!", email);
for (path, _) in paths.iter() {
if let Ok(cert) = cert_store.lookup_by_cert_fpr(&path.target().fingerprint()) {
@@ -125,34 +122,32 @@ pub async fn lookup_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
let collect_certs = |certs: Vec<Result<Cert, anyhow::Error>>, email: String, policy: &StandardPolicy| {
let mut result = Vec::new();
for cert in certs {
if let Ok(c) = cert {
if let Ok(vc) = c.with_policy(policy, None) {
for cert in certs.into_iter().flatten() {
if let Ok(vc) = cert.with_policy(policy, None) {
// check if the returned certificate contains a userid with the
// email address in question.
let mut userid_found = false;
for userid in vc.userids() {
if let Ok(Some(u)) = userid.userid().email() {
if u == email {
userid_found = true;
}
// check if the returned certificate contains a userid with the
// email address in question.
let mut userid_found = false;
for userid in vc.userids() {
if let Ok(Some(u)) = userid.userid().email() {
if u == email {
userid_found = true;
}
}
}
if userid_found {
// check if the certificate can be used (for encryption).
vc.keys()
.supported()
.alive()
.revoked(false)
.for_transport_encryption()
.for_each(|_| {
// XXX: cert gets returned for each transport key
// once would be enough
result.push(c.clone());
});
}
if userid_found {
// check if the certificate can be used (for encryption).
vc.keys()
.supported()
.alive()
.revoked(false)
.for_transport_encryption()
.for_each(|_| {
// XXX: cert gets returned for each transport key
// once would be enough
result.push(cert.clone());
});
}
}
}
@@ -239,7 +234,7 @@ pub async fn get_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
log::debug!("get certificate for {}", email);
let locals = get_local_certificates(context, email);
if locals.len() > 0 {
if !locals.is_empty() {
return locals;
}
@@ -363,7 +358,7 @@ pub fn encrypt(context: &HuskContext<'_>, body: &Bytes, recipients: &Vec<Recipie
}
}
}
if keys.len() > 0 {
if !keys.is_empty() {
let mut sink = Vec::new();
let message = Message::new(&mut sink);
let message = Armorer::new(message).build()?;
+6 -7
View File
@@ -94,7 +94,7 @@ impl Daemon {
match HuskContext::new(&config) {
Ok(context) => {
log::debug!("found introducers: {:?}", context.introducers);
cx.data = Some(context).take();
cx.data = Some(context);
Status::Continue
},
Err(e) => {
@@ -138,13 +138,12 @@ impl Daemon {
break;
}
}
if rcpt.is_none() {
Status::Tempfail
} else {
context.add_recipient(rcpt.unwrap()).await;
if let Some(rcpt) = rcpt {
context.add_recipient(rcpt).await;
Status::Continue
} else {
Status::Tempfail
}
} else {
Status::Tempfail
}
@@ -213,7 +212,7 @@ impl Daemon {
if protection == ProtectionPossibility::Full {
// if an error occures the body is not exchanged
match crypto::encrypt(&context, &body, &context.mail.recipients) {
match crypto::encrypt(context, &body, &context.mail.recipients) {
Ok(encrypted) => {
if cx.actions.replace_body(&encrypted).await.is_err() {
log::error!("Cannot exchange body");
+1 -1
View File
@@ -59,7 +59,7 @@ impl<'hc> HuskContext<'hc> {
pub async fn add_recipient(&mut self, rcpt: String) {
let certs = crypto::get_certificates(&self, rcpt.as_str()).await;
let certs = crypto::get_certificates(self, rcpt.as_str()).await;
self.mail.add_recipient(rcpt, certs)
}
+1 -1
View File
@@ -64,7 +64,7 @@ impl Display for Introducer {
.map(|u| String::from_utf8_lossy(u.userid().value()).to_string())
.collect::<Vec<String>>()
.join(", ");
write!(f, "Introducer: {}\n", self.cert.fingerprint())?;
writeln!(f, "Introducer: {}", self.cert.fingerprint())?;
write!(f, " UserIDs: {}", uids)?;
Ok(())
}
+7
View File
@@ -66,6 +66,13 @@ impl<'mc> MailContext<'mc> {
}
/// Default Mailcontext
impl<'mc> Default for MailContext<'mc> {
fn default() -> Self {
Self::new()
}
}
impl From<&MailContext<'_>> for ProtectionPossibility {
fn from(mail_context: &MailContext<'_>) -> ProtectionPossibility {
let mut can_encrypt = false;
+3 -3
View File
@@ -17,8 +17,8 @@ pub struct Recipient<'r> {
impl From<String> for Recipient<'_> {
fn from(email: String) -> Self {
Recipient {
email: email,
Recipient {
email,
certs: Vec::new()
}
}
@@ -40,7 +40,7 @@ impl Recipient<'_> {
/// check if this Recipient can encrypt.
// XXX: currently this check is naive
pub fn can_encrypt(&self) -> bool {
if self.certs.len() == 0 {
if self.certs.is_empty() {
return false;
}