|
|
||
|---|---|---|
| src | ||
| tests | ||
| .gitignore | ||
| AGENTS.md | ||
| Cargo.lock | ||
| Cargo.toml | ||
| LICENSE | ||
| README.md | ||
| clippy.toml | ||
README.md
asn1parse
A tiny Rust CLI to pretty‑print DER‑encoded 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 pretty‑printer 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 256or--bits-truncate-bytes 32
Development
- Lint:
cargo clippy --all-targets -- -D warnings(configured viaclippy.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.pemopenssl 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
--fileor provide hex on stdin. - Colors auto‑detect TTY; use
--color alwaysto force.
License
MIT — see LICENSE.