summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/tasn_new.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/tasn_new.c')
-rw-r--r--src/lib/libcrypto/asn1/tasn_new.c90
1 files changed, 50 insertions, 40 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c
index 00aa31dd63..dc9ddc413a 100644
--- a/src/lib/libcrypto/asn1/tasn_new.c
+++ b/src/lib/libcrypto/asn1/tasn_new.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -65,12 +65,13 @@
65#include <string.h> 65#include <string.h>
66 66
67static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, 67static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
68 int combine); 68 int combine);
69static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); 69static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
70static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); 70static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
71static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); 71static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
72 72
73ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) 73ASN1_VALUE *
74ASN1_item_new(const ASN1_ITEM *it)
74{ 75{
75 ASN1_VALUE *ret = NULL; 76 ASN1_VALUE *ret = NULL;
76 if (ASN1_item_ex_new(&ret, it) > 0) 77 if (ASN1_item_ex_new(&ret, it) > 0)
@@ -80,13 +81,14 @@ ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
80 81
81/* Allocate an ASN1 structure */ 82/* Allocate an ASN1 structure */
82 83
83int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 84int
85ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
84{ 86{
85 return asn1_item_ex_combine_new(pval, it, 0); 87 return asn1_item_ex_combine_new(pval, it, 0);
86} 88}
87 89
88static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, 90static int
89 int combine) 91asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
90{ 92{
91 const ASN1_TEMPLATE *tt = NULL; 93 const ASN1_TEMPLATE *tt = NULL;
92 const ASN1_COMPAT_FUNCS *cf; 94 const ASN1_COMPAT_FUNCS *cf;
@@ -95,20 +97,21 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
95 ASN1_aux_cb *asn1_cb; 97 ASN1_aux_cb *asn1_cb;
96 ASN1_VALUE **pseqval; 98 ASN1_VALUE **pseqval;
97 int i; 99 int i;
100
98 if (aux && aux->asn1_cb) 101 if (aux && aux->asn1_cb)
99 asn1_cb = aux->asn1_cb; 102 asn1_cb = aux->asn1_cb;
100 else 103 else
101 asn1_cb = 0; 104 asn1_cb = 0;
102 105
103 if (!combine) *pval = NULL; 106 if (!combine)
107 *pval = NULL;
104 108
105#ifdef CRYPTO_MDEBUG 109#ifdef CRYPTO_MDEBUG
106 if (it->sname) 110 if (it->sname)
107 CRYPTO_push_info(it->sname); 111 CRYPTO_push_info(it->sname);
108#endif 112#endif
109 113
110 switch(it->itype) { 114 switch (it->itype) {
111
112 case ASN1_ITYPE_EXTERN: 115 case ASN1_ITYPE_EXTERN:
113 ef = it->funcs; 116 ef = it->funcs;
114 if (ef && ef->asn1_ex_new) { 117 if (ef && ef->asn1_ex_new) {
@@ -130,14 +133,13 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
130 if (it->templates) { 133 if (it->templates) {
131 if (!ASN1_template_new(pval, it->templates)) 134 if (!ASN1_template_new(pval, it->templates))
132 goto memerr; 135 goto memerr;
133 } 136 } else if (!ASN1_primitive_new(pval, it))
134 else if (!ASN1_primitive_new(pval, it)) 137 goto memerr;
135 goto memerr;
136 break; 138 break;
137 139
138 case ASN1_ITYPE_MSTRING: 140 case ASN1_ITYPE_MSTRING:
139 if (!ASN1_primitive_new(pval, it)) 141 if (!ASN1_primitive_new(pval, it))
140 goto memerr; 142 goto memerr;
141 break; 143 break;
142 144
143 case ASN1_ITYPE_CHOICE: 145 case ASN1_ITYPE_CHOICE:
@@ -145,7 +147,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
145 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); 147 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
146 if (!i) 148 if (!i)
147 goto auxerr; 149 goto auxerr;
148 if (i==2) { 150 if (i == 2) {
149#ifdef CRYPTO_MDEBUG 151#ifdef CRYPTO_MDEBUG
150 if (it->sname) 152 if (it->sname)
151 CRYPTO_pop_info(); 153 CRYPTO_pop_info();
@@ -161,7 +163,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
161 } 163 }
162 asn1_set_choice_selector(pval, -1, it); 164 asn1_set_choice_selector(pval, -1, it);
163 if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) 165 if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
164 goto auxerr; 166 goto auxerr;
165 break; 167 break;
166 168
167 case ASN1_ITYPE_NDEF_SEQUENCE: 169 case ASN1_ITYPE_NDEF_SEQUENCE:
@@ -170,7 +172,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
170 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); 172 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
171 if (!i) 173 if (!i)
172 goto auxerr; 174 goto auxerr;
173 if (i==2) { 175 if (i == 2) {
174#ifdef CRYPTO_MDEBUG 176#ifdef CRYPTO_MDEBUG
175 if (it->sname) 177 if (it->sname)
176 CRYPTO_pop_info(); 178 CRYPTO_pop_info();
@@ -192,47 +194,50 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
192 goto memerr; 194 goto memerr;
193 } 195 }
194 if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) 196 if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
195 goto auxerr; 197 goto auxerr;
196 break; 198 break;
197} 199 }
198#ifdef CRYPTO_MDEBUG 200#ifdef CRYPTO_MDEBUG
199 if (it->sname) CRYPTO_pop_info(); 201 if (it->sname)
202 CRYPTO_pop_info();
200#endif 203#endif
201 return 1; 204 return 1;
202 205
203 memerr: 206memerr:
204 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE); 207 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE);
205#ifdef CRYPTO_MDEBUG 208#ifdef CRYPTO_MDEBUG
206 if (it->sname) CRYPTO_pop_info(); 209 if (it->sname)
210 CRYPTO_pop_info();
207#endif 211#endif
208 return 0; 212 return 0;
209 213
210 auxerr: 214auxerr:
211 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ASN1_R_AUX_ERROR); 215 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ASN1_R_AUX_ERROR);
212 ASN1_item_ex_free(pval, it); 216 ASN1_item_ex_free(pval, it);
213#ifdef CRYPTO_MDEBUG 217#ifdef CRYPTO_MDEBUG
214 if (it->sname) CRYPTO_pop_info(); 218 if (it->sname)
219 CRYPTO_pop_info();
215#endif 220#endif
216 return 0; 221 return 0;
217 222
218} 223}
219 224
220static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) 225static void
226asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
221{ 227{
222 const ASN1_EXTERN_FUNCS *ef; 228 const ASN1_EXTERN_FUNCS *ef;
223 229
224 switch(it->itype) { 230 switch (it->itype) {
225
226 case ASN1_ITYPE_EXTERN: 231 case ASN1_ITYPE_EXTERN:
227 ef = it->funcs; 232 ef = it->funcs;
228 if (ef && ef->asn1_ex_clear) 233 if (ef && ef->asn1_ex_clear)
229 ef->asn1_ex_clear(pval, it); 234 ef->asn1_ex_clear(pval, it);
230 else *pval = NULL; 235 else
236 *pval = NULL;
231 break; 237 break;
232 238
233
234 case ASN1_ITYPE_PRIMITIVE: 239 case ASN1_ITYPE_PRIMITIVE:
235 if (it->templates) 240 if (it->templates)
236 asn1_template_clear(pval, it->templates); 241 asn1_template_clear(pval, it->templates);
237 else 242 else
238 asn1_primitive_clear(pval, it); 243 asn1_primitive_clear(pval, it);
@@ -251,11 +256,12 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
251 } 256 }
252} 257}
253 258
254 259int
255int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 260ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
256{ 261{
257 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); 262 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
258 int ret; 263 int ret;
264
259 if (tt->flags & ASN1_TFLG_OPTIONAL) { 265 if (tt->flags & ASN1_TFLG_OPTIONAL) {
260 asn1_template_clear(pval, tt); 266 asn1_template_clear(pval, tt);
261 return 1; 267 return 1;
@@ -285,7 +291,7 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
285 } 291 }
286 /* Otherwise pass it back to the item routine */ 292 /* Otherwise pass it back to the item routine */
287 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); 293 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
288 done: 294done:
289#ifdef CRYPTO_MDEBUG 295#ifdef CRYPTO_MDEBUG
290 if (it->sname) 296 if (it->sname)
291 CRYPTO_pop_info(); 297 CRYPTO_pop_info();
@@ -293,10 +299,11 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
293 return ret; 299 return ret;
294} 300}
295 301
296static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 302static void
303asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
297{ 304{
298 /* If ADB or STACK just NULL the field */ 305 /* If ADB or STACK just NULL the field */
299 if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) 306 if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
300 *pval = NULL; 307 *pval = NULL;
301 else 308 else
302 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); 309 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
@@ -307,7 +314,8 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
307 * all the old functions. 314 * all the old functions.
308 */ 315 */
309 316
310int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 317int
318ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
311{ 319{
312 ASN1_TYPE *typ; 320 ASN1_TYPE *typ;
313 ASN1_STRING *str; 321 ASN1_STRING *str;
@@ -323,7 +331,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
323 utype = -1; 331 utype = -1;
324 else 332 else
325 utype = it->utype; 333 utype = it->utype;
326 switch(utype) { 334 switch (utype) {
327 case V_ASN1_OBJECT: 335 case V_ASN1_OBJECT:
328 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); 336 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
329 return 1; 337 return 1;
@@ -357,14 +365,15 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
357 return 0; 365 return 0;
358} 366}
359 367
360static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) 368static void
369asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
361{ 370{
362 int utype; 371 int utype;
363 if (it && it->funcs) { 372 if (it && it->funcs) {
364 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; 373 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
365 if (pf->prim_clear) 374 if (pf->prim_clear)
366 pf->prim_clear(pval, it); 375 pf->prim_clear(pval, it);
367 else 376 else
368 *pval = NULL; 377 *pval = NULL;
369 return; 378 return;
370 } 379 }
@@ -374,5 +383,6 @@ static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
374 utype = it->utype; 383 utype = it->utype;
375 if (utype == V_ASN1_BOOLEAN) 384 if (utype == V_ASN1_BOOLEAN)
376 *(ASN1_BOOLEAN *)pval = it->size; 385 *(ASN1_BOOLEAN *)pval = it->size;
377 else *pval = NULL; 386 else
387 *pval = NULL;
378} 388}