diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-11-15 16:03:55 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-11-15 16:03:55 +0100 |
commit | c2cf12bbb75653640ecd9d665f8956077e6a8a7e (patch) | |
tree | e1a0285f3635bfdfa1503c382bc38c70793bbe1a /net/src/wkd.rs | |
parent | a95b701503dee6557ca57eb9e08df9072aac153c (diff) |
net: Deduplicate code.
- This was duplicated by accident in
bc1f27770002690f6117eaec59e8b11ca6196489.
Diffstat (limited to 'net/src/wkd.rs')
-rw-r--r-- | net/src/wkd.rs | 44 |
1 files changed, 1 insertions, 43 deletions
diff --git a/net/src/wkd.rs b/net/src/wkd.rs index c1bb0852..420cb03c 100644 --- a/net/src/wkd.rs +++ b/net/src/wkd.rs @@ -33,6 +33,7 @@ use sequoia_openpgp::{ cert::prelude::*, }; +use crate::email::EmailAddress; use crate::{Result, Error}; /// WKD variants. @@ -357,49 +358,6 @@ impl KeyRing { } } -/// Stores the local_part and domain of an email address. -pub(crate) struct EmailAddress { - pub(crate) local_part: String, - pub(crate) 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. - ///``` - pub(crate) 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) - } -} - #[cfg(test)] mod tests { use super::*; |