summaryrefslogtreecommitdiffstats
path: root/net/src/wkd.rs
diff options
context:
space:
mode:
authorWiktor Kwapisiewicz <wiktor@metacode.biz>2022-07-11 10:42:51 +0200
committerWiktor Kwapisiewicz <wiktor@metacode.biz>2022-09-15 09:45:39 +0200
commit9cee22c8dbcd55f1b7e41668e9feb35bd1a250c3 (patch)
tree6c1def18c2d7866a9042e1f307b7967543dc4e26 /net/src/wkd.rs
parente0e5174262ac3203eb378677f063abdc8d98d187 (diff)
net: Add support for DANE certificate retrieval.
- Add dane::get. - Make EmailAddress functions pub(crate) to use them from the DANE module. - Add tests for generating correct FQDN. - See #865.
Diffstat (limited to 'net/src/wkd.rs')
-rw-r--r--net/src/wkd.rs46
1 files changed, 1 insertions, 45 deletions
diff --git a/net/src/wkd.rs b/net/src/wkd.rs
index 0289508d..7a81831e 100644
--- a/net/src/wkd.rs
+++ b/net/src/wkd.rs
@@ -38,6 +38,7 @@ use sequoia_openpgp::{
};
use super::{Result, Error};
+use super::email::EmailAddress;
/// WKD variants.
///
@@ -62,51 +63,6 @@ impl Default for Variant {
}
}
-
-/// Stores the local_part and domain of an email address.
-pub struct EmailAddress {
- local_part: String,
- domain: String,
-}
-
-
-impl EmailAddress {
- /// Returns an EmailAddress from an email address string.
- ///
- /// From [draft-koch]:
- ///
- ///```text
- /// To help with the common pattern of using capitalized names
- /// (e.g. "Joe.Doe@example.org") for mail addresses, and under the
- /// premise that almost all MTAs treat the local-part case-insensitive
- /// and that the domain-part is required to be compared
- /// case-insensitive anyway, all upper-case ASCII characters in a User
- /// ID are mapped to lowercase. Non-ASCII characters are not changed.
- ///```
- fn from<S: AsRef<str>>(email_address: S) -> Result<Self> {
- // Ensure that is a valid email address by parsing it and return the
- // errors that it returns.
- // This is also done in hagrid.
- let email_address = email_address.as_ref();
- let v: Vec<&str> = email_address.split('@').collect();
- if v.len() != 2 {
- return Err(Error::MalformedEmail(email_address.into()).into())
- };
-
- // Convert domain to lowercase without tailoring, i.e. without taking any
- // locale into account. See:
- // https://doc.rust-lang.org/std/primitive.str.html#method.to_lowercase
- //
- // Keep the local part as-is as we'll need that to generate WKD URLs.
- let email = EmailAddress {
- local_part: v[0].to_string(),
- domain: v[1].to_lowercase()
- };
- Ok(email)
- }
-}
-
-
/// Stores the parts needed to create a Web Key Directory URL.
///
/// NOTE: This is a different `Url` than [`url::Url`] (`url` crate) that is