Rust Development Guide

Set up your Rust development environment for the data plane, including building, testing, linting, and contributing to PQC-TLS.

Prerequisites

  • Rust 1.70+ with cargo (install via rustup)
  • liboqs -- Open Quantum Safe library for PQC algorithms
  • pkg-config and cmake -- for native dependency builds

Environment Setup

# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Navigate to the data plane
cd rust/dataplane

# Build all crates
cargo build --locked

# Run tests
cargo test

# Run linter
cargo clippy --all-targets --all-features -- -D warnings

# Format code
cargo fmt

Crate Structure

rust/dataplane/
  Cargo.toml             # Workspace manifest
  crates/
    pqc_tls/             # Post-quantum TLS (ML-KEM, ML-DSA)
    dpdk_engine/         # DPDK packet capture
    dpi_engine/          # Deep packet inspection
    io_engine/           # I/O engine, HA clustering, metrics
    ai_bridge/           # Python AI Engine bridge
    k8s_operator/        # Kubernetes operator
  bin/
    qbitel-bridge/       # Main binary

Building

# Build all crates in debug mode
cargo build

# Build in release mode (optimized)
cargo build --release

# Build a specific crate
cargo build -p pqc_tls

# Build with all features enabled
cargo build --all-features

Testing

# Run all tests
cargo test

# Run tests for a specific crate
cargo test -p pqc_tls

# Run a specific test
cargo test test_kyber_key_exchange

# Run tests with output
cargo test -- --nocapture

# Run integration tests
cargo test --test integration

Code Quality

Linting with Clippy

# Run Clippy with strict settings
cargo clippy --all-targets --all-features -- -D warnings

# Apply automatic fixes
cargo clippy --fix

Formatting with rustfmt

# Format all files
cargo fmt

# Check formatting without modifying
cargo fmt -- --check

Dependency Audit

# Audit dependencies for known vulnerabilities
cargo audit

# Check for outdated dependencies
cargo outdated

PQC-TLS Development

The pqc_tls crate wraps the liboqs library and provides a Rust-native API for quantum-safe cryptography. When adding new algorithms:

  1. Add the algorithm binding in crates/pqc_tls/src/
  2. Write unit tests verifying key generation, encapsulation, and decapsulation
  3. Add benchmarks using the criterion crate
  4. Verify against NIST test vectors

Kubernetes Operator Development

The k8s_operator crate uses the kube-rs framework. Controllers are organized by resource type:

  • controller/controlplane.rs -- control plane resources
  • controller/policy.rs -- OPA policy resources
  • controller/servicemesh.rs -- service mesh resources

Next Steps