]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/inc/asn-config.h
Security-28.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c++-lib / inc / asn-config.h
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++-lib/inc/asn-config.h - decoder alloc routines and buffer routines and other configuration stuff.
20 //
21 // MS 92/06/18
22 // Copyright (C) 1992 Michael Sample and the University of British Columbia
23 //
24 // This library is free software; you can redistribute it and/or
25 // modify it provided that this copyright/license information is retained
26 // in original form.
27 //
28 // If you modify this file, you must clearly indicate your changes.
29 //
30 // This source code is distributed in the hope that it will be
31 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
32 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
33 //
34 // $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/c++-lib/inc/asn-config.h,v 1.3 2001/06/27 23:09:16 dmitch Exp $
35 // $Log: asn-config.h,v $
36 // Revision 1.3 2001/06/27 23:09:16 dmitch
37 // Pusuant to Radar 2664258, avoid all cerr-based output in NDEBUG configuration.
38 //
39 // Revision 1.2 2001/06/26 23:47:26 dmitch
40 // Implemented AsnNullError as replacement for cerr in NDEBUG configuration.
41 //
42 // Revision 1.1.1.1 2001/05/18 23:14:06 mb
43 // Move from private repository to open source repository
44 //
45 // Revision 1.3 2001/05/05 00:59:18 rmurphy
46 // Adding darwin license headers
47 //
48 // Revision 1.2 2000/06/15 18:48:23 dmitch
49 // Snacc-generated source files, now part of CVS tree to allow for cross-platform build of snaccRuntime.
50 //
51 // Revision 1.1.1.1 2000/03/09 01:00:05 rmurphy
52 // Base Fortissimo Tree
53 //
54 // Revision 1.3 1999/04/08 21:20:18 aram
55 // Fixed Asn1Free macro.
56 //
57 // Revision 1.2 1999/03/16 03:04:30 mb
58 // Added common base class SecObject and implemented signing of the digest in SecSigner.
59 //
60 // Revision 1.1 1999/02/25 05:21:41 mb
61 // Added snacc c++ library
62 //
63 // Revision 1.7 1995/09/07 18:48:36 rj
64 // AsnIntType and AsnUIntType introduced to replace (unsigned) long int at a lot of places.
65 // they shall provide 32 bit integer types on all platforms.
66 //
67 // Revision 1.6 1995/07/25 20:19:00 rj
68 // changed `_' to `-' in file names.
69 //
70 // Revision 1.5 1995/02/13 14:47:46 rj
71 // settings for IEEE_REAL_FMT/IEEE_REAL_LIB moved from {c_lib,c++_lib}/inc/asn_config.h to acconfig.h.
72 //
73 // Revision 1.4 1994/10/08 04:17:59 rj
74 // code for meta structures added (provides information about the generated code itself).
75 //
76 // code for Tcl interface added (makes use of the above mentioned meta code).
77 //
78 // virtual inline functions (the destructor, the Clone() function, BEnc(), BDec() and Print()) moved from inc/*.h to src/*.C because g++ turns every one of them into a static non-inline function in every file where the .h file gets included.
79 //
80 // made Print() const (and some other, mainly comparison functions).
81 //
82 // several `unsigned long int' turned into `size_t'.
83 //
84 // Revision 1.3 1994/09/01 00:58:47 rj
85 // redundant code moved into ../../config.h.bot; semicolon removed from end of macro texts.
86 //
87 // Revision 1.2 1994/08/28 10:00:47 rj
88 // comment leader fixed.
89 //
90 // Revision 1.1 1994/08/28 09:20:29 rj
91 // first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
92
93 #ifndef _asn_config_h_
94 #define _asn_config_h_
95
96 #include <ctype.h> /* for isprint() in <<op on AsnOcts */
97 #include <iostream.h>
98 #include <memory.h>
99 #include <string.h>
100 #include <setjmp.h>
101 #include <math.h> /* to get ieee conversion functions & pow */
102
103 #include "snacc.h"
104
105 // used not only by AsnInt (asn-int.h), but by AsnNameDesc (meta.h) as well:
106 #if SIZEOF_INT == 4
107 # define I int
108 #else
109 # if SIZEOF_LONG == 4
110 # define I long
111 # else
112 # if SIZEOF_SHORT == 4
113 # define I short
114 # endif
115 # endif
116 #endif
117 #ifdef I
118 typedef I AsnIntType;
119 typedef unsigned I AsnUIntType;
120 # undef I
121 #else
122 # error "can't find integer type which is 4 bytes in size"
123 #endif
124
125 /* used to test if optionals are present */
126 #define NOT_NULL( ptr) ((ptr) != NULL)
127
128
129 /*
130 * Asn1Error (char *str)
131 * - configure error handler
132 */
133 #ifndef NDEBUG
134 #define Asn1Error cerr
135 #else
136
137 /* silent ostream */
138 class Asn1ErrorClass;
139 class Asn1ErrorClass /* public ostream */
140 {
141 public:
142 Asn1ErrorClass& put (char c) { return *this; };
143 Asn1ErrorClass& write (const char * s, streamsize n) { return *this; };
144 Asn1ErrorClass& flush () { return *this; };
145 template <class T>
146 Asn1ErrorClass &operator << (const T &) { return *this; }
147 };
148
149
150 #ifdef __APPLE__
151
152 /* Avoid the static load-time init of AsnErrorClass */
153 #include <Security/globalizer.h>
154 extern ModuleNexus<Asn1ErrorClass> AsnNullError;
155
156 /* Avoid instantiating cerr and endl */
157 #define Asn1Error AsnNullError()
158 #define endl AsnNullError()
159
160 #else /* NDEBUG, !__APPLE__ */
161
162 /* This does not currently have an instantiation */
163 extern Asn1ErrorClass Asn1Error;
164
165 #endif /* __APPLE__ */
166 #endif /* NDEBUG */
167
168 /*
169 * Asn1Warning (char *str) - configure warning mechanism
170 * (currently not called)
171 */
172 #define Asn1Warning Asn1Error
173
174
175 /*
176 * configure memory scheme used by decoder to allocate memory
177 * for the decoded value. The include file name cannot be
178 * be null.
179 */
180 #define Asn1New( class) new class
181 #define Asn1Delete( ptr) delete ptr
182 #define Asn1Alloc( size) new char[size]
183 #define Asn1Free( ptr) delete[] ptr
184
185 #include "asn-buf.h"
186 #define BUF_TYPE AsnBuf &
187 #define ENV_TYPE jmp_buf
188
189 /* return true if succeeded, false otherwise */
190 #define PDU_MEMBER_MACROS\
191 int BEncPdu (BUF_TYPE b, AsnLen &bytesEncoded)\
192 {\
193 bytesEncoded = BEnc (b);\
194 return !b.WriteError();\
195 }\
196 \
197 int BDecPdu (BUF_TYPE b, AsnLen &bytesDecoded)\
198 {\
199 jmp_buf env;\
200 int val;\
201 \
202 bytesDecoded = 0;\
203 if ((val = setjmp (env)) == 0)\
204 {\
205 BDec (b, bytesDecoded, env);\
206 return !b.ReadError();\
207 }\
208 else\
209 return false;\
210 }
211
212
213 #endif /* conditional include */