[Resolved] ASN.1 ecdsa private key parsing with der-parser


So I’m trying to use the der-parser crate to parse an ecdsa ssh private key. The structure is defined as:

ECPrivateKey ::= SEQUENCE {
version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
privateKey OCTET STRING,
parameters [0] ECDomainParameters {{ SECGCurveNames }} OPTIONAL, publicKey [1] BIT STRING OPTIONAL

I have code to handle the SEQUENCE, INTEGER, and OCTET STRING. Then there’s the “parameters” which is an OID tagged with 0 and a BIT STRING tagged with 1. I’m not sure what that structure is called in ASN.1 terms (is it tagged?, is it a set?), and which der-parser macro/function corresponds to it. I have tried parse_der_explicit but no luck so far.


OK I found some to pair with on this and we got it working using der_read_element_content_as based on the x509 examples in rusticata/x509-parser