2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
19 // file: .../c++examples/simple/genber.C---builds an PersonnelRecord value and writes BER form of the value to a file called "pr.ber"
23 // $Header: /cvs/root/Security/SecuritySNACCRuntime/c++-examples/simple/Attic/genber.C,v 1.1.1.1 2001/05/18 23:14:05 mb Exp $
25 // Revision 1.1.1.1 2001/05/18 23:14:05 mb
26 // Move from private repository to open source repository
28 // Revision 1.2 2001/05/05 00:59:17 rmurphy
29 // Adding darwin license headers
31 // Revision 1.1.1.1 1999/03/16 18:05:57 aram
32 // Originals from SMIME Free Library.
34 // Revision 1.5 1995/07/24 15:40:32 rj
35 // changed `_' to `-' in file names.
37 // Revision 1.4 1994/12/11 15:36:14 rj
38 // const for a constant value [DEC]
40 // Revision 1.3 1994/10/08 01:27:03 rj
43 // Revision 1.2 1994/08/31 08:56:33 rj
44 // first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
57 main (int argc, char *argv[])
62 const size_t dataSize = 1024;
64 ChildInformation *ciPtr;
67 // build internal value of a PersonnelRecord
69 pr.name->givenName = "John"; // this calls pr.name->givenName.Set ("John");
70 pr.name->initial = "E";
71 pr.name->familyName = "Smith";
73 pr.title.Set ("The Big Cheese");
74 pr.employeeNumber = 99999;
75 pr.dateOfHire.Set ("19820104");
77 pr.nameOfSpouse = new Name;
78 pr.nameOfSpouse->givenName.Set ("Mary");
79 pr.nameOfSpouse->initial.Set ("L");
80 pr.nameOfSpouse->familyName.Set ("Smith");
82 pr.children = new PersonnelRecordSeqOf;
84 ciPtr = pr.children->Append();
85 ciPtr->name = new Name;
86 ciPtr->name->givenName.Set ("James");
87 ciPtr->name->initial.Set ("R");
88 ciPtr->name->familyName.Set ("Smith");
89 ciPtr->dateOfBirth.Set ("19570310");
91 ciPtr = pr.children->Append();
92 ciPtr->name = new Name;
93 ciPtr->name->givenName.Set ("Lisa");
94 ciPtr->name->initial.Set ("M");
95 ciPtr->name->familyName.Set ("Smith");
96 ciPtr->dateOfBirth.Set ("19610621");
99 // set up buffer for writing to
100 outputBuf.Init (data, dataSize);
101 outputBuf.ResetInWriteRvsMode();
103 // encode the internal value we just build into the buffer
104 if (!pr.BEncPdu (outputBuf, encodedLen))
105 cout << "failed encoding AnyTestType value" << endl;
107 // open file to hold the BER value
108 outputFile.open ("pr.ber");
111 perror ("ofstream::open");
115 // copy the BER value from the buffer to the file
116 outputBuf.ResetInReadMode();
117 for (; encodedLen > 0; encodedLen--)
118 outputFile.put (outputBuf.GetByte());
121 cout << "Wrote the following BER PersonnelRecord value to pr.ber." << endl;
122 cout << "Test it with \"def\" and \"indef\"." << endl;