This procedure is invoked for a string having an exponent. It is only invoked when called for by another procedure.
If the exponent is constant and evaluates to 1, map the string as if the exponent were not present.
Otherwise, if the base is a reference to bit and the exponent is constant and less than or equal to 32, this procedure produces type INTEGER(0..k) where k = 2^exponent - 1. The encoding for this type encodes the integer in binary in "exponent" bits.
Otherwise, if the base is a reference to bit and the exponent is variable or greater than 32, this procedure produces type BIT STRING. The size constraint clause (below) applies.
Otherwise, if the base is a reference to octet, this procedure produces type OCTET STRING. The size constraint clause (below) applies.
Otherwise, invoke the CSN1String mapping procedure for the base string.
If an ASN.1 type is produced, let T be that type.
Otherwise, if an ASN.1 component is produced, wrap it in a SEQUENCE and let T be the result.
Otherwise, if the procedure specified that the base string is a pad bit and the exponent is infinite, the string is considered padding. The calling procedure shall specify what to do with the padding or else it is an error.
Otherwise, if the procedure specified that the base string is a pad bit, the exponent is a constant integer less than or equal to 32, and the pad bit is a one-bit or zero-bit (not an L or H), then this procedure produces type INTEGER(0..k), where k = 2^exponent - 1. The calling procedure shall create a component for this type with DEFAULT j, where j = 0 if the pad bit is a zero-bit and k otherwise. The calling procedure shall specify that this component must be present in the encoding. (This is useful for dealing with so-called spare bits.) The encoding for this type encodes the integer in binary in "exponent" bits. Normally, the default value should be encoded, as that was the intention expressed in the CSN.1 (pad bits originate from the SEND expression), but a decoder may encounter any value.
Otherwise, if the base is a literal bit and the exponent is infinite, the calling procedure shall either recognize this (as part of) an INTEGER type with count-bits encoding or else it is an error.
Otherwise, if none of the above clauses applied, it is an error.
If the above clauses specified a type for T, this procedure produces the type SEQUENCE OF T. The size constraint clause (below) applies.
If the above procedures produced a type and noted that the "size constraint clause" applied, then the exponent shall be evaluated to determine whether a size constraint should be added to the type. This is done as follows.
If the exponent is a constant integer k, then the size constraint SIZE(k), shall be added. The encoding shall consist of k bits, k octets, or k encodings of type T, depending on whether the type was a BIT STRING, OCTET STRING, or SEQUENCE OF T.
Otherwise, if the exponent is infinite or non-reversible, no size constraint is added. The encoding shall consist simply of the bits, octets, or encodings of type T based on the value, depending on whether the type was a BIT STRING, OCTET STRING, or SEQUENCE OF T. Unless the calling procedure specifies otherwise, the encoding is delimited by its container. It is an error for an encoder to encode anything following this type within the same container. A decoder will recognize the end of the encoding when it finds the end of the container.
Otherwise, we evaluate the exponent. The exponent uses the val function to refer to a single, labeled string (or else it would be non-reversible or a constant integer). Call the reference string RefString. RefString shall have already been mapped and shall have been mapped to a constrained INTEGER type. Let min and max be the range for that type. Evaluate the exponent using RefString equal to min and max, and order the results to give the minimum and maximum values for the exponent, minexp and maxexp. Add a size constraint to the type as SIZE(minexp..maxexp). The encoding shall consist simply of the bits, octets, or encodings of type T based on the value, depending on whether the type was a BIT STRING, OCTET STRING, or SEQUENCE OF T. The RefString shall serve as a length determinant, so that when the exponent expression is evaluated at the value of RefString, the result is the number of bits/octets/occurrences of T in the encoding.