Skip to content

Commit eb01099

Browse files
committed
feat(decode): add domain_name_without_compression function
This function decodes a domain name while explicitly disallowing label compression.
1 parent e27a931 commit eb01099

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/decode/domain_name.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@ impl<'a, 'b: 'a> Decoder<'a, 'b> {
8282
}
8383
}
8484
}
85+
86+
pub(super) fn domain_name_without_compression(&mut self) -> DecodeResult<DomainName> {
87+
let mut domain_name = DomainName::default();
88+
89+
loop {
90+
match self.domain_name_length()? {
91+
DomainNameLength::Compressed(offset) => {
92+
return Err(DecodeError::DomainNameCompressed(offset))
93+
}
94+
DomainNameLength::Label(0) => return Ok(domain_name),
95+
DomainNameLength::Label(length) => {
96+
self.domain_name_label(&mut domain_name, length)?
97+
}
98+
}
99+
}
100+
}
85101
}
86102

87103
impl_decode!(DomainName, domain_name);
104+
impl_decode!(
105+
DomainName,
106+
domain_name_without_compression,
107+
decode_without_compression
108+
);

src/decode/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,6 @@ pub enum DecodeError {
105105
TagError(#[from] TagError),
106106
#[error("ECH length mismatch. Expected {0} got {1}")]
107107
ECHLengthMismatch(usize, usize),
108+
#[error("The domain name is compressed: {0}")]
109+
DomainNameCompressed(u16),
108110
}

0 commit comments

Comments
 (0)