guarantee 0.1.0

guarantee is a tee-secured web application framework that focuses on security.
Documentation
# 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-sgx` out of the box.

## Prerequisites

To build and run this project, you need:

1.  **Rust Nightly**: Required for some SGX features.
    ```bash
    rustup toolchain install nightly
    rustup default nightly
    ```

2.  **SGX Target**:
    ```bash
    rustup target add x86_64-fortanix-unknown-sgx
    ```

3.  **Fortanix SGX Runner** (Optional, for running locally):
    ```bash
    cargo install ftxsgx-runner-cargo
    ```

## 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.

```bash
cargo build --example health
```

To run it (if you have the runner installed/configured):
```bash
cargo run --example health
```

#### 2. Counter (Stateful)
Demonstrates using the generic `HandlerState<T>` to share atomic state between requests.

```bash
cargo build --example counter
```

## Creating Your Own Service

1.  **Define your State**: Create a struct for your application state (or use `()` if stateless).
2.  **Initialize Router**:
    ```rust
    use tee_template::http::router::Router;
    use tee_template::state::HandlerState;
    use std::sync::Arc;

    // Define your state type
    type AppState = AtomicUsize;

    let my_state = AtomicUsize::new(0);
    let state = Arc::new(HandlerState::new(Some(my_state)));
    let mut router = Router::new(state);
    ```
3.  **Register Handlers**:
    ```rust
    router.register("/my-endpoint", my_handler);
    ```
4.  **Start Server**:
    ```rust
    HttpServer::new("0.0.0.0:8080", router)?.run()?;
    ```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.