]>
Commit | Line | Data |
---|---|---|
bac41a7b A |
1 | (RCS control information is at the end of this file.) |
2 | ||
3 | ||
4 | C++ Simple Example README | |
5 | ------------------------- | |
6 | ||
7 | This directory should have 6 files in it: | |
8 | ||
9 | README - this file | |
10 | ||
11 | genber.C - C++ source code for a program that creates and encodes | |
12 | a PersonnelRecord value to a file. | |
13 | ||
14 | example.C - C++ source code for a program that decodes a given | |
15 | PersonnelRecord value and re-encodes it to stdout. | |
16 | ||
17 | makefile - compiles the example programs | |
18 | ||
19 | good_pr.ber - BER encoding of a Personnel Record (all definite lengths) | |
20 | ||
21 | ||
22 | ||
23 | Type "make" to generate the 3 example programs: | |
24 | genber | |
25 | def | |
26 | indef | |
27 | ||
28 | ||
29 | ||
30 | snacc is called from the makefile on .../asn1specs/p_rec.asn1 to | |
31 | generate the following files: | |
32 | ||
33 | p_rec.h - C++ classes for PersonnelRecord types. | |
34 | ||
35 | p_rec.C - C++ source code for the PersonnelRecord encode, decode, | |
36 | print, and free methods. | |
37 | ||
38 | These source files are then compiled with example.C to make the | |
39 | programs def and indef. Each program takes 1 argument, the name of a | |
40 | file containing an BER encoded PersonnelRecord value. | |
41 | ||
42 | ||
43 | Try the following: | |
44 | ||
45 | %1 genber # create a file called pr.ber | |
46 | %2 indef good_pr.ber > indef_pr.ber | |
47 | %3 def indef_pr.ber > def_pr.ber | |
48 | %4 diff good_pr.ber def_pr.ber # should be no differences | |
49 | ||
50 | (commands 2-4 can be made via the `check' phony target.) | |
51 | ||
52 | The above commands decode the BER value in "good_pr.ber" and | |
53 | indef_pr.ber respectively and then re-encode them to stdout. | |
54 | Both programs will decode any valid BER representation of a | |
55 | PersonnelRecord value but, the def program will re-encode the | |
56 | given data using only the definite length BER format and the | |
57 | indef program will re-encode the given data using only the | |
58 | indefinite length BER format. | |
59 | ||
60 | Compare the lengths of the def_pr.ber and indef_pr.ber files, | |
61 | indefinite length encodings are usually larger. | |
62 | ||
63 | ||
64 | ||
65 | Things to Note | |
66 | -------------- | |
67 | ||
68 | Look at genber.C to see how to build a C++ value and then encode it. | |
69 | look at the example.C file to see buffer usage. Look at | |
70 | .../c++_lib/inc/asn_config.h and .../c++_lib/inc/asn_buf.h if you | |
71 | want to change the buffer managment. | |
72 | ||
73 | ||
74 | Snacc ASN.1 comment commands | |
75 | ||
76 | Notice the special "--snacc" ASN.1 comment in .../asn1specs/p_rec.asn1. | |
77 | ||
78 | PersonnelRecord ::= --snacc isPdu:"TRUE" -- [APPLICATION 0] IMPLICIT SET | |
79 | { ... etc. ... } | |
80 | ||
81 | The "isPdu" flag tells snacc that the PersonnelRecord is a PDU type. | |
82 | This flag has no effect on the generated C++ code, since each type gets | |
83 | PDU members automatically for C++. | |
84 | ||
85 | ||
86 | ||
87 | Length formats | |
88 | ||
89 | Both the def and indef programs were generated from the same source | |
90 | file, example.c. Indefinite length encoders can be created by giving | |
91 | the -DUSE_INDEF_LEN flag to the C++ compiler when compiling. Currently | |
92 | the indefinite/definite length encoder choice is made a compile time. | |
93 | To change this to a run-time decision, a simple solution would be to | |
94 | modify BerEncodeConsLen and BerEncodeEocIfNec macros in | |
95 | .../c++_lib/inc/asn_len.h to check a global flag. | |
96 | ||
97 | #------------------------------------------------------------------------------- | |
5a719ac8 | 98 | # $Header: /cvs/Darwin/src/live/Security/SecuritySNACCRuntime/c++-examples/simple/README,v 1.1.1.1 2001/05/18 23:14:05 mb Exp $ |
bac41a7b A |
99 | # $Log: README,v $ |
100 | # Revision 1.1.1.1 2001/05/18 23:14:05 mb | |
101 | # Move from private repository to open source repository | |
102 | # | |
103 | # Revision 1.1.1.1 1999/03/16 18:05:57 aram | |
104 | # Originals from SMIME Free Library. | |
105 | # | |
106 | # Revision 1.2 1994/10/08 04:43:46 rj | |
107 | # the test csh skript has been integrated into the makefile | |
108 | # | |
109 | # Revision 1.1 1994/08/31 08:48:05 rj | |
110 | # first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog. | |
111 | # |