| OLD | NEW |
| 1 /* tasn_new.c */ | 1 /* tasn_new.c */ |
| 2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 * project 2000. | 3 * project 2000. |
| 4 */ | 4 */ |
| 5 /* ==================================================================== | 5 /* ==================================================================== |
| 6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved. | 6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 #include <openssl/asn1.h> | 61 #include <openssl/asn1.h> |
| 62 #include <openssl/objects.h> | 62 #include <openssl/objects.h> |
| 63 #include <openssl/err.h> | 63 #include <openssl/err.h> |
| 64 #include <openssl/asn1t.h> | 64 #include <openssl/asn1t.h> |
| 65 #include <string.h> | 65 #include <string.h> |
| 66 | 66 |
| 67 static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, | 67 static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, |
| 68 int combine); | 68 int combine); |
| 69 static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); | 69 static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); |
| 70 static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | 70 static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); |
| 71 void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); | 71 static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); |
| 72 | 72 |
| 73 ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) | 73 ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) |
| 74 { | 74 { |
| 75 ASN1_VALUE *ret = NULL; | 75 ASN1_VALUE *ret = NULL; |
| 76 if (ASN1_item_ex_new(&ret, it) > 0) | 76 if (ASN1_item_ex_new(&ret, it) > 0) |
| 77 return ret; | 77 return ret; |
| 78 return NULL; | 78 return NULL; |
| 79 } | 79 } |
| 80 | 80 |
| 81 /* Allocate an ASN1 structure */ | 81 /* Allocate an ASN1 structure */ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 break; | 139 break; |
| 140 | 140 |
| 141 case ASN1_ITYPE_MSTRING: | 141 case ASN1_ITYPE_MSTRING: |
| 142 if (!ASN1_primitive_new(pval, it)) | 142 if (!ASN1_primitive_new(pval, it)) |
| 143 goto memerr; | 143 goto memerr; |
| 144 break; | 144 break; |
| 145 | 145 |
| 146 case ASN1_ITYPE_CHOICE: | 146 case ASN1_ITYPE_CHOICE: |
| 147 if (asn1_cb) | 147 if (asn1_cb) |
| 148 { | 148 { |
| 149 » » » i = asn1_cb(ASN1_OP_NEW_PRE, pval, it); | 149 » » » i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); |
| 150 if (!i) | 150 if (!i) |
| 151 goto auxerr; | 151 goto auxerr; |
| 152 if (i==2) | 152 if (i==2) |
| 153 { | 153 { |
| 154 #ifdef CRYPTO_MDEBUG | 154 #ifdef CRYPTO_MDEBUG |
| 155 if (it->sname) | 155 if (it->sname) |
| 156 CRYPTO_pop_info(); | 156 CRYPTO_pop_info(); |
| 157 #endif | 157 #endif |
| 158 return 1; | 158 return 1; |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 if (!combine) | 161 if (!combine) |
| 162 { | 162 { |
| 163 *pval = OPENSSL_malloc(it->size); | 163 *pval = OPENSSL_malloc(it->size); |
| 164 if (!*pval) | 164 if (!*pval) |
| 165 goto memerr; | 165 goto memerr; |
| 166 memset(*pval, 0, it->size); | 166 memset(*pval, 0, it->size); |
| 167 } | 167 } |
| 168 asn1_set_choice_selector(pval, -1, it); | 168 asn1_set_choice_selector(pval, -1, it); |
| 169 » » if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it)) | 169 » » if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) |
| 170 goto auxerr; | 170 goto auxerr; |
| 171 break; | 171 break; |
| 172 | 172 |
| 173 case ASN1_ITYPE_NDEF_SEQUENCE: | 173 case ASN1_ITYPE_NDEF_SEQUENCE: |
| 174 case ASN1_ITYPE_SEQUENCE: | 174 case ASN1_ITYPE_SEQUENCE: |
| 175 if (asn1_cb) | 175 if (asn1_cb) |
| 176 { | 176 { |
| 177 » » » i = asn1_cb(ASN1_OP_NEW_PRE, pval, it); | 177 » » » i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); |
| 178 if (!i) | 178 if (!i) |
| 179 goto auxerr; | 179 goto auxerr; |
| 180 if (i==2) | 180 if (i==2) |
| 181 { | 181 { |
| 182 #ifdef CRYPTO_MDEBUG | 182 #ifdef CRYPTO_MDEBUG |
| 183 if (it->sname) | 183 if (it->sname) |
| 184 CRYPTO_pop_info(); | 184 CRYPTO_pop_info(); |
| 185 #endif | 185 #endif |
| 186 return 1; | 186 return 1; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 if (!combine) | 189 if (!combine) |
| 190 { | 190 { |
| 191 *pval = OPENSSL_malloc(it->size); | 191 *pval = OPENSSL_malloc(it->size); |
| 192 if (!*pval) | 192 if (!*pval) |
| 193 goto memerr; | 193 goto memerr; |
| 194 memset(*pval, 0, it->size); | 194 memset(*pval, 0, it->size); |
| 195 asn1_do_lock(pval, 0, it); | 195 asn1_do_lock(pval, 0, it); |
| 196 asn1_enc_init(pval, it); | 196 asn1_enc_init(pval, it); |
| 197 } | 197 } |
| 198 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) | 198 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) |
| 199 { | 199 { |
| 200 pseqval = asn1_get_field_ptr(pval, tt); | 200 pseqval = asn1_get_field_ptr(pval, tt); |
| 201 if (!ASN1_template_new(pseqval, tt)) | 201 if (!ASN1_template_new(pseqval, tt)) |
| 202 goto memerr; | 202 goto memerr; |
| 203 } | 203 } |
| 204 » » if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it)) | 204 » » if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) |
| 205 goto auxerr; | 205 goto auxerr; |
| 206 break; | 206 break; |
| 207 } | 207 } |
| 208 #ifdef CRYPTO_MDEBUG | 208 #ifdef CRYPTO_MDEBUG |
| 209 if (it->sname) CRYPTO_pop_info(); | 209 if (it->sname) CRYPTO_pop_info(); |
| 210 #endif | 210 #endif |
| 211 return 1; | 211 return 1; |
| 212 | 212 |
| 213 memerr: | 213 memerr: |
| 214 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE); | 214 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 318 } |
| 319 | 319 |
| 320 | 320 |
| 321 /* NB: could probably combine most of the real XXX_new() behaviour and junk | 321 /* NB: could probably combine most of the real XXX_new() behaviour and junk |
| 322 * all the old functions. | 322 * all the old functions. |
| 323 */ | 323 */ |
| 324 | 324 |
| 325 int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | 325 int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) |
| 326 { | 326 { |
| 327 ASN1_TYPE *typ; | 327 ASN1_TYPE *typ; |
| 328 ASN1_STRING *str; |
| 328 int utype; | 329 int utype; |
| 329 | 330 |
| 330 if (it && it->funcs) | 331 if (it && it->funcs) |
| 331 { | 332 { |
| 332 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | 333 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; |
| 333 if (pf->prim_new) | 334 if (pf->prim_new) |
| 334 return pf->prim_new(pval, it); | 335 return pf->prim_new(pval, it); |
| 335 } | 336 } |
| 336 | 337 |
| 337 if (!it || (it->itype == ASN1_ITYPE_MSTRING)) | 338 if (!it || (it->itype == ASN1_ITYPE_MSTRING)) |
| 338 utype = -1; | 339 utype = -1; |
| 339 else | 340 else |
| 340 utype = it->utype; | 341 utype = it->utype; |
| 341 switch(utype) | 342 switch(utype) |
| 342 { | 343 { |
| 343 case V_ASN1_OBJECT: | 344 case V_ASN1_OBJECT: |
| 344 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); | 345 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); |
| 345 return 1; | 346 return 1; |
| 346 | 347 |
| 347 case V_ASN1_BOOLEAN: | 348 case V_ASN1_BOOLEAN: |
| 348 » » if (it) | 349 » » *(ASN1_BOOLEAN *)pval = it->size; |
| 349 » » » *(ASN1_BOOLEAN *)pval = it->size; | |
| 350 » » else | |
| 351 » » » *(ASN1_BOOLEAN *)pval = -1; | |
| 352 return 1; | 350 return 1; |
| 353 | 351 |
| 354 case V_ASN1_NULL: | 352 case V_ASN1_NULL: |
| 355 *pval = (ASN1_VALUE *)1; | 353 *pval = (ASN1_VALUE *)1; |
| 356 return 1; | 354 return 1; |
| 357 | 355 |
| 358 case V_ASN1_ANY: | 356 case V_ASN1_ANY: |
| 359 typ = OPENSSL_malloc(sizeof(ASN1_TYPE)); | 357 typ = OPENSSL_malloc(sizeof(ASN1_TYPE)); |
| 360 if (!typ) | 358 if (!typ) |
| 361 return 0; | 359 return 0; |
| 362 typ->value.ptr = NULL; | 360 typ->value.ptr = NULL; |
| 363 typ->type = -1; | 361 typ->type = -1; |
| 364 *pval = (ASN1_VALUE *)typ; | 362 *pval = (ASN1_VALUE *)typ; |
| 365 break; | 363 break; |
| 366 | 364 |
| 367 default: | 365 default: |
| 368 » » *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype); | 366 » » str = ASN1_STRING_type_new(utype); |
| 367 » » if (it->itype == ASN1_ITYPE_MSTRING && str) |
| 368 » » » str->flags |= ASN1_STRING_FLAG_MSTRING; |
| 369 » » *pval = (ASN1_VALUE *)str; |
| 369 break; | 370 break; |
| 370 } | 371 } |
| 371 if (*pval) | 372 if (*pval) |
| 372 return 1; | 373 return 1; |
| 373 return 0; | 374 return 0; |
| 374 } | 375 } |
| 375 | 376 |
| 376 void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | 377 static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) |
| 377 { | 378 { |
| 378 int utype; | 379 int utype; |
| 379 if (it && it->funcs) | 380 if (it && it->funcs) |
| 380 { | 381 { |
| 381 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; | 382 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; |
| 382 if (pf->prim_clear) | 383 if (pf->prim_clear) |
| 383 pf->prim_clear(pval, it); | 384 pf->prim_clear(pval, it); |
| 384 else | 385 else |
| 385 *pval = NULL; | 386 *pval = NULL; |
| 386 return; | 387 return; |
| 387 } | 388 } |
| 388 if (!it || (it->itype == ASN1_ITYPE_MSTRING)) | 389 if (!it || (it->itype == ASN1_ITYPE_MSTRING)) |
| 389 utype = -1; | 390 utype = -1; |
| 390 else | 391 else |
| 391 utype = it->utype; | 392 utype = it->utype; |
| 392 if (utype == V_ASN1_BOOLEAN) | 393 if (utype == V_ASN1_BOOLEAN) |
| 393 *(ASN1_BOOLEAN *)pval = it->size; | 394 *(ASN1_BOOLEAN *)pval = it->size; |
| 394 else *pval = NULL; | 395 else *pval = NULL; |
| 395 } | 396 } |
| OLD | NEW |