Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AsRef impl for Record to allow for passing records by references when signing #288

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/base/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ impl<N, D> From<(N, u32, D)> for Record<N, D> {
}
}

//--- AsRef

impl<N, D> AsRef<Record<N, D>> for Record<N, D> {
fn as_ref(&self) -> &Record<N, D> {
self
}
}

//--- OctetsFrom and FlattenInto
//
// XXX We don’t have blanket FromOctets for a type T into itself, so this may
Expand Down
6 changes: 3 additions & 3 deletions src/rdata/zonemd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<Octs> Zonemd<Octs> {
}

pub(super) fn flatten<Target: OctetsFrom<Octs>>(
self
self,
) -> Result<Zonemd<Target>, Target::Error> {
self.convert_octets()
}
Expand Down Expand Up @@ -361,8 +361,6 @@ mod test {
use crate::base::rdata::test::{
test_compose_parse, test_rdlen, test_scan,
};
use crate::base::Dname;
use crate::rdata::ZoneRecordData;
use crate::utils::base16::decode;
use std::string::ToString;
use std::vec::Vec;
Expand Down Expand Up @@ -393,6 +391,8 @@ mod test {
#[cfg(feature = "zonefile")]
#[test]
fn zonemd_parse_zonefile() {
use crate::base::Dname;
use crate::rdata::ZoneRecordData;
use crate::zonefile::inplace::{Entry, Zonefile};

// section A.1
Expand Down
1 change: 0 additions & 1 deletion src/utils/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ impl<Builder: OctetsBuilder> Decoder<Builder> {

//--- Default

#[cfg(feature = "bytes")]
impl<Builder: EmptyBuilder> Default for Decoder<Builder> {
fn default() -> Self {
Self::new()
Expand Down
10 changes: 6 additions & 4 deletions src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub trait RrsigExt {
fn signed_data<N: ToDname, D: RecordData, B: Composer>(
&self,
buf: &mut B,
records: &mut [Record<N, D>],
records: &mut [impl AsRef<Record<N, D>>],
) -> Result<(), B::AppendError>
where
D: CanonicalOrd + ComposeRecordData + Sized;
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<Octets: AsRef<[u8]>, Name: ToDname> RrsigExt for Rrsig<Octets, Name> {
fn signed_data<N: ToDname, D: RecordData, B: Composer>(
&self,
buf: &mut B,
records: &mut [Record<N, D>],
records: &mut [impl AsRef<Record<N, D>>],
) -> Result<(), B::AppendError>
where
D: CanonicalOrd + ComposeRecordData + Sized,
Expand All @@ -170,10 +170,12 @@ impl<Octets: AsRef<[u8]>, Name: ToDname> RrsigExt for Rrsig<Octets, Name> {

// The set of all RR(i) is sorted into canonical order.
// See https://tools.ietf.org/html/rfc4034#section-6.3
records.sort_by(|a, b| a.data().canonical_cmp(b.data()));
records.sort_by(|a, b| {
a.as_ref().data().canonical_cmp(b.as_ref().data())
});

// RR(i) = name | type | class | OrigTTL | RDATA length | RDATA
for rr in records {
for rr in records.iter().map(|r| r.as_ref()) {
// Handle expanded wildcards as per [RFC4035, Section 5.3.2]
// (https://tools.ietf.org/html/rfc4035#section-5.3.2).
let rrsig_labels = usize::from(self.labels());
Expand Down
Loading