TOC PREV NEXT INDEX


OCTET STRING



The ASN.1 OCTET STRING type is converted into a C structured type containing an integer to hold the number of octets and an array of unsigned characters ("OCTETs") to hold the octet string contents. The number of octets integer specifies the actual number of octets in the contents field.

The allocation for the contents field depends on how the octet string is specified in the ASN.1 definition. If a size constraint is used, a static array of that size is generated; otherwise, a pointer variable is generated to hold a dynamically allocated string. The decoder will automatically allocate memory to hold a parsed string based on the received length of the string.

For C++, constructors and assignment operators are generated to make assigning variables to the structures easier. In addition to the default constructor, a constructor is provided for string or binary data. An assignment operator is generated for direct assignment of a null-terminated string to the structure (note: this assignment operator copies the null terminator at the end of the string to the data).

Dynamic OCTET STRING

	ASN.1 production:   <name> ::= OCTET STRING
 

	Generated C code:    typedef ASN1DynOctStr <name>;
 

	Generated C++ code:  typedef ASN1TDynOctStr ASN1T_<name>;
 

In this case, different base types are used for C and C++. The difference between the two is the C++ version includes constructors and assignment operators that make setting the value a bit easier.

The ASN1DynOctStr type (i.e., the type used in the C mapping) is defined in the asn1type.h header file as follows:

typedef struct ASN1DynOctStr {
 
   ASN1UINT numbits;
 
   ASN1OCTET* data;
 
} ASN1TDynBitStr;
 

The ASN1TDynOctStr type is defined in the asn1CppTypes.h header file and has the following definition:

typedef struct ASN1TDynOctStr {
 
   ASN1UINT numocts;
 
   ASN1OCTET* data;
 
   // ctors
 
   ASN1TDynOctStr ();
 
   ASN1TDynOctStr (ASN1UINT _numocts, ASN1OCTET* _data);
 
   ASN1TDynOctStr (char* cstring);
 
   // assignment operators
 
   ASN1TDynOctStr& operator= (char* cstring) 
 
} ASN1TDynOctStr;
 

Static (sized) OCTET STRING

     ASN.1 production:    <name> ::= OCTET STRING (SIZE (<len>))
 

     Generated C code:    typedef struct {
 
		             ASN1UINT   numocts;
 
		             ASN1OCTET  data[<len>];
 
		          } <name>;
 

     Generated C++ code:  typedef struct {
 
		             ASN1UINT   numocts;
 
		             ASN1OCTET  data[<len>];
 

		             // ctors
 
		             ASN1T_<name> ();
 
		             ASN1T_<name> (ASN1UINT _numocts, 
 
		             ASN1OCTET* _data);
 
		             ASN1T_<name> (char* cstring);
 

 
		             // assignment operators
 
		             ASN1T_<name>& operator= (char* cstring); 
 

 
		          } ASN1T_<name>;
 


Objective Systems, Inc.

102 Pickering Way, Suite #506
Exton, Pennsylvania 19341
http://www.obj-sys.com
Phone: (484) 875-9841
Toll-free: (877) 307-6855 (US only)
Fax: (484) 875-9830
info@obj-sys.com
TOC PREV NEXT INDEX