# Repository Guidelines ## Project Structure & Module Organization - `src/main.rs`: Entry point; wires CLI to parser. - `src/cli.rs`: Clap-based argument parsing (flags like `--file`, `--input-format`). - `src/color.rs`: Minimal ANSI color helpers. - `src/parser/`: Parser submodule containing all DER decoding and pretty-printing logic. - `mod.rs`: Public API surface for the parser (re-exports types and `pretty_print_der`, `parse_and_print`). - `asn1_types.rs`: TLV parsing, OID decode, helpers. - `encoding_utils.rs`: Hex/bits formatting utilities and truncation logic. - `pretty_printer.rs`: Recursive DER walker and structure rendering. - `value_printer.rs`: Leaf value formatting (strings, times, OIDs, bit/octet strings). - `certificate_utils.rs`: X.509-specific helpers and detection. - `time_utils.rs`: UTCTime/GeneralizedTime humanization. - `oid_registry.rs`: Friendly OID names. - `tests/data/`: Sample keys/certs used by integration tests or manual runs. - `Cargo.toml`: Rust 2021 package config and dependencies. ## Build, Test, and Development Commands - Build: `cargo build` (use `--release` for optimized binary). - Run help: `cargo run -- --help`. - Parse DER file: `cargo run -- --file tests/data/test.cert.der --input-format der`. - Parse hex string: `cargo run -- 3082...` (whitespace allowed; auto-detected). - Lint: `cargo clippy --all-targets -- -D warnings`. - Format: `cargo fmt`. - Tests: `cargo test`. ## Linting & Defaults - Clippy: configured via `clippy.toml`; we keep warnings at deny to avoid regressions. - BIT STRINGs: truncated by default for readability (bits: 128, hex bytes: 16). Override with `--bits-truncate` or `--bits-truncate-bytes`. ## Coding Style & Naming Conventions - Rust 2021; 4-space indent; `rustfmt` defaults (`cargo fmt`). - Naming: modules `snake_case`; types/enums `CamelCase`; functions `snake_case`; constants `SCREAMING_SNAKE_CASE`. - Avoid `unsafe`; prefer clear, small functions. Keep CLI parsing in `cli.rs`, decoding/formatting in `src/parser/`. - Run `cargo clippy` locally and fix lints before PRs. ## Testing Guidelines - Framework: built-in Rust tests (`cargo test`). - Unit tests: add `#[cfg(test)] mod tests { ... }` near code in the relevant file under `src/parser/`. - Integration tests: create Rust files under `tests/` (e.g., `tests/parse_certificate.rs`) and use fixtures in `tests/data/`. - Naming: prefer descriptive test names (e.g., `it_parses_bit_string_flags`). - If output formats change, update or add tests that assert on rendered lines. ## Commit & Pull Request Guidelines - Commits: write imperative, concise subjects (e.g., "parse: handle BIT STRING hex mode"). Conventional Commit prefixes are welcome. - PRs: include a clear description, reproduction or sample command, and before/after output when changing formatting. - Link related issues; add tests or fixtures when fixing bugs or adding options. - CI expectations: code compiles, `cargo fmt` has no diff, and `cargo clippy` shows no warnings. ## Notes & Tips - Binary DER from stdin isn’t supported in text mode; use `--file` with `--input-format der`. - Colors auto-detect TTY; force with `--color always`.