I am new to ASN.1 and DER. I have a naive question about parsing a certificate stored in DER format.
How do I tell the difference between a SET (0x31) and a SEQUENCE OF booleans (0x31)?
As I understand it the tag for a SET is 0x31.
But wouldn't the tag for a SEQUENCE OF (0x30) + BOOLEAN (0x01) also be 0x31 ?
What am I missing? How do I treat a tag byte with a value of 0x31?
Please be gentle.
If you look around the questions on asn.1, you'll find that most people are mixing specification and encoding ...
ASN.1 specification tells you the difference between SET, SEQUENCE, SET OF, SEQUENCE OF
The specification explains what data you expect. Look at this example
ASN.1 encoding rules tells you how the data (from the specification) is going to be serialized as bytes on the wire
This is where we speak of DER being a set of encoding rules that use tags
(back to your question) to keep it simple: if you know that you must decode a SEQUENCE you know that you must expect 0x30 (same for SET with 0x31)
Note there is something wrong in your question
SEQUENCE OF universal tag is 0x30 (like SEQUENCE)
Keep in mind the basics: you don't try to understand the data when you decode it, you know how to decode because you know the specification (and this should be ideally done by some generated code ... not you)