can somebody please explain when an "enum" variable is used vs when a "choice" variable is used in ASN1 ?
Asked
Active
Viewed 670 times
2 Answers
1
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
Colors ::= ENUMERATED {red, green, blue, yellow, purple}
A CHOICE type is used when you would like to choose between different ASN.1 types.
PreferredContactMethod ::= CHOICE {
mail PrintableString,
mobilePhone NumericString,
email VisibleString,
homephone NumericString
}
Only one item in the choice can be selected at a time.

Paul Thorpe
- 1,930
- 17
- 23
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

YaFred
- 9,698
- 3
- 28
- 40