]> git.saurik.com Git - apple/security.git/blame - SecuritySNACCRuntime/c++-examples/simple/genber.C
Security-54.1.9.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c++-examples / simple / genber.C
CommitLineData
bac41a7b
A
1/*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19// file: .../c++examples/simple/genber.C---builds an PersonnelRecord value and writes BER form of the value to a file called "pr.ber"
20//
21// MS 92
22//
a66d0d4a 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 $
bac41a7b
A
24// $Log: genber.C,v $
25// Revision 1.1.1.1 2001/05/18 23:14:05 mb
26// Move from private repository to open source repository
27//
28// Revision 1.2 2001/05/05 00:59:17 rmurphy
29// Adding darwin license headers
30//
31// Revision 1.1.1.1 1999/03/16 18:05:57 aram
32// Originals from SMIME Free Library.
33//
34// Revision 1.5 1995/07/24 15:40:32 rj
35// changed `_' to `-' in file names.
36//
37// Revision 1.4 1994/12/11 15:36:14 rj
38// const for a constant value [DEC]
39//
40// Revision 1.3 1994/10/08 01:27:03 rj
41// several \size_t'
42//
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.
45//
46
47
48#include <stddef.h>
49#include <stdlib.h>
50#include <errno.h>
51#include <fstream.h>
52
53#include "asn-incl.h"
54#include "p-rec.h"
55
56
57main (int argc, char *argv[])
58{
59 ofstream outputFile;
60 AsnBuf outputBuf;
61 size_t encodedLen;
62 const size_t dataSize = 1024;
63 char data[dataSize];
64 ChildInformation *ciPtr;
65 PersonnelRecord pr;
66
67 // build internal value of a PersonnelRecord
68 pr.name = new Name;
69 pr.name->givenName = "John"; // this calls pr.name->givenName.Set ("John");
70 pr.name->initial = "E";
71 pr.name->familyName = "Smith";
72
73 pr.title.Set ("The Big Cheese");
74 pr.employeeNumber = 99999;
75 pr.dateOfHire.Set ("19820104");
76
77 pr.nameOfSpouse = new Name;
78 pr.nameOfSpouse->givenName.Set ("Mary");
79 pr.nameOfSpouse->initial.Set ("L");
80 pr.nameOfSpouse->familyName.Set ("Smith");
81
82 pr.children = new PersonnelRecordSeqOf;
83
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");
90
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");
97
98
99 // set up buffer for writing to
100 outputBuf.Init (data, dataSize);
101 outputBuf.ResetInWriteRvsMode();
102
103 // encode the internal value we just build into the buffer
104 if (!pr.BEncPdu (outputBuf, encodedLen))
105 cout << "failed encoding AnyTestType value" << endl;
106
107 // open file to hold the BER value
108 outputFile.open ("pr.ber");
109 if (!outputFile)
110 {
111 perror ("ofstream::open");
112 exit (1);
113 }
114
115 // copy the BER value from the buffer to the file
116 outputBuf.ResetInReadMode();
117 for (; encodedLen > 0; encodedLen--)
118 outputFile.put (outputBuf.GetByte());
119
120
121 cout << "Wrote the following BER PersonnelRecord value to pr.ber." << endl;
122 cout << "Test it with \"def\" and \"indef\"." << endl;
123 cout << pr << endl;
124
125 return 0;
126}