# dalof41014/ruipmi architecture

> Architecture diagram of the GitHub repository dalof41014/ruipmi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dalof41014/ruipmi
- Repository: https://github.com/dalof41014/ruipmi

## Overview

##### Project Type and Purpose
- ruipmi is an open-source Rust library (crate) that implements an asynchronous RMCP+ IPMI v2.0 client over UDP.
- It provides session handshake (Open Session + RAKP1–4), message encryption (AES-CBC-128), integrity (HMAC-SHA1/MD5/SHA256), and IPMB encapsulation.
- Consumers embed it in higher-level tooling to manage BMCs (baseboard management controllers) over the network.

##### File-Structure Analysis
- Top level:
- Cargo.toml / Cargo.lock: Rust build config and dependencies.
- README.md, LICENSE, .gitignore: project metadata.
- src/
– lib.rs: crate root, public API (IpmiClient, CipherSuite, etc.).
– ruipmi.rs: internal implementation (session builder, crypto, encode/decode).
- No binary or example folder in tree, but README references examples/demo.rs.

##### Key README Insights
- Dependencies: tokio (async UDP), aes, cbc, hmac, md-5, sha1, sha2, rand, thiserror, log.
- Core functions: build_open_session_request, build_rakp1/3, build_v2_encrypted_msg, decode_and_decrypt.
- Layers: RMCP header → RMCP+ session header → payload → integrity trailer.
- API: IpmiClient::new, connect, request, close, build_ipmb_send_message.

##### Main Components
a. Consumer Application
- e.g. examples/demo.rs or any management tool that calls IpmiClient API.
b. IpmiClient Library
- Session Manager: orchestrates RMCP+ handshake (OpenSession, RAKP1–4).
- Message Builder / Parser: constructs RMCP/RMCP+ headers, payload, trailers.
- Crypto Module: AES-CBC-128 encryption/decryption, HMAC-SHA*/MD5, key derivation (SIK, K1, K2).
- UDP Transport Layer: tokio::net::UdpSocket for send/receive.
c. External Service
- Remote BMC (IPMI server) over the LAN.
d. Third-party Dependencies
- tokio runtime, aes/cbc crates, hmac, md-5, sha1, sha2, rand, thiserror, log.

##### Relationships and Data Flow
1. Application calls IpmiClient::new() → instantiates Session Manager.
2. IpmiClient.connect():
- Session Manager → Message Builder → UDP Transport → BMC.
- BMC → UDP Transport → Session Manager → Crypto Module → parser.
3. Once session is open:
- Application → IpmiClient.request() → Message Builder → Crypto Module → UDP Transport → BMC.
- Responses flow back → UDP Transport → Crypto Module → Session Manager → Application.
4. IpmiClient.close() sends Close Session command via same path.

##### Architectural Patterns & Principles
- Modular layering: separation of concerns between session orchestration, message composition, cryptography, and I/O.
- Asynchronous, event-driven I/O using Tokio.
- Clean library boundary: public API (lib.rs) vs. implementation (ruipmi.rs).
- Dependency Injection: configurable CipherSuite.
- Error handling via thiserror.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Consumer Application
    App["Consumer Application"]:::external
    click App "https://github.com/dalof41014/ruipmi/blob/main/examples/demo.rs"

    %% Public API
    API["Public API\n(IpmiClient, CipherSuite, errors)"]:::api
    click API "https://github.com/dalof41014/ruipmi/blob/main/src/lib.rs"

    %% IpmiClient Library
    subgraph "IpmiClient Library"
        direction TB
        SM["Session Manager\n(OpenSession, RAKP1–4)"]:::internal
        click SM "https://github.com/dalof41014/ruipmi/blob/main/src/ruipmi.rs"

        subgraph "Message Builder/Parser"
            direction TB
            MB["RMCP Header"]:::builder
            MH["RMCP+ Session Header"]:::builder
            PL["Payload"]:::builder
            IT["Integrity Trailer"]:::builder
        end
        click MB "https://github.com/dalof41014/ruipmi/blob/main/src/ruipmi.rs"

        CM["Crypto Module\nAES-CBC-128, HMAC-SHA*, key derivation (SIK/K1/K2)"]:::crypto
        click CM "https://github.com/dalof41014/ruipmi/blob/main/src/ruipmi.rs"

        UT["UDP Transport\n(tokio::net::UdpSocket, timeouts)"]:::transport
        click UT "https://github.com/dalof41014/ruipmi/blob/main/src/ruipmi.rs"
    end

    %% Remote BMC
    BMC["Remote BMC\n(IPMI Server)"]:::external

    %% External Crates
    subgraph "External Crates"
        direction TB
        TC["tokio"]:::external
        AC["aes, cbc"]:::external
        HC["hmac, md-5, sha1, sha2"]:::external
        RC["rand"]:::external
        EC["thiserror, log"]:::external
    end

    %% Documentation and Config
    Docs["README.md"]:::docs
    click Docs "https://github.com/dalof41014/ruipmi/blob/main/README.md"
    CFG["Cargo.toml / Cargo.lock"]:::docs
    click CFG "https://github.com/dalof41014/ruipmi/blob/main/Cargo.toml"

    %% Relationships
    App -->|"IpmiClient::new()/connect()/request()/close()"| API
    API -->|calls| SM
    SM -->|builds handshake messages| MB
    MB -->|uses crypto| CM
    MB -->|sends packets| UT
    UT -->|UDP send/receive| BMC
    BMC -->|UDP send/receive| UT
    UT -->|delivers packets| MB
    MB -->|parses/decrypts| CM
    CM -->|delivers keys/messages| SM
    SM -->|session events| API
    API -->|returns results| App

    %% Dependencies flows
    TC -->|async I/O| UT
    AC -->|encryption| CM
    HC -->|integrity/hashing| CM
    RC -->|random nonces| CM
    EC -->|error handling/logging| API

    %% Styles
    classDef external fill:#FFEBEE,stroke:#E57373,stroke-width:1px
    classDef api fill:#E3F2FD,stroke:#64B5F6,stroke-width:1px
    classDef internal fill:#E8F5E9,stroke:#81C784,stroke-width:1px
    classDef builder fill:#FFFDE7,stroke:#FDD835,stroke-width:1px
    classDef crypto fill:#F3E5F5,stroke:#BA68C8,stroke-width:1px
    classDef transport fill:#FFF3E0,stroke:#FFB74D,stroke-width:1px
    classDef docs fill:#ECEFF1,stroke:#90A4AE,stroke-width:1px
```
