# mimetype-cli

MIME type lookup, detection and reverse lookup CLI
tool.

## Features

- **Magic-byte detection** via `infer` (~70 formats)
- **Content sniffing** for text formats (JSON, XML,
  YAML, HTML, SVG, TOML, shebangs, programming
  languages)
- **Extension lookup** via `mime_guess` (2500+ types)
- **Reverse lookup** — find extensions for a MIME type
- **Output formats** — plain text, JSON, Markdown,
  SARIF 2.1.0
- **Auto-generated reports** — `report.sarif` +
  `report.md` on every file scan

## Installation

```bash
cargo install --path .
```

## Usage

```bash
# Detect MIME type of a file
mimetype-cli file document.pdf

# Recursive directory scan
mimetype-cli file -R /path/to/dir

# Look up MIME type by extension
mimetype-cli ext png

# Reverse lookup: extensions for a MIME type
mimetype-cli mime image/png

# JSON output
mimetype-cli -j file photo.jpg

# SARIF output
mimetype-cli --format sarif file archive.zip

# Suppress auto-generated report files
mimetype-cli --no-report file document.pdf

# Custom output directory for reports
mimetype-cli --output-dir /tmp file document.pdf
```

## Output Formats

| Flag | Format | Description |
|------|--------|-------------|
| (default) | Plain text | Coloured terminal output |
| `-j` / `--format json` | JSON | Structured JSON array |
| `--format markdown` | Markdown | SARIF-based GFM report |
| `--format sarif` | SARIF 2.1.0 | Static analysis format |

## Quality Assurance

| Tool | Result |
|------|--------|
| rust-doctor | **99/100** — 0 errors |
| cargo clippy | Clean (pedantic + nursery) |
| cargo fmt | Clean |
| cargo audit | 2 allowed warnings (transitive) |
| cargo test | **588 passed**, 0 failed |
| cargo fuzz | 10 targets, 89M+ runs, 0 crashes |
| Kani | 5/5 proofs verified |

## Security

- All findings documented as CSAF 2.1 VEX advisories
  in `csaf/2026/` with dual CVSS 3.1 + 4.0 scoring
- Zero `unsafe` code (`#![forbid(unsafe_code)]`)
- Strict Clippy lints: `unwrap_used`, `expect_used`,
  `panic`, `indexing_slicing` all denied
- Supply-chain audited via `cargo-audit`

## Dependencies

| Crate | Purpose |
|-------|---------|
| `infer` | Magic-byte signature detection |
| `mime_guess` | Extension-to-MIME mapping |
| `content_inspector` | Text/binary classification |
| `phf` | Compile-time perfect hash set |
| `sarif_rust` | SARIF 2.1.0 generation |
| `sarif-to-md-core` | SARIF-to-Markdown conversion |
| `clap` | CLI argument parsing |
| `colored` | Terminal colour output |
| `serde` / `serde_json` | JSON serialization |
| `walkdir` | Recursive directory traversal |

## License

Apache-2.0

## Author

Pierre Gronau, ndaal GmbH & Co KG, Cologne
