can somebody please explain when an "enum" variable is used vs when a "choice" variable is used in ASN1 ?
difference between "enum" and "choice" type in ASN1
816 Views Asked by siri gowtham At
2
There are 2 best solutions below
0

CHOICE is richer because the alternatives can be whatever type you want.
PreferredContactMethod ::= CHOICE {
mail PrintableString,
identity SEQUENCE {
firstName PrintableString,
lastName PrintableString
}
}
However, you are right. You could use a CHOICE to define a enumeration (you could also use named INTEGERs) ...
Colors ::= ENUMERATED {red, green, blue, yellow, purple}
Colors ::= INTEGER {red(0), green(1), blue(2), yellow(3), purple(4)}
Colors ::= CHOICE {red NULL, green NULL, blue NULL, yellow NULL, purple NULL}
I have seen the 3 ways used in specifications (note that the encoding will be different)
My 2 cents: if your type is clearly an enumeration, use ENUMERATED
An ENUMERATED type in ASN.1 is a used when you have a list of named items you would like to choose from such as
A CHOICE type is used when you would like to choose between different ASN.1 types.
Only one item in the choice can be selected at a time.