35 lines
816 B
Rust
35 lines
816 B
Rust
use bytes::Bytes;
|
|
use errors::*;
|
|
use ser::packet::DnsPacketData;
|
|
use ser::text::{DnsTextData, DnsTextFormatter, next_field};
|
|
use std::fmt;
|
|
use std::io::Cursor;
|
|
|
|
/// timestamp in seconds since epoch (ignoring leap seconds)
|
|
///
|
|
/// Is expected to wrap around.
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
pub struct Time(u32);
|
|
|
|
impl DnsPacketData for Time {
|
|
fn deserialize(data: &mut Cursor<Bytes>) -> Result<Self> {
|
|
Ok(Time(DnsPacketData::deserialize(data)?))
|
|
}
|
|
}
|
|
|
|
impl DnsTextData for Time {
|
|
fn dns_parse(data: &mut &str) -> ::errors::Result<Self> {
|
|
let field = next_field(data)?;
|
|
let epoch = field.parse::<u32>();
|
|
if field.len() == 14 && epoch.is_err() {
|
|
unimplemented!()
|
|
} else {
|
|
Ok(Time(epoch?))
|
|
}
|
|
}
|
|
|
|
fn dns_format(&self, f: &mut DnsTextFormatter) -> fmt::Result {
|
|
write!(f, "{}", self.0)
|
|
}
|
|
}
|