summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/tasn_prn.c
diff options
context:
space:
mode:
authortedu <>2014-04-18 00:58:49 +0000
committertedu <>2014-04-18 00:58:49 +0000
commita1df5b66c7ad477a535e56a504d8da47e1998cfa (patch)
treeb216ca6fba673789f2c494699c4cf41d23337bfa /src/lib/libcrypto/asn1/tasn_prn.c
parent07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d (diff)
downloadopenbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.tar.gz
openbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.tar.bz2
openbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.zip
lob a few more knf grenades in here to soften things up.
Diffstat (limited to 'src/lib/libcrypto/asn1/tasn_prn.c')
-rw-r--r--src/lib/libcrypto/asn1/tasn_prn.c139
1 files changed, 52 insertions, 87 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c
index f62c085f3b..345daeb0f3 100644
--- a/src/lib/libcrypto/asn1/tasn_prn.c
+++ b/src/lib/libcrypto/asn1/tasn_prn.c
@@ -86,8 +86,7 @@ ASN1_PCTX *ASN1_PCTX_new(void)
86{ 86{
87 ASN1_PCTX *ret; 87 ASN1_PCTX *ret;
88 ret = malloc(sizeof(ASN1_PCTX)); 88 ret = malloc(sizeof(ASN1_PCTX));
89 if (ret == NULL) 89 if (ret == NULL) {
90 {
91 ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE); 90 ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE);
92 return NULL; 91 return NULL;
93 } 92 }
@@ -199,8 +198,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
199 ASN1_aux_cb *asn1_cb; 198 ASN1_aux_cb *asn1_cb;
200 ASN1_PRINT_ARG parg; 199 ASN1_PRINT_ARG parg;
201 int i; 200 int i;
202 if (aux && aux->asn1_cb) 201 if (aux && aux->asn1_cb) {
203 {
204 parg.out = out; 202 parg.out = out;
205 parg.indent = indent; 203 parg.indent = indent;
206 parg.pctx = pctx; 204 parg.pctx = pctx;
@@ -208,10 +206,8 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
208 } 206 }
209 else asn1_cb = 0; 207 else asn1_cb = 0;
210 208
211 if(*fld == NULL) 209 if(*fld == NULL) {
212 { 210 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) {
213 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT)
214 {
215 if (!nohdr && !asn1_print_fsname(out, indent, 211 if (!nohdr && !asn1_print_fsname(out, indent,
216 fname, sname, pctx)) 212 fname, sname, pctx))
217 return 0; 213 return 0;
@@ -221,29 +217,26 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
221 return 1; 217 return 1;
222 } 218 }
223 219
224 switch(it->itype) 220 switch(it->itype) {
225 { 221 case ASN1_ITYPE_PRIMITIVE:
226 case ASN1_ITYPE_PRIMITIVE: 222 if(it->templates) {
227 if(it->templates)
228 {
229 if (!asn1_template_print_ctx(out, fld, indent, 223 if (!asn1_template_print_ctx(out, fld, indent,
230 it->templates, pctx)) 224 it->templates, pctx))
231 return 0; 225 return 0;
232 } 226 }
233 /* fall thru */ 227 /* fall thru */
234 case ASN1_ITYPE_MSTRING: 228 case ASN1_ITYPE_MSTRING:
235 if (!asn1_primitive_print(out, fld, it, 229 if (!asn1_primitive_print(out, fld, it,
236 indent, fname, sname,pctx)) 230 indent, fname, sname,pctx))
237 return 0; 231 return 0;
238 break; 232 break;
239 233
240 case ASN1_ITYPE_EXTERN: 234 case ASN1_ITYPE_EXTERN:
241 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) 235 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
242 return 0; 236 return 0;
243 /* Use new style print routine if possible */ 237 /* Use new style print routine if possible */
244 ef = it->funcs; 238 ef = it->funcs;
245 if (ef && ef->asn1_ex_print) 239 if (ef && ef->asn1_ex_print) {
246 {
247 i = ef->asn1_ex_print(out, fld, indent, "", pctx); 240 i = ef->asn1_ex_print(out, fld, indent, "", pctx);
248 if (!i) 241 if (!i)
249 return 0; 242 return 0;
@@ -256,7 +249,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
256 return 0; 249 return 0;
257 break; 250 break;
258 251
259 case ASN1_ITYPE_CHOICE: 252 case ASN1_ITYPE_CHOICE:
260#if 0 253#if 0
261 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) 254 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
262 return 0; 255 return 0;
@@ -264,8 +257,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
264 /* CHOICE type, get selector */ 257 /* CHOICE type, get selector */
265 i = asn1_get_choice_selector(fld, it); 258 i = asn1_get_choice_selector(fld, it);
266 /* This should never happen... */ 259 /* This should never happen... */
267 if((i < 0) || (i >= it->tcount)) 260 if((i < 0) || (i >= it->tcount)) {
268 {
269 if (BIO_printf(out, 261 if (BIO_printf(out,
270 "ERROR: selector [%d] invalid\n", i) <= 0) 262 "ERROR: selector [%d] invalid\n", i) <= 0)
271 return 0; 263 return 0;
@@ -277,26 +269,21 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
277 return 0; 269 return 0;
278 break; 270 break;
279 271
280 case ASN1_ITYPE_SEQUENCE: 272 case ASN1_ITYPE_SEQUENCE:
281 case ASN1_ITYPE_NDEF_SEQUENCE: 273 case ASN1_ITYPE_NDEF_SEQUENCE:
282 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) 274 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
283 return 0; 275 return 0;
284 if (fname || sname) 276 if (fname || sname) {
285 { 277 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
286 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE)
287 {
288 if (BIO_puts(out, " {\n") <= 0) 278 if (BIO_puts(out, " {\n") <= 0)
289 return 0; 279 return 0;
290 } 280 } else {
291 else
292 {
293 if (BIO_puts(out, "\n") <= 0) 281 if (BIO_puts(out, "\n") <= 0)
294 return 0; 282 return 0;
295 } 283 }
296 } 284 }
297 285
298 if (asn1_cb) 286 if (asn1_cb) {
299 {
300 i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg); 287 i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg);
301 if (i == 0) 288 if (i == 0)
302 return 0; 289 return 0;
@@ -305,8 +292,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
305 } 292 }
306 293
307 /* Print each field entry */ 294 /* Print each field entry */
308 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) 295 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
309 {
310 const ASN1_TEMPLATE *seqtt; 296 const ASN1_TEMPLATE *seqtt;
311 seqtt = asn1_do_adb(fld, tt, 1); 297 seqtt = asn1_do_adb(fld, tt, 1);
312 tmpfld = asn1_get_field_ptr(fld, seqtt); 298 tmpfld = asn1_get_field_ptr(fld, seqtt);
@@ -314,14 +300,12 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
314 indent + 2, seqtt, pctx)) 300 indent + 2, seqtt, pctx))
315 return 0; 301 return 0;
316 } 302 }
317 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) 303 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
318 {
319 if (BIO_printf(out, "%*s}\n", indent, "") < 0) 304 if (BIO_printf(out, "%*s}\n", indent, "") < 0)
320 return 0; 305 return 0;
321 } 306 }
322 307
323 if (asn1_cb) 308 if (asn1_cb) {
324 {
325 i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg); 309 i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg);
326 if (i == 0) 310 if (i == 0)
327 return 0; 311 return 0;
@@ -350,17 +334,14 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
350 fname = NULL; 334 fname = NULL;
351 else 335 else
352 fname = tt->field_name; 336 fname = tt->field_name;
353 if(flags & ASN1_TFLG_SK_MASK) 337 if(flags & ASN1_TFLG_SK_MASK) {
354 {
355 char *tname; 338 char *tname;
356 ASN1_VALUE *skitem; 339 ASN1_VALUE *skitem;
357 STACK_OF(ASN1_VALUE) *stack; 340 STACK_OF(ASN1_VALUE) *stack;
358 341
359 /* SET OF, SEQUENCE OF */ 342 /* SET OF, SEQUENCE OF */
360 if (fname) 343 if (fname) {
361 { 344 if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) {
362 if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF)
363 {
364 if(flags & ASN1_TFLG_SET_OF) 345 if(flags & ASN1_TFLG_SET_OF)
365 tname = "SET"; 346 tname = "SET";
366 else 347 else
@@ -374,8 +355,7 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
374 return 0; 355 return 0;
375 } 356 }
376 stack = (STACK_OF(ASN1_VALUE) *)*fld; 357 stack = (STACK_OF(ASN1_VALUE) *)*fld;
377 for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) 358 for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) {
378 {
379 if ((i > 0) && (BIO_puts(out, "\n") <= 0)) 359 if ((i > 0) && (BIO_puts(out, "\n") <= 0))
380 return 0; 360 return 0;
381 361
@@ -386,8 +366,7 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
386 } 366 }
387 if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0) 367 if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
388 return 0; 368 return 0;
389 if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) 369 if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
390 {
391 if (BIO_printf(out, "%*s}\n", indent, "") <= 0) 370 if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
392 return 0; 371 return 0;
393 } 372 }
@@ -409,8 +388,7 @@ static int asn1_print_fsname(BIO *out, int indent,
409 return 1; 388 return 1;
410#endif 389#endif
411 390
412 while (indent > nspaces) 391 while (indent > nspaces) {
413 {
414 if (BIO_write(out, spaces, nspaces) != nspaces) 392 if (BIO_write(out, spaces, nspaces) != nspaces)
415 return 0; 393 return 0;
416 indent -= nspaces; 394 indent -= nspaces;
@@ -423,20 +401,15 @@ static int asn1_print_fsname(BIO *out, int indent,
423 fname = NULL; 401 fname = NULL;
424 if (!sname && !fname) 402 if (!sname && !fname)
425 return 1; 403 return 1;
426 if (fname) 404 if (fname) {
427 {
428 if (BIO_puts(out, fname) <= 0) 405 if (BIO_puts(out, fname) <= 0)
429 return 0; 406 return 0;
430 } 407 }
431 if (sname) 408 if (sname) {
432 { 409 if (fname) {
433 if (fname)
434 {
435 if (BIO_printf(out, " (%s)", sname) <= 0) 410 if (BIO_printf(out, " (%s)", sname) <= 0)
436 return 0; 411 return 0;
437 } 412 } else {
438 else
439 {
440 if (BIO_puts(out, sname) <= 0) 413 if (BIO_puts(out, sname) <= 0)
441 return 0; 414 return 0;
442 } 415 }
@@ -450,13 +423,12 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval,
450 const ASN1_PCTX *pctx) 423 const ASN1_PCTX *pctx)
451{ 424{
452 const char *str; 425 const char *str;
453 switch (boolval) 426 switch (boolval) {
454 { 427 case -1:
455 case -1:
456 str = "BOOL ABSENT"; 428 str = "BOOL ABSENT";
457 break; 429 break;
458 430
459 case 0: 431 case 0:
460 str = "FALSE"; 432 str = "FALSE";
461 break; 433 break;
462 434
@@ -501,8 +473,7 @@ static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid,
501static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, 473static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
502 const ASN1_PCTX *pctx) 474 const ASN1_PCTX *pctx)
503{ 475{
504 if (str->type == V_ASN1_BIT_STRING) 476 if (str->type == V_ASN1_BIT_STRING) {
505 {
506 if (BIO_printf(out, " (%ld unused bits)\n", 477 if (BIO_printf(out, " (%ld unused bits)\n",
507 str->flags & 0x7) <= 0) 478 str->flags & 0x7) <= 0)
508 return 0; 479 return 0;
@@ -536,8 +507,7 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
536 utype = str->type & ~V_ASN1_NEG; 507 utype = str->type & ~V_ASN1_NEG;
537 else 508 else
538 utype = it->utype; 509 utype = it->utype;
539 if (utype == V_ASN1_ANY) 510 if (utype == V_ASN1_ANY) {
540 {
541 ASN1_TYPE *atype = (ASN1_TYPE *)*fld; 511 ASN1_TYPE *atype = (ASN1_TYPE *)*fld;
542 utype = atype->type; 512 utype = atype->type;
543 fld = &atype->value.asn1_value; 513 fld = &atype->value.asn1_value;
@@ -546,33 +516,28 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
546 pname = NULL; 516 pname = NULL;
547 else 517 else
548 pname = ASN1_tag2str(utype); 518 pname = ASN1_tag2str(utype);
549 } 519 } else {
550 else
551 {
552 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE) 520 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE)
553 pname = ASN1_tag2str(utype); 521 pname = ASN1_tag2str(utype);
554 else 522 else
555 pname = NULL; 523 pname = NULL;
556 } 524 }
557 525
558 if (utype == V_ASN1_NULL) 526 if (utype == V_ASN1_NULL) {
559 {
560 if (BIO_puts(out, "NULL\n") <= 0) 527 if (BIO_puts(out, "NULL\n") <= 0)
561 return 0; 528 return 0;
562 return 1; 529 return 1;
563 } 530 }
564 531
565 if (pname) 532 if (pname) {
566 {
567 if (BIO_puts(out, pname) <= 0) 533 if (BIO_puts(out, pname) <= 0)
568 return 0; 534 return 0;
569 if (BIO_puts(out, ":") <= 0) 535 if (BIO_puts(out, ":") <= 0)
570 return 0; 536 return 0;
571 } 537 }
572 538
573 switch (utype) 539 switch (utype) {
574 { 540 case V_ASN1_BOOLEAN:
575 case V_ASN1_BOOLEAN:
576 { 541 {
577 int boolval = *(int *)fld; 542 int boolval = *(int *)fld;
578 if (boolval == -1) 543 if (boolval == -1)
@@ -581,32 +546,32 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
581 } 546 }
582 break; 547 break;
583 548
584 case V_ASN1_INTEGER: 549 case V_ASN1_INTEGER:
585 case V_ASN1_ENUMERATED: 550 case V_ASN1_ENUMERATED:
586 ret = asn1_print_integer_ctx(out, str, pctx); 551 ret = asn1_print_integer_ctx(out, str, pctx);
587 break; 552 break;
588 553
589 case V_ASN1_UTCTIME: 554 case V_ASN1_UTCTIME:
590 ret = ASN1_UTCTIME_print(out, str); 555 ret = ASN1_UTCTIME_print(out, str);
591 break; 556 break;
592 557
593 case V_ASN1_GENERALIZEDTIME: 558 case V_ASN1_GENERALIZEDTIME:
594 ret = ASN1_GENERALIZEDTIME_print(out, str); 559 ret = ASN1_GENERALIZEDTIME_print(out, str);
595 break; 560 break;
596 561
597 case V_ASN1_OBJECT: 562 case V_ASN1_OBJECT:
598 ret = asn1_print_oid_ctx(out, (const ASN1_OBJECT *)*fld, pctx); 563 ret = asn1_print_oid_ctx(out, (const ASN1_OBJECT *)*fld, pctx);
599 break; 564 break;
600 565
601 case V_ASN1_OCTET_STRING: 566 case V_ASN1_OCTET_STRING:
602 case V_ASN1_BIT_STRING: 567 case V_ASN1_BIT_STRING:
603 ret = asn1_print_obstring_ctx(out, str, indent, pctx); 568 ret = asn1_print_obstring_ctx(out, str, indent, pctx);
604 needlf = 0; 569 needlf = 0;
605 break; 570 break;
606 571
607 case V_ASN1_SEQUENCE: 572 case V_ASN1_SEQUENCE:
608 case V_ASN1_SET: 573 case V_ASN1_SET:
609 case V_ASN1_OTHER: 574 case V_ASN1_OTHER:
610 if (BIO_puts(out, "\n") <= 0) 575 if (BIO_puts(out, "\n") <= 0)
611 return 0; 576 return 0;
612 if (ASN1_parse_dump(out, str->data, str->length, 577 if (ASN1_parse_dump(out, str->data, str->length,
@@ -615,7 +580,7 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
615 needlf = 0; 580 needlf = 0;
616 break; 581 break;
617 582
618 default: 583 default:
619 ret = ASN1_STRING_print_ex(out, str, pctx->str_flags); 584 ret = ASN1_STRING_print_ex(out, str, pctx->str_flags);
620 585
621 } 586 }