-
Notifications
You must be signed in to change notification settings - Fork 20
Description
First of all I'd like to thank you for your work, asn1-combinators is a great library and
I'm using it every day.
At cryptosense we're open sourcing some the of the asn1 cryptographic key parsers we've wrote
so far and we're facing an issue.
I'm trying to express an ASN grammar for algorithmIdentifier which is defined in
RFC 5280 as:
AlgorithmIdentifier ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
parameters ANY DEFINED BY algorithm OPTIONAL }
When only considering RSA and DSA, it works well because RSA params are NULL and DSA ones are
a 3 integer sequence. The thing is when adding EC keys to the equation the grammar becomes
ambiguous because EC parameters can also be a sequence, even though it's completely
different from the DSA one.
Currently we have a different grammar for each key types and the generic decode function
is a very ugly doubly nested try ... with Asn.Parse_error _ ->.
I wrote a wildcard grammar with choice and fix allowing me to accept "almost" everything
but then I have to manipulate the recursive type and to write converters from and to it which
adds a lot of code and doesn't really look prettier in the end.
ASN.1 construction like:
Something ::= SEQUENCE {
id OID,
params ANY IDENTIFIED BY id }
is pretty usual and I guess I'm not the only one that could run into this kind of problem.
I'd really like to know what you suggest to adress this issue.
Thank you :)