Guarantee
A lightweight, boilerplate-free Rust library designed for building HTTP services inside Trusted Execution Environments (TEEs), specifically targeting Intel SGX (via the Fortanix EDP).
This template provides a custom, dependency-light HTTP server and router, allowing you to build secure enclaves with minimal overhead.
Features
- Custom HTTP Server: Lightweight TCP-based HTTP implementation.
- Routing: Simple, pattern-matching router.
- Generic State Management: Share state across handlers in a thread-safe way using
Arc<HandlerState<T>>. - SGX Ready: Configured for
x86_64-fortanix-unknown-sgxout of the box.
Prerequisites
To build and run this project, you need:
-
Rust Nightly: Required for some SGX features.
-
SGX Target:
-
Fortanix SGX Runner (Optional, for running locally):
Usage
Library Structure
The project is structured as a library (src/lib.rs) which exports core modules:
server: The TCP/HTTP server implementation.http: Request/Response parsing and Router.state: Generic state container.handlers: Example handlers.
Building Examples
This template includes examples demonstrating different use cases.
1. Health Check (Stateless)
A simple "Hello World" style example.
To run it (if you have the runner installed/configured):
2. Counter (Stateful)
Demonstrates using the generic HandlerState<T> to share atomic state between requests.
Creating Your Own Service
- Define your State: Create a struct for your application state (or use
()if stateless). - Initialize Router:
use Router; use HandlerState; use Arc; // Define your state type type AppState = AtomicUsize; let my_state = new; let state = new; let mut router = new; - Register Handlers:
router.register; - Start Server:
new?.run?;
License
This project is licensed under the MIT License - see the LICENSE file for details.