]> git.saurik.com Git - apple/security.git/blame - SecuritySNACCRuntime/c-examples/simple/README
Security-54.1.9.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c-examples / simple / README
CommitLineData
bac41a7b
A
1(RCS control information is at the end of this file.)
2
3
4C Simple Example README
5-----------------------
6
7This directory should have 8 files in it:
8
9README - this file
10genber.c - C source code for a program that creates and encodes
11 a PersonnelRecord value to a file.
12expbuf_ex.c - C source code for a program that calls the generated
13 PersonnelRecord encoder and decoder routines
14 using the ExpBuf buffer type
15minbuf_ex.c - C source code for program that calls the generated
16 PersonnelRecord encoder and decoder routines
17 using the MinBuf buffer type
18sbuf_ex.c - C source code for a program that calls the generated
19 PersonnelRecord encoder and decoder routines
20 using the MinBuf buffer type
21makefile - compiles the example programs
22good_pr.ber - BER encoding of a Personnel Record (all definite lengths)
23
24
25
26Type "make" to generate the 7 example programs:
27 genber
28 expbuf_def
29 expbuf_indef
30 minbuf_def
31 minbuf_indef
32 sbuf_def
33 sbuf_indef
34
35
36snacc is called from the makefile on snacc/asn1specs/p_rec.asn1 to
37generate the following files:
38
39p_rec.h - C data structs for PersonnelRecord and prototypes for
40 the generated encode, decode, print and free routines.
41p_rec.c - C source code for the PersonnelRecord encode, decode,
42 print, and free routines.
43
44These source files are then compiled with *_ex.c and genber.c files to
45make 7 programs. Each program takes 1 argument (except genber), the
46name of a file containing an BER encoded PersonnelRecord value.
47
48
49Try the following: (or use the makefile's `check' phony target)
50
51eg% ./genber # create a file called pr.ber
52eg% ./sbuf_indef good_pr.ber > indef_pr.ber
53eg% ./sbuf_def indef_pr.ber > def_pr.ber
54eg% diff good_pr.ber def_pr.ber # should be no differences
55
56
57The above commands decode the BER value in "good_pr.ber" and
58indef_pr.ber respectively and then re-encode then to stdout.
59Both programs will decode any valid BER representation of a
60PersonnelRecord value but, the sbuf_def program will re-encode the
61given data using only the definite length BER format and the
62sbuf_indef program will re-encode the given data using only the
63indefinite length BER format.
64
65Compare the lengths of the def_pr.ber and indef_pr.ber files,
66indefinite length encodings are usually larger.
67
68
69
70Things to Note
71--------------
72
73
74Look at genber.c to see how to build a C value and then encode it.
75look at the *_ex.c files to see the different types of buffer
76manipulation. Read the comments in the code.
77
78It should be relatively simple to change the memory and buffer
79management to fit your target environment.
80(see snacc/c_include/asn_config.h.)
81
82
83Snacc ASN.1 comment commands
84
85Notice the special "--snacc" ASN.1 comment in snacc/asn1specs/p_rec.asn1.
86
87PersonnelRecord ::= --snacc isPdu:"TRUE" -- [APPLICATION 0] IMPLICIT SET
88 { ... etc. ... }
89
90The "isPdu" flag tells snacc that the PersonnelRecord is a PDU type
91that you will be calling the encoding and decoding routines directly
92from your code. This causes snacc to generate the
93"BEncPersonnelRecord" and "BDecPersonnelRecord" routines in addition
94to the standard "BEncPersonnelRecordContent" and
95"BDecPersonnelRecordContent".
96
97The Content encoding and decoding routines only deal with the content
98of the type, ignoring all of the tag and length pairs on the given
99type (in this case the APPLICATION (CONSTRUCTED) 0 tag and the length
100for the SET). The "BEncPersonnelRecord" and "BDecPersonnelRecord"
101routines do encode the APPLICATION tag and the SET's length. This
102design is motivated by IMPLICIT tagging.
103
104The compiler generated routines generally only call the content
105oriented routines except in the case of ANY and ANY DEFINED BY types.
106For ANY and ANY DEFINED BY types the PDU form of the rouine is called
107since the tags are not known by the containing type.
108
109
110Length formats
111
112Each pair of *_def and *_indef programs were generated from the same
113source file, *_ex.c. Indefinite length encoders can be created by
114giving the -DUSE_INDEF_LEN flag to the C compiler when compiling.
115Currently the indefinite/definite length encoder choice is made a
116compile time. To change this to a run-time decision, a simple
117solution would be to modify BerEncodeConsLen and BerEncodeEocIfNec
118macros in snacc/c_lib/asn_len.h to check a global flag.
119
120#-------------------------------------------------------------------------------
a66d0d4a 121# $Header: /cvs/root/Security/SecuritySNACCRuntime/c-examples/simple/Attic/README,v 1.1.1.1 2001/05/18 23:14:07 mb Exp $
bac41a7b
A
122# $Log: README,v $
123# Revision 1.1.1.1 2001/05/18 23:14:07 mb
124# Move from private repository to open source repository
125#
126# Revision 1.1.1.1 1999/03/16 18:06:09 aram
127# Originals from SMIME Free Library.
128#
129# Revision 1.2 1995/02/17 16:17:24 rj
130# reflect the test script's integration into the makefile.
131#
132# Revision 1.1 1994/08/31 08:46:22 rj
133# first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
134#