use rpki::data_model::rc::{ Afi, IpAddressChoice, IpAddressFamily, IpAddressOrRange, IpAddressRange, IpPrefix, IpResourceSet, }; #[test] fn ip_resource_range_covers_prefix_ipv4() { let set = IpResourceSet { families: vec![IpAddressFamily { afi: Afi::Ipv4, choice: IpAddressChoice::AddressesOrRanges(vec![IpAddressOrRange::Range(IpAddressRange { min: vec![10, 0, 0, 0], max: vec![10, 255, 255, 255], })]), }], }; let inside = IpPrefix { afi: Afi::Ipv4, prefix_len: 16, addr: vec![10, 1, 0, 0], }; assert!(set.contains_prefix(&inside)); let outside = IpPrefix { afi: Afi::Ipv4, prefix_len: 16, addr: vec![11, 0, 0, 0], }; assert!(!set.contains_prefix(&outside)); } #[test] fn ip_resource_range_covers_prefix_ipv6() { let set = IpResourceSet { families: vec![IpAddressFamily { afi: Afi::Ipv6, choice: IpAddressChoice::AddressesOrRanges(vec![IpAddressOrRange::Range(IpAddressRange { min: vec![0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], max: vec![0x20, 0x01, 0x0d, 0xb8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], })]), }], }; let inside = IpPrefix { afi: Afi::Ipv6, prefix_len: 64, addr: vec![0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], }; assert!(set.contains_prefix(&inside)); let outside = IpPrefix { afi: Afi::Ipv6, prefix_len: 64, addr: vec![0x20, 0x01, 0x0d, 0xb9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], }; assert!(!set.contains_prefix(&outside)); }