#![no_std]
#![warn(
clippy::alloc_instead_of_core,
clippy::print_stdout,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc,
missing_docs
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "std")]
extern crate std;
#[macro_use]
extern crate alloc;
#[cfg(feature = "access-control")]
pub mod access_control;
#[cfg(any(feature = "dnssec-aws-lc-rs", feature = "dnssec-ring"))]
pub mod dnssec;
mod error;
pub use error::ProtoError;
pub mod op;
pub mod rr;
pub mod serialize;
#[cfg(feature = "std")]
pub(crate) use rand::random;
#[cfg(all(not(feature = "std"), feature = "no-std-rand"))]
pub(crate) use no_std_rand::random;
#[cfg(all(not(feature = "std"), feature = "no-std-rand"))]
pub use no_std_rand::seed;
use core::net::{IpAddr, Ipv4Addr, Ipv6Addr};
#[cfg(all(not(feature = "std"), feature = "no-std-rand"))]
mod no_std_rand {
use core::cell::RefCell;
use critical_section::Mutex;
use rand::distr::{Distribution, StandardUniform};
use rand::{RngExt, SeedableRng, rngs::StdRng};
pub(crate) fn random<T>() -> T
where
StandardUniform: Distribution<T>,
{
critical_section::with(|cs| {
RNG.borrow_ref_mut(cs)
.as_mut()
.expect("the no_std rng was not seeded using `hickory_proto::seed()`")
.random()
})
}
pub fn seed(seed: u64) {
critical_section::with(|cs| *RNG.borrow_ref_mut(cs) = Some(StdRng::seed_from_u64(seed)));
}
static RNG: Mutex<RefCell<Option<StdRng>>> = Mutex::new(RefCell::new(None));
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_no_std_rand() {
seed(0x1337);
let _ = random::<u32>();
}
}
}
pub const ROOTS: &[IpAddr] = &[
IpAddr::V4(Ipv4Addr::new(198, 41, 0, 4)),
IpAddr::V6(Ipv6Addr::new(
0x2001, 0x503, 0xba3e, 0x0, 0x0, 0x0, 0x2, 0x30,
)),
IpAddr::V4(Ipv4Addr::new(170, 247, 170, 2)),
IpAddr::V6(Ipv6Addr::new(0x2801, 0x1b8, 0x10, 0x0, 0x0, 0x0, 0x0, 0xb)),
IpAddr::V4(Ipv4Addr::new(192, 33, 4, 12)),
IpAddr::V6(Ipv6Addr::new(0x2001, 0x500, 0x2, 0x0, 0x0, 0x0, 0x0, 0xc)),
IpAddr::V4(Ipv4Addr::new(199, 7, 91, 13)),
IpAddr::V6(Ipv6Addr::new(0x2001, 0x500, 0x2d, 0x0, 0x0, 0x0, 0x0, 0xd)),
IpAddr::V4(Ipv4Addr::new(192, 203, 230, 10)),
IpAddr::V6(Ipv6Addr::new(0x2001, 0x500, 0xa8, 0x0, 0x0, 0x0, 0x0, 0xe)),
IpAddr::V4(Ipv4Addr::new(192, 5, 5, 241)),
IpAddr::V6(Ipv6Addr::new(0x2001, 0x500, 0x2f, 0x0, 0x0, 0x0, 0x0, 0xf)),
IpAddr::V4(Ipv4Addr::new(192, 112, 36, 4)),
IpAddr::V6(Ipv6Addr::new(
0x2001, 0x500, 0x12, 0x0, 0x0, 0x0, 0x0, 0xd0d,
)),
IpAddr::V4(Ipv4Addr::new(198, 97, 190, 53)),
IpAddr::V6(Ipv6Addr::new(0x2001, 0x500, 0x1, 0x0, 0x0, 0x0, 0x0, 0x53)),
IpAddr::V4(Ipv4Addr::new(192, 36, 148, 17)),
IpAddr::V6(Ipv6Addr::new(0x2001, 0x7fe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x53)),
IpAddr::V4(Ipv4Addr::new(192, 58, 128, 30)),
IpAddr::V6(Ipv6Addr::new(
0x2001, 0x503, 0xc27, 0x0, 0x0, 0x0, 0x2, 0x30,
)),
IpAddr::V4(Ipv4Addr::new(193, 0, 14, 129)),
IpAddr::V6(Ipv6Addr::new(0x2001, 0x7fd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1)),
IpAddr::V4(Ipv4Addr::new(199, 7, 83, 42)),
IpAddr::V6(Ipv6Addr::new(0x2001, 0x500, 0x9f, 0x0, 0x0, 0x0, 0x0, 0x42)),
IpAddr::V4(Ipv4Addr::new(202, 12, 27, 33)),
IpAddr::V6(Ipv6Addr::new(0x2001, 0xdc3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x35)),
];