(RCS control information is at the end of this file.) C ANY example README ------------------ This example shows how the snacc compiler handles the ANY DEFINED BY type in C. ANY types (not ANY DEFINED BY) require the modifications to the generated code. Type "make" to build this example. This directory should have the following files in it: README genber.c example.c makefile There are 3 programs generated by the makefile: genber - builds a BER value of the AnyTestType and writes it to a file called "att.ber" def - takes file name of an AnyTestType value. Decodes the file and re-encodes it to stdout. Uses definite lengths for constructed values. indef - takes file name of an AnyTestType value. Decodes the file and re-encodes it to stdout. Uses indefinite lengths for constructed values. These files use the code generated by snacc from the snacc/asn1specs/any.asn1 file. (see the makefile) Look at genber.c to see how values can be built and printed. Look at the generated code in any_test.c and any_test.h to see how the any hash table is built. try the following commands in your c-shell: %1 genber # generate the att.ber file %2 indef att.ber > tmp.ber # decode att.ber an re-encode into tmp.ber %3 def tmp.ber > tmp2.ber # decode tmp.ber an re-encode into tmp2.ber %4 diff att.ber tmp2.ber # compare .ber files (should be the same) When you are finished with the example type "make clean" to remove the binaries and generated code. Things To Note -------------- Snacc ASN.1 comment commands In the snacc/asn1specs/any.asn1 file, the AnyTestType has a special "--snacc" ASN.1 comment after ::= to give snacc some extra information about the AnyTestType. AnyTestType ::= --snacc isPdu:"TRUE" -- SEQUENCE { ... etc. ... } The "isPdu" flag tells snacc that the AnyTestType is a PDU type that you will be calling the encoding and decoding routines directly from your code. This causes snacc to generate the "BEncAnyTestType" and "BDecAnyTestType" routines in addition to the standard "BEncAnyTestTypeContent" and "BDecAnyTestTypeContent". The Content encoding and decoding routines only deal with the content of the type, ignoring all of the tag and length pairs on the given type (in this case the UNIVERSAL (CONSTRUCTED) 16 tag and the length for the SEQUENCE). The "BEncAnyTestType" and "BDecAnyTestType" routines do encode the SEQUENCE tag and its length. This design is motivated by IMPLICIT tagging. The compiler generated routines generally only call the content oriented routines except in the case of ANY and ANY DEFINED BY types. For ANY and ANY DEFINED BY types the PDU form of the rouine is called since the tags are not known by the containing type. SNMP OBJECT-TYPE Macro The SNMP OBJECT-TYPE macro is used to define the id to type mapping for ANY DEFINED BY types. The macro has been modified to accept both INTEGERs and OBJECT IDENTIFIERs as values (see snacc/asn1specs/any.asn1). This macro can be used with other protocols to define the id to type mapping. Two hash tables are used to hold the id to type mappings. One for INTEGER to type mappings and the other for OBJECT IDENTIFIER to type mappings. You must explicitly initialize the hash tables by calling generated init routines once at the beginning of your program. Each module that has OBJECT-TYPE macros in it will generate an "InitAny" routine. You must call every init routine to add all the mappings to the hash table(s). #------------------------------------------------------------------------------- # $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/c-examples/any/README,v 1.1.1.1 2001/05/18 23:14:07 mb Exp $ # $Log: README,v $ # Revision 1.1.1.1 2001/05/18 23:14:07 mb # Move from private repository to open source repository # # Revision 1.1.1.1 1999/03/16 18:06:08 aram # Originals from SMIME Free Library. # # Revision 1.2 1997/02/16 20:26:14 rj # check-in of a few cosmetic changes # # Revision 1.1 1994/08/31 08:46:17 rj # first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog. #