Skip to content

3.5. Enumerateds

An additional sparse data type, called "enum" or "enumerated", is
available.  Each definition is a different type.  Only enumerateds of
the same type may be assigned or compared.  Every element of an
enumerated must be assigned a value, as demonstrated in the following
example.  Since the elements of the enumerated are not ordered, they
can be assigned any unique value, in any order.

    enum { e1(v1), e2(v2), ... , en(vn) [[, (n)]] } Te;

Future extensions or additions to the protocol may define new values.
Implementations need to be able to parse and ignore unknown values
unless the definition of the field states otherwise.

An enumerated occupies as much space in the byte stream as would its
maximal defined ordinal value.  The following definition would cause
one byte to be used to carry fields of type Color.

    enum { red(3), blue(5), white(7) } Color;

One may optionally specify a value without its associated tag to
force the width definition without defining a superfluous element.

In the following example, Taste will consume two bytes in the data
stream but can only assume the values 1, 2, or 4 in the current
version of the protocol.

    enum { sweet(1), sour(2), bitter(4), (32000) } Taste;

The names of the elements of an enumeration are scoped within the
defined type.  In the first example, a fully qualified reference to
the second element of the enumeration would be Color.blue.  Such
qualification is not required if the target of the assignment is well
specified.

    Color color = Color.blue;     /* overspecified, legal */
    Color color = blue;           /* correct, type implicit */

The names assigned to enumerateds do not need to be unique.  The
numerical value can describe a range over which the same name
applies.  The value includes the minimum and maximum inclusive values
in that range, separated by two period characters.  This is
principally useful for reserving regions of the space.

    enum { sad(0), meh(1..254), happy(255) } Mood;

There is no enumeration type in Tamarin but the model uses macros to set a global constant for each enumeration value. An example for this can be found in the Handshake Protocol section.