-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding rdata trait, tightening question parsing
- Loading branch information
Showing
12 changed files
with
448 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::fmt::{Debug, Formatter}; | ||
use std::net::{IpAddr, Ipv4Addr}; | ||
Check warning on line 2 in dnstp/src/message/answer/ip_address.rs GitHub Actions / Build & Test
|
||
use crate::message::answer::RData; | ||
|
||
pub struct IpRData { | ||
pub rdata: Ipv4Addr | ||
} | ||
|
||
impl Debug for IpRData { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("IP") | ||
.field("data", &self.rdata) | ||
.finish() | ||
} | ||
} | ||
|
||
impl RData for IpRData { | ||
fn to_bytes(&self) -> Vec<u8> { | ||
return self.rdata.octets().to_vec(); | ||
} | ||
} | ||
|
||
impl IpRData { | ||
pub fn from(rdata: Ipv4Addr) -> IpRData | ||
{ | ||
IpRData { | ||
rdata | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::fmt::{Debug, Formatter}; | ||
use crate::message::answer::RData; | ||
|
||
pub struct RawRData { | ||
pub rdata: Vec<u8> | ||
} | ||
|
||
impl Debug for RawRData { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("RawRData") | ||
.field("data", &self.rdata) | ||
.finish() | ||
} | ||
} | ||
|
||
impl RData for RawRData { | ||
fn to_bytes(&self) -> Vec<u8> { | ||
return self.rdata.clone(); | ||
} | ||
} | ||
|
||
impl RawRData { | ||
pub fn from(rdata: Vec<u8>) -> RawRData | ||
{ | ||
RawRData { | ||
rdata | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::message::question::{DNSQuestion, QClass, QType, questions_from_bytes}; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
#[ignore] | ||
fn one_answer_back_and_forth() { | ||
let q = DNSAnswer { | ||
name: "google.com".to_string(), | ||
answer_type: QType::A, | ||
class: QClass::Internet, | ||
ttl: 0, | ||
rd_length: 0, | ||
r_data: Box::from(RawRData::from(vec![])) | ||
}; | ||
|
||
let mut q_bytes = q.to_bytes(); | ||
q_bytes.append(&mut vec![0, 0, 0, 0, 0, 0]); | ||
|
||
let (q_read, q_reconstructed) = answers_from_bytes(q_bytes, 0).unwrap(); | ||
|
||
assert_eq!(q.name, q_reconstructed[0].name); | ||
assert_eq!(q.answer_type, q_reconstructed[0].answer_type); | ||
assert_eq!(q.class, q_reconstructed[0].class); | ||
assert_eq!(q.ttl, q_reconstructed[0].ttl); | ||
assert_eq!(q.rd_length, q_reconstructed[0].rd_length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.