39 lines
1001 B
Rust
39 lines
1001 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;
|
|
|
|
/// A single quoted non-empty URL.
|
|
///
|
|
/// Actually shouldn't allow escapes (i.e. no backslash in the content);
|
|
/// but to make sure we can export and import any data we allow standard
|
|
/// escape mechanisms and even accept unquoted input.
|
|
///
|
|
/// No whitespace allowed, last field.
|
|
#[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)
|
|
}
|
|
}
|