diff --git a/src/repository/resources/asres.rs b/src/repository/resources/asres.rs index d1c7786..c23471c 100644 --- a/src/repository/resources/asres.rs +++ b/src/repository/resources/asres.rs @@ -25,7 +25,7 @@ use routecore::asn::ParseAsnError; use super::super::cert::Overclaim; use super::super::x509::encode_extension; use super::super::error::VerificationError; -use super::chain::{Block, SharedChain}; +use super::chain::{Block, OwnedChain, SharedChain}; use super::choice::{InheritedResources, ResourcesChoice}; @@ -296,6 +296,17 @@ impl AsBlocks { AsBlocks(SharedChain::empty()) } + /// Creates a value covering all ASNs. + pub fn all() -> Self { + AsBlocks(SharedChain::from_owned( + unsafe { + OwnedChain::from_vec_unchecked(vec![ + AsBlock::all() + ]) + } + )) + } + /// Creates AS blocks from AS resources. /// /// If the AS resources are of the inherited variant, a validation error @@ -603,6 +614,11 @@ pub enum AsBlock { } impl AsBlock { + /// Returns an AS block covering all ASNs. + pub fn all() -> AsBlock { + AsBlock::Range(AsRange::all()) + } + /// The smallest AS number that is part of this block. pub fn min(&self) -> Asn { match *self { @@ -885,6 +901,11 @@ impl AsRange { AsRange { min, max } } + /// Returns an AS block covering all ASNs. + pub fn all() -> AsRange { + AsRange::new(Asn::MIN, Asn::MAX) + } + /// Returns the smallest AS number that is part of this range. pub fn min(self) -> Asn { self.min @@ -1061,6 +1082,11 @@ impl From for VerificationError { mod test { use super::*; + #[test] + fn as_blocks_all() { + assert_eq!(AsBlocks::all().to_string(), "AS0-AS4294967295"); + } + #[test] fn as_block_from_str() { // Good diff --git a/src/repository/resources/chain.rs b/src/repository/resources/chain.rs index b57c05e..a77676c 100644 --- a/src/repository/resources/chain.rs +++ b/src/repository/resources/chain.rs @@ -566,7 +566,7 @@ impl Eq for Chain {} pub struct OwnedChain(Vec); impl OwnedChain { - unsafe fn from_vec_unchecked(vec: Vec) -> Self { + pub unsafe fn from_vec_unchecked(vec: Vec) -> Self { OwnedChain(vec) } diff --git a/src/repository/resources/ipres.rs b/src/repository/resources/ipres.rs index 611be6a..43d56b6 100644 --- a/src/repository/resources/ipres.rs +++ b/src/repository/resources/ipres.rs @@ -21,7 +21,7 @@ use super::super::cert::Overclaim; use super::super::error::VerificationError; use super::super::roa::RoaIpAddress; use super::super::x509::encode_extension; -use super::chain::{Block, SharedChain}; +use super::chain::{Block, OwnedChain, SharedChain}; use super::choice::{InheritedResources, ResourcesChoice}; @@ -310,6 +310,17 @@ impl IpBlocks { IpBlocks(SharedChain::empty()) } + /// Creates a value covering all addresses. + pub fn all() -> Self { + IpBlocks(SharedChain::from_owned( + unsafe { + OwnedChain::from_vec_unchecked(vec![ + IpBlock::all() + ]) + } + )) + } + /// Creates address blocks from address resources. /// /// If the resources are of the inherited variant, returns an error. @@ -654,6 +665,11 @@ pub enum IpBlock { } impl IpBlock { + /// Creates a new block covering all addresses. + pub fn all() -> Self { + IpBlock::Prefix(Prefix::all()) + } + /// Creates a new block from an IPv4 representation. pub fn from_v4_str(s: &str) -> Result { if let Some(sep) = s.find('/') { @@ -1225,6 +1241,11 @@ impl Prefix { } } + /// Creates a prefix covering all addresses. + pub fn all() -> Self { + Prefix::new(0, 0) + } + /// Creates a new prefix from its encoding as a BIT STRING. pub fn from_bit_string( src: &BitString @@ -1702,6 +1723,11 @@ impl Ipv4Blocks { Ipv4Blocks(IpBlocks::empty()) } + /// Creates a value covering all addresses. + pub fn all() -> Self { + Ipv4Blocks(IpBlocks::all()) + } + pub fn to_ip_resources(&self) -> IpResources { IpResources::blocks(self.0.clone()) } @@ -1788,6 +1814,11 @@ impl Ipv6Blocks { Ipv6Blocks(IpBlocks::empty()) } + /// Creates a value covering all addresses. + pub fn all() -> Self { + Ipv6Blocks(IpBlocks::all()) + } + pub fn to_ip_resources(&self) -> IpResources { IpResources::blocks(self.0.clone()) } @@ -2051,6 +2082,12 @@ mod test { use bcder::encode::Values; use super::*; + #[test] + fn ip_blocks_all() { + assert_eq!(Ipv4Blocks::all().to_string(), "0.0.0.0/0"); + assert_eq!(Ipv6Blocks::all().to_string(), "::/0"); + } + #[test] fn ip_blocks_to_v4_str() { let expected_str = "10.0.0.0, 10.1.0.0-10.1.2.255, 192.168.0.0/16"; diff --git a/src/repository/resources/set.rs b/src/repository/resources/set.rs index 8210291..4d59722 100644 --- a/src/repository/resources/set.rs +++ b/src/repository/resources/set.rs @@ -45,11 +45,11 @@ impl ResourceSet { } pub fn all() -> ResourceSet { - let asns = "0-4294967295"; - let v4 = "0.0.0.0-255.255.255.255"; - let v6 = "::0/0"; - - ResourceSet::from_strs(asns, v4, v6).unwrap() + ResourceSet { + asn: AsBlocks::all(), + ipv4: Ipv4Blocks::all(), + ipv6: Ipv6Blocks::all(), + } } pub fn is_empty(&self) -> bool {