@@ -18,6 +18,21 @@ pub struct NsecRdata {
18
18
pub type_bit_maps : Vec < Rtype > ,
19
19
}
20
20
21
+ impl ToBytes for NsecRdata {
22
+ /// Returns a `Vec<u8>` of bytes that represents the NSEC RDATA.
23
+ fn to_bytes ( & self ) -> Vec < u8 > {
24
+ let mut bytes: Vec < u8 > = Vec :: new ( ) ;
25
+
26
+ let next_domain_name_bytes = self . get_next_domain_name ( ) . to_bytes ( ) ;
27
+
28
+ for byte in next_domain_name_bytes. as_slice ( ) {
29
+ bytes. push ( * byte) ;
30
+ }
31
+
32
+ bytes
33
+ }
34
+ }
35
+
21
36
impl FromBytes < Result < Self , & ' static str > > for NsecRdata {
22
37
/// Reads the next_domain_name and type_bit_maps from the slice and returns a `NsecRdata` struct.
23
38
@@ -120,4 +135,22 @@ impl NsecRdata{
120
135
pub fn set_type_bit_maps ( & mut self , type_bit_maps : Vec < Rtype > ) {
121
136
self . type_bit_maps = type_bit_maps;
122
137
}
138
+ }
139
+
140
+ impl NsecRdata {
141
+ /// Complementary functions for to_bytes
142
+ fn add_rtype_to_bitmap ( rtype : & Rtype , bitmap : & mut Vec < u8 > ) {
143
+ // Calculate the offset and bit for the specific Qtype
144
+ let rr_type = Rtype :: from_rtype_to_int ( * rtype) ;
145
+ let offset = ( rr_type % 256 ) / 8 ;
146
+ let bit = 7 - ( rr_type % 8 ) ;
147
+
148
+ // Ensure the bitmap has enough space
149
+ if offset >= bitmap. len ( ) as u16 {
150
+ bitmap. resize ( ( offset + 1 ) as usize , 0 ) ;
151
+ }
152
+
153
+ // Set the bit in the bitmap
154
+ bitmap[ offset as usize ] |= 1 << bit;
155
+ }
123
156
}
0 commit comments