Go to file
Christopher Williams 43a0bf36e1 docs: update AGENTS.md for parser/ submodule layout 2025-08-21 10:56:48 -04:00
src refactor(parser): move parsing modules into parser/ submodule; feat(x509): detect Certificate and label version/serial; fix: clippy warnings and context labels 2025-08-21 10:54:58 -04:00
tests Refactor parser.rs 2025-08-20 21:26:37 -04:00
.gitignore Remove target folder and add .gitignore 2025-08-20 20:58:54 -04:00
AGENTS.md docs: update AGENTS.md for parser/ submodule layout 2025-08-21 10:56:48 -04:00
Cargo.lock test: fix integration test to use generic pretty-printer for X.509 DER 2025-08-20 20:09:10 -04:00
Cargo.toml perf: add maximum performance and size optimizations to release profile 2025-08-20 20:54:09 -04:00
LICENSE docs: add README, MIT LICENSE, and clippy/linting notes to AGENTS.md 2025-08-20 20:39:49 -04:00
README.md docs: add README, MIT LICENSE, and clippy/linting notes to AGENTS.md 2025-08-20 20:39:49 -04:00
clippy.toml chore(lints): add clippy config, fix warnings, refactor print args; run clippy clean 2025-08-20 20:37:05 -04:00

README.md

asn1parse

A tiny Rust CLI to prettyprint DERencoded ASN.1 structures. It uses yasna for DER parsing and prints a readable tree with optional ANSI colors. Helpful for inspecting X.509 certificates and general DER blobs.

Features

  • Generic DER prettyprinter with colorized types.
  • Heuristics: decodes nested DER inside OCTET/Bit Strings.
  • Friendly outputs for common X.509 bits (SAN names, iPAddress, keyUsage summary).
  • Sensible defaults: BIT STRINGs are truncated for readability (bits=128, hex bytes=16) and marked with an ellipsis and “(truncated)”.

Install

  • Build: cargo build --release
  • Run help: cargo run -- --help

Usage

  • Parse DER file: cargo run -- --file tests/data/test.cert.der --input-format der --color never
  • Parse hex string: cargo run -- "3006020101020102"
  • Force hex view for bit strings: cargo run -- 030300DEAD --bits-format hex
  • Override truncation: --bits-truncate 256 or --bits-truncate-bytes 32

Development

  • Lint: cargo clippy --all-targets -- -D warnings (configured via clippy.toml)
  • Format: cargo fmt
  • Test: cargo test

Generating a sample certificate

  • Generate rich test cert (SAN, keyUsage, policies, constraints):
    • openssl req -new -newkey rsa:2048 -nodes -keyout tests/data/rich.key.pem -x509 -days 7 -config tests/data/openssl-rich.cnf -out tests/data/rich.cert.pem
    • openssl x509 -in tests/data/rich.cert.pem -outform der -out tests/data/rich.cert.der
  • View: cargo run -- --file tests/data/rich.cert.der --input-format der --color never

Notes

  • Binary DER via stdin is not supported in text mode; use --file or provide hex on stdin.
  • Colors autodetect TTY; use --color always to force.

License

MIT — see LICENSE.