[Redbutton-devel] SF.net SVN: redbutton: [458] redbutton-author/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-11-08 17:32:04
|
Revision: 458
http://redbutton.svn.sourceforge.net/redbutton/?rev=458&view=rev
Author: skilvington
Date: 2007-11-08 09:31:58 -0800 (Thu, 08 Nov 2007)
Log Message:
-----------
back to where we were before, but with a prettier asn1decode.c
Modified Paths:
--------------
redbutton-author/trunk/TODO
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO 2007-11-02 17:24:31 UTC (rev 457)
+++ redbutton-author/trunk/TODO 2007-11-08 17:31:58 UTC (rev 458)
@@ -11,9 +11,8 @@
---
mhegd
-HorizontalJustification doesn't work
-EventTypeEnum does
-ie ENUMERATED types without an explicit ENUMERATED tag don't work
+HorizontalJustification needs writing
+ie ENUMERATED types without an explicit ENUMERATED tag
---
@@ -25,6 +24,7 @@
mhegd
:ContentRef ContentReference keeps the tag as part of the OctetString
+(eg enh_gateway.mhg)
---
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-11-02 17:24:31 UTC (rev 457)
+++ redbutton-author/trunk/ccc.y 2007-11-08 17:31:58 UTC (rev 458)
@@ -825,19 +825,16 @@
/* assert */
if(item->type != IT_IDENTIFIER && item->type != IT_ONEORMORE && item->type != IT_OPTIONAL)
fatal("not IDENTIFIER, ONEORMORE or OPTIONAL");
+/* TODO */
/* is it OPTIONAL - check if length == 0, if so bomb out now */
-/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
- /* if it is ONEORMORE we need a while loop */
- if(item->type == IT_ONEORMORE)
- buf_append(&state.decode_fns, "\twhile(left > 0)\n\t{\n");
/* is it a primitive type */
if(strcmp(item->name, "BOOLEAN") == 0
|| strcmp(item->name, "INTEGER") == 0
|| strcmp(item->name, "OctetString") == 0)
{
/* assert */
- if(item->type != IT_IDENTIFIER && item->type != IT_ONEORMORE)
- fatal("Primitive but not Identifier or Identifier+");
+ if(item->type != IT_IDENTIFIER)
+ fatal("Primitive but not Identifier");
/* does it need an extra explicit tag for the primitive type? */
if(asn1tagclass(name) != asn1tagclass(item->name))
{
@@ -850,11 +847,11 @@
{
/* do need an explicit primitive tag */
buf_append(&state.decode_fns, "\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
- buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n", name);
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n\n", name);
buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n", item->name);
buf_append(&state.decode_fns, "\t{\n");
buf_append(&state.decode_fns, "\t\tfseek(der, -sublen, SEEK_CUR);\n");
- buf_append(&state.decode_fns, "\t\tif((sublen = asn1decode_%s(der, out, sublen + tag.length)) < 0)\n", item->name);
+ buf_append(&state.decode_fns, "\t\tif((sublen = asn1decode_%s(der, out, length)) < 0)\n", item->name);
buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n", name);
buf_append(&state.decode_fns, "\t\tleft -= sublen;\n");
buf_append(&state.decode_fns, "\t}\n");
@@ -864,123 +861,79 @@
buf_append(&state.decode_fns, "\t}\n");
}
}
-#if 0
- /* is it an ENUMERATED type */
- else if(asn1tagclass(item->name) == ASN1TAGCLASS_ENUMERATED)
+ /* is it an ENUMERATED type which does not need an explicit ENUMERATED tag */
+ else if(asn1tagclass(name) != ASN1TAGCLASS_ENUMERATED
+ && asn1tagclass(item->name) == ASN1TAGCLASS_ENUMERATED)
{
/* assert */
if(item->type != IT_IDENTIFIER)
fatal("ENUMERATED but not Identifier");
+/* TODO */
buf_append(&state.decode_fns, "printf(\"TODO: %s->%s\\n\");\nexit(1);\n",name,item->name);
}
-#endif
- /* else the whole length is the sub types value */
- else
+ /* is the whole length one or more sub types */
+ else if(item->type == IT_ONEORMORE)
{
+ /* if it is ONEORMORE we need a while loop */
+ if(item->type == IT_ONEORMORE)
+ buf_append(&state.decode_fns, "\twhile(left > 0)\n\t{\n");
/* decode the item */
- buf_append(&state.decode_fns, "\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
- buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n", name);
- buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t\t{\n", item->name);
- /* if it is a synthetic or primitive type, we still need the current tag */
- if(keep_tag(asn1tagclass(item->name)))
- {
- buf_append(&state.decode_fns, "\t\tfseek(der, -sublen, SEEK_CUR);\n");
- buf_append(&state.decode_fns, "\t\tsublen = asn1decode_%s(der, out, sublen + tag.length);\n", item->name);
- }
- else
- {
- buf_append(&state.decode_fns, "\t\tleft -= sublen;\n");
- buf_append(&state.decode_fns, "\t\tsublen = asn1decode_%s(der, out, tag.length);\n", item->name);
- }
- buf_append(&state.decode_fns, "\t\tif(sublen < 0)\n");
- buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n", name);
- buf_append(&state.decode_fns, "\t\tleft -= sublen;\n\n");
- buf_append(&state.decode_fns, "\t}\n");
- buf_append(&state.decode_fns, "\telse\n");
- buf_append(&state.decode_fns, "\t{\n");
- buf_append(&state.decode_fns, "\t\treturn der_error(\"%s: unexpected tag [%%s %%u]\", asn1class_name(tag.class), tag.number);\n", name);
- buf_append(&state.decode_fns, "\t}");
- }
- /* if it is ONEORMORE we need a while loop */
- if(item->type == IT_ONEORMORE)
- buf_append(&state.decode_fns, "\t}\n");
- buf_append(&state.decode_fns, "\n");
-#if 0
-/* is it OPTIONAL - check if length == 0, if so bomb out now */
-/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
- /* is it a primitive type */
- if(strcmp(item->name, "OctetString") == 0
- || asn1tagclass(item->name) == ASN1TAGCLASS_BOOLEAN
- || asn1tagclass(item->name) == ASN1TAGCLASS_INTEGER
- || asn1tagclass(item->name) == ASN1TAGCLASS_ENUMERATED)
- {
- /* assert */
- if(item->type != IT_IDENTIFIER && item->type != IT_ONEORMORE)
- fatal("Primitive but not Identifier");
- /* does it need an extra explicit tag for the primitive type? */
- buf_append(&state.decode_fns, "\tif(ASN1TAGCLASS_%s != ASN1TAGCLASS_%s)\n", name, item->name);
- buf_append(&state.decode_fns, "\t{\n");
- if(asn1tagclass(item->name) != ASN1TAGCLASS_ENUMERATED)
- buf_append(&state.decode_fns, "\t\tif((sublen = der_decode_%s(der, out, length)) < 0)\n", item->name);
- else
- buf_append(&state.decode_fns, "\t\tif((sublen = asn1decode_%s(der, out, length)) < 0)\n", item->name);
- buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n", name);
- buf_append(&state.decode_fns, "\t\tleft -= sublen;\n");
- buf_append(&state.decode_fns, "\t}\n");
- buf_append(&state.decode_fns, "\telse\n");
- }
- /* is it ONEORMORE - need a while(left > 0) loop */
- if(item->type == IT_ONEORMORE)
- {
- buf_append(&state.decode_fns, "\twhile(left > 0)\n\t{\n");
- /* decode the item */
buf_append(&state.decode_fns, "\t\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
- buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n", name);
- buf_append(&state.decode_fns, "\t\tleft -= sublen;\n\n");
- buf_append(&state.decode_fns, "\t\tif(is_%s(tag.class, tag.number))\n\t\t{\n", item->name);
+ buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n\n", name);
+ buf_append(&state.decode_fns, "\t\tif(is_%s(tag.class, tag.number))\n", item->name);
+ buf_append(&state.decode_fns, "\t\t{\n");
/* if it is a synthetic or primitive type, we still need the current tag */
if(keep_tag(asn1tagclass(item->name)))
{
buf_append(&state.decode_fns, "\t\t\tfseek(der, -sublen, SEEK_CUR);\n");
- buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\t\tsublen = asn1decode_%s(der, out, sublen + tag.length);\n", item->name);
}
else
{
- buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\t\tleft -= sublen;\n");
+ buf_append(&state.decode_fns, "\t\t\tsublen = asn1decode_%s(der, out, tag.length);\n", item->name);
}
- buf_append(&state.decode_fns, "\t\t\tleft -= tag.length;\n");
- buf_append(&state.decode_fns, "\t\t}\n\t\telse\n");
- buf_append(&state.decode_fns, "\t\t{\n\t\t\treturn der_error(\"%s\");\n\t\t}\n", name);
- buf_append(&state.decode_fns, "\t}\n");
+ buf_append(&state.decode_fns, "\t\t\tif(sublen < 0)\n");
+ buf_append(&state.decode_fns, "\t\t\t\treturn der_error(\"%s\");\n", name);
+ buf_append(&state.decode_fns, "\t\t\tleft -= sublen;\n");
+ buf_append(&state.decode_fns, "\t\t}\n");
+ buf_append(&state.decode_fns, "\t\telse\n");
+ buf_append(&state.decode_fns, "\t\t{\n");
+ buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s: unexpected tag [%%s %%u]\", asn1class_name(tag.class), tag.number);\n", name);
+ buf_append(&state.decode_fns, "\t\t}\n");
+ /* if it is ONEORMORE we need a while loop */
+ if(item->type == IT_ONEORMORE)
+ buf_append(&state.decode_fns, "\t}\n");
}
+ /* else the whole length is the sub types value */
else
{
- /* the whole length is the sub types value */
- buf_append(&state.decode_fns, "\t{\n");
/* decode the item */
- buf_append(&state.decode_fns, "\t\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
- buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n", name);
- buf_append(&state.decode_fns, "\t\tif(is_%s(tag.class, tag.number))\n\t\t{\n", item->name);
+ buf_append(&state.decode_fns, "\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n\n", name);
+ buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n", item->name);
+ buf_append(&state.decode_fns, "\t{\n");
/* if it is a synthetic or primitive type, we still need the current tag */
if(keep_tag(asn1tagclass(item->name)))
{
- buf_append(&state.decode_fns, "\t\t\tfseek(der, -sublen, SEEK_CUR);\n");
- buf_append(&state.decode_fns, "\t\t\tsublen = asn1decode_%s(der, out, length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\tfseek(der, -sublen, SEEK_CUR);\n");
+ buf_append(&state.decode_fns, "\t\tsublen = asn1decode_%s(der, out, length);\n", item->name);
}
else
{
- buf_append(&state.decode_fns, "\t\t\tleft -= sublen;\n");
- buf_append(&state.decode_fns, "\t\t\tsublen = asn1decode_%s(der, out, tag.length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\tleft -= sublen;\n");
+ buf_append(&state.decode_fns, "\t\tsublen = asn1decode_%s(der, out, tag.length);\n", item->name);
}
- buf_append(&state.decode_fns, "\t\t\tif(sublen < 0)\n");
- buf_append(&state.decode_fns, "\t\t\t\treturn der_error(\"%s\");\n", name);
- buf_append(&state.decode_fns, "\t\t\tleft -= sublen;\n\n");
- buf_append(&state.decode_fns, "\t\t}\n\t\telse\n");
- buf_append(&state.decode_fns, "\t\t{\n\t\t\treturn der_error(\"%s\");\n\t\t}\n", name);
+ buf_append(&state.decode_fns, "\t\tif(sublen < 0)\n");
+ buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n", name);
+ buf_append(&state.decode_fns, "\t\tleft -= sublen;\n");
buf_append(&state.decode_fns, "\t}\n");
+ buf_append(&state.decode_fns, "\telse\n");
+ buf_append(&state.decode_fns, "\t{\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s: unexpected tag [%%s %%u]\", asn1class_name(tag.class), tag.number);\n", name);
+ buf_append(&state.decode_fns, "\t}\n");
}
buf_append(&state.decode_fns, "\n");
-#endif
/* is_Xxx() function */
buf_append(&state.decode_is_fns, "\t\treturn is_%s(class, number);\n", item->name);
/* output any literals at the end */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|