Expand description
Validation and helper functions for Tor-related data.
This module provides utilities for validating Tor-specific identifiers and performing secure operations. These functions are used throughout the library to ensure data integrity and prevent protocol injection attacks.
§Conceptual Role
The validation functions in this module check format correctness for:
- Relay fingerprints (40-character hex strings)
- Relay nicknames (1-19 alphanumeric characters)
- Circuit and stream identifiers
- Hidden service addresses (v2 and v3)
- IP addresses and ports
§Security Considerations
secure_compareuses constant-time comparison to prevent timing attacks- Input validation prevents protocol injection in control commands
- All validation functions are pure and have no side effects
§Example
use stem_rs::util::{is_valid_fingerprint, is_valid_nickname, is_valid_hidden_service_address};
// Validate a relay fingerprint
assert!(is_valid_fingerprint("9695DFC35FFEB861329B9F1AB04C46397020CE31"));
// Validate a relay nickname
assert!(is_valid_nickname("MyRelay"));
assert!(!is_valid_nickname("invalid-name")); // hyphens not allowed
// Validate hidden service addresses
assert!(is_valid_hidden_service_address("facebookcorewwwi")); // v2§See Also
Controller- Uses these validators for input checking- Python Stem equivalent:
stem.util.tor_tools
Functions§
- expand_
ipv6_ address - Expands a compressed IPv6 address to full notation.
- is_
hex_ digits - Checks if a string contains exactly the specified number of hex digits.
- is_
private_ address - Checks if an IPv4 address is in a private range.
- is_
valid_ circuit_ id - Validates a circuit identifier.
- is_
valid_ connection_ id - Validates a connection_id(s: &str.
- is_
valid_ fingerprint - Validates a relay fingerprint string.
- is_
valid_ fingerprint_ with_ prefix - Validates a relay fingerprint with optional
$prefix. - is_
valid_ hidden_ service_ address - Validates a hidden service address (v2 or v3).
- is_
valid_ hidden_ service_ address_ v2 - Validates a v2 hidden service address.
- is_
valid_ hidden_ service_ address_ v3 - Validates a v3 hidden service address.
- is_
valid_ ipv4_ address - Validates an IPv4 address string.
- is_
valid_ ipv6_ address - Validates an IPv6 address string.
- is_
valid_ ipv6_ address_ bracketed - Validates an IPv6 address string, optionally with brackets.
- is_
valid_ nickname - Validates a relay nickname.
- is_
valid_ port - Validates a port number string.
- is_
valid_ port_ number - Validates a port number.
- is_
valid_ stream_ id - Validates a stream identifier.
- secure_
compare - Compares two byte slices in constant time.