Phase 5: Pure Rust Crypto#
Implement an ASN.1 DER (Distinguished Encoding Rules) parser in the crypto crate. This is needed for X.509 certificate parsing and RSA/ECDSA key parsing.
Requirements#
- Parse DER-encoded TLV (Tag-Length-Value) structures
- Support primitive types: INTEGER, BIT STRING, OCTET STRING, NULL, OID, UTF8String, PrintableString, IA5String, UTCTime, GeneralizedTime, BOOLEAN
- Support constructed types: SEQUENCE, SET
- Support context-specific tags (implicit and explicit)
- OID encoding/decoding (dotted notation and binary)
- Nested structure traversal
Acceptance Criteria#
-
DerParserthat reads TLV items from a byte slice - Parse all ASN.1 types needed for X.509 and PKCS#1
- OID comparison (e.g.,
oid == OID_SHA256_WITH_RSA) - Parse nested SEQUENCE/SET structures
- Handle context-specific tagged values [0], [1], etc.
- Reject non-DER encodings (indefinite length, non-minimal integers)
- Test with real DER-encoded certificate fragments
-
cargo test -p we-cryptopasses -
cargo clippy -p we-crypto -- -D warningsclean