pub fn is_valid_handle(handle: &str) -> Option<String>Expand description
Validates and normalizes an AT Protocol handle.
A valid AT Protocol handle must:
- Be a valid hostname (after stripping prefixes)
- Contain at least one period (to distinguish from simple hostnames)
- Follow all hostname validation rules (RFC 1035)
The function automatically strips common prefixes (at:// and @) before validation.
§Arguments
handle- The handle string to validate and normalize
§Returns
Some(String) containing the normalized handle if valid, None if invalid
§Examples
use atproto_identity::validation::is_valid_handle;
// Valid handles
assert_eq!(is_valid_handle("alice.bsky.social"), Some("alice.bsky.social".to_string()));
assert_eq!(is_valid_handle("@bob.example.com"), Some("bob.example.com".to_string()));
assert_eq!(is_valid_handle("at://charlie.test.com"), Some("charlie.test.com".to_string()));
// Invalid handles
assert_eq!(is_valid_handle("localhost"), None); // No period
assert_eq!(is_valid_handle("192.168.1.1"), None); // IPv4 address
assert_eq!(is_valid_handle("invalid..handle.com"), None); // Double dot