Skip to content

Commit

Permalink
[validate] format DNSKEYs using 'ZonefileFmt'
Browse files Browse the repository at this point in the history
The 'Dnskey' impl of 'fmt::Display' was no longer accurate to the zone
file format because 'SecAlg' now prints '<code>(<mnemonic>)'.
  • Loading branch information
arya dradjica committed Oct 24, 2024
1 parent 59650a4 commit 0f54a8d
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::base::rdata::{ComposeRecordData, RecordData};
use crate::base::record::Record;
use crate::base::scan::{IterScanner, Scanner};
use crate::base::wire::{Compose, Composer};
use crate::base::zonefile_fmt::ZonefileFmt;
use crate::base::Rtype;
use crate::rdata::{Dnskey, Ds, Rrsig};
use bytes::Bytes;
Expand Down Expand Up @@ -281,34 +282,25 @@ impl<Octs: AsRef<[u8]>> Key<Octs> {
let (line, rest) =
next_line(data).ok_or(ParseDnskeyTextError::Misformatted)?;
if next_line(rest).is_some() {
eprintln!("DEBUG: next line was Some");
return Err(ParseDnskeyTextError::Misformatted);
}

// Parse the entire record.
let mut scanner = IterScanner::new(line.split_ascii_whitespace());

eprintln!("DEBUG: line = '{}'", line);
let name = scanner
.scan_name()
.map_err(|_| ParseDnskeyTextError::Misformatted)?;

let name = scanner.scan_name().map_err(|_| {
eprintln!("DEBUG: owner name failed");
ParseDnskeyTextError::Misformatted
})?;

let _ = Class::scan(&mut scanner).map_err(|_| {
eprintln!("DEBUG: class parsing failed");
ParseDnskeyTextError::Misformatted
})?;
let _ = Class::scan(&mut scanner)
.map_err(|_| ParseDnskeyTextError::Misformatted)?;

if Rtype::scan(&mut scanner).map_or(true, |t| t != Rtype::DNSKEY) {
eprintln!("DEBUG: rtype parsing failed");
return Err(ParseDnskeyTextError::Misformatted);
}

let data = Dnskey::scan(&mut scanner).map_err(|err| {
eprintln!("DEBUG: record data parsing failed {err}");
ParseDnskeyTextError::Misformatted
})?;
let data = Dnskey::scan(&mut scanner)
.map_err(|_| ParseDnskeyTextError::Misformatted)?;

Self::from_dnskey(name, data)
.map_err(ParseDnskeyTextError::FromDnskey)
Expand All @@ -330,7 +322,7 @@ impl<Octs: AsRef<[u8]>> Key<Octs> {
"{} {} DNSKEY {}",
self.owner().fmt_with_dot(),
class,
self.to_dnskey(),
self.to_dnskey().display_zonefile(false),
)
}
}
Expand Down

0 comments on commit 0f54a8d

Please sign in to comment.