18 static int do_dumpBER(FILE *f,
const char *buf,
int len,
int level,
int offset)
20 int res, ll, zclass, tag, cons, lenlen, taglen;
25 sprintf(level_str,
"level=%-6d%*s", level, 18,
"");
27 sprintf(level_str,
"%*s", level * 2,
"");
31 if (!buf[0] && !buf[1])
33 if ((res =
ber_dectag(b, &zclass, &tag, &cons, len)) <= 0)
37 fprintf(f,
"%5d: %s : Unexpected end of buffer\n", offset, level_str);
40 fprintf(f,
"%5d: %s", offset, level_str);
45 "[Univ 0]",
"BOOLEAN",
"INTEGER",
"BIT STRING",
"OCTET STRING",
46 "NULL",
"OID",
"OBJECT DESCRIPTOR",
"EXTERNAL",
"REAL",
47 "ENUM",
"[UNIV 11]",
"[UNIV 12]",
"[UNIV 13]",
"[UNIV 14]",
48 "[UNIV 15]",
"SEQUENCE",
"SET",
"NUMERICSTRING",
"PRINTABLESTRING",
49 "[UNIV 20]",
"[UNIV 21]",
"[UNIV 22]",
"[UNIV 23]",
"[UNIV 24]",
50 "GRAPHICSTRING",
"VISIBLESTRING",
"GENERALSTRING",
"[UNIV 28]"
53 if (tag >= 0 && tag < 28)
54 fprintf(f,
"%s", nl[tag]);
56 fprintf(f,
"[UNIV %d]", tag);
59 fprintf(f,
"[%d]", tag);
61 fprintf(f,
"[%d:%d]", zclass, tag);
67 fprintf(f,
"\n%sBad length\n", level_str);
74 fprintf(f,
" len=%d", ll);
77 fprintf(f,
" tl=%d, ll=%d cons=%d\n", taglen, lenlen, cons);
80 if (ll < 0 || ll > len)
82 fprintf(f,
"%sBad length on primitive type. ll=%d len=%d\n",
86 return ll + (b - buf);
92 fprintf(f,
"%sBad length of constructed type ll=%d len=%d\n",
99 while ((ll == -1 && len >= 2) || (ll >= 0 && len))
101 if (ll == -1 && *b == 0 && *(b + 1) == 0)
103 if (!(res =
do_dumpBER(f, b, len, level + 1, offset + (b - buf))))
105 fprintf(f,
"%s Dump of content element failed\n", level_str);
112 fprintf(f,
"%sBad length\n", level_str);
120 fprintf(f,
"%sBuffer too short in indefinite length\n",
124 return (b - buf) + 2;
int ber_declen(const char *buf, int *len, int max)
int ber_dectag(const char *cp, int *zclass, int *tag, int *constructed, int max)
Decodes BER identifier octets.
static int do_dumpBER(FILE *f, const char *buf, int len, int level, int offset)
int odr_dumpBER(FILE *f, const char *buf, int len)
Internal ODR definitions.