Use char-based predicates in DNS resolver
What changed, and why it matters
This commit is a minor code cleanup in the DNS resolver module. It changes several string-predicate calls from using multi-character string literals (like "." or "?") to single-character literals (like '.'). In Rust, using a char for single-character matching is slightly more efficient and idiomatic, but it does not change program behavior or fix any security issue. There is no security relevance in this change.
No security action required. Treat as normal code-quality refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies lightning/src/onion_message/dns_resolution.rs to use char-based predicates in strip_suffix, strip_prefix, split_once, and split calls. It also replaces explicit HumanReadableName return types with Self and simplifies from_encoded using ok_or. These are idiomatic Rust refactorings with no functional change to parsing logic, validation, or memory safety. No security bug is introduced or fixed.
Changed components
lightning/src/onion_message/dns_resolution.rsInspect captured patch +10 / −17
diff --git a/lightning/src/onion_message/dns_resolution.rs b/lightning/src/onion_message/dns_resolution.rs
index 6d9d4d6..47d4bc0 100644
--- a/lightning/src/onion_message/dns_resolution.rs
+++ b/lightning/src/onion_message/dns_resolution.rs
@@ -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(());
}
@@ -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
@@ -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;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.