Skip to content

Commit a39e274

Browse files
committed
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.
1 parent b0bd437 commit a39e274

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lightning/src/onion_message/dns_resolution.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ pub struct HumanReadableName {
198198
impl HumanReadableName {
199199
/// Constructs a new [`HumanReadableName`] from the `user` and `domain` parts. See the
200200
/// struct-level documentation for more on the requirements on each.
201-
pub fn new(user: String, domain: String) -> Result<HumanReadableName, ()> {
201+
pub fn new(user: String, mut domain: String) -> Result<HumanReadableName, ()> {
202+
// First normalize domain and remove the optional trailing `.`
203+
if domain.ends_with(".") {
204+
domain.pop();
205+
}
206+
// Note that `REQUIRED_EXTRA_LEN` includes the (now implicit) trailing `.`
202207
const REQUIRED_EXTRA_LEN: usize = ".user._bitcoin-payment.".len() + 1;
203208
if user.len() + domain.len() + REQUIRED_EXTRA_LEN > 255 {
204209
return Err(());

0 commit comments

Comments
 (0)