Cotton code
25 lines · 857 B · RustRaw
//! The relay's NAME shape — a handle's, since a handle is a relay name.//!//! Two readers need it here: `server_address::server_name_of` (the label of a//! `<name>.relay.cottondb.com` address) and the peer handle claim//! (`devices::device_auth::parse_peer_headers`). A third copy would be a third//! opinion about what a handle is./// `[a-z0-9][a-z0-9-]{1,30}` — the shape of a cottondb.com handle.pub fn name_pattern(name: &str) -> bool {    let bytes = name.as_bytes();    if bytes.len() < 2 || bytes.len() > 31 {        return false;    }    let first = bytes[0];    if !(first.is_ascii_lowercase() || first.is_ascii_digit()) {        return false;    }    bytes[1..]        .iter()        .all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || *b == b'-')}#[cfg(test)]#[path = "relay_name_tests.rs"]mod relay_name_tests;