trojan-proto
Zero-copy parser and serializer for the Trojan protocol.
Overview
This crate handles the wire format of the Trojan protocol:
- Request parsing — Parse Trojan request headers (command, address, port) from raw bytes
- UDP packet parsing — Parse Trojan UDP relay packets with address and payload
- Serialization — Write request headers and UDP packets to buffers
- Hash validation — Verify SHA-224 password hashes
All parsers are zero-copy, borrowing from the input buffer to avoid allocations.
Protocol Format
+-----------+-----------+-----+------+----------+
| hash (56) | CRLF (2) | CMD | ADDR | CRLF (2) |
+-----------+-----------+-----+------+----------+
hash— 56-byte hex-encoded SHA-224 of the passwordCMD—0x01(CONNECT),0x03(UDP ASSOCIATE), or0x7f(MUX)ADDR— SOCKS5-style address: IPv4/IPv6/domain + port
Usage
use ;
let = parse_request?;
assert_eq!;
println!;
License
GPL-3.0-only