Mapping an Alternation
requires first evaluating the alternation so that we can determine what pattern it matches. After the pattern is determined, then we map the Alternation
to ASN.1
The mapping procedure treats error alternatives identically to normal alternatives.
Analyze each alternative of the alternation as follows.
Determine whether the alternative would produce either an ASN.1 type or ASN.1 component. This clause is not meant to invoke a mapping procedure for the alternative. Currently, we use the rule that any non-literal string (a string which matches more than one bit string) would produce an ASN.1 type or ASN.1 component. This rule has worked for us thus far. It is for further study whether it is really an adequate rule.
Determine whether the alternative consists of the empty string, a determinant without a remainder, a determinant with a remainder, or a remainder only, and identify the parts of the alternative that make up each of these parts. Additionally, if there is a determinant, determine its name, if it has one. Refer to the subsection on determinants below.
Determine the pattern that is matched by the alternation as follows.
Optional component with presence bit. The alternation matches this pattern if the following conditions are met.
There are exactly two alternatives.
One alternative would not produce an ASN.1 type and has a determinant which is either unamed or is not uniquely named. The determinant has length 1.
The other alternative would produce an ASN.1 type and has a determinant. The determinant has length 1.
The determinant values for the two alternatives are unique.
Optional component with presence bit and container determined. The alternation matches this pattern if the following conditions are met.
There are exactly three alternatives.
One alternative is a null alternative.
One alternative would not produce an ASN.1 type and has a determinant which is either unamed or is not uniquely named. The determinant has length 1.
The other alternative would produce an ASN.1 type and has a determinant. The determinant has length 1.
The determinant values (for the two alternatives having them) are unique.
Optional component container determined. The alternation matches this pattern if the following conditions are met.
There are exactly two alternatives.
One alternative is a null alternative.
The other alternative produces an ASN.1 type
L-H Alternative. The alternation matches this pattern if there are exactly two alternatives, each consisting of only a determinant, with one determinant value being "L" and the other "H".
Particular-General. The alternation matches this pattern if the following conditions are met:
None of the above patterns applied to the alternation.
There are exactly two alternatives. One of these must meet the requirements below for the "particular alternative" while the must meet the requirements below for the "general alternative".
The particular alternative has a determinant. Call it the particular-determinant.
The general alternative does not have a determinant and would produce an ASN.1 type. The general alternative begins with, or is itself, a bit string of a fixed length (e.g. <bit(4)>). Call this fixed-length bit string the "general-determinant". Note that the general-determinant is not a determinant as that term is being used in this section (it is not a fixed value), but we can think of it as preceding the alternation and determining which alternative is encoded.
The length of the particular-determinant equals the length of the general-determinat. The general-determinant excludes the value of the particular-determinant.
Stereotypical choice. The alternation matches this pattern if the following conditions are met:
None of the above patterns applied to the alternation.
There are at least two non-null alternatives.
Each of the non-null alternatives has a determinant.
Each of the non-null alternatives either would produce an ASN.1 type or else has a uniquely-named determinant.
If the alternation matches either of the "Optional component with presence bit" patterns, then the mapping produces an ASN.1 component, C, as follows.
For this alternation pattern, one of the alternatives would produce an ASN.1 type. Let typeString be the remainder for that alternative, which is the string that would produce the ASN.1 type.
Invoke the CSN1String Mapping procedure for typeString. This will produce an ASN.1 type, T. C's type shall be T. C shall be an OPTIONAL component.
The name of the component is derived from the CSN.1, but the CSN.1 does not always provide a name. The calling procedure (e.g. the Concatenation mapping procedure) is ultimately responsible for assigning the name to the component. This procedure merely assigns a CSN.1 name to the component, if there is one. If typeString was labeled, the CSN.1 name is that label name. Otherwise, if the alternation as a whole was labeled, the CSN.1 name is that label name. Otherwise, the component does not have a CSN.1 name.
The encoding for C may be empty if and only if the "Optional component with presence bit and container determined" pattern was matched. In that case, a decoder shall assume that C's encoding is not empty if there are more bits to be decoded where C should appear. If the encoding for C is empty, C is absent.
If C is absent, the encoding of C consists of the determinant for the non-type-producing alternative. When C is present, the encoding consists of the determinant for the type-producing alternative followed by the encoding for T (C's type), which will have been defined by the procedure that produced T.
If C is absent and the encoder is permitted to, and elects to, use an empty encoding, it is an error for an encoder to encode any bits within the same container (i.e. you can't encode bits that the decoder might interpret as being an encoding for C.)
If the alternation matches the "Optional component container determined" pattern, then the mapping produces an ASN.1 component, C, as follows.
For this alternation pattern, one of the alternatives would produce an ASN.1 type. Let typeString be the remainder for that alternative, which is the string that would produce the ASN.1 type.
Invoke the CSN1String Mapping procedure for typeString. This will produce an ASN.1 type, T. C's type shall be T. C shall be an OPTIONAL component.
The name of the component is derived from the CSN.1, but the CSN.1 does not always provide a name. The calling procedure (e.g. the Concatenation mapping procedure) is ultimately responsible for assigning the name to the component. This procedure merely assigns a CSN.1 name to the component, if there is one. If typeString was labeled, the CSN.1 name is that label name. Otherwise, if the alternation as a whole was labeled, the CSN.1 name is that label name. Otherwise, the component does not have a CSN.1 name.
The encoding for C may be empty. A decoder shall assume that C's encoding is not empty if there are more bits to be decoded where C should appear. If the encoding for C is empty, C is absent.
If C is absent, the encoding of C is empty. When C is present, the encoding consists of the encoding for T (C's type), which will have been defined by the procedure that produced T. After encoding C as absent, it is an error for an encoder to encode any bits within the same container (i.e. you can't encode bits that the decoder might interpret as being an encoding for C.)
If the alternation matches the "L-H Alternative" pattern, then the mapping produces an ASN.1 type. The type is an DefinedType with typerefence equal to "LHType". The encoding for this is the encoding of LHType.
If the alternation matches the "Stereotypical choice" pattern, then the mapping is as follows.
If the alternation includes one or more null alternatives, the mapping produces an ASN.1 component C. C shall be OPTIONAL. C.type shall be a CHOICE type, constructed as in the case where the alternation has no null alternatives (described in the following clauses). If the alternation itself is labeled, that name shall be the CSN.1 name for C; otherwise, C does not have a CSN.1 name.
If the alternation does not include a null alternative (or it does but we are constructng the CHOICE type as mentioned above), the mapping produces an ASN.1 CHOICE type as follows.
For each alternative (null alternatives excluded), do the following.
Add a NamedType, N, to the CHOICE. The identifier for N is determined according to the rules in "ASN.1 Identifier Assignment". The type for N is specified in the following clauses.
If the alternative would produce a type, invoke the CSN1String mapping procedure on the remainder part of that alternative. Let N.type be the type produced.
Otherwise, let N.type be the NULL type.
The encoding of the CHOICE type shall depend upon the chosen alternative within the CHOICE. It shall consist of the chosen alternative's determinant followed by the encoding of the chosen alternative's type. It is an error if the determinants of the alternatives are non-deterministic: in decoding the determinant, there must not be any ambiguity as to which alternative has been chosen or whether the end of the determinant has been reached.
If the alternation matches the "Particular-General" pattern, the result of the mapping depends on what procedure invoked this mapping. If this procedure was invoked by the Concatentation mapping, this procedure produces two ASN.1 components which will become components in a SEQUENCE created by the Concatenation mapping. Otherwise (if this procedure was not invoked by the Concatenation mapping), this procedure produces a SEQUENCE consisting of the same two components that would have been produced in the first case.
We currently do not support the case where the particular-determinant uses L or H bits.
If the general-determinant is not labeled and the general-determinant's exclusion string is labeled, copy the label from the exclusion string to the general-determinant itself.
Invoke the CSN1String mapping procedure for the general-determinant. This will produce the determinant type, DT.
Create an ASN.1 CHOICE type.
Remove the particular-determinant from the particular alternative. The result is the new particular alternative. If nothing remains, let the particular-type be the ASN.1 NULL type. Otherwise (something remains), invoke the CSN1String mapping procedure on what remains in order to produce the particular-type.
Add a NamedType to the CHOICE type for the particular alternative. The type shall be the particular-type. The identifier shall be determined according to the rules in "ASN.1 Identifier Assignment".
Remove the general-determinant from the general alternative. The result is the new general alternative. Invoke the CSN1String mapping procedure on what remains to produce the general-type.
Add a NamedType to the CHOICE type for the general alternative. The type shall be the general-type. The identifier shall be determined according to the rules in "ASN.1 Identifier Assignment".
Define an ASN.1 component, DC. It's CSN.1 name is the general-determinant's label name. DC.type is DT.
Define a second ASN.1 component, CC. It does not have a CSN.1 name. CC.type is the CHOICE type created above.
If this procedure was invoked by the Concatenation mapping, then this procdure produces two ASN.1 components, namely DC and CC.
Otherwise (this procedure was not invoked by the Concatentation mapping), then this procedure produces an ASN.1 SEQUENCE type, having two component types which are DC and CC. These components shall be named according to the rules in "ASN.1 Identifier Assignment". The encoding of the SEQUENCE shall be the encoding of DC followed by the encoding of CC.
If and only if DC has the value given by the particular-determinant, the chosen alternative for CC shall correspond to the particular alternative.
The encoding of CC's CHOICE type shall be the encoding of the chosen alternative. A decoder will use the previous rule, and the encoded value of the DC component, to determine which alternative is present in an encoding.