I'm implementing an ASN1 parser to decode x509 certificates. There are sequence and set tags that you can use. I don't see a reason why those two shouldn't be the same thing.
What is the difference, and appropriate time to use each?
Join Stack Overflow to learn, share knowledge, and build your career.
I'm implementing an ASN1 parser to decode x509 certificates. There are sequence and set tags that you can use. I don't see a reason why those two shouldn't be the same thing.
What is the difference, and appropriate time to use each?
A sequence is ordered, a set is not.
When would a set be appropriate? One example might be when encoding huge chunks of data, where bringing them in the right order at the sender would cause more work than mandating that they be accepted in any order.
As an addendum to @ChristophSommer's answer
A sequence is ordered, a set is not.
... and this makes a difference e.g. when encoding some object. Using DER (distinguished encoding rules) requires a distinguished order of set elements while sequence elements keep their original order.
appropriate time to use each
As Christoph's answer indicates, you use a sequence for entries for which the order of appearance in the sequence is relevant, and a set for entries for which the order is irrelevant.
Furthermore the entries of a set usually are assumed to be unique, no two identical entries in a set, while a sequence may contain many identical entries.