Skip to content

Commit

Permalink
Rename SecAlg to SecurityAlgorithm and *Alg to *Algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-NLnetLabs committed Dec 19, 2024
1 parent d062747 commit 0408092
Show file tree
Hide file tree
Showing 17 changed files with 346 additions and 315 deletions.
14 changes: 7 additions & 7 deletions src/base/iana/digestalg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Delegation signer digest algorithm numbers.
//------------ DigestAlg -----------------------------------------------------
//------------ DigestAlgorithm -----------------------------------------------

int_enum! {
/// Delegation signer digest algorithm numbers.
Expand All @@ -13,7 +13,7 @@ int_enum! {
///
/// [IANA registration]: https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml#ds-rr-types-1
=>
DigestAlg, u8;
DigestAlgorithm, u8;

/// Specifies that the SHA-1 hash function is used.
///
Expand Down Expand Up @@ -42,8 +42,8 @@ int_enum! {
(SHA384 => 4, "SHA-384")
}

int_enum_str_decimal!(DigestAlg, u8);
int_enum_zonefile_fmt_decimal!(DigestAlg, "digest type");
int_enum_str_decimal!(DigestAlgorithm, u8);
int_enum_zonefile_fmt_decimal!(DigestAlgorithm, "digest type");

//============ Tests =========================================================

Expand All @@ -52,10 +52,10 @@ mod test {
#[cfg(feature = "serde")]
#[test]
fn ser_de() {
use super::DigestAlg;
use super::DigestAlgorithm;
use serde_test::{assert_tokens, Token};

assert_tokens(&DigestAlg::SHA384, &[Token::U8(4)]);
assert_tokens(&DigestAlg(100), &[Token::U8(100)]);
assert_tokens(&DigestAlgorithm::SHA384, &[Token::U8(4)]);
assert_tokens(&DigestAlgorithm(100), &[Token::U8(100)]);
}
}
8 changes: 4 additions & 4 deletions src/base/iana/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
//! `FromStrError` without having to resort to devilishly long names.
pub use self::class::Class;
pub use self::digestalg::DigestAlg;
pub use self::digestalg::DigestAlgorithm;
pub use self::exterr::ExtendedErrorCode;
pub use self::nsec3::Nsec3HashAlg;
pub use self::nsec3::Nsec3HashAlgorithm;
pub use self::opcode::Opcode;
pub use self::opt::OptionCode;
pub use self::rcode::{OptRcode, Rcode, TsigRcode};
pub use self::rtype::Rtype;
pub use self::secalg::SecAlg;
pub use self::secalg::SecurityAlgorithm;
pub use self::svcb::SvcParamKey;
pub use self::zonemd::{ZonemdAlg, ZonemdScheme};
pub use self::zonemd::{ZonemdAlgorithm, ZonemdScheme};

#[macro_use]
mod macros;
Expand Down
8 changes: 4 additions & 4 deletions src/base/iana/nsec3.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! NSEC3 hash algorithms.
//------------ Nsec3HashAlg --------------------------------------------------
//------------ Nsec3HashAlgorithm --------------------------------------------

int_enum! {
/// NSEC3 hash algorithm numbers.
Expand All @@ -14,11 +14,11 @@ int_enum! {
/// [NSEC3]: ../../../rdata/rfc5155/index.html
/// [IANA registration]: https://www.iana.org/assignments/dnssec-nsec3-parameters/dnssec-nsec3-parameters.xhtml#dnssec-nsec3-parameters-3
=>
Nsec3HashAlg, u8;
Nsec3HashAlgorithm, u8;

/// Specifies that the SHA-1 hash function is used.
(SHA1 => 1, "SHA-1")
}

int_enum_str_decimal!(Nsec3HashAlg, u8);
int_enum_zonefile_fmt_decimal!(Nsec3HashAlg, "hash algorithm");
int_enum_str_decimal!(Nsec3HashAlgorithm, u8);
int_enum_zonefile_fmt_decimal!(Nsec3HashAlgorithm, "hash algorithm");
8 changes: 4 additions & 4 deletions src/base/iana/secalg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! DNSSEC Algorithm Numbers
//------------ SecAlg -------------------------------------------------------
//------------ SecurityAlgorithm ---------------------------------------------

int_enum! {
/// Security Algorithm Numbers.
Expand All @@ -11,7 +11,7 @@ int_enum! {
///
/// [IANA registration]: http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml#dns-sec-alg-numbers-1].
=>
SecAlg, u8;
SecurityAlgorithm, u8;

/// Delete DS
///
Expand Down Expand Up @@ -116,5 +116,5 @@ int_enum! {
(PRIVATEOID => 254, "PRIVATEOID")
}

int_enum_str_decimal!(SecAlg, u8);
int_enum_zonefile_fmt_decimal!(SecAlg, "algorithm");
int_enum_str_decimal!(SecurityAlgorithm, u8);
int_enum_zonefile_fmt_decimal!(SecurityAlgorithm, "algorithm");
8 changes: 4 additions & 4 deletions src/base/iana/zonemd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int_enum! {
int_enum_str_decimal!(ZonemdScheme, u8);
int_enum_zonefile_fmt_decimal!(ZonemdScheme, "scheme");

//------------ ZonemdAlg -----------------------------------------------------
//------------ ZonemdAlgorithm -----------------------------------------------

int_enum! {
/// ZONEMD algorithms.
Expand All @@ -37,7 +37,7 @@ int_enum! {
/// [ZONEMD]: ../../../rdata/zonemd/index.html
/// [IANA registration]: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#zonemd-hash-algorithms
=>
ZonemdAlg, u8;
ZonemdAlgorithm, u8;

/// Specifies that the SHA-384 algorithm is used.
(SHA384 => 1, "SHA384")
Expand All @@ -46,5 +46,5 @@ int_enum! {
(SHA512 => 2, "SHA512")
}

int_enum_str_decimal!(ZonemdAlg, u8);
int_enum_zonefile_fmt_decimal!(ZonemdAlg, "hash algorithm");
int_enum_str_decimal!(ZonemdAlgorithm, u8);
int_enum_zonefile_fmt_decimal!(ZonemdAlgorithm, "hash algorithm");
44 changes: 22 additions & 22 deletions src/base/opt/algsig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//!
//! [RFC 6975]: https://tools.ietf.org/html/rfc6975
use super::super::iana::{OptionCode, SecAlg};
use super::super::iana::{OptionCode, SecurityAlgorithm};
use super::super::message_builder::OptBuilder;
use super::super::wire::{Compose, Composer, ParseError};
use super::{
Expand All @@ -34,14 +34,14 @@ use core::marker::PhantomData;
/// This type provides the option data for the three options DAU, DHU, and
/// N3U which allow a client to specify the cryptographic algorithms it
/// supports for DNSSEC signatures, DS hashes, and NSEC3 hashes respectively.
/// Each of them contains a sequence of [`SecAlg`] values in wire format.
/// Each of them contains a sequence of [`SecurityAlgorithm`] values in wire format.
///
/// Which exact option is to be used is specified via the `Variant` type
/// argument. Three marker types `DauVariant`, `DhuVariant` and `N3uVariant`
/// are defined with accompanying type aliases [`Dau`], [`Dhu`], and [`N3u`].
///
/// You can create a new value from anything that can be turned into an
/// iterator over [`SecAlg`] via the
/// iterator over [`SecurityAlgorithm`] via the
/// [`from_sec_algs`][Understood::from_sec_algs] associated function.
/// Once you have a value, you can iterate over the algorithms via the
/// [`iter`][Understood::iter] method or use the [`IntoIterator`] implementation
Expand All @@ -54,7 +54,7 @@ pub struct Understood<Variant, Octs: ?Sized> {

/// The octets with the data.
///
/// These octets contain a sequence of composed [`SecAlg`] values.
/// These octets contain a sequence of composed [`SecurityAlgorithm`] values.
octets: Octs,
}

Expand Down Expand Up @@ -119,7 +119,7 @@ impl<Variant, Octs> Understood<Variant, Octs> {
/// The operation will fail if the iterator returns more than 32,767
/// algorithms.
pub fn from_sec_algs(
sec_algs: impl IntoIterator<Item = SecAlg>
sec_algs: impl IntoIterator<Item = SecurityAlgorithm>
) -> Result<Self, BuildDataError>
where
Octs: FromBuilder,
Expand Down Expand Up @@ -211,11 +211,11 @@ impl<Variant, Octs: ?Sized> Understood<Variant, Octs> {
}

/// Returns an iterator over the algorithms in the data.
pub fn iter(&self) -> SecAlgsIter
pub fn iter(&self) -> SecurityAlgorithmsIter
where
Octs: AsRef<[u8]>,
{
SecAlgsIter::new(self.octets.as_ref())
SecurityAlgorithmsIter::new(self.octets.as_ref())
}
}

Expand Down Expand Up @@ -377,8 +377,8 @@ impl<'a, Variant, Octs> IntoIterator for &'a Understood<Variant, Octs>
where
Octs: AsRef<[u8]> + ?Sized
{
type Item = SecAlg;
type IntoIter = SecAlgsIter<'a>;
type Item = SecurityAlgorithm;
type IntoIter = SecurityAlgorithmsIter<'a>;

fn into_iter(self) -> Self::IntoIter {
self.iter()
Expand Down Expand Up @@ -480,12 +480,12 @@ impl<Target: Composer> OptBuilder<'_, Target> {
/// The DAU option lists the DNSSEC signature algorithms the requester
/// supports.
pub fn dau(
&mut self, algs: &impl AsRef<[SecAlg]>,
&mut self, algs: &impl AsRef<[SecurityAlgorithm]>,
) -> Result<(), BuildDataError> {
Ok(self.push_raw_option(
OptionCode::DAU,
u16::try_from(
algs.as_ref().len() * usize::from(SecAlg::COMPOSE_LEN)
algs.as_ref().len() * usize::from(SecurityAlgorithm::COMPOSE_LEN)
).map_err(|_| BuildDataError::LongOptData)?,
|octs| {
algs.as_ref().iter().try_for_each(|item| item.compose(octs))
Expand All @@ -497,12 +497,12 @@ impl<Target: Composer> OptBuilder<'_, Target> {
///
/// The DHU option lists the DS hash algorithms the requester supports.
pub fn dhu(
&mut self, algs: &impl AsRef<[SecAlg]>,
&mut self, algs: &impl AsRef<[SecurityAlgorithm]>,
) -> Result<(), BuildDataError> {
Ok(self.push_raw_option(
OptionCode::DHU,
u16::try_from(
algs.as_ref().len() * usize::from(SecAlg::COMPOSE_LEN)
algs.as_ref().len() * usize::from(SecurityAlgorithm::COMPOSE_LEN)
).map_err(|_| BuildDataError::LongOptData)?,
|octs| {
algs.as_ref().iter().try_for_each(|item| item.compose(octs))
Expand All @@ -514,12 +514,12 @@ impl<Target: Composer> OptBuilder<'_, Target> {
///
/// The N3U option lists the NSEC3 hash algorithms the requester supports.
pub fn n3u(
&mut self, algs: &impl AsRef<[SecAlg]>,
&mut self, algs: &impl AsRef<[SecurityAlgorithm]>,
) -> Result<(), BuildDataError> {
Ok(self.push_raw_option(
OptionCode::N3U,
u16::try_from(
algs.as_ref().len() * usize::from(SecAlg::COMPOSE_LEN)
algs.as_ref().len() * usize::from(SecurityAlgorithm::COMPOSE_LEN)
).map_err(|_| BuildDataError::LongOptData)?,
|octs| {
algs.as_ref().iter().try_for_each(|item| item.compose(octs))
Expand All @@ -528,21 +528,21 @@ impl<Target: Composer> OptBuilder<'_, Target> {
}
}

//------------ SecAlgsIter ---------------------------------------------------
//------------ SecurityAlgorithmsIter ----------------------------------------

pub struct SecAlgsIter<'a>(slice::Iter<'a, u8>);
pub struct SecurityAlgorithmsIter<'a>(slice::Iter<'a, u8>);

impl<'a> SecAlgsIter<'a> {
impl<'a> SecurityAlgorithmsIter<'a> {
fn new(slice: &'a [u8]) -> Self {
SecAlgsIter(slice.iter())
SecurityAlgorithmsIter(slice.iter())
}
}

impl Iterator for SecAlgsIter<'_> {
type Item = SecAlg;
impl Iterator for SecurityAlgorithmsIter<'_> {
type Item = SecurityAlgorithm;

fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(|x| SecAlg::from_int(*x))
self.0.next().map(|x| SecurityAlgorithm::from_int(*x))
}
}

Expand Down
Loading

0 comments on commit 0408092

Please sign in to comment.