3.1 KiB
3.1 KiB
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 andpretty_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--releasefor 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-truncateor--bits-truncate-bytes.
Coding Style & Naming Conventions
- Rust 2021; 4-space indent;
rustfmtdefaults (cargo fmt). - Naming: modules
snake_case; types/enumsCamelCase; functionssnake_case; constantsSCREAMING_SNAKE_CASE. - Avoid
unsafe; prefer clear, small functions. Keep CLI parsing incli.rs, decoding/formatting insrc/parser/. - Run
cargo clippylocally 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 undersrc/parser/. - Integration tests: create Rust files under
tests/(e.g.,tests/parse_certificate.rs) and use fixtures intests/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 fmthas no diff, andcargo clippyshows no warnings.
Notes & Tips
- Binary DER from stdin isn’t supported in text mode; use
--filewith--input-format der. - Colors auto-detect TTY; force with
--color always.