Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions lightning/src/onion_message/dns_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ 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: &str, domain: &str) -> Result<HumanReadableName, ()> {
pub fn new(user: &str, domain: &str) -> Result<Self, ()> {
// First normalize domain and remove the optional trailing `.`
let domain = domain.strip_suffix(".").unwrap_or(domain);
let domain = domain.strip_suffix('.').unwrap_or(domain);
if user.len() + domain.len() + REQUIRED_EXTRA_LEN > 255 {
return Err(());
}
Expand All @@ -233,24 +233,17 @@ impl HumanReadableName {
let mut contents = [0; 255 - REQUIRED_EXTRA_LEN];
contents[..user.len()].copy_from_slice(user.as_bytes());
contents[user.len()..user.len() + domain.len()].copy_from_slice(domain.as_bytes());
Ok(HumanReadableName {
contents,
user_len: user.len() as u8,
domain_len: domain.len() as u8,
})
Ok(Self { contents, user_len: user.len() as u8, domain_len: domain.len() as u8 })
}

/// Constructs a new [`HumanReadableName`] from the standard encoding - `user`@`domain`.
///
/// If `user` includes the standard BIP 353 ₿ prefix it is automatically removed as required by
/// BIP 353.
pub fn from_encoded(encoded: &str) -> Result<HumanReadableName, ()> {
if let Some((user, domain)) = encoded.strip_prefix('₿').unwrap_or(encoded).split_once("@")
{
Self::new(user, domain)
} else {
Err(())
}
pub fn from_encoded(encoded: &str) -> Result<Self, ()> {
let encoded = encoded.strip_prefix('₿').unwrap_or(encoded);
let (user, domain) = encoded.split_once('@').ok_or(())?;
Self::new(user, domain)
}

/// Gets the `user` part of this Human Readable Name
Expand Down Expand Up @@ -438,9 +431,9 @@ impl OMNameResolver {
&self, msg: DNSSECProof, context: DNSResolverContext,
) -> Option<(Vec<(HumanReadableName, PaymentId)>, Offer)> {
let (completed_requests, uri) = self.handle_dnssec_proof_for_uri(msg, context)?;
if let Some((_onchain, params)) = uri.split_once("?") {
for param in params.split("&") {
let (k, v) = if let Some(split) = param.split_once("=") {
if let Some((_onchain, params)) = uri.split_once('?') {
for param in params.split('&') {
let (k, v) = if let Some(split) = param.split_once('=') {
split
} else {
continue;
Expand Down
Loading