How do I parse ASN.1 input with Haskell?
Is there a generator that is able to generate algebraic datatype declarations and parser code for a given ASN.1 description file?
(like e.g. asn1c for generating C code ...)
A quick summary what ASN.1 is about:
ASN.1 is like Google Protocol Buffers, but is was developed way earlier and it is an actual standard. Basically, ASN.1 defines several methods for serializing hierarchically structured data and a syntax for defining a grammar that describes the structure. Such a grammar can be used to automatically generate a parser and data structures for building a syntax tree.
You can decode binary ASN.1 using the asn1-encoding package, which you can parse either by hand using pattern matching, or the asn1-parse package.
For example the following helper function will decode a BER binary file into a list of ASN1:
import Data.ASN1.Encoding
import Data.ASN1.BinaryEncoding
import Data.ASN1.Types
import qualified Data.ByteString as B
decodeASN1File file = decodeASN1' BER `fmap` B.readFile file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With