]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c-lib/inc/asn-config.h
Security-54.1.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 /*
20 * asn_config.h - configures the ANSI/non ansi, defines
21 * decoder alloc routines and buffer routines
22 *
23 * MS 91
24 * Copyright (C) 1992 Michael Sample and the University of British Columbia
25 *
26 * This library is free software; you can redistribute it and/or
27 * modify it provided that this copyright/license information is retained
28 * in original form.
29 *
30 * If you modify this file, you must clearly indicate your changes.
31 *
32 * This source code is distributed in the hope that it will be
33 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
34 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35 */
36
37 #ifndef _asn_config_h_
38 #define _asn_config_h_
39
40 #include <stdio.h>
41 #include <setjmp.h> /* for jmp_buf type, setjmp and longjmp */
42
43 /* for pow() used in asn_real.c - must include to avoid casting err on pow */
44 #include <math.h>
45
46 #include "snacc.h"
47
48
49 /* used to test if optionals are present */
50 #define NOT_NULL( ptr) ((ptr) != NULL)
51
52
53 /*
54 * Asn1Error (char *str) - configure error handler
55 */
56 void Asn1Error PROTO ((char* str));
57
58
59 /*
60 * Asn1Warning (char *str) - configure warning mechanism
61 * (currently never called)
62 */
63 void Asn1Warning PROTO ((char* str));
64
65 /*
66 * Asn1ErrorHandler - procedure to call upon Asn1Warning (severity 0)
67 * and Asn1Error (severity 1).
68 */
69 typedef void (*Asn1ErrorHandler) PROTO ((char* str, int severity));
70
71 /*
72 * Asn1InstallErrorHandler - installs new error handler, returns former one
73 */
74 Asn1ErrorHandler Asn1InstallErrorHandler PROTO ((Asn1ErrorHandler handler));
75
76 /*
77 * configure memory scheme used by decoder to allocate memory
78 * for the decoded value.
79 * The Asn1Free will be called in the optionally generated
80 * hierachical free routines.
81 *
82 * nibble_alloc allocs from a single buffer and EVERYTHING
83 * is freed by a single fcn call. Individual elmts cannot be freed
84 */
85
86 #ifndef USE_NIBBLE_MEMORY
87 #define USE_NIBBLE_MEMORY 1
88 #endif
89
90 #if USE_NIBBLE_MEMORY
91
92 #include "nibble-alloc.h"
93
94 #define Asn1Alloc( size) NibbleAlloc (size)
95 #define Asn1Free( ptr) /* empty */
96 #define CheckAsn1Alloc( ptr, env) \
97 if ((ptr) == NULL)\
98 longjmp (env, -27)
99
100 #else /* !USE_NIBBLE_MEMORY */
101
102 #include "mem.h"
103
104 #define Asn1Alloc( size) Malloc (size)
105 #define Asn1Free( ptr) Free (ptr)
106 #define CheckAsn1Alloc( ptr, env) \
107 if ((ptr) == NULL)\
108 longjmp (env, -27)
109
110 #endif /* USE_NIBBLE_MEMORY */
111
112 #define ENV_TYPE jmp_buf
113
114 /*
115 * configure buffer routines that the encoders (write)
116 * and decoders (read) use. This config technique kind
117 * of bites but is allows efficient macro calls. The
118 * Generated code & lib routines call/use the "Buf????"
119 * version of the macro - you define their meaning here.
120 */
121 #ifdef USE_EXP_BUF
122
123 #include "exp-buf.h"
124
125 #define BUF_TYPE ExpBuf **
126 #define BufGetByte( b) ExpBufGetByte (b)
127 #define BufGetSeg( b, lenPtr) ExpBufGetSeg (b, lenPtr)
128 #define BufCopy( dst, b, len) ExpBufCopy (dst, b, len)
129 #define BufSkip( b, len) ExpBufSkip (b, len)
130 #define BufPeekByte( b) ExpBufPeekByte (b)
131 #define BufPutByteRvs( b, byte) ExpBufPutByteRvs (b, byte)
132 #define BufPutSegRvs( b, data, len) ExpBufPutSegRvs (b, data, len)
133 #define BufReadError( b) ExpBufReadError (b)
134 #define BufWriteError( b) ExpBufWriteError (b)
135
136 #else /* !USE_EXP_BUF */
137
138 #ifdef USE_MIN_BUF
139
140 #include "min-buf.h"
141
142 #define BUF_TYPE char **
143 #define BufGetByte( b) MinBufGetByte (b)
144 #define BufGetSeg( b, lenPtr) MinBufGetSeg (b, lenPtr)
145 #define BufCopy( dst, b, len) MinBufCopy (dst, b, len)
146 #define BufSkip( b, len) MinBufSkip (b, len)
147 #define BufPeekByte( b) MinBufPeekByte (b)
148 #define BufPutByteRvs( b, byte) MinBufPutByteRvs (b, byte)
149 #define BufPutSegRvs( b, data, len) MinBufPutSegRvs (b, data, len)
150 #define BufReadError( b) MinBufReadError (b)
151 #define BufWriteError( b) MinBufWriteError (b)
152
153 #else /* !USE_EXP_BUF && !USE_MIN_BUF */
154
155 #ifdef USE_SBUF
156
157 #include "sbuf.h"
158
159 #define BUF_TYPE SBuf *
160 #define BufGetByte( b) SBufGetByte (b)
161 #define BufGetSeg( b, lenPtr) SBufGetSeg (b, lenPtr)
162 #define BufCopy( dst, b, len) SBufCopy (dst, b, len)
163 #define BufSkip( b, len) SBufSkip (b, len)
164 #define BufPeekByte( b) SBufPeekByte (b)
165 #define BufPutByteRvs( b, byte) SBufPutByteRvs (b, byte)
166 #define BufPutSegRvs( b, data, len) SBufPutSegRvs (b, data, len)
167 #define BufReadError( b) SBufReadError (b)
168 #define BufWriteError( b) SBufWriteError (b)
169
170 #else /* !USE_EXP_BUF && !USE_MIN_BUF && !USE_SBUF*/
171
172 #ifdef USE_GEN_BUF
173
174 /*
175 * NOTE: for use with tables, I defined the (slower)
176 * GenBuf type that is more flexible (à la ISODE and XDR).
177 * This allows the encode/decode libs to support other
178 * buffer types dynamically instead of having different
179 * libs for each buffer type.
180 * The GenBufs are not provided for the compiled code
181 * (ie the c_lib directory) but could easily be added
182 * (I don't have time, tho). Tables tools are
183 * around 4x slower than the compiled version so a
184 * the GenBufs aren't such a big performance hit for table stuff.
185 *
186 */
187 #include "gen-buf.h"
188
189 #define BUF_TYPE GenBuf *
190 #define BufGetByte( b) GenBufGetByte (b)
191 #define BufGetSeg( b, lenPtr) GenBufGetSeg (b, lenPtr)
192 #define BufCopy( dst, b, len) GenBufCopy (dst, b, len)
193 #define BufSkip( b, len) GenBufSkip (b, len)
194 #define BufPeekByte( b) GenBufPeekByte (b)
195 #define BufPeekSeg( b, lenPtr) GenBufPeekSeg (b, lenPtr)
196 #define BufPeekCopy( dst, b, len) GenBufPeekCopy (dst, b, len)
197 #define BufPutByteRvs( b, byte) GenBufPutByteRvs (b, byte)
198 #define BufPutSegRvs( b, data, len) GenBufPutSegRvs (b, data, len)
199 #define BufReadError( b) GenBufReadError (b)
200 #define BufWriteError( b) GenBufWriteError (b)
201
202 #else /* none?! */
203
204 #ifndef MAKEDEPEND
205 #error "don't know what buffer type to use!"
206 #endif
207
208 #endif /* USE_GEN_BUF */
209 #endif /* USE_SBUF */
210 #endif /* USE_MIN_BUF */
211 #endif /* USE_EXP_BUF */
212
213 #include "print.h" /* for printing set up */
214
215 /*
216 * Enables throw/catch as replacement for setjmp/longjmp in C++ lib.
217 * BDecPdu still returns int (1 = OK, 0 = fail) in either config.
218 * The compiler gets this symbol from this file; runtime support uses
219 * the same symbol in c++_lib/inc/asn-config.h There is currently no
220 * straightforward way to have one symbol used in both environments.
221 */
222 #define SNACC_EXCEPTION_ENABLE 1
223
224 /*
225 * Enable BEncPdu, BDecPdu. Same remarks apply as above w.r.t the
226 * c++ config file.
227 */
228 #define SNACC_ENABLE_PDU 0
229
230 #endif /* conditional include */