
INTEGER
The ASN.1 INTEGER type is converted into one of several different C types depending on constraints specified on the type. By default, an INTEGER with no constraints results in the generation of an "ASN1INT" type. In the global include file "asn1type.h", ASN1INT is defined to be an "int" which is normally a signed 32-bit integer value on most computer systems.
ASN.1 production: <name> ::= INTEGER Generated C code: typedef ASN1INT <name>; Generated C++ code: typedef ASN1INT ASN1T_<name>;Value range constraints can be used to alter the C type used to represent a given integer value. For example, the following declaration from the SNMP SMI specification would cause an ASN1UINT type (mapped to a C unsigned int) to be used:
Counter ::= [APPLICATION 1] IMPLICIT INTEGER (0..4294967295)In this case, an ASN1INT could not be used because all values within the given range could not be represented. Other value ranges would cause different integer types to be used that provide the most efficient amount of storage. The following table shows the types that would be used for the different range values:
The C type that is used to represent a given integer value can also be altered using the "<ctype>" configuration variable setting. This allows any of the integer types above to be used for a given integer type as well as a 64-bit integer type. The values that can be used with <ctype> are: byte, int16, uint16, int32, uint32, and int64. An example of using this setting is as follows:
MyIntType ::= [APPLICATION 1] INTEGERYou could then have ASN1C use a 64-bit integer type for this integer by adding the following declaration to a configuration file to be associated with this module:
<production> <name>MyIntType</name> <ctype>int64</ctype> </production>The "<intCType>" setting is also available at the module level to specify that the given C integer type be used for all unconstrained integers within the module.
In C and C++, the maximum size for an integer type is normally 64 bits (or 32 bits on some older platforms). ASN.1 has no such limitation on integer sizes and some applications (security key values for example) demand larger sizes. In order to accommodate these types of applications, the ASN1C compiler allows an integer to be declared a "big integer" via a configuration file variable (the <isBigInteger/> setting is used to do this - see the section describing the configuration file for full details). When the compiler detects this setting, it will declare the integer to be a character string variable instead of a C int or unsigned int type. The character string would then be populated with a character string representation of the value to be encoded. Only hexadecimal string representations of the integer value are supported in this release.
SecurityKeyType ::= [APPLICATION 2] INTEGERThen, in a configuration file used with the ASN.1 definition above, the following declaration can be made:
<production> <name>SecurityKeyType</name> <isBigInteger/> </production>typedef ASN1ConstCharPtr SecurityKeyTypeThe ASN1ConstCharPtr type is declared to be a `char*' type for C and a `const char*' type for C++ in the asn1type.h header file. The SecurityKeyType variable can now be populated with a hexadecimal string for encoding such as the following:
SecurityKeyType secKey = "0xfd09874da875cc90240087cd12fd";Note that in this definition the `0x' prefix is required to identify the string as containing hexadecimal characters.
On the decode side, the decoder will populate the variable with the same type of character string after decoding.
There are also a number of run-time functions available for big integer support. This set of functions provides an arbitrary length integer math package that can be used to perform mathematical operations as well as convert values into various string forms. See the ASN1C C/C++ Common Run-time User's Manual for a description of these functions.
Objective Systems, Inc.102 Pickering Way, Suite #506Exton, 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 |