| Crates.io | legion-protocol |
| lib.rs | legion-protocol |
| version | 0.1.0 |
| created_at | 2025-08-21 03:19:09.157002+00 |
| updated_at | 2025-08-21 03:19:09.157002+00 |
| description | ๐๏ธ Legion Protocol - Secure, IRC-compatible communication protocol with E2E encryption |
| homepage | https://github.com/exec/legion-protocol |
| repository | https://github.com/exec/legion-protocol |
| max_upload_size | |
| id | 1804241 |
| size | 257,997 |
Modern IRC extensions with enhanced capabilities and security.
A comprehensive protocol library that extends IRC with modern features while maintaining complete backward compatibility. Part of the Legion ecosystem designed for secure, self-hostable communication.
Legion Protocol is a Rust library that implements IRC protocol parsing and extensions, providing the foundation for modern IRC servers and clients. It includes support for IRCv3 capabilities, message tagging, and enhanced channel management while maintaining 100% compatibility with standard IRC.
๐๏ธ LEGION ECOSYSTEM
โโโ ๐ก legion-protocol (THIS REPO) - Core protocol library
โโโ ๐๏ธ centurion - IRC server implementation
โโโ โ๏ธ legionnaire - IRC client with modern features
โโโ ๐ก๏ธ phalanx - E2E encryption library (future)
#, &, !, +)Add Legion Protocol to your Cargo.toml:
[dependencies]
legion-protocol = { git = "https://github.com/dylan-k/legion-protocol.git" }
Or for local development:
[dependencies]
legion-protocol = { path = "../legion-protocol" }
use legion_protocol::{Message, Command};
// Parse IRC message
let raw = ":nick!user@host PRIVMSG #channel :Hello world!";
let message = Message::parse(raw)?;
assert_eq!(message.prefix, Some("nick!user@host".to_string()));
assert_eq!(message.command, "PRIVMSG");
assert_eq!(message.params, vec!["#channel", "Hello world!"]);
// Convert back to raw format
let formatted = message.to_string();
use legion_protocol::Command;
let command = Command::parse("PRIVMSG", vec!["#channel".to_string(), "Hello!".to_string()]);
match command {
Command::Privmsg { target, message } => {
println!("Message to {}: {}", target, message);
}
Command::Join(channels, keys) => {
println!("Joining channels: {:?}", channels);
}
_ => {}
}
use legion_protocol::Capability;
// Server advertising capabilities
let caps = vec![
Capability::MessageTags,
Capability::ServerTime,
Capability::Sasl,
Capability::Batch,
Capability::EchoMessage,
];
// Convert to CAP LS format
let cap_string = caps.iter()
.map(|cap| cap.to_string())
.collect::<Vec<_>>()
.join(" ");
use legion_protocol::Message;
// Create message with tags
let mut message = Message::new("PRIVMSG")
.with_params(vec!["#channel".to_string(), "Hello!".to_string()]);
// Add server-time tag
message = message.with_tag("time".to_string(), Some("2024-01-01T12:00:00.000Z".to_string()));
// Add message ID
message = message.with_tag("msgid".to_string(), Some("abc123".to_string()));
// Parse message with tags
let raw = "@time=2024-01-01T12:00:00.000Z;msgid=abc123 PRIVMSG #channel :Hello!";
let parsed = Message::parse(raw)?;
assert_eq!(parsed.tags.get("time"), Some(&Some("2024-01-01T12:00:00.000Z".to_string())));
use legion_protocol::SaslMechanism;
// SASL PLAIN mechanism
let mechanism = SaslMechanism::Plain;
let credentials = "username\0username\0password";
let encoded = base64::encode(credentials);
// Send AUTHENTICATE command
println!("AUTHENTICATE PLAIN");
println!("AUTHENTICATE {}", encoded);
message.rs - IRC message parsing and formattingcommand.rs - IRC command enumeration and parsingcapabilities.rs - IRCv3 capability negotiationreplies.rs - IRC numeric replies and errorssasl.rs - SASL authentication mechanismsadmin.rs - Server administration commandsvalidation.rs - Input validation and security checksutils.rs - Utility functions and helpers# Run all tests
cargo test
# Run specific test module
cargo test test_message_parsing
# Run with output
cargo test -- --nocapture
# Run benchmarks
cargo bench
Contributions are welcome! Please see the issues section for current development needs.
git clone https://github.com/dylan-k/legion-protocol.git
cd legion-protocol
cargo build
cargo test
cargo fmt and cargo clippy before submittingLegion Protocol is licensed under the MIT License. See LICENSE for details.
Legion Protocol: Modern IRC extensions built with Rust's safety and performance in mind.