Open Type

Note: The X.680 Open Type replaces the X.208 ANY or ANY DEFINED BY constructs. An ANY or ANY DEFINED BY encountered within an ASN.1 module will result in the generation of code corresponding to the Open Type described below.

The ASN.1 Open Type is converted into a C# class that inherits the Asn1OpenType class. This class in turn inherits the Asn1OctetString class and provides the following public member variable for storing the encoded message component:

   public byte[] mValue;

The number of octets to be encoded or that were decoded is specified in the built-in length component of the array object (i.e., mValue.length).

The following shows the basic mapping from ASN.1 type to C# class definition:

ASN.1 Production:
<name> ::= <openType>
Generated C# class:
   public class <name> : Asn1OpenType {
  public <name> () : base() { }

  public <name> (byte[] data) : base (data) {
  }

  public <name> (byte[] data,
                 int offset,
                 int nbytes) :
     base (data, offset, nbytes)
  {
  }

  public <name> (Asn1EncodeBuffer buffer) :
     base ()
  {
  }
}

The <openType> placeholder is to be replaced with any type of open type specification. It could be the ANY or ANY DEFINED BY keywords from the X.208 specification or an open type from X.681 (for example, TYPEIDENTIFIER.& Type).

The last form of the constructor shown above is for an optimized form of Open Type encoding. When encoding is done using BER, an open type header can be directly added to the beginning of an encoded message component. By using this form of the constructor, you are indicating to the run-time encoder that the encoded message component onto which a header is to be added is already present in the message buffer. The advantage is that binary copies of the encoded message components are avoided both from the encode buffer to the open type object and from the open type object back to the encode buffer.

For XER, a new class derived from the Asn1OpenType class was created. This is the Asn1XerOpenType class and this must be used whenever an open type is required for XER. The reason for creating a special derived class is because of dependencies on XML parser classes defined within this class. If these were added directly to the Asn1OpenType class, a user would need to always have XML parser files included in their classpath – even if working with BER, DER, or PER only.

If the –tables command line option is selected and the ASN.1 type definition references a table constraint, the code generated is different. In this case, Asn1OpenType above is replaced with Asn1Type. This the base class for all ASN.1 types. This allows a value of any ASN.1 type to be specified. On the encoding side, a user can assign an object of any ASN.1 type to this variable and the encoding routine will call the appropriate encoder according to the table index value. If the variable type is not present in the table and the Object Set is extensible, than it can be encoded as an open type. Otherwise an exception will be thrown. On the decoding side, the appropriate variable type is populated from the table based on the decoded index parameters. The user can determine the variable type from the table index value. If the variable type is not present in table, then it will be decoded as an open type if the Object Set is extensible; otherwise and exception will be thrown.