From 3d5816596e70afeb2d38b2edced75ccfd3bd3d3d Mon Sep 17 00:00:00 2001 From: Martin Hoffmann Date: Tue, 19 Oct 2021 13:00:58 +0200 Subject: [PATCH] Rename MasterRecordData to ZoneRecordData. (#113) --- src/master/entry.rs | 6 +- src/rdata/macros.rs | 149 +++++++++++++++++++++++--------------------- src/rdata/mod.rs | 26 ++++---- src/validate.rs | 6 +- 4 files changed, 96 insertions(+), 91 deletions(-) diff --git a/src/master/entry.rs b/src/master/entry.rs index 21537215..045b4bd8 100644 --- a/src/master/entry.rs +++ b/src/master/entry.rs @@ -2,7 +2,7 @@ use super::scan::{CharSource, Pos, Scan, ScanError, Scanner, SyntaxError}; use crate::base::iana::{Class, Rtype}; use crate::base::name::Dname; use crate::base::record::Record; -use crate::rdata::MasterRecordData; +use crate::rdata::ZoneRecordData; use bytes::Bytes; /// A master file entry. use std::borrow::ToOwned; @@ -158,7 +158,7 @@ impl Entry { let (ttl, class) = Self::scan_ttl_class(scanner, last_class, default_ttl)?; let rtype = Rtype::scan(scanner)?; - let rdata = MasterRecordData::scan(rtype, scanner)?; + let rdata = ZoneRecordData::scan(rtype, scanner)?; scanner.scan_newline()?; Ok(Record::new(owner, class, ttl, rdata)) } @@ -255,4 +255,4 @@ impl Scan for ControlType { //------------ MasterRecord -------------------------------------------------- pub type MasterRecord = - Record, MasterRecordData>>; + Record, ZoneRecordData>>; diff --git a/src/rdata/macros.rs b/src/rdata/macros.rs index 4138e68c..4bad4beb 100644 --- a/src/rdata/macros.rs +++ b/src/rdata/macros.rs @@ -7,7 +7,7 @@ macro_rules! rdata_types { ( $( $module:ident::{ $( - master { + zone { $( $mtype:ident $( < $( $mn:ident ),* > )*, )* } )* @@ -29,32 +29,32 @@ macro_rules! rdata_types { use crate::base::name::ParsedDname; - //------------- MasterRecordData ------------------------------------- + //------------- ZoneRecordData --------------------------------------- - /// Record data for all record types allowed in master files. + /// Record data for all record types allowed in zone files. /// /// This enum collects the record data types for all currently - /// implemented record types that are allowed to be included in master + /// implemented record types that are allowed to be included in zone /// files. #[derive(Clone)] #[non_exhaustive] - pub enum MasterRecordData { + pub enum ZoneRecordData { $( $( $( $mtype($mtype $( < $( $mn ),* > )*), )* )* )* Other($crate::base::rdata::UnknownRecordData), } - impl MasterRecordData { + impl ZoneRecordData { fn rtype(&self) -> $crate::base::iana::Rtype { match *self { $( $( $( - MasterRecordData::$mtype(_) => { + ZoneRecordData::$mtype(_) => { <$mtype $( < $( $mn ),* > )* as $crate::base::rdata::RtypeRecordData>::RTYPE } )* )* )* - MasterRecordData::Other(ref inner) => inner.rtype(), + ZoneRecordData::Other(ref inner) => inner.rtype(), } } } @@ -64,28 +64,28 @@ macro_rules! rdata_types { impl $crate::base::octets::OctetsFrom< - MasterRecordData + ZoneRecordData > - for MasterRecordData + for ZoneRecordData where Octets: $crate::base::octets::OctetsFrom, Name: $crate::base::octets::OctetsFrom { fn octets_from( - source: MasterRecordData + source: ZoneRecordData ) -> Result { match source { $( $( $( - MasterRecordData::$mtype(inner) => { + ZoneRecordData::$mtype(inner) => { $mtype::octets_from(inner).map( - MasterRecordData::$mtype + ZoneRecordData::$mtype ) } )* )* )* - MasterRecordData::Other(inner) => { + ZoneRecordData::Other(inner) => { $crate::base::rdata:: UnknownRecordData::octets_from(inner).map( - MasterRecordData::Other + ZoneRecordData::Other ) } } @@ -97,43 +97,43 @@ macro_rules! rdata_types { $( $( $( impl From<$mtype $( < $( $mn ),* >)*> - for MasterRecordData { + for ZoneRecordData { fn from(value: $mtype $( < $( $mn ),* >)*) -> Self { - MasterRecordData::$mtype(value) + ZoneRecordData::$mtype(value) } } )* )* )* impl From<$crate::base::rdata::UnknownRecordData> - for MasterRecordData { + for ZoneRecordData { fn from(value: $crate::base::rdata::UnknownRecordData) -> Self { - MasterRecordData::Other(value) + ZoneRecordData::Other(value) } } //--- PartialEq and Eq - impl PartialEq> - for MasterRecordData + impl PartialEq> + for ZoneRecordData where O: AsRef<[u8]>, OO: AsRef<[u8]>, N: $crate::base::name::ToDname, NN: $crate::base::name::ToDname, { - fn eq(&self, other: &MasterRecordData) -> bool { + fn eq(&self, other: &ZoneRecordData) -> bool { match (self, other) { $( $( $( ( - &MasterRecordData::$mtype(ref self_inner), - &MasterRecordData::$mtype(ref other_inner) + &ZoneRecordData::$mtype(ref self_inner), + &ZoneRecordData::$mtype(ref other_inner) ) => { self_inner.eq(other_inner) } )* )* )* ( - &MasterRecordData::Other(ref self_inner), - &MasterRecordData::Other(ref other_inner) + &ZoneRecordData::Other(ref self_inner), + &ZoneRecordData::Other(ref other_inner) ) => { self_inner.eq(other_inner) } @@ -142,35 +142,35 @@ macro_rules! rdata_types { } } - impl Eq for MasterRecordData + impl Eq for ZoneRecordData where O: AsRef<[u8]>, N: $crate::base::name::ToDname { } //--- PartialOrd, Ord, and CanonicalOrd - impl PartialOrd> - for MasterRecordData + impl PartialOrd> + for ZoneRecordData where O: AsRef<[u8]>, OO: AsRef<[u8]>, N: $crate::base::name::ToDname, NN: $crate::base::name::ToDname, { fn partial_cmp( &self, - other: &MasterRecordData + other: &ZoneRecordData ) -> Option { match (self, other) { $( $( $( ( - &MasterRecordData::$mtype(ref self_inner), - &MasterRecordData::$mtype(ref other_inner) + &ZoneRecordData::$mtype(ref self_inner), + &ZoneRecordData::$mtype(ref other_inner) ) => { self_inner.partial_cmp(other_inner) } )* )* )* ( - &MasterRecordData::Other(ref self_inner), - &MasterRecordData::Other(ref other_inner) + &ZoneRecordData::Other(ref self_inner), + &ZoneRecordData::Other(ref other_inner) ) => { self_inner.partial_cmp(other_inner) } @@ -179,8 +179,8 @@ macro_rules! rdata_types { } } - impl $crate::base::cmp::CanonicalOrd> - for MasterRecordData + impl $crate::base::cmp::CanonicalOrd> + for ZoneRecordData where O: AsRef<[u8]>, OO: AsRef<[u8]>, N: $crate::base::cmp::CanonicalOrd + $crate::base::name::ToDname, @@ -188,21 +188,21 @@ macro_rules! rdata_types { { fn canonical_cmp( &self, - other: &MasterRecordData + other: &ZoneRecordData ) -> core::cmp::Ordering { match (self, other) { $( $( $( ( - &MasterRecordData::$mtype(ref self_inner), - &MasterRecordData::$mtype(ref other_inner) + &ZoneRecordData::$mtype(ref self_inner), + &ZoneRecordData::$mtype(ref other_inner) ) => { self_inner.canonical_cmp(other_inner) } )* )* )* ( - &MasterRecordData::Other(ref self_inner), - &MasterRecordData::Other(ref other_inner) + &ZoneRecordData::Other(ref self_inner), + &ZoneRecordData::Other(ref other_inner) ) => { self_inner.canonical_cmp(other_inner) } @@ -213,17 +213,17 @@ macro_rules! rdata_types { //--- Hash - impl core::hash::Hash for MasterRecordData + impl core::hash::Hash for ZoneRecordData where O: AsRef<[u8]>, N: core::hash::Hash { fn hash(&self, state: &mut H) { match *self { $( $( $( - MasterRecordData::$mtype(ref inner) => { + ZoneRecordData::$mtype(ref inner) => { $crate::base::iana::Rtype::$mtype.hash(state); inner.hash(state) } )* )* )* - MasterRecordData::Other(ref inner) => { + ZoneRecordData::Other(ref inner) => { inner.rtype().hash(state); inner.data().as_ref().hash(state); } @@ -237,7 +237,7 @@ macro_rules! rdata_types { // No Parse or ParseAll because Other variant needs to know the // record type. - impl $crate::base::octets::Compose for MasterRecordData + impl $crate::base::octets::Compose for ZoneRecordData where O: AsRef<[u8]>, N: $crate::base::name::ToDname { fn compose( &self, @@ -245,11 +245,11 @@ macro_rules! rdata_types { ) -> Result<(), $crate::base::octets::ShortBuf> { match *self { $( $( $( - MasterRecordData::$mtype(ref inner) => { + ZoneRecordData::$mtype(ref inner) => { inner.compose(target) } )* )* )* - MasterRecordData::Other(ref inner) => { + ZoneRecordData::Other(ref inner) => { inner.compose(target) } } @@ -261,11 +261,11 @@ macro_rules! rdata_types { ) -> Result<(), $crate::base::octets::ShortBuf> { match *self { $( $( $( - MasterRecordData::$mtype(ref inner) => { + ZoneRecordData::$mtype(ref inner) => { inner.compose_canonical(target) } )* )* )* - MasterRecordData::Other(ref inner) => { + ZoneRecordData::Other(ref inner) => { inner.compose_canonical(target) } } @@ -275,25 +275,25 @@ macro_rules! rdata_types { //--- RecordData and ParseRecordData - impl<'a, O, N> $crate::base::rdata::RecordData for &'a MasterRecordData + impl<'a, O, N> $crate::base::rdata::RecordData for &'a ZoneRecordData where O: AsRef<[u8]>, N: $crate::base::name::ToDname { fn rtype(&self) -> $crate::base::iana::Rtype { - MasterRecordData::rtype(self) + ZoneRecordData::rtype(self) } } - impl $crate::base::rdata::RecordData for MasterRecordData + impl $crate::base::rdata::RecordData for ZoneRecordData where O: AsRef<[u8]>, N: $crate::base::name::ToDname { fn rtype(&self) -> $crate::base::iana::Rtype { - MasterRecordData::rtype(self) + ZoneRecordData::rtype(self) } } impl $crate::base::rdata::ParseRecordData - for MasterRecordData> { + for ZoneRecordData> { fn parse_data( rtype: $crate::base::iana::Rtype, parser: &mut $crate::base::octets::Parser, @@ -303,7 +303,7 @@ macro_rules! rdata_types { match rtype { $( $( $( $crate::base::iana::Rtype::$mtype => { - Ok(Some(MasterRecordData::$mtype( + Ok(Some(ZoneRecordData::$mtype( $mtype::parse(parser)? ))) } @@ -311,7 +311,7 @@ macro_rules! rdata_types { _ => { Ok($crate::base::rdata::UnknownRecordData::parse_data( rtype, parser - )?.map(MasterRecordData::Other)) + )?.map(ZoneRecordData::Other)) } } } @@ -322,7 +322,7 @@ macro_rules! rdata_types { #[cfg(feature="master")] #[cfg_attr(docsrs, doc(cfg(feature = "master")))] - impl MasterRecordData< + impl ZoneRecordData< bytes::Bytes, $crate::base::name::Dname > { pub fn scan(rtype: $crate::base::iana::Rtype, @@ -335,18 +335,18 @@ macro_rules! rdata_types { $( $( $( $crate::base::iana::Rtype::$mtype => { $mtype::scan(scanner) - .map(MasterRecordData::$mtype) + .map(ZoneRecordData::$mtype) } )* )* )* _ => { $crate::base::rdata::UnknownRecordData::scan(rtype, scanner) - .map(MasterRecordData::Other) + .map(ZoneRecordData::Other) } } } } - impl core::fmt::Display for MasterRecordData + impl core::fmt::Display for ZoneRecordData where O: AsRef<[u8]>, N: core::fmt::Display @@ -355,18 +355,18 @@ macro_rules! rdata_types { -> core::fmt::Result { match *self { $( $( $( - MasterRecordData::$mtype(ref inner) => { + ZoneRecordData::$mtype(ref inner) => { inner.fmt(f) } )* )* )* - MasterRecordData::Other(ref inner) => inner.fmt(f), + ZoneRecordData::Other(ref inner) => inner.fmt(f), } } } //--- Debug - impl core::fmt::Debug for MasterRecordData + impl core::fmt::Debug for ZoneRecordData where O: AsRef<[u8]>, N: core ::fmt::Debug @@ -375,10 +375,10 @@ macro_rules! rdata_types { -> core::fmt::Result { match *self { $( $( $( - MasterRecordData::$mtype(ref inner) => { + ZoneRecordData::$mtype(ref inner) => { f.write_str( concat!( - "MasterRecordData::", + "ZoneRecordData::", stringify!($mtype), "(" ) @@ -387,8 +387,8 @@ macro_rules! rdata_types { f.write_str(")") } )* )* )* - MasterRecordData::Other(ref inner) => { - f.write_str("MasterRecordData::Other(")?; + ZoneRecordData::Other(ref inner) => { + f.write_str("ZoneRecordData::Other(")?; core::fmt::Debug::fmt(inner, f)?; f.write_str(")") } @@ -466,21 +466,26 @@ macro_rules! rdata_types { impl From<$crate::base::rdata::UnknownRecordData> for AllRecordData { - fn from(value: $crate::base::rdata::UnknownRecordData) -> Self { + fn from( + value: $crate::base::rdata::UnknownRecordData + ) -> Self { AllRecordData::Other(value) } } - impl From> for Result, AllRecordData> { - fn from(value: AllRecordData) -> Result, AllRecordData> { + impl From> + for Result, AllRecordData> { + fn from( + value: AllRecordData + ) -> Result, AllRecordData> { match value { $( $( $( AllRecordData::$mtype(inner) => { - Ok(MasterRecordData::$mtype(inner)) + Ok(ZoneRecordData::$mtype(inner)) } )* )* )* AllRecordData::Other(inner) => { - Ok(MasterRecordData::Other(inner)) + Ok(ZoneRecordData::Other(inner)) } value => Err(value), } diff --git a/src/rdata/mod.rs b/src/rdata/mod.rs index f359d7f7..b70c2357 100644 --- a/src/rdata/mod.rs +++ b/src/rdata/mod.rs @@ -19,8 +19,8 @@ //! In addition, the module provides two enums combining the known types. //! [`AllRecordData`] indeed contains all record data types known plus //! [`UnknownRecordData`][crate::base::rdata::UnknownRecordData] for the -//! rest, while [`MasterRecordData`] only -//! contains those types that can appear in master files plus, again, +//! rest, while [`ZoneRecordData`] only +//! contains those types that can appear in zone files plus, again, //! [`UnknownRecordData`][crate::base::rdata::UnknownRecordData] for //! everything else. @@ -36,9 +36,9 @@ pub mod rfc5155; pub mod rfc6672; pub mod rfc7344; -// The rdata_types! macro (defined in self::macros) reexports the record data -// types here and creates the MasterRecordData and AllRecordData enums -// containing all record types that can appear in master files or all record +// The rdata_types! macro (defined in self::macros) re-exports the record data +// types here and creates the ZoneRecordData and AllRecordData enums +// containing all record types that can appear in a zone and all record // types that exist. // // All record data types listed here MUST have the same name as the @@ -46,7 +46,7 @@ pub mod rfc7344; // relies on that. // // Add any new module here and then add all record types in that module that -// can appear in master files under "master" and all others under "pseudo". +// can appear in zone files under "zone" and all others under "pseudo". // Your type can be generic over an octet type "O" and a domain name type "N". // Add these as needed. // @@ -54,7 +54,7 @@ pub mod rfc7344; // is messy enough as it is ... rdata_types! { rfc1035::{ - master { + zone { A, Cname, Hinfo, @@ -74,7 +74,7 @@ rdata_types! { } } rfc2782::{ - master { + zone { Srv, } } @@ -84,12 +84,12 @@ rdata_types! { } } rfc3596::{ - master { + zone { Aaaa, } } rfc4034::{ - master { + zone { Dnskey, Rrsig, Nsec, @@ -97,18 +97,18 @@ rdata_types! { } } rfc6672::{ - master { + zone { Dname, } } rfc5155::{ - master { + zone { Nsec3, Nsec3param, } } rfc7344::{ - master { + zone { Cdnskey, Cds, } diff --git a/src/validate.rs b/src/validate.rs index 565a5493..020cf684 100644 --- a/src/validate.rs +++ b/src/validate.rs @@ -338,7 +338,7 @@ mod test { use crate::base::iana::{Class, Rtype, SecAlg}; use crate::base::serial::Serial; use crate::master::scan::Scanner; - use crate::rdata::{MasterRecordData, Mx}; + use crate::rdata::{Mx, ZoneRecordData}; use crate::utils::base64; use bytes::Bytes; use std::str::FromStr; @@ -622,12 +622,12 @@ mod test { .into(), ); - let mut records: Vec>> = + let mut records: Vec>> = [&ksk, &zsk] .iter() .cloned() .map(|x| { - let data = MasterRecordData::from(x.clone()); + let data = ZoneRecordData::from(x.clone()); Record::new( rrsig.signer_name().clone(), Class::In,