# usernob/rust-rsa architecture

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

- Interactive diagram: https://gitdiagram.com/usernob/rust-rsa
- Repository: https://github.com/usernob/rust-rsa

## Overview

Rust RSA is an educational command-line tool for generating RSA keypairs and encrypting or decrypting files and Unix streams. The primary workflow starts at the CLI: key generation delegates to prime generation and RSA key construction, then saves public/private keys; encryption and decryption load the appropriate key, open file or standard-stream endpoints, and process fixed-size binary blocks. The graph separates CLI orchestration, key/prime mathematics, and key and stream I/O. Major stages are documented in the README; links are limited to relationships shown in the excerpts or README.

Main entry points: [`src/main.rs`](https://github.com/usernob/rust-rsa/blob/master/src/main.rs) (CLI commands), [`src/file.rs`](https://github.com/usernob/rust-rsa/blob/master/src/file.rs) (Stream endpoints), [`src/rsa.rs`](https://github.com/usernob/rust-rsa/blob/master/src/rsa.rs) (RSA operations), [`src/constant.rs`](https://github.com/usernob/rust-rsa/blob/master/src/constant.rs) (RSA constants)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI orchestration"]
  node_commands["CLI commands<br/>[main.rs]"]
end

subgraph group_crypto["RSA mathematics"]
  node_keygen["Key generation<br/>[rsa.rs]"]
  node_primegen["Prime generation<br/>[prime_number.rs]"]
  node_rsa_ops["RSA operations<br/>[rsa.rs]"]
  node_crypto_constants["RSA constants<br/>[constant.rs]"]
end

subgraph group_io["Key and stream I/O"]
  node_keyfiles["Key file handling<br/>[file.rs]"]
  node_streamio["Stream endpoints<br/>[file.rs]"]
end

node_user(("CLI user"))
node_plaintext["Plaintext stream"]
node_ciphertext["Binary ciphertext"]
node_keypair_files["Keypair files"]
node_stdin(("stdin"))
node_stdout(("stdout"))

node_user -->|"runs commands"| node_commands
node_commands -->|"requests keys"| node_keygen
node_keygen -->|"generates primes"| node_primegen
node_primegen -->|"checks exponent"| node_crypto_constants
node_keygen -->|"uses exponent"| node_crypto_constants
node_commands -->|"saves keys"| node_keyfiles
node_keyfiles -->|"writes keypair"| node_keypair_files
node_commands -->|"loads key"| node_keyfiles
node_commands -->|"opens streams"| node_streamio
node_commands -->|"processes data"| node_rsa_ops
node_rsa_ops -->|"uses exponent"| node_crypto_constants
node_streamio -->|"reads default"| node_stdin
node_streamio -->|"writes default"| node_stdout
node_plaintext -.->|"input bytes"| node_streamio
node_streamio -->|"feeds blocks"| node_rsa_ops
node_rsa_ops -->|"writes blocks"| node_ciphertext
node_ciphertext -.->|"input blocks"| node_streamio
node_rsa_ops -->|"writes bytes"| node_plaintext

click node_commands "https://github.com/usernob/rust-rsa/blob/master/src/main.rs"
click node_keygen "https://github.com/usernob/rust-rsa/blob/master/src/rsa.rs"
click node_primegen "https://github.com/usernob/rust-rsa/blob/master/src/prime_number.rs"
click node_rsa_ops "https://github.com/usernob/rust-rsa/blob/master/src/rsa.rs"
click node_crypto_constants "https://github.com/usernob/rust-rsa/blob/master/src/constant.rs"
click node_keyfiles "https://github.com/usernob/rust-rsa/blob/master/src/file.rs"
click node_streamio "https://github.com/usernob/rust-rsa/blob/master/src/file.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_commands,node_user toneBlue
class node_keygen,node_primegen,node_rsa_ops,node_crypto_constants toneAmber
class node_keyfiles,node_streamio toneMint
class node_plaintext,node_ciphertext,node_keypair_files,node_stdin,node_stdout toneIndigo
```

## Components

### CLI orchestration

- [CLI commands](https://github.com/usernob/rust-rsa/blob/master/src/main.rs): `src/main.rs`

### RSA mathematics

- [Key generation](https://github.com/usernob/rust-rsa/blob/master/src/rsa.rs): `src/rsa.rs`
- [Prime generation](https://github.com/usernob/rust-rsa/blob/master/src/prime_number.rs): `src/prime_number.rs`
- [RSA operations](https://github.com/usernob/rust-rsa/blob/master/src/rsa.rs): `src/rsa.rs`
- [RSA constants](https://github.com/usernob/rust-rsa/blob/master/src/constant.rs): `src/constant.rs`

### Key and stream I/O

- [Key file handling](https://github.com/usernob/rust-rsa/blob/master/src/file.rs): `src/file.rs`
- [Stream endpoints](https://github.com/usernob/rust-rsa/blob/master/src/file.rs): `src/file.rs`

### Other components

- **CLI user**
- **Plaintext stream**
- **Binary ciphertext**
- **Keypair files**
- **stdin**
- **stdout**

## Connections

- CLI user → CLI commands: runs commands (evidence: `README.md`)
- CLI commands → Key generation: requests keys (evidence: `src/main.rs`)
- Key generation → Prime generation: generates primes (evidence: `src/rsa.rs`)
- Prime generation → RSA constants: checks exponent (evidence: `src/prime_number.rs`)
- Key generation → RSA constants: uses exponent (evidence: `src/rsa.rs`)
- CLI commands → Key file handling: saves keys (evidence: `src/main.rs`)
- Key file handling → Keypair files: writes keypair (evidence: `src/file.rs`)
- CLI commands → Key file handling: loads key (evidence: `src/main.rs`)
- CLI commands → Stream endpoints: opens streams (evidence: `src/main.rs`)
- CLI commands → RSA operations: processes data (evidence: `src/main.rs`)
- RSA operations → RSA constants: uses exponent (evidence: `src/rsa.rs`)
- Stream endpoints → stdin: reads default (evidence: `src/file.rs`)
- Stream endpoints → stdout: writes default (evidence: `src/file.rs`)
- Plaintext stream → Stream endpoints: input bytes (evidence: `README.md`)
- Stream endpoints → RSA operations: feeds blocks (evidence: `src/main.rs`)
- RSA operations → Binary ciphertext: writes blocks (evidence: `README.md`)
- Binary ciphertext → Stream endpoints: input blocks (evidence: `README.md`)
- RSA operations → Plaintext stream: writes bytes (evidence: `README.md`)
