summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/tasn_new.c
diff options
context:
space:
mode:
authortedu <>2014-04-18 00:10:08 +0000
committertedu <>2014-04-18 00:10:08 +0000
commit07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d (patch)
tree6327d50d69a1982f840dc68fe928ea459e2c41e0 /src/lib/libcrypto/asn1/tasn_new.c
parent288a9e368d9d4a72792b12a00ad69e3592d94073 (diff)
downloadopenbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.tar.gz
openbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.tar.bz2
openbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.zip
putting most of the braces in the right column is the very least we can do.
Diffstat (limited to 'src/lib/libcrypto/asn1/tasn_new.c')
-rw-r--r--src/lib/libcrypto/asn1/tasn_new.c100
1 files changed, 50 insertions, 50 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c
index aab9ef08c4..f5d7c690b8 100644
--- a/src/lib/libcrypto/asn1/tasn_new.c
+++ b/src/lib/libcrypto/asn1/tasn_new.c
@@ -71,23 +71,23 @@ static 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 *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 */
82 82
83int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 83int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
84 { 84{
85 return asn1_item_ex_combine_new(pval, it, 0); 85 return asn1_item_ex_combine_new(pval, it, 0);
86 } 86}
87 87
88static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, 88static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
89 int combine) 89 int combine)
90 { 90{
91 const ASN1_TEMPLATE *tt = NULL; 91 const ASN1_TEMPLATE *tt = NULL;
92 const ASN1_COMPAT_FUNCS *cf; 92 const ASN1_COMPAT_FUNCS *cf;
93 const ASN1_EXTERN_FUNCS *ef; 93 const ASN1_EXTERN_FUNCS *ef;
@@ -108,15 +108,15 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
108#endif 108#endif
109 109
110 switch(it->itype) 110 switch(it->itype)
111 { 111 {
112 112
113 case ASN1_ITYPE_EXTERN: 113 case ASN1_ITYPE_EXTERN:
114 ef = it->funcs; 114 ef = it->funcs;
115 if (ef && ef->asn1_ex_new) 115 if (ef && ef->asn1_ex_new)
116 { 116 {
117 if (!ef->asn1_ex_new(pval, it)) 117 if (!ef->asn1_ex_new(pval, it))
118 goto memerr; 118 goto memerr;
119 } 119 }
120 break; 120 break;
121 121
122 case ASN1_ITYPE_COMPAT: 122 case ASN1_ITYPE_COMPAT:
@@ -125,15 +125,15 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
125 *pval = cf->asn1_new(); 125 *pval = cf->asn1_new();
126 if (!*pval) 126 if (!*pval)
127 goto memerr; 127 goto memerr;
128 } 128 }
129 break; 129 break;
130 130
131 case ASN1_ITYPE_PRIMITIVE: 131 case ASN1_ITYPE_PRIMITIVE:
132 if (it->templates) 132 if (it->templates)
133 { 133 {
134 if (!ASN1_template_new(pval, it->templates)) 134 if (!ASN1_template_new(pval, it->templates))
135 goto memerr; 135 goto memerr;
136 } 136 }
137 else if (!ASN1_primitive_new(pval, it)) 137 else if (!ASN1_primitive_new(pval, it))
138 goto memerr; 138 goto memerr;
139 break; 139 break;
@@ -145,26 +145,26 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
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, NULL); 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 }
160 } 159 }
160 }
161 if (!combine) 161 if (!combine)
162 { 162 {
163 *pval = malloc(it->size); 163 *pval = 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, NULL)) 169 if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
170 goto auxerr; 170 goto auxerr;
@@ -173,38 +173,38 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
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, NULL); 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 }
188 } 187 }
188 }
189 if (!combine) 189 if (!combine)
190 { 190 {
191 *pval = malloc(it->size); 191 *pval = 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, NULL)) 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
@@ -225,14 +225,14 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
225#endif 225#endif
226 return 0; 226 return 0;
227 227
228 } 228}
229 229
230static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) 230static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
231 { 231{
232 const ASN1_EXTERN_FUNCS *ef; 232 const ASN1_EXTERN_FUNCS *ef;
233 233
234 switch(it->itype) 234 switch(it->itype)
235 { 235 {
236 236
237 case ASN1_ITYPE_EXTERN: 237 case ASN1_ITYPE_EXTERN:
238 ef = it->funcs; 238 ef = it->funcs;
@@ -259,45 +259,45 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
259 case ASN1_ITYPE_NDEF_SEQUENCE: 259 case ASN1_ITYPE_NDEF_SEQUENCE:
260 *pval = NULL; 260 *pval = NULL;
261 break; 261 break;
262 }
263 } 262 }
263}
264 264
265 265
266int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 266int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
267 { 267{
268 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); 268 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
269 int ret; 269 int ret;
270 if (tt->flags & ASN1_TFLG_OPTIONAL) 270 if (tt->flags & ASN1_TFLG_OPTIONAL)
271 { 271 {
272 asn1_template_clear(pval, tt); 272 asn1_template_clear(pval, tt);
273 return 1; 273 return 1;
274 } 274 }
275 /* If ANY DEFINED BY nothing to do */ 275 /* If ANY DEFINED BY nothing to do */
276 276
277 if (tt->flags & ASN1_TFLG_ADB_MASK) 277 if (tt->flags & ASN1_TFLG_ADB_MASK)
278 { 278 {
279 *pval = NULL; 279 *pval = NULL;
280 return 1; 280 return 1;
281 } 281 }
282#ifdef CRYPTO_MDEBUG 282#ifdef CRYPTO_MDEBUG
283 if (tt->field_name) 283 if (tt->field_name)
284 CRYPTO_push_info(tt->field_name); 284 CRYPTO_push_info(tt->field_name);
285#endif 285#endif
286 /* If SET OF or SEQUENCE OF, its a STACK */ 286 /* If SET OF or SEQUENCE OF, its a STACK */
287 if (tt->flags & ASN1_TFLG_SK_MASK) 287 if (tt->flags & ASN1_TFLG_SK_MASK)
288 { 288 {
289 STACK_OF(ASN1_VALUE) *skval; 289 STACK_OF(ASN1_VALUE) *skval;
290 skval = sk_ASN1_VALUE_new_null(); 290 skval = sk_ASN1_VALUE_new_null();
291 if (!skval) 291 if (!skval)
292 { 292 {
293 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); 293 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
294 ret = 0; 294 ret = 0;
295 goto done; 295 goto done;
296 } 296 }
297 *pval = (ASN1_VALUE *)skval; 297 *pval = (ASN1_VALUE *)skval;
298 ret = 1; 298 ret = 1;
299 goto done; 299 goto done;
300 } 300 }
301 /* Otherwise pass it back to the item routine */ 301 /* Otherwise pass it back to the item routine */
302 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); 302 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
303 done: 303 done:
@@ -306,16 +306,16 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
306 CRYPTO_pop_info(); 306 CRYPTO_pop_info();
307#endif 307#endif
308 return ret; 308 return ret;
309 } 309}
310 310
311static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 311static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
312 { 312{
313 /* If ADB or STACK just NULL the field */ 313 /* If ADB or STACK just NULL the field */
314 if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) 314 if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
315 *pval = NULL; 315 *pval = NULL;
316 else 316 else
317 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); 317 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
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
@@ -323,24 +323,24 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
323 */ 323 */
324 324
325int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 325int 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 ASN1_STRING *str;
329 int utype; 329 int utype;
330 330
331 if (it && it->funcs) 331 if (it && it->funcs)
332 { 332 {
333 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; 333 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
334 if (pf->prim_new) 334 if (pf->prim_new)
335 return pf->prim_new(pval, it); 335 return pf->prim_new(pval, it);
336 } 336 }
337 337
338 if (!it || (it->itype == ASN1_ITYPE_MSTRING)) 338 if (!it || (it->itype == ASN1_ITYPE_MSTRING))
339 utype = -1; 339 utype = -1;
340 else 340 else
341 utype = it->utype; 341 utype = it->utype;
342 switch(utype) 342 switch(utype)
343 { 343 {
344 case V_ASN1_OBJECT: 344 case V_ASN1_OBJECT:
345 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); 345 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
346 return 1; 346 return 1;
@@ -368,24 +368,24 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
368 str->flags |= ASN1_STRING_FLAG_MSTRING; 368 str->flags |= ASN1_STRING_FLAG_MSTRING;
369 *pval = (ASN1_VALUE *)str; 369 *pval = (ASN1_VALUE *)str;
370 break; 370 break;
371 } 371 }
372 if (*pval) 372 if (*pval)
373 return 1; 373 return 1;
374 return 0; 374 return 0;
375 } 375}
376 376
377static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) 377static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
378 { 378{
379 int utype; 379 int utype;
380 if (it && it->funcs) 380 if (it && it->funcs)
381 { 381 {
382 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; 382 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
383 if (pf->prim_clear) 383 if (pf->prim_clear)
384 pf->prim_clear(pval, it); 384 pf->prim_clear(pval, it);
385 else 385 else
386 *pval = NULL; 386 *pval = NULL;
387 return; 387 return;
388 } 388 }
389 if (!it || (it->itype == ASN1_ITYPE_MSTRING)) 389 if (!it || (it->itype == ASN1_ITYPE_MSTRING))
390 utype = -1; 390 utype = -1;
391 else 391 else
@@ -393,4 +393,4 @@ static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
393 if (utype == V_ASN1_BOOLEAN) 393 if (utype == V_ASN1_BOOLEAN)
394 *(ASN1_BOOLEAN *)pval = it->size; 394 *(ASN1_BOOLEAN *)pval = it->size;
395 else *pval = NULL; 395 else *pval = NULL;
396 } 396}