antidns/
query_type.rs

1#[derive(PartialEq, Eq, Debug, Clone, Hash, Copy)]
2#[allow(clippy::upper_case_acronyms)]
3pub enum QueryType {
4    UNKNOWN(u16),
5    A,     // 1
6    NS,    // 2
7    CNAME, // 5
8    MX,    // 15
9    TXT,   // 16
10    AAAA,  // 28
11    CAA,   // 257
12}
13
14impl QueryType {
15    pub fn to_num(self) -> u16 {
16        match self {
17            QueryType::UNKNOWN(x) => x,
18            QueryType::A => 1,
19            QueryType::NS => 2,
20            QueryType::CNAME => 5,
21            QueryType::MX => 15,
22            QueryType::TXT => 16,
23            QueryType::AAAA => 28,
24            QueryType::CAA => 257,
25        }
26    }
27
28    pub fn from_num(num: u16) -> QueryType {
29        match num {
30            1 => QueryType::A,
31            2 => QueryType::NS,
32            5 => QueryType::CNAME,
33            15 => QueryType::MX,
34            16 => QueryType::TXT,
35            28 => QueryType::AAAA,
36            257 => QueryType::CAA,
37            _ => QueryType::UNKNOWN(num),
38        }
39    }
40}