Try to parse inner structure of an octet string (limited to CONS SEQ right now)

This commit is contained in:
Love Hornquist Astrand
2011-04-25 11:33:58 -07:00
parent b3811999f7
commit 074a30618f

View File

@@ -41,9 +41,8 @@
#include <err.h>
#include <der.h>
RCSID("$Id$");
static int indent_flag = 1;
static int inner_flag = 0;
static unsigned long indefinite_form_loop;
static unsigned long indefinite_form_loop_max = 10000;
@@ -167,17 +166,39 @@ loop (unsigned char *buf, size_t len, int indent)
}
case UT_OctetString : {
heim_octet_string str;
int i;
unsigned char *uc;
size_t i;
ret = der_get_octet_string (buf, length, &str, NULL);
if (ret)
errx (1, "der_get_octet_string: %s", error_message (ret));
printf ("(length %lu), ", (unsigned long)length);
uc = (unsigned char *)str.data;
for (i = 0; i < min(16,length); ++i)
printf ("%02x", uc[i]);
printf ("\n");
if (inner_flag) {
Der_class class;
Der_type type;
unsigned int tag;
ret = der_get_tag(str.data, str.length,
&class, &type, &tag, &sz);
if (ret || sz > str.length ||
type != CONS || tag != UT_Sequence)
goto just_an_octet_string;
printf("{\n");
loop (str.data, str.length, indent + 2);
for (i = 0; i < indent; ++i)
printf (" ");
printf ("}\n");
} else {
unsigned char *uc;
just_an_octet_string:
uc = (unsigned char *)str.data;
for (i = 0; i < min(16,length); ++i)
printf ("%02x", uc[i]);
printf ("\n");
}
free (str.data);
break;
}
@@ -295,6 +316,7 @@ static int version_flag;
static int help_flag;
struct getargs args[] = {
{ "indent", 0, arg_negative_flag, &indent_flag },
{ "inner", 0, arg_flag, &inner_flag, "try to parse inner structures of OCTET STRING" },
{ "version", 0, arg_flag, &version_flag },
{ "help", 0, arg_flag, &help_flag }
};