asn1_mac.h

Go to the documentation of this file.
00001 /* crypto/asn1/asn1_mac.h */
00002 /* Copyright (C) 1995-1998 Eric Young ([email protected])
00003  * All rights reserved.
00004  *
00005  * This package is an SSL implementation written
00006  * by Eric Young ([email protected]).
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 ([email protected]).
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 ([email protected])"
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 ([email protected])"
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  © Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00060  */
00061 
00062 #ifndef HEADER_ASN1_MAC_H
00063 #define HEADER_ASN1_MAC_H
00064 
00065 #if (defined(__SYMBIAN32__) && !defined(SYMBIAN))
00066 #define SYMBIAN
00067 #endif
00068 
00069 #ifdef SYMBIAN
00070 #include <e32def.h>
00071 #endif
00072 #include <openssl/asn1.h>
00073 
00074 #ifdef  __cplusplus
00075 extern "C" {
00076 #endif
00077 
00078 #ifndef ASN1_MAC_ERR_LIB
00079 #define ASN1_MAC_ERR_LIB        ERR_LIB_ASN1
00080 #endif 
00081 
00082 #define ASN1_MAC_H_err(f,r,line) \
00083         ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))
00084 
00085 #define M_ASN1_D2I_vars(a,type,func) \
00086         ASN1_const_CTX c; \
00087         type ret=NULL; \
00088         \
00089         c.pp=(const unsigned char **)pp; \
00090         c.q= *(const unsigned char **)pp; \
00091         c.error=ERR_R_NESTED_ASN1_ERROR; \
00092         if ((a == NULL) || ((*a) == NULL)) \
00093                 { if ((ret=(type)func()) == NULL) \
00094                         { c.line=__LINE__; goto err; } } \
00095         else    ret=(*a);
00096 
00097 #define M_ASN1_D2I_Init() \
00098         c.p= *(const unsigned char **)pp; \
00099         c.max=(length == 0)?0:(c.p+length);
00100 
00101 #define M_ASN1_D2I_Finish_2(a) \
00102         if (!asn1_const_Finish(&c)) \
00103                 { c.line=__LINE__; goto err; } \
00104         *(const unsigned char **)pp=c.p; \
00105         if (a != NULL) (*a)=ret; \
00106         return(ret);
00107 
00108 #define M_ASN1_D2I_Finish(a,func,e) \
00109         M_ASN1_D2I_Finish_2(a); \
00110 err:\
00111         ASN1_MAC_H_err((e),c.error,c.line); \
00112         asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \
00113         if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
00114         return(NULL)
00115 
00116 #define M_ASN1_D2I_start_sequence() \
00117         if (!asn1_GetSequence(&c,&length)) \
00118                 { c.line=__LINE__; goto err; }
00119 /* Begin reading ASN1 without a surrounding sequence */
00120 #define M_ASN1_D2I_begin() \
00121         c.slen = length;
00122 
00123 /* End reading ASN1 with no check on length */
00124 #define M_ASN1_D2I_Finish_nolen(a, func, e) \
00125         *pp=c.p; \
00126         if (a != NULL) (*a)=ret; \
00127         return(ret); \
00128 err:\
00129         ASN1_MAC_H_err((e),c.error,c.line); \
00130         asn1_add_error(*pp,(int)(c.q- *pp)); \
00131         if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
00132         return(NULL)
00133 
00134 #define M_ASN1_D2I_end_sequence() \
00135         (((c.inf&1) == 0)?(c.slen <= 0): \
00136                 (c.eos=ASN1_const_check_infinite_end(&c.p,c.slen)))
00137 
00138 /* Don't use this with d2i_ASN1_BOOLEAN() */
00139 #define M_ASN1_D2I_get(b, func) \
00140         c.q=c.p; \
00141         if (func(&(b),&c.p,c.slen) == NULL) \
00142                 {c.line=__LINE__; goto err; } \
00143         c.slen-=(c.p-c.q);
00144 
00145 /* Don't use this with d2i_ASN1_BOOLEAN() */
00146 #define M_ASN1_D2I_get_x(type,b,func) \
00147         c.q=c.p; \
00148         if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \
00149                 {c.line=__LINE__; goto err; } \
00150         c.slen-=(c.p-c.q);
00151 
00152 /* use this instead () */
00153 #define M_ASN1_D2I_get_int(b,func) \
00154         c.q=c.p; \
00155         if (func(&(b),&c.p,c.slen) < 0) \
00156                 {c.line=__LINE__; goto err; } \
00157         c.slen-=(c.p-c.q);
00158 
00159 #define M_ASN1_D2I_get_opt(b,func,type) \
00160         if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
00161                 == (V_ASN1_UNIVERSAL|(type)))) \
00162                 { \
00163                 M_ASN1_D2I_get(b,func); \
00164                 }
00165 
00166 #define M_ASN1_D2I_get_imp(b,func, type) \
00167         M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
00168         c.q=c.p; \
00169         if (func(&(b),&c.p,c.slen) == NULL) \
00170                 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
00171         c.slen-=(c.p-c.q);\
00172         M_ASN1_next_prev=_tmp;
00173 
00174 #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
00175         if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
00176                 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
00177                 { \
00178                 unsigned char _tmp = M_ASN1_next; \
00179                 M_ASN1_D2I_get_imp(b,func, type);\
00180                 }
00181 
00182 #define M_ASN1_D2I_get_set(r,func,free_func) \
00183                 M_ASN1_D2I_get_imp_set(r,func,free_func, \
00184                         V_ASN1_SET,V_ASN1_UNIVERSAL);
00185 
00186 #define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
00187                 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
00188                         V_ASN1_SET,V_ASN1_UNIVERSAL);
00189 
00190 #define M_ASN1_D2I_get_set_opt(r,func,free_func) \
00191         if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
00192                 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
00193                 { M_ASN1_D2I_get_set(r,func,free_func); }
00194 
00195 #define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
00196         if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
00197                 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
00198                 { M_ASN1_D2I_get_set_type(type,r,func,free_func); }
00199 
00200 #define M_ASN1_I2D_len_SET_opt(a,f) \
00201         if ((a != NULL) && (sk_num(a) != 0)) \
00202                 M_ASN1_I2D_len_SET(a,f);
00203 
00204 #define M_ASN1_I2D_put_SET_opt(a,f) \
00205         if ((a != NULL) && (sk_num(a) != 0)) \
00206                 M_ASN1_I2D_put_SET(a,f);
00207 
00208 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
00209         if ((a != NULL) && (sk_num(a) != 0)) \
00210                 M_ASN1_I2D_put_SEQUENCE(a,f);
00211 
00212 #define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
00213         if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00214                 M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
00215 
00216 #define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
00217         if ((c.slen != 0) && \
00218                 (M_ASN1_next == \
00219                 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
00220                 { \
00221                 M_ASN1_D2I_get_imp_set(b,func,free_func,\
00222                         tag,V_ASN1_CONTEXT_SPECIFIC); \
00223                 }
00224 
00225 #define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
00226         if ((c.slen != 0) && \
00227                 (M_ASN1_next == \
00228                 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
00229                 { \
00230                 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
00231                         tag,V_ASN1_CONTEXT_SPECIFIC); \
00232                 }
00233 
00234 #define M_ASN1_D2I_get_seq(r,func,free_func) \
00235                 M_ASN1_D2I_get_imp_set(r,func,free_func,\
00236                         V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
00237 
00238 #define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
00239                 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
00240                                             V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
00241 
00242 #define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
00243         if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
00244                 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
00245                 { M_ASN1_D2I_get_seq(r,func,free_func); }
00246 
00247 #define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
00248         if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
00249                 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
00250                 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
00251 
00252 #define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
00253                 M_ASN1_D2I_get_imp_set(r,func,free_func,\
00254                         x,V_ASN1_CONTEXT_SPECIFIC);
00255 
00256 #define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
00257                 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
00258                         x,V_ASN1_CONTEXT_SPECIFIC);
00259 
00260 #define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
00261         c.q=c.p; \
00262         if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
00263                 (void (*)())free_func,a,b) == NULL) \
00264                 { c.line=__LINE__; goto err; } \
00265         c.slen-=(c.p-c.q);
00266 
00267 #define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
00268         c.q=c.p; \
00269         if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
00270                                    free_func,a,b) == NULL) \
00271                 { c.line=__LINE__; goto err; } \
00272         c.slen-=(c.p-c.q);
00273 
00274 #define M_ASN1_D2I_get_set_strings(r,func,a,b) \
00275         c.q=c.p; \
00276         if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
00277                 { c.line=__LINE__; goto err; } \
00278         c.slen-=(c.p-c.q);
00279 
00280 #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
00281         if ((c.slen != 0L) && (M_ASN1_next == \
00282                 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
00283                 { \
00284                 int Tinf,Ttag,Tclass; \
00285                 long Tlen; \
00286                 \
00287                 c.q=c.p; \
00288                 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
00289                 if (Tinf & 0x80) \
00290                         { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
00291                         c.line=__LINE__; goto err; } \
00292                 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
00293                                         Tlen = c.slen - (c.p - c.q) - 2; \
00294                 if (func(&(r),&c.p,Tlen) == NULL) \
00295                         { c.line=__LINE__; goto err; } \
00296                 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
00297                         Tlen = c.slen - (c.p - c.q); \
00298                         if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \
00299                                 { c.error=ERR_R_MISSING_ASN1_EOS; \
00300                                 c.line=__LINE__; goto err; } \
00301                 }\
00302                 c.slen-=(c.p-c.q); \
00303                 }
00304 
00305 #define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
00306         if ((c.slen != 0) && (M_ASN1_next == \
00307                 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
00308                 { \
00309                 int Tinf,Ttag,Tclass; \
00310                 long Tlen; \
00311                 \
00312                 c.q=c.p; \
00313                 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
00314                 if (Tinf & 0x80) \
00315                         { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
00316                         c.line=__LINE__; goto err; } \
00317                 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
00318                                         Tlen = c.slen - (c.p - c.q) - 2; \
00319                 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
00320                         (void (*)())free_func, \
00321                         b,V_ASN1_UNIVERSAL) == NULL) \
00322                         { c.line=__LINE__; goto err; } \
00323                 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
00324                         Tlen = c.slen - (c.p - c.q); \
00325                         if(!ASN1_check_infinite_end(&c.p, Tlen)) \
00326                                 { c.error=ERR_R_MISSING_ASN1_EOS; \
00327                                 c.line=__LINE__; goto err; } \
00328                 }\
00329                 c.slen-=(c.p-c.q); \
00330                 }
00331 
00332 #define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
00333         if ((c.slen != 0) && (M_ASN1_next == \
00334                 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
00335                 { \
00336                 int Tinf,Ttag,Tclass; \
00337                 long Tlen; \
00338                 \
00339                 c.q=c.p; \
00340                 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
00341                 if (Tinf & 0x80) \
00342                         { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
00343                         c.line=__LINE__; goto err; } \
00344                 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
00345                                         Tlen = c.slen - (c.p - c.q) - 2; \
00346                 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
00347                         free_func,b,V_ASN1_UNIVERSAL) == NULL) \
00348                         { c.line=__LINE__; goto err; } \
00349                 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
00350                         Tlen = c.slen - (c.p - c.q); \
00351                         if(!ASN1_check_infinite_end(&c.p, Tlen)) \
00352                                 { c.error=ERR_R_MISSING_ASN1_EOS; \
00353                                 c.line=__LINE__; goto err; } \
00354                 }\
00355                 c.slen-=(c.p-c.q); \
00356                 }
00357 
00358 /* New macros */
00359 #define M_ASN1_New_Malloc(ret,type) \
00360         if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \
00361                 { c.line=__LINE__; goto err2; }
00362 
00363 #define M_ASN1_New(arg,func) \
00364         if (((arg)=func()) == NULL) return(NULL)
00365 
00366 #define M_ASN1_New_Error(a) \
00367 /*      err:    ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
00368                 return(NULL);*/ \
00369         err2:   ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
00370                 return(NULL)
00371 
00372 
00373 /* BIG UGLY WARNING!  This is so damn ugly I wanna puke.  Unfortunately,
00374    some macros that use ASN1_const_CTX still insist on writing in the input
00375    stream.  ARGH!  ARGH!  ARGH!  Let's get rid of this macro package.
00376    Please?                                              -- Richard Levitte */
00377 #define M_ASN1_next             (*((unsigned char *)(c.p)))
00378 #define M_ASN1_next_prev        (*((unsigned char *)(c.q)))
00379 
00380 /*************************************************/
00381 
00382 #define M_ASN1_I2D_vars(a)      int r=0,ret=0; \
00383                                 unsigned char *p; \
00384                                 if (a == NULL) return(0)
00385 
00386 /* Length Macros */
00387 #define M_ASN1_I2D_len(a,f)     ret+=f(a,NULL)
00388 #define M_ASN1_I2D_len_IMP_opt(a,f)     if (a != NULL) M_ASN1_I2D_len(a,f)
00389 
00390 #define M_ASN1_I2D_len_SET(a,f) \
00391                 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
00392 
00393 #define M_ASN1_I2D_len_SET_type(type,a,f) \
00394                 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
00395                                             V_ASN1_UNIVERSAL,IS_SET);
00396 
00397 #define M_ASN1_I2D_len_SEQUENCE(a,f) \
00398                 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
00399                                   IS_SEQUENCE);
00400 
00401 #define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
00402                 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
00403                                             V_ASN1_UNIVERSAL,IS_SEQUENCE)
00404 
00405 #define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
00406                 if ((a != NULL) && (sk_num(a) != 0)) \
00407                         M_ASN1_I2D_len_SEQUENCE(a,f);
00408 
00409 #define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
00410                 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00411                         M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
00412 
00413 #define M_ASN1_I2D_len_IMP_SET(a,f,x) \
00414                 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
00415 
00416 #define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
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_SET_opt(a,f,x) \
00421                 if ((a != NULL) && (sk_num(a) != 0)) \
00422                         ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
00423                                           IS_SET);
00424 
00425 #define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
00426                 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00427                         ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
00428                                                V_ASN1_CONTEXT_SPECIFIC,IS_SET);
00429 
00430 #define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
00431                 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
00432                                   IS_SEQUENCE);
00433 
00434 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
00435                 if ((a != NULL) && (sk_num(a) != 0)) \
00436                         ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
00437                                           IS_SEQUENCE);
00438 
00439 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
00440                 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00441                         ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
00442                                                     V_ASN1_CONTEXT_SPECIFIC, \
00443                                                     IS_SEQUENCE);
00444 
00445 #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
00446                 if (a != NULL)\
00447                         { \
00448                         v=f(a,NULL); \
00449                         ret+=ASN1_object_size(1,v,mtag); \
00450                         }
00451 
00452 #define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
00453                 if ((a != NULL) && (sk_num(a) != 0))\
00454                         { \
00455                         v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
00456                         ret+=ASN1_object_size(1,v,mtag); \
00457                         }
00458 
00459 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
00460                 if ((a != NULL) && (sk_num(a) != 0))\
00461                         { \
00462                         v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
00463                                        IS_SEQUENCE); \
00464                         ret+=ASN1_object_size(1,v,mtag); \
00465                         }
00466 
00467 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
00468                 if ((a != NULL) && (sk_##type##_num(a) != 0))\
00469                         { \
00470                         v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
00471                                                  V_ASN1_UNIVERSAL, \
00472                                                  IS_SEQUENCE); \
00473                         ret+=ASN1_object_size(1,v,mtag); \
00474                         }
00475 
00476 /* Put Macros */
00477 #define M_ASN1_I2D_put(a,f)     f(a,&p)
00478 
00479 #define M_ASN1_I2D_put_IMP_opt(a,f,t)   \
00480                 if (a != NULL) \
00481                         { \
00482                         unsigned char *q=p; \
00483                         f(a,&p); \
00484                         *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
00485                         }
00486 
00487 #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
00488                         V_ASN1_UNIVERSAL,IS_SET)
00489 #define M_ASN1_I2D_put_SET_type(type,a,f) \
00490      i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
00491 #define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
00492                         V_ASN1_CONTEXT_SPECIFIC,IS_SET)
00493 #define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
00494      i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
00495 #define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
00496                         V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
00497 
00498 #define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
00499                                              V_ASN1_UNIVERSAL,IS_SEQUENCE)
00500 
00501 #define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
00502      i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
00503                             IS_SEQUENCE)
00504 
00505 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
00506                 if ((a != NULL) && (sk_num(a) != 0)) \
00507                         M_ASN1_I2D_put_SEQUENCE(a,f);
00508 
00509 #define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
00510                 if ((a != NULL) && (sk_num(a) != 0)) \
00511                         { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
00512                                        IS_SET); }
00513 
00514 #define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
00515                 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00516                         { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
00517                                                  V_ASN1_CONTEXT_SPECIFIC, \
00518                                                  IS_SET); }
00519 
00520 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
00521                 if ((a != NULL) && (sk_num(a) != 0)) \
00522                         { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
00523                                        IS_SEQUENCE); }
00524 
00525 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
00526                 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00527                         { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
00528                                                  V_ASN1_CONTEXT_SPECIFIC, \
00529                                                  IS_SEQUENCE); }
00530 
00531 #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
00532                 if (a != NULL) \
00533                         { \
00534                         ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
00535                         f(a,&p); \
00536                         }
00537 
00538 #define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
00539                 if ((a != NULL) && (sk_num(a) != 0)) \
00540                         { \
00541                         ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
00542                         i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
00543                         }
00544 
00545 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
00546                 if ((a != NULL) && (sk_num(a) != 0)) \
00547                         { \
00548                         ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
00549                         i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
00550                         }
00551 
00552 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
00553                 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
00554                         { \
00555                         ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
00556                         i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
00557                                                IS_SEQUENCE); \
00558                         }
00559 
00560 #define M_ASN1_I2D_seq_total() \
00561                 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
00562                 if (pp == NULL) return(r); \
00563                 p= *pp; \
00564                 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
00565 
00566 #define M_ASN1_I2D_INF_seq_start(tag,ctx) \
00567                 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
00568                 *(p++)=0x80
00569 
00570 #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
00571 
00572 #define M_ASN1_I2D_finish()     *pp=p; \
00573                                 return(r);
00574 
00575 IMPORT_C int asn1_GetSequence(ASN1_const_CTX *c, long *length);
00576 IMPORT_C void asn1_add_error(const unsigned char *address,int offset);
00577 #ifdef  __cplusplus
00578 }
00579 #endif
00580 
00581 #endif

Copyright © Nokia Corporation 2001-2008
Back to top