Skip to content

Commit 5888468

Browse files
committed
Add getters and contructor for nsec rdata
1 parent 3b9e3af commit 5888468

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/message/rdata/nsec_rdata.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use crate::message::resource_record::{FromBytes, ToBytes};
2+
use crate::domain_name::DomainName;
3+
use crate::message::type_rtype::Rtype;
4+
5+
#[derive(Clone, Debug, PartialEq)]
6+
/// Struct for NSEC Rdata
7+
/// [RFC 4034](https://tools.ietf.org/html/rfc4034#section-4.1)
8+
/// 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
9+
/// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
10+
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
11+
/// / Next Domain Name /
12+
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
13+
/// / Type Bit Maps /
14+
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
15+
16+
pub struct NsecRdata {
17+
pub next_domain_name: DomainName,
18+
pub type_bit_maps: Vec<Rtype>,
19+
}
20+
21+
impl NsecRdata{
22+
/// Creates a new `NsecRdata` with next_domain_name and type_bit_maps
23+
pub fn new(next_domain_name: DomainName, type_bit_maps: Vec<Rtype>) -> Self {
24+
NsecRdata {
25+
next_domain_name,
26+
type_bit_maps,
27+
}
28+
}
29+
30+
/// Returns the next_domain_name of the `NsecRdata`.
31+
/// # Example
32+
/// ```
33+
/// let nsec_rdata = NsecRdata::new(String::from("www.example.com"), vec![Rtype::A, Rtype::NS]);
34+
/// assert_eq!(nsec_rdata.get_next_domain_name().get_name(), String::from("www.example.com"));
35+
/// ```
36+
pub fn get_next_domain_name(&self) -> DomainName {
37+
self.next_domain_name.clone()
38+
}
39+
40+
/// Returns the type_bit_maps of the `NsecRdata`.
41+
/// # Example
42+
/// ```
43+
/// let nsec_rdata = NsecRdata::new(String::from("www.example.com"), vec![Rtype::A, Rtype::NS]);
44+
/// assert_eq!(nsec_rdata.get_type_bit_maps(), vec![Rtype::A, Rtype::NS]);
45+
/// ```
46+
pub fn get_type_bit_maps(&self) -> Vec<Rtype> {
47+
self.type_bit_maps.clone()
48+
}
49+
}

0 commit comments

Comments
 (0)