2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-06-27 13:20:51 quinn
8 * Fixed sign-clash. Non-fatal warning
10 * Revision 1.1 1995/06/19 12:38:45 quinn
19 static int do_dumpBER(FILE *f, char *buf, int len, int level)
21 int res, ll, class, tag, cons;
26 if (!buf[0] && !buf[1])
28 if ((res = ber_dectag((unsigned char*)b, &class, &tag, &cons)) <= 0)
32 fprintf(stderr, "Unexpected end of buffer\n");
35 fprintf(stderr, "%*s", level * 4, "");
36 if (class == ODR_UNIVERSAL)
40 "Ugh", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING",
41 "NULL", "OID", "OBJECT DESCIPTOR", "EXTERNAL", "REAL",
42 "ENUM", "[UNIV 11]", "[UNIV 12]", "[UNIV 13]", "[UNIV 14]",
43 "[UNIV 15]", "SEQUENCE", "SET", "NUMERICSTRING", "PRINTABLESTRING",
44 "[UNIV 20]", "[UNIV 21]", "[UNIV 22]", "[UNIV 23]", "[UNIV 24]",
45 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", "[UNIV 28]"
49 fprintf(stderr, "%s", nl[tag]);
51 fprintf(stderr, "[UNIV %d]", tag);
53 else if (class == ODR_CONTEXT)
54 fprintf(stderr, "[%d]", tag);
56 fprintf(stderr, "[%d:%d]", class, tag);
59 if ((res = ber_declen((unsigned char*)b, &ll)) <= 0)
61 fprintf(stderr, "bad length\n");
66 fprintf(stderr, "Unexpected end of buffer\n");
72 fprintf(stderr, " len=%d\n", ll);
74 fprintf(stderr, " len=?\n");
79 fprintf(stderr, "Bad length on primitive type.\n");
82 return ll + (b - buf);
86 /* constructed - cycle through children */
87 while ((ll == -1 && len >= 2) || (ll >= 0 && len))
89 if (ll == -1 && *b == 0 && *(b + 1) == 0)
91 if (!(res = do_dumpBER(f, b, len, level + 1)))
93 fprintf(stderr, "Dump of content element failed.\n");
103 fprintf(stderr, "Buffer too short in indefinite lenght.\n");
106 return (b - buf) + 2;
111 int odr_dumpBER(FILE *f, char *buf, int len)
113 return do_dumpBER(f, buf, len, 0);