flex_dns/rdata/
cdnskey.rs1use crate::{Buffer, DnsMessage, DnsMessageError, MutBuffer};
2use crate::characters::Characters;
3use crate::parse::Parse;
4use crate::rdata::{RData, RDataParse};
5use crate::write::WriteBytes;
6
7#[derive(Copy, Clone, Debug, PartialEq)]
10pub struct CdnsKey<'a> {
11 pub flags: u16,
14 pub protocol: u8,
16 pub algorithm: u8,
18 pub public_key: Characters<'a>
20}
21
22impl<'a> RDataParse<'a> for CdnsKey<'a> {
23 #[inline]
24 fn parse(rdata: &RData<'a>, i: &mut usize) -> Result<Self, DnsMessageError> {
25 let flags = u16::parse(rdata, i)?;
26 let protocol = u8::parse(rdata, i)?;
27 let algorithm = u8::parse(rdata, i)?;
28 let public_key = Characters::parse(rdata, i)?;
29
30 Ok(Self {
31 flags,
32 protocol,
33 algorithm,
34 public_key
35 })
36 }
37}
38
39impl<'a> WriteBytes for CdnsKey<'a> {
40 #[inline]
41 fn write<
42 const PTR_STORAGE: usize,
43 const DNS_SECTION: usize,
44 B: MutBuffer + Buffer,
45 >(&self, message: &mut DnsMessage<PTR_STORAGE, DNS_SECTION, B>) -> Result<usize, DnsMessageError> {
46 let mut bytes = 0;
47
48 bytes += self.flags.write(message)?;
49 bytes += self.protocol.write(message)?;
50 bytes += self.algorithm.write(message)?;
51 bytes += self.public_key.write(message)?;
52
53 Ok(bytes)
54 }
55}
56
57#[cfg(test)]
58mod test {
59 use crate::rdata::testutils::parse_write_test;
60
61 use super::*;
62
63 parse_write_test!(
64 5,
65 [
66 0x01, 0x02, 0x03, 0x04, 0x00, ],
71 CdnsKey {
72 flags: 0x0102,
73 protocol: 0x03,
74 algorithm: 0x04,
75 public_key: unsafe { Characters::new_unchecked(&[]) },
76 },
77 );
78}