diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-11-22 16:57:15 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-11-22 17:40:39 +0100 |
commit | 213d8c35c9d526b4b2843adf681ed16cdff4a6cf (patch) | |
tree | 2b9823ed512efaf4e19be536f5fa28e5f7e86c05 /net/src/wkd.rs | |
parent | 4eb3585bf11776578cc0a67d522b244cf053c697 (diff) |
net: Fix wkd::get to return a Vec<Result<Cert>>.
- We may not understand all of the certs, but that is no reason not
to return them.
Diffstat (limited to 'net/src/wkd.rs')
-rw-r--r-- | net/src/wkd.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/net/src/wkd.rs b/net/src/wkd.rs index 420cb03c..ab69139d 100644 --- a/net/src/wkd.rs +++ b/net/src/wkd.rs @@ -152,26 +152,28 @@ fn encode_local_part<S: AsRef<str>>(local_part: S) -> String { /// address. /// ``` fn parse_body<S: AsRef<str>>(body: &[u8], email_address: S) - -> Result<Vec<Cert>> { + -> Result<Vec<Result<Cert>>> { let email_address = email_address.as_ref(); // This will fail on the first packet that can not be parsed. let packets = CertParser::from_bytes(&body)?; // Collect only the correct packets. - let certs: Vec<Cert> = packets.flatten().collect(); + let certs: Vec<Result<Cert>> = packets.collect(); if certs.is_empty() { return Err(Error::NotFound.into()); } // Collect only the Certs that contain the email in any of their userids - let valid_certs: Vec<Cert> = certs.iter() + let valid_certs: Vec<Result<Cert>> = certs.into_iter() // XXX: This filter could become a Cert method, but it adds other API // method to maintain - .filter(|cert| {cert.userids() - .any(|uidb| - if let Ok(Some(a)) = uidb.userid().email2() { - a == email_address - } else { false }) - }).cloned().collect(); + .filter(|cert| match cert { + Ok(cert) => cert.userids() + .any(|uidb| + if let Ok(Some(a)) = uidb.userid().email2() { + a == email_address + } else { false }), + Err(_) => true, + }).collect(); if valid_certs.is_empty() { Err(Error::EmailNotInUserids(email_address.into()).into()) } else { @@ -205,6 +207,7 @@ fn parse_body<S: AsRef<str>>(body: &[u8], email_address: S) /// ``` /// /// [draft-koch]: https://datatracker.ietf.org/doc/html/draft-koch-openpgp-webkey-service/#section-3.1 +/// /// # Examples /// /// ```no_run @@ -212,7 +215,8 @@ fn parse_body<S: AsRef<str>>(body: &[u8], email_address: S) /// # use sequoia_openpgp::Cert; /// # async fn f() -> Result<()> { /// let email_address = "foo@bar.baz"; -/// let certs: Vec<Cert> = wkd::get(&reqwest::Client::new(), &email_address).await?; +/// let certs: Vec<Result<Cert>> = +/// wkd::get(&reqwest::Client::new(), &email_address).await?; /// # Ok(()) /// # } /// ``` @@ -220,7 +224,7 @@ fn parse_body<S: AsRef<str>>(body: &[u8], email_address: S) // XXX: Maybe the direct method should be tried on other errors too. // https://mailarchive.ietf.org/arch/msg/openpgp/6TxZc2dQFLKXtS0Hzmrk963EteE pub async fn get<S: AsRef<str>>(c: &reqwest::Client, email_address: S) - -> Result<Vec<Cert>> + -> Result<Vec<Result<Cert>>> { let email = email_address.as_ref().to_string(); // First, prepare URIs and client. |