Skip to content

Commit

Permalink
Add support for CAA record type
Browse files Browse the repository at this point in the history
  • Loading branch information
weilence committed Nov 6, 2024
1 parent 24ecebe commit 570be82
Show file tree
Hide file tree
Showing 4 changed files with 393 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/base/charstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,22 @@ impl<Octs: AsRef<[u8]> + ?Sized> CharStr<Octs> {
.compose(target)?;
target.append_slice(self.0.as_ref())
}

/// Appends the canonical wire format representation to an octets builder.
pub fn compose_canonical<Target: OctetsBuilder + ?Sized>(
&self,
target: &mut Target,
) -> Result<(), Target::AppendError> {
u8::try_from(self.0.as_ref().len())
.expect("long charstr")
.compose(target)?;

for ch in self.0.as_ref() {
ch.compose(target)?;
}

Ok(())
}
}

impl<Octs> CharStr<Octs> {
Expand Down
14 changes: 14 additions & 0 deletions src/base/zonefile_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,18 @@ mod test {
record.display_zonefile(false).to_string()
);
}

#[test]
fn caa_record() {
use crate::rdata::Caa;
let record = create_record(Caa::new(
0,
"issue".parse().unwrap(),
"ca.example.net".as_bytes().to_vec(),
));
assert_eq!(
"example.com. 3600 IN CAA 0 issue \"ca.example.net\"",
record.display_zonefile(false).to_string()
);
}
}
Loading

0 comments on commit 570be82

Please sign in to comment.