2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1995-06-19 12:38:45 quinn
16 static int do_dumpBER(FILE *f, char *buf, int len, int level)
18 int res, ll, class, tag, cons;
23 if (!buf[0] && !buf[1])
25 if ((res = ber_dectag(b, &class, &tag, &cons)) <= 0)
29 fprintf(stderr, "Unexpected end of buffer\n");
32 fprintf(stderr, "%*s", level * 4, "");
33 if (class == ODR_UNIVERSAL)
37 "Ugh", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING",
38 "NULL", "OID", "OBJECT DESCIPTOR", "EXTERNAL", "REAL",
39 "ENUM", "[UNIV 11]", "[UNIV 12]", "[UNIV 13]", "[UNIV 14]",
40 "[UNIV 15]", "SEQUENCE", "SET", "NUMERICSTRING", "PRINTABLESTRING",
41 "[UNIV 20]", "[UNIV 21]", "[UNIV 22]", "[UNIV 23]", "[UNIV 24]",
42 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", "[UNIV 28]"
46 fprintf(stderr, "%s", nl[tag]);
48 fprintf(stderr, "[UNIV %d]", tag);
50 else if (class == ODR_CONTEXT)
51 fprintf(stderr, "[%d]", tag);
53 fprintf(stderr, "[%d:%d]", class, tag);
56 if ((res = ber_declen(b, &ll)) <= 0)
58 fprintf(stderr, "bad length\n");
63 fprintf(stderr, "Unexpected end of buffer\n");
69 fprintf(stderr, " len=%d\n", ll);
71 fprintf(stderr, " len=?\n");
76 fprintf(stderr, "Bad length on primitive type.\n");
79 return ll + (b - buf);
83 /* constructed - cycle through children */
84 while ((ll == -1 && len >= 2) || (ll >= 0 && len))
86 if (ll == -1 && *b == 0 && *(b + 1) == 0)
88 if (!(res = do_dumpBER(f, b, len, level + 1)))
90 fprintf(stderr, "Dump of content element failed.\n");
100 fprintf(stderr, "Buffer too short in indefinite lenght.\n");
103 return (b - buf) + 2;
108 int odr_dumpBER(FILE *f, char *buf, int len)
110 return do_dumpBER(f, buf, len, 0);