Make clippy happy
- Applied many of the `clippy` suggestions.
This commit is contained in:
+7
-12
@@ -46,10 +46,7 @@ pub fn get_local_trust_root(cert_store: &CertStore) -> anyhow::Result<Cert> {
|
|||||||
Ok(mut parser) => {
|
Ok(mut parser) => {
|
||||||
match parser.next() {
|
match parser.next() {
|
||||||
Some(Ok(cert)) => {
|
Some(Ok(cert)) => {
|
||||||
match Cert::from_bytes(cert.as_bytes()) {
|
Cert::from_bytes(cert.as_bytes()).ok()
|
||||||
Ok(c) => Some(c),
|
|
||||||
Err(_) => None,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Some(Err(_))
|
Some(Err(_))
|
||||||
| None => None
|
| None => None
|
||||||
@@ -89,7 +86,7 @@ pub fn get_local_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
|
|||||||
for (fpr, some_userid) in bindings {
|
for (fpr, some_userid) in bindings {
|
||||||
if let Some(userid) = some_userid {
|
if let Some(userid) = some_userid {
|
||||||
let paths = n.authenticate(userid, &fpr, wot::FULLY_TRUSTED);
|
let paths = n.authenticate(userid, &fpr, wot::FULLY_TRUSTED);
|
||||||
if paths.len() > 0 {
|
if !paths.is_empty() {
|
||||||
log::debug!("{} authenticated!!!", email);
|
log::debug!("{} authenticated!!!", email);
|
||||||
for (path, _) in paths.iter() {
|
for (path, _) in paths.iter() {
|
||||||
if let Ok(cert) = cert_store.lookup_by_cert_fpr(&path.target().fingerprint()) {
|
if let Ok(cert) = cert_store.lookup_by_cert_fpr(&path.target().fingerprint()) {
|
||||||
@@ -125,9 +122,8 @@ 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 collect_certs = |certs: Vec<Result<Cert, anyhow::Error>>, email: String, policy: &StandardPolicy| {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
|
|
||||||
for cert in certs {
|
for cert in certs.into_iter().flatten() {
|
||||||
if let Ok(c) = cert {
|
if let Ok(vc) = cert.with_policy(policy, None) {
|
||||||
if let Ok(vc) = c.with_policy(policy, None) {
|
|
||||||
|
|
||||||
// check if the returned certificate contains a userid with the
|
// check if the returned certificate contains a userid with the
|
||||||
// email address in question.
|
// email address in question.
|
||||||
@@ -150,12 +146,11 @@ pub async fn lookup_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
|
|||||||
.for_each(|_| {
|
.for_each(|_| {
|
||||||
// XXX: cert gets returned for each transport key
|
// XXX: cert gets returned for each transport key
|
||||||
// once would be enough
|
// once would be enough
|
||||||
result.push(c.clone());
|
result.push(cert.clone());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
result
|
result
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -239,7 +234,7 @@ pub async fn get_certificates<'hc>(context: &HuskContext<'hc>, email: &str)
|
|||||||
log::debug!("get certificate for {}", email);
|
log::debug!("get certificate for {}", email);
|
||||||
|
|
||||||
let locals = get_local_certificates(context, email);
|
let locals = get_local_certificates(context, email);
|
||||||
if locals.len() > 0 {
|
if !locals.is_empty() {
|
||||||
return locals;
|
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 mut sink = Vec::new();
|
||||||
let message = Message::new(&mut sink);
|
let message = Message::new(&mut sink);
|
||||||
let message = Armorer::new(message).build()?;
|
let message = Armorer::new(message).build()?;
|
||||||
|
|||||||
+6
-7
@@ -94,7 +94,7 @@ impl Daemon {
|
|||||||
match HuskContext::new(&config) {
|
match HuskContext::new(&config) {
|
||||||
Ok(context) => {
|
Ok(context) => {
|
||||||
log::debug!("found introducers: {:?}", context.introducers);
|
log::debug!("found introducers: {:?}", context.introducers);
|
||||||
cx.data = Some(context).take();
|
cx.data = Some(context);
|
||||||
Status::Continue
|
Status::Continue
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -138,13 +138,12 @@ impl Daemon {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rcpt.is_none() {
|
if let Some(rcpt) = rcpt {
|
||||||
Status::Tempfail
|
context.add_recipient(rcpt).await;
|
||||||
} else {
|
|
||||||
context.add_recipient(rcpt.unwrap()).await;
|
|
||||||
Status::Continue
|
Status::Continue
|
||||||
|
} else {
|
||||||
|
Status::Tempfail
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Status::Tempfail
|
Status::Tempfail
|
||||||
}
|
}
|
||||||
@@ -213,7 +212,7 @@ impl Daemon {
|
|||||||
|
|
||||||
if protection == ProtectionPossibility::Full {
|
if protection == ProtectionPossibility::Full {
|
||||||
// if an error occures the body is not exchanged
|
// 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) => {
|
Ok(encrypted) => {
|
||||||
if cx.actions.replace_body(&encrypted).await.is_err() {
|
if cx.actions.replace_body(&encrypted).await.is_err() {
|
||||||
log::error!("Cannot exchange body");
|
log::error!("Cannot exchange body");
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ impl<'hc> HuskContext<'hc> {
|
|||||||
|
|
||||||
pub async fn add_recipient(&mut self, rcpt: String) {
|
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)
|
self.mail.add_recipient(rcpt, certs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ impl Display for Introducer {
|
|||||||
.map(|u| String::from_utf8_lossy(u.userid().value()).to_string())
|
.map(|u| String::from_utf8_lossy(u.userid().value()).to_string())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
write!(f, "Introducer: {}\n", self.cert.fingerprint())?;
|
writeln!(f, "Introducer: {}", self.cert.fingerprint())?;
|
||||||
write!(f, " UserIDs: {}", uids)?;
|
write!(f, " UserIDs: {}", uids)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
impl From<&MailContext<'_>> for ProtectionPossibility {
|
||||||
fn from(mail_context: &MailContext<'_>) -> ProtectionPossibility {
|
fn from(mail_context: &MailContext<'_>) -> ProtectionPossibility {
|
||||||
let mut can_encrypt = false;
|
let mut can_encrypt = false;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub struct Recipient<'r> {
|
|||||||
impl From<String> for Recipient<'_> {
|
impl From<String> for Recipient<'_> {
|
||||||
fn from(email: String) -> Self {
|
fn from(email: String) -> Self {
|
||||||
Recipient {
|
Recipient {
|
||||||
email: email,
|
email,
|
||||||
certs: Vec::new()
|
certs: Vec::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ impl Recipient<'_> {
|
|||||||
/// check if this Recipient can encrypt.
|
/// check if this Recipient can encrypt.
|
||||||
// XXX: currently this check is naive
|
// XXX: currently this check is naive
|
||||||
pub fn can_encrypt(&self) -> bool {
|
pub fn can_encrypt(&self) -> bool {
|
||||||
if self.certs.len() == 0 {
|
if self.certs.is_empty() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user