Skip to content

Commit

Permalink
test to bytes for tsig rdata
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Nov 2, 2023
1 parent a7ca0a9 commit 0932e87
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/message/rdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ mod resolver_query_tests {
use super::ptr_rdata::PtrRdata;
use super::soa_rdata::SoaRdata;
use super::txt_rdata::TxtRdata;
use super::tsig_rdata::TSigRdata;
use std::net::IpAddr;

#[test]
Expand Down Expand Up @@ -427,6 +428,36 @@ mod resolver_query_tests {
assert_eq!(bytes, expected_bytes);
}

#[test]
fn to_bytes_tsigrdata(){
let expected_bytes = vec![
0x8, 0x68, 0x6D, 0x61, 0x63, 0x2D, 0x6D, 0x64,
0x35, 0x7, 0x73, 0x69, 0x67, 0x2D, 0x61, 0x6C, 0x67,
0x3, 0x72, 0x65, 0x67, 0x3, 0x69, 0x6E, 0x74, 0x0, 0x0, 0x0, 0x0,
0x0, 0x7, 0x5B, 0xCD, 0x15, 0x4, 0xD2, 0x0, 0x4, 0xA1, 0xB2, 0xC3, 0xD4,
0x4, 0xD2, 0x0, 0x0, 0x0, 0x0
];

let mut tsig_rdata = TSigRdata::new();

let mut domain_name = DomainName::new();
domain_name.set_name(String::from("hmac-md5.sig-alg.reg.int"));
tsig_rdata.set_algorithm_name(domain_name);
tsig_rdata.set_time_signed(123456789);
tsig_rdata.set_fudge(1234);
tsig_rdata.set_mac_size(4);
tsig_rdata.set_mac(vec![0xA1, 0xB2, 0xC3, 0xD4]);
tsig_rdata.set_original_id(1234);
tsig_rdata.set_error(0);
tsig_rdata.set_other_len(0);
tsig_rdata.set_other_data(Vec::new());

let rdata = Rdata::SomeTSigRdata(tsig_rdata);
let bytes = rdata.to_bytes();

assert_eq!(bytes, expected_bytes);
}

//from bytes tests
#[test]
fn from_bytes_a_ch_rdata(){
Expand Down

0 comments on commit 0932e87

Please sign in to comment.