asn1_mac.h

Go to the documentation of this file.
00001 /* crypto/asn1/asn1_mac.h */
00002 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
00003  * All rights reserved.
00004  *
00005  * This package is an SSL implementation written
00006  * by Eric Young (eay@cryptsoft.com).
00007  * The implementation was written so as to conform with Netscapes SSL.
00008  *
00009  * This library is free for commercial and non-commercial use as long as
00010  * the following conditions are aheared to.  The following conditions
00011  * apply to all code found in this distribution, be it the RC4, RSA,
00012  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
00013  * included with this distribution is covered by the same copyright terms
00014  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
00015  *
00016  * Copyright remains Eric Young's, and as such any Copyright notices in
00017  * the code are not to be removed.
00018  * If this package is used in a product, Eric Young should be given attribution
00019  * as the author of the parts of the library used.
00020  * This can be in the form of a textual message at program startup or
00021  * in documentation (online or textual) provided with the package.
00022  *
00023  * Redistribution and use in source and binary forms, with or without
00024  * modification, are permitted provided that the following conditions
00025  * are met:
00026  * 1. Redistributions of source code must retain the copyright
00027  *    notice, this list of conditions and the following disclaimer.
00028  * 2. Redistributions in binary form must reproduce the above copyright
00029  *    notice, this list of conditions and the following disclaimer in the
00030  *    documentation and/or other materials provided with the distribution.
00031  * 3. All advertising materials mentioning features or use of this software
00032  *    must display the following acknowledgement:
00033  *    "This product includes cryptographic software written by
00034  *     Eric Young (eay@cryptsoft.com)"
00035  *    The word 'cryptographic' can be left out if the rouines from the library
00036  *    being used are not cryptographic related :-).
00037  * 4. If you include any Windows specific code (or a derivative thereof) from
00038  *    the apps directory (application code) you must include an acknowledgement:
00039  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
00040  *
00041  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
00042  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00043  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00044  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00045  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00046  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00047  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00048  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00049  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00050  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00051  * SUCH DAMAGE.
00052  *
00053  * The licence and distribution terms for any publically available version or
00054  * derivative of this code cannot be changed.  i.e. this code cannot simply be
00055  * copied and put under another distribution licence
00056  * [including the GNU Public Licence.]
00057  */
00058 
00059 #ifndef HEADER_ASN1_MAC_H
00060 #define HEADER_ASN1_MAC_H
00061 
00062 #include <openssl/asn1.h>
00063 
00064 #ifdef  __cplusplus
00065 extern "C" {
00066 #endif
00067 
00068 #ifndef ASN1_MAC_ERR_LIB
00069 #define ASN1_MAC_ERR_LIB   ERR_LIB_ASN1
00070 #endif
00071 
00072 #define ASN1_MAC_H_err(f,r,line) \
00073    ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))
00074 
00075 #define M_ASN1_D2I_vars(a,type,func) \
00076    ASN1_const_CTX c; \
00077    type ret=NULL; \
00078    \
00079    c.pp=(const unsigned char **)pp; \
00080    c.q= *(const unsigned char **)pp; \
00081    c.error=ERR_R_NESTED_ASN1_ERROR; \
00082    if ((a == NULL) || ((*a) == NULL)) \
00083       { if ((ret=(type)func()) == NULL) \
00084          { c.line=__LINE__; goto err; } } \
00085    else  ret=(*a);
00086 
00087 #define M_ASN1_D2I_Init() \
00088    c.p= *(const unsigned char **)pp; \
00089    c.max=(length == 0)?0:(c.p+length);
00090 
00091 #define M_ASN1_D2I_Finish_2(a) \
00092    if (!asn1_const_Finish(&c)) \
00093       { c.line=__LINE__; goto err; } \
00094    *(const unsigned char **)pp=c.p; \
00095    if (a != NULL) (*a)=ret; \
00096    return(ret);
00097 
00098 #define M_ASN1_D2I_Finish(a,func,e) \
00099    M_ASN1_D2I_Finish_2(a); \
00100 err:\
00101    ASN1_MAC_H_err((e),c.error,c.line); \
00102    asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \
00103    if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
00104    return(NULL)
00105 
00106 #define M_ASN1_D2I_start_sequence() \
00107    if (!asn1_GetSequence(&c,&length)) \
00108       { c.line=__LINE__; goto err; }
00109 /* Begin reading ASN1 without a surrounding sequence */
00110 #define M_ASN1_D2I_begin() \
00111    c.slen = length;
00112 
00113 /* End reading ASN1 with no check on length */
00114 #define M_ASN1_D2I_Finish_nolen(a, func, e) \
00115    *pp=c.p; \
00116    if (a != NULL) (*a)=ret; \
00117    return(ret); \
00118 err:\
00119    ASN1_MAC_H_err((e),c.error,c.line); \
00120    asn1_add_error(*pp,(int)(c.q- *pp)); \
00121    if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
00122    return(NULL)
00123 
00124 #define M_ASN1_D2I_end_sequence() \
00125    (((c.inf&1) == 0)?(c.slen <= 0): \
00126       (c.eos=ASN1_const_check_infinite_end(&c.p,c.slen)))
00127 
00128 /* Don't use this with d2i_ASN1_BOOLEAN() */
00129 #define M_ASN1_D2I_get(b, func) \
00130    c.q=c.p; \
00131    if (func(&(b),&c.p,c.slen) == NULL) \
00132       {c.line=__LINE__; goto err; } \
00133    c.slen-=(c.p-c.q);
00134 
00135 /* Don't use this with d2i_ASN1_BOOLEAN() */
00136 #define M_ASN1_D2I_get_x(type,b,func) \
00137    c.q=c.p; \
00138    if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \
00139       {c.line=__LINE__; goto err; } \
00140    c.slen-=(c.p-c.q);
00141 
00142 /* use this instead () */
00143 #define M_ASN1_D2I_get_int(b,func) \
00144    c.q=c.p; \
00145    if (func(&(b),&c.p,c.slen) < 0) \
00146       {c.line=__LINE__; goto err; } \
00147    c.slen-=(c.p-c.q);
00148 
00149 #define M_ASN1_D2I_get_opt(b,func,type) \
00150    if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
00151       == (V_ASN1_UNIVERSAL|(type)))) \
00152       { \
00153       M_ASN1_D2I_get(b,func); \
00154       }
00155 
00156 #define M_ASN1_D2I_get_imp(b,func, type) \
00157    M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
00158    c.q=c.p; \
00159    if (func(&(b),&c.p,c.slen) == NULL) \
00160       {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
00161    c.slen-=(c.p-c.q);\
00162    M_ASN1_next_prev=_tmp;
00163 
00164 #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
00165    if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
00166       (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
00167       { \
00168       unsigned char _tmp = M_ASN1_next; \
00169       M_ASN1_D2I_get_imp(b,func, type);\
00170       }
00171 
00172 #define M_ASN1_D2I_get_set(r,func,free_func) \
00173       M_ASN1_D2I_get_imp_set(r,func,free_func, \
00174          V_ASN1_SET,V_ASN1_UNIVERSAL);
00175 
00176 #define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
00177       M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
00178          V_ASN1_SET,V_ASN1_UNIVERSAL);
00179 
00180 #define M_ASN1_D2I_get_set_opt(r,func,free_func) \
00181    if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
00182       V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
00183       { M_ASN1_D2I_get_set(r,func,free_func); }
00184 
00185 #define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
00186    if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
00187       V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
00188       { M_ASN1_D2I_get_set_type(type,r,func,free_func); }
00189 
00190 #define M_ASN1_I2D_len_SET_opt(a,f) \
00191    if ((a != NULL) && (sk_num(a) != 0)) \
00192       M_ASN1_I2D_len_SET(a,f);
00193 
00194 #define M_ASN1_I2D_put_SET_opt(a,f) \
00195    if ((a != NULL) && (sk_num(a) != 0)) \
00196       M_ASN1_I2D_put_SET(a,f);
00197 
00198 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
00199    if ((a != NULL) && (sk_num(a) != 0)) \
00200       M_ASN1_I2D_put_SEQUENCE(a,f);
00201 
00202 #define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
00203    if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00204       M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
00205 
00206 #define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
00207    if ((c.slen != 0) && \
00208       (M_ASN1_next == \
00209       (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
00210       { \
00211       M_ASN1_D2I_get_imp_set(b,func,free_func,\
00212          tag,V_ASN1_CONTEXT_SPECIFIC); \
00213       }
00214 
00215 #define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
00216    if ((c.slen != 0) && \
00217       (M_ASN1_next == \
00218       (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
00219       { \
00220       M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
00221          tag,V_ASN1_CONTEXT_SPECIFIC); \
00222       }
00223 
00224 #define M_ASN1_D2I_get_seq(r,func,free_func) \
00225       M_ASN1_D2I_get_imp_set(r,func,free_func,\
00226          V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
00227 
00228 #define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
00229       M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
00230                    V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
00231 
00232 #define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
00233    if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
00234       V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
00235       { M_ASN1_D2I_get_seq(r,func,free_func); }
00236 
00237 #define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
00238    if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
00239       V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
00240       { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
00241 
00242 #define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
00243       M_ASN1_D2I_get_imp_set(r,func,free_func,\
00244          x,V_ASN1_CONTEXT_SPECIFIC);
00245 
00246 #define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
00247       M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
00248          x,V_ASN1_CONTEXT_SPECIFIC);
00249 
00250 #define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
00251    c.q=c.p; \
00252    if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
00253       (void (*)())free_func,a,b) == NULL) \
00254       { c.line=__LINE__; goto err; } \
00255    c.slen-=(c.p-c.q);
00256 
00257 #define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
00258    c.q=c.p; \
00259    if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
00260                free_func,a,b) == NULL) \
00261       { c.line=__LINE__; goto err; } \
00262    c.slen-=(c.p-c.q);
00263 
00264 #define M_ASN1_D2I_get_set_strings(r,func,a,b) \
00265    c.q=c.p; \
00266    if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
00267       { c.line=__LINE__; goto err; } \
00268    c.slen-=(c.p-c.q);
00269 
00270 #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
00271    if ((c.slen != 0L) && (M_ASN1_next == \
00272       (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
00273       { \
00274       int Tinf,Ttag,Tclass; \
00275       long Tlen; \
00276       \
00277       c.q=c.p; \
00278       Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
00279       if (Tinf & 0x80) \
00280          { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
00281          c.line=__LINE__; goto err; } \
00282       if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
00283                Tlen = c.slen - (c.p - c.q) - 2; \
00284       if (func(&(r),&c.p,Tlen) == NULL) \
00285          { c.line=__LINE__; goto err; } \
00286       if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
00287          Tlen = c.slen - (c.p - c.q); \
00288          if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \
00289             { c.error=ERR_R_MISSING_ASN1_EOS; \
00290             c.line=__LINE__; goto err; } \
00291       }\
00292       c.slen-=(c.p-c.q); \
00293       }
00294 
00295 #define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
00296    if ((c.slen != 0) && (M_ASN1_next == \
00297       (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
00298       { \
00299       int Tinf,Ttag,Tclass; \
00300       long Tlen; \
00301       \
00302       c.q=c.p; \
00303       Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
00304       if (Tinf & 0x80) \
00305          { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
00306          c.line=__LINE__; goto err; } \
00307       if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
00308                Tlen = c.slen - (c.p - c.q) - 2; \
00309       if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
00310          (void (*)())free_func, \
00311          b,V_ASN1_UNIVERSAL) == NULL) \
00312          { c.line=__LINE__; goto err; } \
00313       if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
00314          Tlen = c.slen - (c.p - c.q); \
00315          if(!ASN1_check_infinite_end(&c.p, Tlen)) \
00316             { c.error=ERR_R_MISSING_ASN1_EOS; \
00317             c.line=__LINE__; goto err; } \
00318       }\
00319       c.slen-=(c.p-c.q); \
00320       }
00321 
00322 #define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
00323    if ((c.slen != 0) && (M_ASN1_next == \
00324       (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
00325       { \
00326       int Tinf,Ttag,Tclass; \
00327       long Tlen; \
00328       \
00329       c.q=c.p; \
00330       Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
00331       if (Tinf & 0x80) \
00332          { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
00333          c.line=__LINE__; goto err; } \
00334       if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
00335                Tlen = c.slen - (c.p - c.q) - 2; \
00336       if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
00337          free_func,b,V_ASN1_UNIVERSAL) == NULL) \
00338          { c.line=__LINE__; goto err; } \
00339       if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
00340          Tlen = c.slen - (c.p - c.q); \
00341          if(!ASN1_check_infinite_end(&c.p, Tlen)) \
00342             { c.error=ERR_R_MISSING_ASN1_EOS; \
00343             c.line=__LINE__; goto err; } \
00344       }\
00345       c.slen-=(c.p-c.q); \
00346       }
00347 
00348 /* New macros */
00349 #define M_ASN1_New_Malloc(ret,type) \
00350    if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \
00351       { c.line=__LINE__; goto err2; }
00352 
00353 #define M_ASN1_New(arg,func) \
00354    if (((arg)=func()) == NULL) return(NULL)
00355 
00356 #define M_ASN1_New_Error(a) \
00357 /* err:  ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
00358       return(NULL);*/ \
00359    err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
00360       return(NULL)
00361 
00362 
00363 /* BIG UGLY WARNING!  This is so damn ugly I wanna puke.  Unfortunately,
00364    some macros that use ASN1_const_CTX still insist on writing in the input
00365    stream.  ARGH!  ARGH!  ARGH!  Let's get rid of this macro package.
00366    Please?                 -- Richard Levitte */
00367 #define M_ASN1_next     (*((unsigned char *)(c.p)))
00368 #define M_ASN1_next_prev   (*((unsigned char *)(c.q)))
00369 
00370 /*************************************************/
00371 
00372 #define M_ASN1_I2D_vars(a) int r=0,ret=0; \
00373             unsigned char *p; \
00374             if (a == NULL) return(0)
00375 
00376 /* Length Macros */
00377 #define M_ASN1_I2D_len(a,f)   ret+=f(a,NULL)
00378 #define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
00379 
00380 #define M_ASN1_I2D_len_SET(a,f) \
00381       ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
00382 
00383 #define M_ASN1_I2D_len_SET_type(type,a,f) \
00384       ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
00385                    V_ASN1_UNIVERSAL,IS_SET);
00386 
00387 #define M_ASN1_I2D_len_SEQUENCE(a,f) \
00388       ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
00389               IS_SEQUENCE);
00390 
00391 #define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
00392       ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
00393                    V_ASN1_UNIVERSAL,IS_SEQUENCE)
00394 
00395 #define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
00396       if ((a != NULL) && (sk_num(a) != 0)) \
00397          M_ASN1_I2D_len_SEQUENCE(a,f);
00398 
00399 #define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
00400       if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00401          M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
00402 
00403 #define M_ASN1_I2D_len_IMP_SET(a,f,x) \
00404       ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
00405 
00406 #define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
00407       ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
00408                    V_ASN1_CONTEXT_SPECIFIC,IS_SET);
00409 
00410 #define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
00411       if ((a != NULL) && (sk_num(a) != 0)) \
00412          ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
00413                  IS_SET);
00414 
00415 #define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
00416       if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00417          ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
00418                       V_ASN1_CONTEXT_SPECIFIC,IS_SET);
00419 
00420 #define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
00421       ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
00422               IS_SEQUENCE);
00423 
00424 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
00425       if ((a != NULL) && (sk_num(a) != 0)) \
00426          ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
00427                  IS_SEQUENCE);
00428 
00429 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
00430       if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00431          ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
00432                       V_ASN1_CONTEXT_SPECIFIC, \
00433                       IS_SEQUENCE);
00434 
00435 #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
00436       if (a != NULL)\
00437          { \
00438          v=f(a,NULL); \
00439          ret+=ASN1_object_size(1,v,mtag); \
00440          }
00441 
00442 #define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
00443       if ((a != NULL) && (sk_num(a) != 0))\
00444          { \
00445          v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
00446          ret+=ASN1_object_size(1,v,mtag); \
00447          }
00448 
00449 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
00450       if ((a != NULL) && (sk_num(a) != 0))\
00451          { \
00452          v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
00453                    IS_SEQUENCE); \
00454          ret+=ASN1_object_size(1,v,mtag); \
00455          }
00456 
00457 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
00458       if ((a != NULL) && (sk_##type##_num(a) != 0))\
00459          { \
00460          v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
00461                    V_ASN1_UNIVERSAL, \
00462                    IS_SEQUENCE); \
00463          ret+=ASN1_object_size(1,v,mtag); \
00464          }
00465 
00466 /* Put Macros */
00467 #define M_ASN1_I2D_put(a,f)   f(a,&p)
00468 
00469 #define M_ASN1_I2D_put_IMP_opt(a,f,t)  \
00470       if (a != NULL) \
00471          { \
00472          unsigned char *q=p; \
00473          f(a,&p); \
00474          *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
00475          }
00476 
00477 #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
00478          V_ASN1_UNIVERSAL,IS_SET)
00479 #define M_ASN1_I2D_put_SET_type(type,a,f) \
00480      i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
00481 #define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
00482          V_ASN1_CONTEXT_SPECIFIC,IS_SET)
00483 #define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
00484      i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
00485 #define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
00486          V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
00487 
00488 #define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
00489                     V_ASN1_UNIVERSAL,IS_SEQUENCE)
00490 
00491 #define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
00492      i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
00493              IS_SEQUENCE)
00494 
00495 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
00496       if ((a != NULL) && (sk_num(a) != 0)) \
00497          M_ASN1_I2D_put_SEQUENCE(a,f);
00498 
00499 #define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
00500       if ((a != NULL) && (sk_num(a) != 0)) \
00501          { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
00502                    IS_SET); }
00503 
00504 #define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
00505       if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00506          { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
00507                    V_ASN1_CONTEXT_SPECIFIC, \
00508                    IS_SET); }
00509 
00510 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
00511       if ((a != NULL) && (sk_num(a) != 0)) \
00512          { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
00513                    IS_SEQUENCE); }
00514 
00515 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
00516       if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00517          { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
00518                    V_ASN1_CONTEXT_SPECIFIC, \
00519                    IS_SEQUENCE); }
00520 
00521 #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
00522       if (a != NULL) \
00523          { \
00524          ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
00525          f(a,&p); \
00526          }
00527 
00528 #define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
00529       if ((a != NULL) && (sk_num(a) != 0)) \
00530          { \
00531          ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
00532          i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
00533          }
00534 
00535 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
00536       if ((a != NULL) && (sk_num(a) != 0)) \
00537          { \
00538          ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
00539          i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
00540          }
00541 
00542 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
00543       if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00544          { \
00545          ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
00546          i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
00547                       IS_SEQUENCE); \
00548          }
00549 
00550 #define M_ASN1_I2D_seq_total() \
00551       r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
00552       if (pp == NULL) return(r); \
00553       p= *pp; \
00554       ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
00555 
00556 #define M_ASN1_I2D_INF_seq_start(tag,ctx) \
00557       *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
00558       *(p++)=0x80
00559 
00560 #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
00561 
00562 #define M_ASN1_I2D_finish()   *pp=p; \
00563             return(r);
00564 
00565 int asn1_GetSequence(ASN1_const_CTX *c, long *length);
00566 void asn1_add_error(const unsigned char *address,int offset);
00567 #ifdef  __cplusplus
00568 }
00569 #endif
00570 
00571 #endif

Generated on Thu Aug 20 22:33:05 2009 for OpenXDAS by  doxygen 1.5.6