1 /* crypto/asn1/asn1_mac.h */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
59 #ifndef HEADER_ASN1_MAC_H
60 #define HEADER_ASN1_MAC_H
62 #include <openssl/asn1.h>
68 #ifndef ASN1_MAC_ERR_LIB
69 #define ASN1_MAC_ERR_LIB ERR_LIB_ASN1
72 #define ASN1_MAC_H_err(f,r,line) \
73 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),ERR_file_name,(line))
75 #define M_ASN1_D2I_vars(a,type,func) \
81 c.error=ERR_R_NESTED_ASN1_ERROR; \
82 if ((a == NULL) || ((*a) == NULL)) \
83 { if ((ret=(type)func()) == NULL) \
84 { c.line=__LINE__; goto err; } } \
87 #define M_ASN1_D2I_Init() \
89 c.max=(length == 0)?0:(c.p+length);
91 #define M_ASN1_D2I_Finish_2(a) \
92 if (!asn1_Finish(&c)) \
93 { c.line=__LINE__; goto err; } \
95 if (a != NULL) (*a)=ret; \
98 #define M_ASN1_D2I_Finish(a,func,e) \
99 M_ASN1_D2I_Finish_2(a); \
101 ASN1_MAC_H_err((e),c.error,c.line); \
102 asn1_add_error(*pp,(int)(c.q- *pp)); \
103 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
106 #define M_ASN1_D2I_start_sequence() \
107 if (!asn1_GetSequence(&c,&length)) \
108 { c.line=__LINE__; goto err; }
109 /* Begin reading ASN1 without a surrounding sequence */
110 #define M_ASN1_D2I_begin() \
113 /* End reading ASN1 with no check on length */
114 #define M_ASN1_D2I_Finish_nolen(a, func, e) \
116 if (a != NULL) (*a)=ret; \
119 ASN1_MAC_H_err((e),c.error,c.line); \
120 asn1_add_error(*pp,(int)(c.q- *pp)); \
121 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
124 #define M_ASN1_D2I_end_sequence() \
125 (((c.inf&1) == 0)?(c.slen <= 0): \
126 (c.eos=ASN1_check_infinite_end(&c.p,c.slen)))
128 /* Don't use this with d2i_ASN1_BOOLEAN() */
129 #define M_ASN1_D2I_get(b,func) \
131 if (func(&(b),&c.p,c.slen) == NULL) \
132 {c.line=__LINE__; goto err; } \
135 /* use this instead () */
136 #define M_ASN1_D2I_get_int(b,func) \
138 if (func(&(b),&c.p,c.slen) < 0) \
139 {c.line=__LINE__; goto err; } \
142 #define M_ASN1_D2I_get_opt(b,func,type) \
143 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
144 == (V_ASN1_UNIVERSAL|(type)))) \
146 M_ASN1_D2I_get(b,func); \
149 #define M_ASN1_D2I_get_imp(b,func, type) \
150 M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
152 if (func(&(b),&c.p,c.slen) == NULL) \
153 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
155 M_ASN1_next_prev=_tmp;
157 #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
158 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
159 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
161 unsigned char _tmp = M_ASN1_next; \
162 M_ASN1_D2I_get_imp(b,func, type);\
165 #define M_ASN1_D2I_get_set(r,func,free_func) \
166 M_ASN1_D2I_get_imp_set(r,func,free_func, \
167 V_ASN1_SET,V_ASN1_UNIVERSAL);
169 #define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
170 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
171 V_ASN1_SET,V_ASN1_UNIVERSAL);
173 #define M_ASN1_D2I_get_set_opt(r,func,free_func) \
174 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
175 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
176 { M_ASN1_D2I_get_set(r,func,free_func); }
178 #define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
179 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
180 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
181 { M_ASN1_D2I_get_set_type(type,r,func,free_func); }
183 #define M_ASN1_I2D_len_SET_opt(a,f) \
184 if ((a != NULL) && (sk_num(a) != 0)) \
185 M_ASN1_I2D_len_SET(a,f);
187 #define M_ASN1_I2D_put_SET_opt(a,f) \
188 if ((a != NULL) && (sk_num(a) != 0)) \
189 M_ASN1_I2D_put_SET(a,f);
191 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
192 if ((a != NULL) && (sk_num(a) != 0)) \
193 M_ASN1_I2D_put_SEQUENCE(a,f);
195 #define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
196 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
197 M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
199 #define M_ASN1_I2D_put_SEQUENCE_opt_ex_type(type,a,f) \
200 if (a) M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
202 #define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
203 if ((c.slen != 0) && \
205 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
207 M_ASN1_D2I_get_imp_set(b,func,free_func,\
208 tag,V_ASN1_CONTEXT_SPECIFIC); \
211 #define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
212 if ((c.slen != 0) && \
214 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
216 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
217 tag,V_ASN1_CONTEXT_SPECIFIC); \
220 #define M_ASN1_D2I_get_seq(r,func,free_func) \
221 M_ASN1_D2I_get_imp_set(r,func,free_func,\
222 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
224 #define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
225 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
226 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
228 #define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
229 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
230 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
231 { M_ASN1_D2I_get_seq(r,func,free_func); }
233 #define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
234 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
235 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
236 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
238 #define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
239 M_ASN1_D2I_get_imp_set(r,func,free_func,\
240 x,V_ASN1_CONTEXT_SPECIFIC);
242 #define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
243 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
244 x,V_ASN1_CONTEXT_SPECIFIC);
246 #define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
248 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
249 (void (*)())free_func,a,b) == NULL) \
250 { c.line=__LINE__; goto err; } \
253 #define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
255 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
256 free_func,a,b) == NULL) \
257 { c.line=__LINE__; goto err; } \
260 #define M_ASN1_D2I_get_set_strings(r,func,a,b) \
262 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
263 { c.line=__LINE__; goto err; } \
266 #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
267 if ((c.slen != 0L) && (M_ASN1_next == \
268 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
270 int Tinf,Ttag,Tclass; \
274 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
276 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
277 c.line=__LINE__; goto err; } \
278 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
279 Tlen = c.slen - (c.p - c.q) - 2; \
280 if (func(&(r),&c.p,Tlen) == NULL) \
281 { c.line=__LINE__; goto err; } \
282 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
283 Tlen = c.slen - (c.p - c.q); \
284 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
285 { c.error=ERR_R_MISSING_ASN1_EOS; \
286 c.line=__LINE__; goto err; } \
291 #define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
292 if ((c.slen != 0) && (M_ASN1_next == \
293 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
295 int Tinf,Ttag,Tclass; \
299 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
301 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
302 c.line=__LINE__; goto err; } \
303 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
304 Tlen = c.slen - (c.p - c.q) - 2; \
305 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
306 (void (*)())free_func, \
307 b,V_ASN1_UNIVERSAL) == NULL) \
308 { c.line=__LINE__; goto err; } \
309 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
310 Tlen = c.slen - (c.p - c.q); \
311 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
312 { c.error=ERR_R_MISSING_ASN1_EOS; \
313 c.line=__LINE__; goto err; } \
318 #define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
319 if ((c.slen != 0) && (M_ASN1_next == \
320 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
322 int Tinf,Ttag,Tclass; \
326 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
328 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
329 c.line=__LINE__; goto err; } \
330 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
331 Tlen = c.slen - (c.p - c.q) - 2; \
332 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
333 free_func,b,V_ASN1_UNIVERSAL) == NULL) \
334 { c.line=__LINE__; goto err; } \
335 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
336 Tlen = c.slen - (c.p - c.q); \
337 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
338 { c.error=ERR_R_MISSING_ASN1_EOS; \
339 c.line=__LINE__; goto err; } \
345 #define M_ASN1_New_Malloc(ret,type) \
346 if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \
347 { c.line=__LINE__; goto err2; }
349 #define M_ASN1_New(arg,func) \
350 if (((arg)=func()) == NULL) return(NULL)
352 #define M_ASN1_New_Error(a) \
353 /* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
355 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
359 #define M_ASN1_next (*c.p)
360 #define M_ASN1_next_prev (*c.q)
362 /*************************************************/
364 #define M_ASN1_I2D_vars(a) int r=0,ret=0; \
366 if (a == NULL) return(0)
369 #define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
370 #define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
372 #define M_ASN1_I2D_len_SET(a,f) \
373 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
375 #define M_ASN1_I2D_len_SET_type(type,a,f) \
376 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
377 V_ASN1_UNIVERSAL,IS_SET);
379 #define M_ASN1_I2D_len_SEQUENCE(a,f) \
380 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
383 #define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
384 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
385 V_ASN1_UNIVERSAL,IS_SEQUENCE)
387 #define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
388 if ((a != NULL) && (sk_num(a) != 0)) \
389 M_ASN1_I2D_len_SEQUENCE(a,f);
391 #define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
392 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
393 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
395 #define M_ASN1_I2D_len_SEQUENCE_opt_ex_type(type,a,f) \
396 if (a) M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
398 #define M_ASN1_I2D_len_IMP_SET(a,f,x) \
399 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
401 #define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
402 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
403 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
405 #define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
406 if ((a != NULL) && (sk_num(a) != 0)) \
407 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
410 #define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
411 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
412 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
413 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
415 #define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
416 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
419 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
420 if ((a != NULL) && (sk_num(a) != 0)) \
421 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
424 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
425 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
426 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
427 V_ASN1_CONTEXT_SPECIFIC, \
430 #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
434 ret+=ASN1_object_size(1,v,mtag); \
437 #define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
438 if ((a != NULL) && (sk_num(a) != 0))\
440 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
441 ret+=ASN1_object_size(1,v,mtag); \
444 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
445 if ((a != NULL) && (sk_num(a) != 0))\
447 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
449 ret+=ASN1_object_size(1,v,mtag); \
452 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
453 if ((a != NULL) && (sk_##type##_num(a) != 0))\
455 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
458 ret+=ASN1_object_size(1,v,mtag); \
461 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt_ex_type(type,a,f,mtag,tag,v) \
464 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
467 ret+=ASN1_object_size(1,v,mtag); \
471 #define M_ASN1_I2D_put(a,f) f(a,&p)
473 #define M_ASN1_I2D_put_IMP_opt(a,f,t) \
476 unsigned char *q=p; \
478 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
481 #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
482 V_ASN1_UNIVERSAL,IS_SET)
483 #define M_ASN1_I2D_put_SET_type(type,a,f) \
484 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
485 #define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
486 V_ASN1_CONTEXT_SPECIFIC,IS_SET)
487 #define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
488 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
489 #define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
490 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
492 #define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
493 V_ASN1_UNIVERSAL,IS_SEQUENCE)
495 #define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
496 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
499 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
500 if ((a != NULL) && (sk_num(a) != 0)) \
501 M_ASN1_I2D_put_SEQUENCE(a,f);
503 #define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
504 if ((a != NULL) && (sk_num(a) != 0)) \
505 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
508 #define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
509 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
510 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
511 V_ASN1_CONTEXT_SPECIFIC, \
514 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
515 if ((a != NULL) && (sk_num(a) != 0)) \
516 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
519 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
520 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
521 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
522 V_ASN1_CONTEXT_SPECIFIC, \
525 #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
528 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
532 #define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
533 if ((a != NULL) && (sk_num(a) != 0)) \
535 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
536 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
539 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
540 if ((a != NULL) && (sk_num(a) != 0)) \
542 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
543 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
546 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
547 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
549 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
550 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
554 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt_ex_type(type,a,f,mtag,tag,v) \
557 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
558 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
562 #define M_ASN1_I2D_seq_total() \
563 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
564 if (pp == NULL) return(r); \
566 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
568 #define M_ASN1_I2D_INF_seq_start(tag,ctx) \
569 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
572 #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
574 #define M_ASN1_I2D_finish() *pp=p; \
577 int asn1_GetSequence(ASN1_CTX *c, long *length);
578 void asn1_add_error(unsigned char *address,int offset);