OCTET STRING

The ASN.1 OCTET STRING type is converted to a C# class that inherits the Asn1OctetString run-time class. This base class encapsulates the following public member variable:

   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> ::= OCTET STRING
XSD Types:
<xsd:hexBinary>, <xsd:base64Binary>
Generated C# class:
   public class <name> : Asn1OctetString {
   public <name> () : base() {
   }

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

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

   public <name> (string value_) : base (value_) {
   }
}

This shows the class generated for a simple OCTET STRING assignment. If a tagged or constrained type is specified, specific encode and decode methods will be generated as well.

The constructors generated for this type provide additional options for populating the member variables in the base class. In addition to passing the string directly using the data argument, the string form can be used. The string is passed in ASN.1 value notation format for either a binary string (i.e., ‘xxxx’B), hexadecimal string (i.e., ‘xxxx’H), or a character string (i.e., ‘xxxx’). A constructor also exists that allows a portion of a byte array starting at a given offset and consisting of a given number of bytes to be used to populate the variable.