summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/tasn_prn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/tasn_prn.c')
-rw-r--r--src/lib/libcrypto/asn1/tasn_prn.c222
1 files changed, 116 insertions, 106 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c
index 345daeb0f3..13624991c4 100644
--- a/src/lib/libcrypto/asn1/tasn_prn.c
+++ b/src/lib/libcrypto/asn1/tasn_prn.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
@@ -56,7 +56,6 @@
56 * 56 *
57 */ 57 */
58 58
59
60#include <stddef.h> 59#include <stddef.h>
61#include "cryptlib.h" 60#include "cryptlib.h"
62#include <openssl/asn1.h> 61#include <openssl/asn1.h>
@@ -72,17 +71,17 @@
72 71
73/* ASN1_PCTX routines */ 72/* ASN1_PCTX routines */
74 73
75ASN1_PCTX default_pctx = 74ASN1_PCTX default_pctx = {
76{
77 ASN1_PCTX_FLAGS_SHOW_ABSENT, /* flags */ 75 ASN1_PCTX_FLAGS_SHOW_ABSENT, /* flags */
78 0, /* nm_flags */ 76 0, /* nm_flags */
79 0, /* cert_flags */ 77 0, /* cert_flags */
80 0, /* oid_flags */ 78 0, /* oid_flags */
81 0 /* str_flags */ 79 0 /* str_flags */
82}; 80};
83
84 81
85ASN1_PCTX *ASN1_PCTX_new(void) 82
83ASN1_PCTX *
84ASN1_PCTX_new(void)
86{ 85{
87 ASN1_PCTX *ret; 86 ASN1_PCTX *ret;
88 ret = malloc(sizeof(ASN1_PCTX)); 87 ret = malloc(sizeof(ASN1_PCTX));
@@ -98,57 +97,68 @@ ASN1_PCTX *ASN1_PCTX_new(void)
98 return ret; 97 return ret;
99} 98}
100 99
101void ASN1_PCTX_free(ASN1_PCTX *p) 100void
101ASN1_PCTX_free(ASN1_PCTX *p)
102{ 102{
103 free(p); 103 free(p);
104} 104}
105 105
106unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p) 106unsigned long
107ASN1_PCTX_get_flags(ASN1_PCTX *p)
107{ 108{
108 return p->flags; 109 return p->flags;
109} 110}
110 111
111void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags) 112void
113ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags)
112{ 114{
113 p->flags = flags; 115 p->flags = flags;
114} 116}
115 117
116unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p) 118unsigned long
119ASN1_PCTX_get_nm_flags(ASN1_PCTX *p)
117{ 120{
118 return p->nm_flags; 121 return p->nm_flags;
119} 122}
120 123
121void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags) 124void
125ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags)
122{ 126{
123 p->nm_flags = flags; 127 p->nm_flags = flags;
124} 128}
125 129
126unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p) 130unsigned long
131ASN1_PCTX_get_cert_flags(ASN1_PCTX *p)
127{ 132{
128 return p->cert_flags; 133 return p->cert_flags;
129} 134}
130 135
131void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags) 136void
137ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags)
132{ 138{
133 p->cert_flags = flags; 139 p->cert_flags = flags;
134} 140}
135 141
136unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p) 142unsigned long
143ASN1_PCTX_get_oid_flags(ASN1_PCTX *p)
137{ 144{
138 return p->oid_flags; 145 return p->oid_flags;
139} 146}
140 147
141void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags) 148void
149ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags)
142{ 150{
143 p->oid_flags = flags; 151 p->oid_flags = flags;
144} 152}
145 153
146unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p) 154unsigned long
155ASN1_PCTX_get_str_flags(ASN1_PCTX *p)
147{ 156{
148 return p->str_flags; 157 return p->str_flags;
149} 158}
150 159
151void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags) 160void
161ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
152{ 162{
153 p->str_flags = flags; 163 p->str_flags = flags;
154} 164}
@@ -156,40 +166,38 @@ void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
156/* Main print routines */ 166/* Main print routines */
157 167
158static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, 168static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
159 const ASN1_ITEM *it, 169 const ASN1_ITEM *it, const char *fname, const char *sname, int nohdr,
160 const char *fname, const char *sname, 170 const ASN1_PCTX *pctx);
161 int nohdr, const ASN1_PCTX *pctx);
162 171
163int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, 172int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
164 const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx); 173 const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx);
165 174
166static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, 175static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
167 const ASN1_ITEM *it, int indent, 176 const ASN1_ITEM *it, int indent, const char *fname, const char *sname,
168 const char *fname, const char *sname, 177 const ASN1_PCTX *pctx);
169 const ASN1_PCTX *pctx);
170 178
171static int asn1_print_fsname(BIO *out, int indent, 179static int asn1_print_fsname(BIO *out, int indent, const char *fname,
172 const char *fname, const char *sname, 180 const char *sname, const ASN1_PCTX *pctx);
173 const ASN1_PCTX *pctx);
174 181
175int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, 182int
176 const ASN1_ITEM *it, const ASN1_PCTX *pctx) 183ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, const ASN1_ITEM *it,
184 const ASN1_PCTX *pctx)
177{ 185{
178 const char *sname; 186 const char *sname;
187
179 if (pctx == NULL) 188 if (pctx == NULL)
180 pctx = &default_pctx; 189 pctx = &default_pctx;
181 if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME) 190 if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME)
182 sname = NULL; 191 sname = NULL;
183 else 192 else
184 sname = it->sname; 193 sname = it->sname;
185 return asn1_item_print_ctx(out, &ifld, indent, it, 194 return asn1_item_print_ctx(out, &ifld, indent, it, NULL, sname,
186 NULL, sname, 0, pctx); 195 0, pctx);
187} 196}
188 197
189static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, 198static int
190 const ASN1_ITEM *it, 199asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, const ASN1_ITEM *it,
191 const char *fname, const char *sname, 200 const char *fname, const char *sname, int nohdr, const ASN1_PCTX *pctx)
192 int nohdr, const ASN1_PCTX *pctx)
193{ 201{
194 const ASN1_TEMPLATE *tt; 202 const ASN1_TEMPLATE *tt;
195 const ASN1_EXTERN_FUNCS *ef; 203 const ASN1_EXTERN_FUNCS *ef;
@@ -198,18 +206,19 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
198 ASN1_aux_cb *asn1_cb; 206 ASN1_aux_cb *asn1_cb;
199 ASN1_PRINT_ARG parg; 207 ASN1_PRINT_ARG parg;
200 int i; 208 int i;
209
201 if (aux && aux->asn1_cb) { 210 if (aux && aux->asn1_cb) {
202 parg.out = out; 211 parg.out = out;
203 parg.indent = indent; 212 parg.indent = indent;
204 parg.pctx = pctx; 213 parg.pctx = pctx;
205 asn1_cb = aux->asn1_cb; 214 asn1_cb = aux->asn1_cb;
206 } 215 } else
207 else asn1_cb = 0; 216 asn1_cb = 0;
208 217
209 if(*fld == NULL) { 218 if (*fld == NULL) {
210 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) { 219 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) {
211 if (!nohdr && !asn1_print_fsname(out, indent, 220 if (!nohdr &&
212 fname, sname, pctx)) 221 !asn1_print_fsname(out, indent, fname, sname, pctx))
213 return 0; 222 return 0;
214 if (BIO_puts(out, "<ABSENT>\n") <= 0) 223 if (BIO_puts(out, "<ABSENT>\n") <= 0)
215 return 0; 224 return 0;
@@ -217,22 +226,23 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
217 return 1; 226 return 1;
218 } 227 }
219 228
220 switch(it->itype) { 229 switch (it->itype) {
221 case ASN1_ITYPE_PRIMITIVE: 230 case ASN1_ITYPE_PRIMITIVE:
222 if(it->templates) { 231 if (it->templates) {
223 if (!asn1_template_print_ctx(out, fld, indent, 232 if (!asn1_template_print_ctx(out, fld, indent,
224 it->templates, pctx)) 233 it->templates, pctx))
225 return 0; 234 return 0;
226 } 235 }
227 /* fall thru */ 236 /* fall thru */
228 case ASN1_ITYPE_MSTRING: 237 case ASN1_ITYPE_MSTRING:
229 if (!asn1_primitive_print(out, fld, it, 238 if (!asn1_primitive_print(out, fld, it,
230 indent, fname, sname,pctx)) 239 indent, fname, sname, pctx))
231 return 0; 240 return 0;
232 break; 241 break;
233 242
234 case ASN1_ITYPE_EXTERN: 243 case ASN1_ITYPE_EXTERN:
235 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) 244 if (!nohdr &&
245 !asn1_print_fsname(out, indent, fname, sname, pctx))
236 return 0; 246 return 0;
237 /* Use new style print routine if possible */ 247 /* Use new style print routine if possible */
238 ef = it->funcs; 248 ef = it->funcs;
@@ -243,23 +253,23 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
243 if ((i == 2) && (BIO_puts(out, "\n") <= 0)) 253 if ((i == 2) && (BIO_puts(out, "\n") <= 0))
244 return 0; 254 return 0;
245 return 1; 255 return 1;
246 } 256 } else if (sname &&
247 else if (sname && 257 BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0)
248 BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0)
249 return 0; 258 return 0;
250 break; 259 break;
251 260
252 case ASN1_ITYPE_CHOICE: 261 case ASN1_ITYPE_CHOICE:
253#if 0 262#if 0
254 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) 263 if (!nohdr &&
264 !asn1_print_fsname(out, indent, fname, sname, pctx))
255 return 0; 265 return 0;
256#endif 266#endif
257 /* CHOICE type, get selector */ 267 /* CHOICE type, get selector */
258 i = asn1_get_choice_selector(fld, it); 268 i = asn1_get_choice_selector(fld, it);
259 /* This should never happen... */ 269 /* This should never happen... */
260 if((i < 0) || (i >= it->tcount)) { 270 if ((i < 0) || (i >= it->tcount)) {
261 if (BIO_printf(out, 271 if (BIO_printf(out,
262 "ERROR: selector [%d] invalid\n", i) <= 0) 272 "ERROR: selector [%d] invalid\n", i) <= 0)
263 return 0; 273 return 0;
264 return 1; 274 return 1;
265 } 275 }
@@ -271,7 +281,8 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
271 281
272 case ASN1_ITYPE_SEQUENCE: 282 case ASN1_ITYPE_SEQUENCE:
273 case ASN1_ITYPE_NDEF_SEQUENCE: 283 case ASN1_ITYPE_NDEF_SEQUENCE:
274 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) 284 if (!nohdr &&
285 !asn1_print_fsname(out, indent, fname, sname, pctx))
275 return 0; 286 return 0;
276 if (fname || sname) { 287 if (fname || sname) {
277 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) { 288 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
@@ -292,12 +303,12 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
292 } 303 }
293 304
294 /* Print each field entry */ 305 /* Print each field entry */
295 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) { 306 for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
296 const ASN1_TEMPLATE *seqtt; 307 const ASN1_TEMPLATE *seqtt;
297 seqtt = asn1_do_adb(fld, tt, 1); 308 seqtt = asn1_do_adb(fld, tt, 1);
298 tmpfld = asn1_get_field_ptr(fld, seqtt); 309 tmpfld = asn1_get_field_ptr(fld, seqtt);
299 if (!asn1_template_print_ctx(out, tmpfld, 310 if (!asn1_template_print_ctx(out, tmpfld, indent + 2,
300 indent + 2, seqtt, pctx)) 311 seqtt, pctx))
301 return 0; 312 return 0;
302 } 313 }
303 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) { 314 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
@@ -312,7 +323,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
312 } 323 }
313 break; 324 break;
314 325
315 default: 326 default:
316 BIO_printf(out, "Unprocessed type %d\n", it->itype); 327 BIO_printf(out, "Unprocessed type %d\n", it->itype);
317 return 0; 328 return 0;
318 } 329 }
@@ -320,65 +331,65 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
320 return 1; 331 return 1;
321} 332}
322 333
323int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, 334int
324 const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx) 335asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
336 const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx)
325{ 337{
326 int i, flags; 338 int i, flags;
327 const char *sname, *fname; 339 const char *sname, *fname;
340
328 flags = tt->flags; 341 flags = tt->flags;
329 if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME) 342 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME)
330 sname = ASN1_ITEM_ptr(tt->item)->sname; 343 sname = ASN1_ITEM_ptr(tt->item)->sname;
331 else 344 else
332 sname = NULL; 345 sname = NULL;
333 if(pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME) 346 if (pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
334 fname = NULL; 347 fname = NULL;
335 else 348 else
336 fname = tt->field_name; 349 fname = tt->field_name;
337 if(flags & ASN1_TFLG_SK_MASK) { 350 if (flags & ASN1_TFLG_SK_MASK) {
338 char *tname; 351 char *tname;
339 ASN1_VALUE *skitem; 352 ASN1_VALUE *skitem;
340 STACK_OF(ASN1_VALUE) *stack; 353 STACK_OF(ASN1_VALUE) *stack;
341 354
342 /* SET OF, SEQUENCE OF */ 355 /* SET OF, SEQUENCE OF */
343 if (fname) { 356 if (fname) {
344 if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) { 357 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) {
345 if(flags & ASN1_TFLG_SET_OF) 358 if (flags & ASN1_TFLG_SET_OF)
346 tname = "SET"; 359 tname = "SET";
347 else 360 else
348 tname = "SEQUENCE"; 361 tname = "SEQUENCE";
349 if (BIO_printf(out, "%*s%s OF %s {\n", 362 if (BIO_printf(out, "%*s%s OF %s {\n",
350 indent, "", tname, tt->field_name) <= 0) 363 indent, "", tname, tt->field_name) <= 0)
351 return 0; 364 return 0;
352 } 365 } else if (BIO_printf(out, "%*s%s:\n", indent, "",
353 else if (BIO_printf(out, "%*s%s:\n", indent, "", 366 fname) <= 0)
354 fname) <= 0)
355 return 0; 367 return 0;
356 } 368 }
357 stack = (STACK_OF(ASN1_VALUE) *)*fld; 369 stack = (STACK_OF(ASN1_VALUE) *)*fld;
358 for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) { 370 for (i = 0; i < sk_ASN1_VALUE_num(stack); i++) {
359 if ((i > 0) && (BIO_puts(out, "\n") <= 0)) 371 if ((i > 0) && (BIO_puts(out, "\n") <= 0))
360 return 0; 372 return 0;
361
362 skitem = sk_ASN1_VALUE_value(stack, i); 373 skitem = sk_ASN1_VALUE_value(stack, i);
363 if (!asn1_item_print_ctx(out, &skitem, indent + 2, 374 if (!asn1_item_print_ctx(out, &skitem, indent + 2,
364 ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx)) 375 ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx))
365 return 0; 376 return 0;
366 } 377 }
367 if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0) 378 if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
368 return 0; 379 return 0;
369 if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) { 380 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
370 if (BIO_printf(out, "%*s}\n", indent, "") <= 0) 381 if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
371 return 0; 382 return 0;
372 } 383 }
373 return 1; 384 return 1;
374 } 385 }
375 return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item), 386 return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item),
376 fname, sname, 0, pctx); 387 fname, sname, 0, pctx);
377} 388}
378 389
379static int asn1_print_fsname(BIO *out, int indent, 390static int
380 const char *fname, const char *sname, 391asn1_print_fsname(BIO *out, int indent, const char *fname, const char *sname,
381 const ASN1_PCTX *pctx) 392 const ASN1_PCTX *pctx)
382{ 393{
383 static char spaces[] = " "; 394 static char spaces[] = " ";
384 const int nspaces = sizeof(spaces) - 1; 395 const int nspaces = sizeof(spaces) - 1;
@@ -419,8 +430,8 @@ static int asn1_print_fsname(BIO *out, int indent,
419 return 1; 430 return 1;
420} 431}
421 432
422static int asn1_print_boolean_ctx(BIO *out, int boolval, 433static int
423 const ASN1_PCTX *pctx) 434asn1_print_boolean_ctx(BIO *out, int boolval, const ASN1_PCTX *pctx)
424{ 435{
425 const char *str; 436 const char *str;
426 switch (boolval) { 437 switch (boolval) {
@@ -432,7 +443,7 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval,
432 str = "FALSE"; 443 str = "FALSE";
433 break; 444 break;
434 445
435 default: 446 default:
436 str = "TRUE"; 447 str = "TRUE";
437 break; 448 break;
438 449
@@ -444,8 +455,8 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval,
444 455
445} 456}
446 457
447static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, 458static int
448 const ASN1_PCTX *pctx) 459asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, const ASN1_PCTX *pctx)
449{ 460{
450 char *s; 461 char *s;
451 int ret = 1; 462 int ret = 1;
@@ -456,13 +467,13 @@ static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str,
456 return ret; 467 return ret;
457} 468}
458 469
459static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, 470static int
460 const ASN1_PCTX *pctx) 471asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, const ASN1_PCTX *pctx)
461{ 472{
462 char objbuf[80]; 473 char objbuf[80];
463 const char *ln; 474 const char *ln;
464 ln = OBJ_nid2ln(OBJ_obj2nid(oid)); 475 ln = OBJ_nid2ln(OBJ_obj2nid(oid));
465 if(!ln) 476 if (!ln)
466 ln = ""; 477 ln = "";
467 OBJ_obj2txt(objbuf, sizeof objbuf, oid, 1); 478 OBJ_obj2txt(objbuf, sizeof objbuf, oid, 1);
468 if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0) 479 if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0)
@@ -470,36 +481,36 @@ static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid,
470 return 1; 481 return 1;
471} 482}
472 483
473static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, 484static int
474 const ASN1_PCTX *pctx) 485asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
486 const ASN1_PCTX *pctx)
475{ 487{
476 if (str->type == V_ASN1_BIT_STRING) { 488 if (str->type == V_ASN1_BIT_STRING) {
477 if (BIO_printf(out, " (%ld unused bits)\n", 489 if (BIO_printf(out, " (%ld unused bits)\n",
478 str->flags & 0x7) <= 0) 490 str->flags & 0x7) <= 0)
479 return 0; 491 return 0;
480 } 492 } else if (BIO_puts(out, "\n") <= 0)
481 else if (BIO_puts(out, "\n") <= 0)
482 return 0; 493 return 0;
483 if ((str->length > 0) 494 if ((str->length > 0) &&
484 && BIO_dump_indent(out, (char *)str->data, str->length, 495 BIO_dump_indent(out, (char *)str->data, str->length,
485 indent + 2) <= 0) 496 indent + 2) <= 0)
486 return 0; 497 return 0;
487 return 1; 498 return 1;
488} 499}
489 500
490static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, 501static int
491 const ASN1_ITEM *it, int indent, 502asn1_primitive_print(BIO *out, ASN1_VALUE **fld, const ASN1_ITEM *it,
492 const char *fname, const char *sname, 503 int indent, const char *fname, const char *sname, const ASN1_PCTX *pctx)
493 const ASN1_PCTX *pctx)
494{ 504{
495 long utype; 505 long utype;
496 ASN1_STRING *str; 506 ASN1_STRING *str;
497 int ret = 1, needlf = 1; 507 int ret = 1, needlf = 1;
498 const char *pname; 508 const char *pname;
499 const ASN1_PRIMITIVE_FUNCS *pf; 509 const ASN1_PRIMITIVE_FUNCS *pf;
510
500 pf = it->funcs; 511 pf = it->funcs;
501 if (!asn1_print_fsname(out, indent, fname, sname, pctx)) 512 if (!asn1_print_fsname(out, indent, fname, sname, pctx))
502 return 0; 513 return 0;
503 if (pf && pf->prim_print) 514 if (pf && pf->prim_print)
504 return pf->prim_print(out, fld, it, indent, pctx); 515 return pf->prim_print(out, fld, it, indent, pctx);
505 str = (ASN1_STRING *)*fld; 516 str = (ASN1_STRING *)*fld;
@@ -514,12 +525,12 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
514 str = (ASN1_STRING *)*fld; 525 str = (ASN1_STRING *)*fld;
515 if (pctx->flags & ASN1_PCTX_FLAGS_NO_ANY_TYPE) 526 if (pctx->flags & ASN1_PCTX_FLAGS_NO_ANY_TYPE)
516 pname = NULL; 527 pname = NULL;
517 else 528 else
518 pname = ASN1_tag2str(utype); 529 pname = ASN1_tag2str(utype);
519 } else { 530 } else {
520 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE) 531 if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE)
521 pname = ASN1_tag2str(utype); 532 pname = ASN1_tag2str(utype);
522 else 533 else
523 pname = NULL; 534 pname = NULL;
524 } 535 }
525 536
@@ -575,14 +586,13 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
575 if (BIO_puts(out, "\n") <= 0) 586 if (BIO_puts(out, "\n") <= 0)
576 return 0; 587 return 0;
577 if (ASN1_parse_dump(out, str->data, str->length, 588 if (ASN1_parse_dump(out, str->data, str->length,
578 indent, 0) <= 0) 589 indent, 0) <= 0)
579 ret = 0; 590 ret = 0;
580 needlf = 0; 591 needlf = 0;
581 break; 592 break;
582 593
583 default: 594 default:
584 ret = ASN1_STRING_print_ex(out, str, pctx->str_flags); 595 ret = ASN1_STRING_print_ex(out, str, pctx->str_flags);
585
586 } 596 }
587 if (!ret) 597 if (!ret)
588 return 0; 598 return 0;