Skip to content

Commit 95e45f1

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 9335c9b commit 95e45f1

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
@@ -189,7 +189,12 @@ pub struct HumanReadableName {
189189
impl HumanReadableName {
190190
/// Constructs a new [`HumanReadableName`] from the `user` and `domain` parts. See the
191191
/// struct-level documentation for more on the requirements on each.
192-
pub fn new(user: String, domain: String) -> Result<HumanReadableName, ()> {
192+
pub fn new(user: String, mut domain: String) -> Result<HumanReadableName, ()> {
193+
// First normalize domain and remove the optional trailing `.`
194+
if domain.ends_with(".") {
195+
domain.pop();
196+
}
197+
// Note that `REQUIRED_EXTRA_LEN` includes the (now implicit) trailing `.`
193198
const REQUIRED_EXTRA_LEN: usize = ".user._bitcoin-payment.".len() + 1;
194199
if user.len() + domain.len() + REQUIRED_EXTRA_LEN > 255 {
195200
return Err(());

0 commit comments

Comments
 (0)