Module datatype

Module datatype 

Source
Expand description

Data types for the Tor relay protocol.

This module provides low-level data types used in ORPort communication with Tor relays. These types handle the binary encoding and decoding of protocol messages as defined in the Tor specification.

§Overview

The module contains several categories of types:

§Conceptual Role

These types form the foundation of the ORPort protocol implementation. They handle the serialization and deserialization of binary data according to Tor’s wire format, which uses big-endian byte ordering throughout.

Most users should interact with the higher-level Relay and RelayCircuit types rather than using these primitives directly.

§Wire Format

All multi-byte integers are encoded in network byte order (big-endian). Variable-length fields are typically prefixed with their length.

§Example

use stem_rs::client::datatype::{Size, Address, AddrType};

// Pack and unpack integers
let packed = Size::Short.pack(9001);
assert_eq!(packed, vec![0x23, 0x29]);

let unpacked = Size::Short.unpack(&packed).unwrap();
assert_eq!(unpacked, 9001);

// Parse an IPv4 address
let addr = Address::new("127.0.0.1").unwrap();
assert_eq!(addr.addr_type, AddrType::IPv4);

§Security Considerations

These types handle untrusted network data. All parsing functions validate input lengths and return errors for malformed data rather than panicking.

§See Also

  • cell - Cell types that use these data types for encoding
  • Relay - High-level relay connection interface
  • RelayCircuit - Circuit management using these primitives

Structs§

Address
A relay address with type information.
Certificate
A relay certificate as defined in tor-spec section 4.2.
KDF
KDF-TOR derived key material.
LinkProtocol
Link protocol version with version-dependent constants.

Enums§

AddrType
Address type identifier for relay addresses.
CertType
Certificate type identifier.
CloseReason
Reason for closing a circuit or stream.
LinkSpecifier
Method of communicating with a relay in a circuit.
RelayCommand
Relay cell command types.
Size
Integer size types for packing and unpacking binary data.

Constants§

HASH_LEN
Length of SHA-1 hash output in bytes (160 bits).
KEY_LEN
Length of symmetric encryption keys in bytes (128 bits).
ZERO
Null byte constant used for padding in the Tor protocol.

Functions§

split
Splits a byte slice at the given position, clamping to the slice length.