Hacker News new | ask | show | jobs
by andrewmcwatters 1619 days ago
What’s so great about ASN.1 and it’s encoding rules is that anyone writing type-length-value serialization for networking purposes, for example[1], is basically independently reinventing ASN.1 because it’s so fundamentally optimal.

It truly will make you wonder why Protobufs and others exist.

[1]: https://github.com/Planimeter/grid-sdk/blob/master/engine/sh...

3 comments

> What’s so great about ASN.1 and it’s encoding rules is that anyone writing type-length-value serialization for networking purposes, for example[1], is basically independently reinventing ASN.1 because it’s so fundamentally optimal.

The challenge arises if you have very large values: by nature, TLVs require that the V be encoded before you can plug in the L. If you use definite-length encodings (as required by DER), you may end up having to hold and encode a pretty large piece of data in memory. You can work around this, of course, but it can be a challenge.

Tags in ASN.1 as noted in another comment can also be pretty complicated: there are four tagging classes, and tags can be applied implicitly, explicitly, or automatically depending on the specification. This can make life a bit uncomfortable at times.

On the balance, I can understand why people find ASN.1 such a pain, especially if you're not inclined to fork over money to have someone else deal with the encodings. For medium- to large-sized companies, though, it's probably not a bad deal: get a support contract from one of the commercial vendors, get training, and save yourself six man-months on writing pretty bullet-proof serialization code without the headache of worrying about standards incompatibilities. If you happen to work in telecommunications or security, you're going to deal with ASN.1 at some point anyway, so having something that can talk to multiple parts of your stack can be helpful, too.

That there's four tag classes is not really a complexity. That there's IMPLICIT and EXPLICIT tagging is.

Using IMPLICIT tagging yields encodings that dumpasn1(1)-like tools can't really give you much insight into.

Using EXPLICIT tagging yields bloat.

The answer is to use non-TLV encodings where possible and to use tools that can refer to the schema ("modules") to decode and pretty-print arbitrary things. dumpasn1(1) is just too simple.

[2]: https://github.com/openssl/openssl/issues/4320 I recently had to deal with that situation too.
I don't agree with the sentiment that TLV is optimal, but the assertion that people are constantly reinventing ASN.1 is most definitely true!