Skip to content

Commit 0ef8b91

Browse files
committed
Add test min values in from_bytes and to_bytes in rrsig
1 parent a74100b commit 0ef8b91

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/message/rdata/rrsig_rdata.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,76 @@ mod rrsig_rdata_test{
533533

534534
assert_eq!(result, bytes_test);
535535
}
536+
537+
#[test]
538+
fn a(){
539+
let a = String::from("\0");
540+
let b = a.into_bytes();
541+
println!("{:?}", b);
542+
}
543+
544+
#[test]
545+
fn from_bytes_min_values() {
546+
let bytes_test: Vec<u8> = vec![0, 0, //typed covered
547+
0, //algorithm
548+
0, //labels
549+
0, 0, 0, 0, //TTL
550+
0, 0, 0, 0, //Signature expiration
551+
0, 0, 0, 0, //Signature Inception
552+
0, 0, // key tag
553+
0, //empty string in signer name
554+
0]; //signature
555+
556+
let mut rrsig_rdata = RRSIGRdata::new();
557+
rrsig_rdata.set_type_covered(Rtype::UNKNOWN(0));
558+
rrsig_rdata.set_algorithm(0);
559+
rrsig_rdata.set_labels(0);
560+
rrsig_rdata.set_original_ttl(0);
561+
rrsig_rdata.set_signature_expiration(0);
562+
rrsig_rdata.set_signature_inception(0);
563+
rrsig_rdata.set_key_tag(0);
564+
rrsig_rdata.set_signer_name(DomainName::new_from_str(""));
565+
rrsig_rdata.set_signature(String::from("\0"));
566+
567+
if let Ok(result) = RRSIGRdata::from_bytes(&bytes_test, &bytes_test) {
568+
assert_eq!(result, rrsig_rdata);
569+
}
570+
else {
571+
assert!(false, "error");
572+
}
573+
574+
}
575+
576+
#[test]
577+
fn to_bytes_min_values() {
578+
let bytes_test: Vec<u8> = vec![0, 0, //typed covered
579+
0, //algorithm
580+
0, //labels
581+
0, 0, 0, 0, //TTL
582+
0, 0, 0, 0, //Signature expiration
583+
0, 0, 0, 0, //Signature Inception
584+
0, 0, // key tag
585+
0, //empty string in signer name
586+
0];
587+
588+
let mut rrsig_rdata = RRSIGRdata::new();
589+
rrsig_rdata.set_type_covered(Rtype::UNKNOWN(0));
590+
rrsig_rdata.set_algorithm(0);
591+
rrsig_rdata.set_labels(0);
592+
rrsig_rdata.set_original_ttl(0);
593+
rrsig_rdata.set_signature_expiration(0);
594+
rrsig_rdata.set_signature_inception(0);
595+
rrsig_rdata.set_key_tag(0);
596+
rrsig_rdata.set_signer_name(DomainName::new_from_str(""));
597+
rrsig_rdata.set_signature(String::from("\0"));
598+
599+
let result = rrsig_rdata.to_bytes();
600+
601+
//FIXME: there is a inconsistency between to_bytes and from_bytes in signer_name
602+
// to_bytes : uses to_bytes() which: "" -> [0,0]
603+
// from_bytes, in while loop, if bytes!=0 then do not go inside the loop
604+
// then if you have [0,0] -> only will not count the first 0, but the other
605+
// will be count it to signature and that is wrong
606+
assert_eq!(result, bytes_test);
607+
}
536608
}

0 commit comments

Comments
 (0)