reserve-core 0.2.0

Core lookup, catalog, and rate-limiting engine behind the reserve domain finder
Documentation
//! Deciding whether a name is registered, and being honest when that cannot be decided.

mod engine;
mod outcome;
mod rdap;
mod referral;
mod registration;
pub(crate) mod registry;
mod resolve;
mod verdict;
mod whois;

pub use engine::{Engine, Settings, SourcePolicy};
pub use outcome::{Finding, Reason, Source, Status, Tally};
pub use referral::Delegation;
pub use registration::Registration;
pub use registry::{BOOTSTRAP_URL, Freshness, ServiceMap};
pub use resolve::{DnsRecords, DnsVerdict, dns_records};
pub use whois::{Server, Servers};

/// @docgen A character device or a pipe reports a length of zero, so the ceiling is measured while reading rather than asked for first.
pub(crate) fn read_capped(path: &std::path::Path, limit: u64) -> std::io::Result<String> {
    use std::io::Read as _;

    let file = std::fs::File::open(path)?;
    let mut text = String::new();
    let read = file.take(limit + 1).read_to_string(&mut text)?;
    if read as u64 > limit {
        return Err(std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            format!("{} is larger than {limit} bytes", path.display()),
        ));
    }
    Ok(text)
}

/// @docgen Sized well above the bundled tables so a real list always fits while a hostile or endless file does not.
pub(crate) const MAX_TABLE_BYTES: u64 = 8 * 1024 * 1024;