From: Matt Corallo Date: Tue, 1 Oct 2024 18:06:19 +0000 (+0000) Subject: Skip the implicit trailing `.` in `HumanReadableName`'s domain X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=a39e274e3df8cd0790d45de14f19aa83a2f1f19f;p=rust-lightning Skip the implicit trailing `.` in `HumanReadableName`'s domain Domain names implicitly have a trailing `.`, which we require in bLIP 32 but generally shouldn't be exposing to the user in `HumanReadableName`s (after all, they're human-readable). Here we make sure the trailing `.` is dropped in `HumanReadableName`s before we re-add them when building the bLIP 32 messages. --- diff --git a/lightning/src/onion_message/dns_resolution.rs b/lightning/src/onion_message/dns_resolution.rs index bbf8caa4f..0f6071e73 100644 --- a/lightning/src/onion_message/dns_resolution.rs +++ b/lightning/src/onion_message/dns_resolution.rs @@ -198,7 +198,12 @@ pub struct HumanReadableName { impl HumanReadableName { /// Constructs a new [`HumanReadableName`] from the `user` and `domain` parts. See the /// struct-level documentation for more on the requirements on each. - pub fn new(user: String, domain: String) -> Result { + pub fn new(user: String, mut domain: String) -> Result { + // First normalize domain and remove the optional trailing `.` + if domain.ends_with(".") { + domain.pop(); + } + // Note that `REQUIRED_EXTRA_LEN` includes the (now implicit) trailing `.` const REQUIRED_EXTRA_LEN: usize = ".user._bitcoin-payment.".len() + 1; if user.len() + domain.len() + REQUIRED_EXTRA_LEN > 255 { return Err(());