Thread: [Redbutton-devel] SF.net SVN: redbutton: [395] redbutton-author/trunk (Page 2)
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-09-18 13:02:59
|
Revision: 395
http://redbutton.svn.sourceforge.net/redbutton/?rev=395&view=rev
Author: skilvington
Date: 2007-09-18 06:02:58 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
resolve synthetic types where needed
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/parser.c.header
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-18 12:55:32 UTC (rev 394)
+++ redbutton-author/trunk/asn1tag.h 2007-09-18 13:02:58 UTC (rev 395)
@@ -555,10 +555,12 @@
#define ASN1TAG_BOOLEAN 1
#define ASN1TAG_INTEGER 2
#define ASN1TAG_OctetString 4
+#define ASN1TAG_Null 5
/* and with the class included */
#define ASN1TAGCLASS_BOOLEAN ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_BOOLEAN)
#define ASN1TAGCLASS_INTEGER ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_INTEGER)
#define ASN1TAGCLASS_OctetString ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_OctetString)
+#define ASN1TAGCLASS_Null ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_Null)
/* UNIVERSAL ASN1 types in the grammar */
#define ASN1TAGCLASS_JointIsoItuIdentifier ASN1TAGCLASS_INTEGER
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-18 12:55:32 UTC (rev 394)
+++ redbutton-author/trunk/parser.c.header 2007-09-18 13:02:58 UTC (rev 395)
@@ -87,6 +87,13 @@
verbose("<BOOLEAN value=%s/>\n", token_text());
+ /* give our parent a UNIVERSAL type if it is synthetic */
+ if(is_synthetic(parent->asn1tag))
+ {
+ parent->asn1tag = ASN1TAG_BOOLEAN;
+ parent->asn1class = ASN1CLASS_UNIVERSAL;
+ }
+
der_encode_BOOLEAN(&parent->value, &parent->length, strcmp(token_text(), "false"));
return;
@@ -100,6 +107,13 @@
verbose("<INTEGER value=%s/>\n", token_text());
+ /* give our parent a UNIVERSAL type if it is synthetic */
+ if(is_synthetic(parent->asn1tag))
+ {
+ parent->asn1tag = ASN1TAG_INTEGER;
+ parent->asn1class = ASN1CLASS_UNIVERSAL;
+ }
+
der_encode_INTEGER(&parent->value, &parent->length, strtol(token_text(), NULL, 0));
return;
@@ -112,6 +126,13 @@
verbose("<STRING value=%s/>\n", token_text());
+ /* give our parent a UNIVERSAL type if it is synthetic */
+ if(is_synthetic(parent->asn1tag))
+ {
+ parent->asn1tag = ASN1TAG_OctetString;
+ parent->asn1class = ASN1CLASS_UNIVERSAL;
+ }
+
der_encode_OctetString(&parent->value, &parent->length, token_text());
return;
@@ -125,6 +146,13 @@
verbose("<QPRINTABLE value=%s/>\n", token_text());
+ /* give our parent a UNIVERSAL type if it is synthetic */
+ if(is_synthetic(parent->asn1tag))
+ {
+ parent->asn1tag = ASN1TAG_OctetString;
+ parent->asn1class = ASN1CLASS_UNIVERSAL;
+ }
+
der_encode_OctetString(&parent->value, &parent->length, token_text());
return;
@@ -138,6 +166,13 @@
verbose("<BASE64 value=%s/>\n", token_text());
+ /* give our parent a UNIVERSAL type if it is synthetic */
+ if(is_synthetic(parent->asn1tag))
+ {
+ parent->asn1tag = ASN1TAG_OctetString;
+ parent->asn1class = ASN1CLASS_UNIVERSAL;
+ }
+
der_encode_OctetString(&parent->value, &parent->length, token_text());
return;
@@ -155,6 +190,13 @@
if(parent->length != 0)
fatal("Null: length=%u", parent->length);
+ /* give our parent a UNIVERSAL type if it is synthetic */
+ if(is_synthetic(parent->asn1tag))
+ {
+ parent->asn1tag = ASN1TAG_Null;
+ parent->asn1class = ASN1CLASS_UNIVERSAL;
+ }
+
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-18 16:23:12
|
Revision: 396
http://redbutton.svn.sourceforge.net/redbutton/?rev=396&view=rev
Author: skilvington
Date: 2007-09-18 09:23:06 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
ENUMERATED, SEQUENCE and SET are not synthetic types
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-18 13:02:58 UTC (rev 395)
+++ redbutton-author/trunk/asn1tag.h 2007-09-18 16:23:06 UTC (rev 396)
@@ -24,11 +24,6 @@
#define ASN1TAG_SYNTHETIC 10000
/* the tag for CHOICE types is determined by which choice we choose */
#define ASN1TAG_CHOICE 10001
-/* ENUMERATED types are encoded as INTEGERs */
-#define ASN1TAG_ENUMERATED 10002
-/* SEQUENCEs and SETs are just used to group their children together */
-#define ASN1TAG_SEQUENCE 10003
-#define ASN1TAG_SET 10004
/* abstract types */
#define ASN1TAGCLASS_Root ASN1TAG_SYNTHETIC
@@ -556,11 +551,17 @@
#define ASN1TAG_INTEGER 2
#define ASN1TAG_OctetString 4
#define ASN1TAG_Null 5
+#define ASN1TAG_ENUMERATED 10
+#define ASN1TAG_SEQUENCE 16
+#define ASN1TAG_SET 17
/* and with the class included */
#define ASN1TAGCLASS_BOOLEAN ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_BOOLEAN)
#define ASN1TAGCLASS_INTEGER ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_INTEGER)
#define ASN1TAGCLASS_OctetString ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_OctetString)
#define ASN1TAGCLASS_Null ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_Null)
+#define ASN1TAGCLASS_ENUMERATED ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_ENUMERATED)
+#define ASN1TAGCLASS_SEQUENCE ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_SEQUENCE)
+#define ASN1TAGCLASS_SET ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_SET)
/* UNIVERSAL ASN1 types in the grammar */
#define ASN1TAGCLASS_JointIsoItuIdentifier ASN1TAGCLASS_INTEGER
@@ -575,14 +576,14 @@
#define ASN1TAGCLASS_SceneWeight ASN1TAGCLASS_INTEGER
#define ASN1TAGCLASS_IncludedContent ASN1TAGCLASS_OctetString
#define ASN1TAGCLASS_EventSource ASN1TAG_SYNTHETIC
-#define ASN1TAGCLASS_EventType ASN1TAG_ENUMERATED
+#define ASN1TAGCLASS_EventType ASN1TAGCLASS_ENUMERATED
#define ASN1TAGCLASS_EventData ASN1TAG_CHOICE
#define ASN1TAGCLASS_ObjectReferenceValue ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_ContentReferenceValue ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_TargetElement ASN1TAGCLASS_INTEGER
#define ASN1TAGCLASS_AVisible ASN1TAG_SYNTHETIC
-#define ASN1TAGCLASS_Position ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_BoxSize ASN1TAG_SEQUENCE
+#define ASN1TAGCLASS_Position ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_BoxSize ASN1TAGCLASS_SEQUENCE
#define ASN1TAGCLASS_XLength ASN1TAGCLASS_INTEGER
#define ASN1TAGCLASS_YLength ASN1TAGCLASS_INTEGER
#define ASN1TAGCLASS_AbsoluteTime ASN1TAG_SYNTHETIC
@@ -599,7 +600,7 @@
#define ASN1TAGCLASS_EllipseHeight ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_EllipseWidth ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_EmulatedEventSource ASN1TAG_SYNTHETIC
-#define ASN1TAGCLASS_EmulatedEventType ASN1TAG_ENUMERATED
+#define ASN1TAGCLASS_EmulatedEventType ASN1TAGCLASS_ENUMERATED
#define ASN1TAGCLASS_EntryPointVar ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_ForkSucceeded ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_Feature ASN1TAG_SYNTHETIC
@@ -704,21 +705,21 @@
#define ASN1TAGCLASS_AbsoluteColour ASN1TAGCLASS_OctetString
#define ASN1TAGCLASS_XPosition ASN1TAGCLASS_INTEGER
#define ASN1TAGCLASS_YPosition ASN1TAGCLASS_INTEGER
-#define ASN1TAGCLASS_ReferencedContent ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_XYPosition ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_Point ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_Rational ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_ExternalReference ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_NewReferencedContent ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_NextScene ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_TokenGroupItem ASN1TAG_SEQUENCE
+#define ASN1TAGCLASS_ReferencedContent ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_XYPosition ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_Point ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_Rational ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_ExternalReference ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_NewReferencedContent ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_NextScene ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_TokenGroupItem ASN1TAGCLASS_SEQUENCE
#define ASN1TAGCLASS_Movement ASN1TAGCLASS_INTEGER
-#define ASN1TAGCLASS_ActionSlots ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_InVariables ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_OutVariables ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_ActionClass ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_Parameters ASN1TAG_SEQUENCE
-#define ASN1TAGCLASS_PointList ASN1TAG_SEQUENCE
+#define ASN1TAGCLASS_ActionSlots ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_InVariables ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_OutVariables ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_ActionClass ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_Parameters ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_PointList ASN1TAGCLASS_SEQUENCE
#endif /* __ASN1TAG_H__ */
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-09-18 13:02:58 UTC (rev 395)
+++ redbutton-author/trunk/ccc.y 2007-09-18 16:23:06 UTC (rev 396)
@@ -459,12 +459,11 @@
/* assert */
if(state.and_items)
fatal("CHOICE or ENUMERATED type, but and_items set");
-/* TODO: these can probably both be ASN1TAGCLASS_SYNTHETIC */
/* add a child ASN1 object */
if(asn1type(name) == ASN1TYPE_CHOICE)
buf_append(&state.parse_fns, "\tparent = add_child(parent, ASN1TAG_CHOICE);\n\n");
- else
- buf_append(&state.parse_fns, "\tparent = add_child(parent, ASN1TAG_ENUMERATED);\n\n");
+// else
+// buf_append(&state.parse_fns, "\tparent = add_child(parent, ASN1TAGCLASS_ENUMERATED);\n\n");
/* peek at the next token */
buf_append(&state.parse_fns, "\tnext = peek_token();\n\n");
buf_append(&state.parse_fns, "\t/* CHOICE or ENUMERATED */\n");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-18 19:52:01
|
Revision: 399
http://redbutton.svn.sourceforge.net/redbutton/?rev=399&view=rev
Author: skilvington
Date: 2007-09-18 12:52:00 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
an OctetString in the grammar is different than an ASN1 OCTETSTRING type
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/parser.c.header
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-18 16:42:05 UTC (rev 398)
+++ redbutton-author/trunk/asn1tag.h 2007-09-18 19:52:00 UTC (rev 399)
@@ -43,6 +43,7 @@
#define ASN1TAGCLASS_LineArtBody ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_TextBody ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_PushButtonBody ASN1TAG_SYNTHETIC
+#define ASN1TAGCLASS_OctetString ASN1TAG_SYNTHETIC
/* ASN1 CONTEXT tag values */
#define ASN1TAG_ApplicationClass 0
@@ -549,16 +550,16 @@
/* ASN1 UNIVERSAL tag values */
#define ASN1TAG_BOOLEAN 1
#define ASN1TAG_INTEGER 2
-#define ASN1TAG_OctetString 4
-#define ASN1TAG_Null 5
+#define ASN1TAG_OCTETSTRING 4
+#define ASN1TAG_NULL 5
#define ASN1TAG_ENUMERATED 10
#define ASN1TAG_SEQUENCE 16
#define ASN1TAG_SET 17
/* and with the class included */
#define ASN1TAGCLASS_BOOLEAN ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_BOOLEAN)
#define ASN1TAGCLASS_INTEGER ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_INTEGER)
-#define ASN1TAGCLASS_OctetString ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_OctetString)
-#define ASN1TAGCLASS_Null ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_Null)
+#define ASN1TAGCLASS_OCTETSTRING ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_OCTETSTRING)
+#define ASN1TAGCLASS_NULL ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_NULL)
#define ASN1TAGCLASS_ENUMERATED ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_ENUMERATED)
#define ASN1TAGCLASS_SEQUENCE ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_SEQUENCE)
#define ASN1TAGCLASS_SET ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_SET)
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-18 16:42:05 UTC (rev 398)
+++ redbutton-author/trunk/parser.c.header 2007-09-18 19:52:00 UTC (rev 399)
@@ -129,7 +129,7 @@
/* give our parent a UNIVERSAL type if it is synthetic */
if(is_synthetic(parent->asn1tag))
{
- parent->asn1tag = ASN1TAG_OctetString;
+ parent->asn1tag = ASN1TAG_OCTETSTRING;
parent->asn1class = ASN1CLASS_UNIVERSAL;
}
@@ -149,7 +149,7 @@
/* give our parent a UNIVERSAL type if it is synthetic */
if(is_synthetic(parent->asn1tag))
{
- parent->asn1tag = ASN1TAG_OctetString;
+ parent->asn1tag = ASN1TAG_OCTETSTRING;
parent->asn1class = ASN1CLASS_UNIVERSAL;
}
@@ -169,7 +169,7 @@
/* give our parent a UNIVERSAL type if it is synthetic */
if(is_synthetic(parent->asn1tag))
{
- parent->asn1tag = ASN1TAG_OctetString;
+ parent->asn1tag = ASN1TAG_OCTETSTRING;
parent->asn1class = ASN1CLASS_UNIVERSAL;
}
@@ -193,7 +193,7 @@
/* give our parent a UNIVERSAL type if it is synthetic */
if(is_synthetic(parent->asn1tag))
{
- parent->asn1tag = ASN1TAG_Null;
+ parent->asn1tag = ASN1TAG_NULL;
parent->asn1class = ASN1CLASS_UNIVERSAL;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-19 11:47:19
|
Revision: 400
http://redbutton.svn.sourceforge.net/redbutton/?rev=400&view=rev
Author: skilvington
Date: 2007-09-19 04:47:16 -0700 (Wed, 19 Sep 2007)
Log Message:
-----------
OctetString nodes need to look at their parent's parent to decide whether to set the tag or not
Modified Paths:
--------------
redbutton-author/trunk/parser.c.header
redbutton-author/trunk/parser.h.header
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-18 19:52:00 UTC (rev 399)
+++ redbutton-author/trunk/parser.c.header 2007-09-19 11:47:16 UTC (rev 400)
@@ -38,6 +38,7 @@
child->asn1class = (asn1tagclass >> 24) & 0xff;
child->length = 0;
child->value = NULL;
+ child->parent = parent;
child->children = NULL;
child->siblings = NULL;
@@ -119,15 +120,16 @@
return;
}
-void parse_STRING(struct node *parent)
+void parse_OCTETSTRING(struct node *parent)
{
- if(next_token() != STRING)
- parse_error("Unexpected token '%s'; expecting \"STRING\"", token_text());
-
- verbose("<STRING value=%s/>\n", token_text());
-
- /* give our parent a UNIVERSAL type if it is synthetic */
- if(is_synthetic(parent->asn1tag))
+ /*
+ * give our parent's parent a UNIVERSAL type if it is synthetic
+ * need to look at our parent's parent because an OctetString in the grammar
+ * is a choice between a STRING, a QPRINTABLE or a BASE64
+ * so our parent will always be a choice node
+ * the OCTETSTRING ASN1 type does not have this extra choice parent node
+ */
+ if(is_synthetic(parent->parent->asn1tag))
{
parent->asn1tag = ASN1TAG_OCTETSTRING;
parent->asn1class = ASN1CLASS_UNIVERSAL;
@@ -138,7 +140,18 @@
return;
}
+void parse_STRING(struct node *parent)
+{
+ if(next_token() != STRING)
+ parse_error("Unexpected token '%s'; expecting \"STRING\"", token_text());
+ verbose("<STRING value=%s/>\n", token_text());
+
+ parse_OCTETSTRING(parent);
+
+ return;
+}
+
void parse_QPRINTABLE(struct node *parent)
{
if(next_token() != QPRINTABLE)
@@ -146,19 +159,11 @@
verbose("<QPRINTABLE value=%s/>\n", token_text());
- /* give our parent a UNIVERSAL type if it is synthetic */
- if(is_synthetic(parent->asn1tag))
- {
- parent->asn1tag = ASN1TAG_OCTETSTRING;
- parent->asn1class = ASN1CLASS_UNIVERSAL;
- }
+ parse_OCTETSTRING(parent);
- der_encode_OctetString(&parent->value, &parent->length, token_text());
-
return;
}
-
void parse_BASE64(struct node *parent)
{
if(next_token() != BASE64)
@@ -166,19 +171,11 @@
verbose("<BASE64 value=%s/>\n", token_text());
- /* give our parent a UNIVERSAL type if it is synthetic */
- if(is_synthetic(parent->asn1tag))
- {
- parent->asn1tag = ASN1TAG_OCTETSTRING;
- parent->asn1class = ASN1CLASS_UNIVERSAL;
- }
+ parse_OCTETSTRING(parent);
- der_encode_OctetString(&parent->value, &parent->length, token_text());
-
return;
}
-
void parse_Null(struct node *parent)
{
if(next_token() != Null)
Modified: redbutton-author/trunk/parser.h.header
===================================================================
--- redbutton-author/trunk/parser.h.header 2007-09-18 19:52:00 UTC (rev 399)
+++ redbutton-author/trunk/parser.h.header 2007-09-19 11:47:16 UTC (rev 400)
@@ -17,6 +17,7 @@
unsigned int length; /* length of the value data */
unsigned char *value; /* DER encoded value */
/* a tree of nodes */
+ struct node *parent; /* NULL if we are the top */
struct node *children; /* NULL if not a constructed type */
struct node *siblings; /* linked list of children */
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-20 12:49:11
|
Revision: 403
http://redbutton.svn.sourceforge.net/redbutton/?rev=403&view=rev
Author: skilvington
Date: 2007-09-20 05:49:08 -0700 (Thu, 20 Sep 2007)
Log Message:
-----------
Don't bother creating synthetic nodes. This means we can easily work out where we need to explicitly tag universal types
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.c
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/parser.c.header
Modified: redbutton-author/trunk/asn1tag.c
===================================================================
--- redbutton-author/trunk/asn1tag.c 2007-09-20 11:33:30 UTC (rev 402)
+++ redbutton-author/trunk/asn1tag.c 2007-09-20 12:49:08 UTC (rev 403)
@@ -21,3 +21,16 @@
/* TODO: only need one value for synthetic types (ie no need for separate ASN1TAG_CHOICE etc) */
return (asn1tag >= ASN1TAG_SYNTHETIC);
}
+
+/*
+ * returns true if we need an explicit tag for this primitive type
+ */
+
+bool
+needs_tagging(unsigned int asn1tag, unsigned int asn1class)
+{
+ /* only need an explicit tag if we are a choice or a constructed type */
+ return (asn1tag == ASN1TAG_CHOICE)
+ || (asn1class == ASN1CLASS_UNIVERSAL && asn1tag == ASN1TAG_SEQUENCE)
+ || (asn1class == ASN1CLASS_UNIVERSAL && asn1tag == ASN1TAG_SET);
+}
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-20 11:33:30 UTC (rev 402)
+++ redbutton-author/trunk/asn1tag.h 2007-09-20 12:49:08 UTC (rev 403)
@@ -15,6 +15,7 @@
char *asn1class_name(unsigned int);
bool is_synthetic(unsigned int);
+bool needs_tagging(unsigned int, unsigned int);
/*
* a synthetic object created as a result of the grammar definition
@@ -43,9 +44,15 @@
#define ASN1TAGCLASS_LineArtBody ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_TextBody ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_PushButtonBody ASN1TAG_SYNTHETIC
-#define ASN1TAGCLASS_OctetString ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_BoxSize ASN1TAG_SYNTHETIC
+/*
+ * this is not the same as an ASN1 OCTET STRING type
+ * rather it a choice about how you define the data in your source file
+ * ie as a STRING, QPRINTABLE or BASE64
+ */
+#define ASN1TAGCLASS_OctetString ASN1TAG_CHOICE
+
/* ASN1 CONTEXT tag values */
#define ASN1TAG_ApplicationClass 0
#define ASN1TAG_SceneClass 1
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-20 11:33:30 UTC (rev 402)
+++ redbutton-author/trunk/parser.c.header 2007-09-20 12:49:08 UTC (rev 403)
@@ -31,8 +31,13 @@
struct node *
add_child(struct node *parent, uint32_t asn1tagclass)
{
- struct node *child = safe_malloc(sizeof(struct node));
+ struct node *child;
+ if(asn1tagclass == ASN1TAG_SYNTHETIC)
+ return parent;
+
+ child = safe_malloc(sizeof(struct node));
+
/* class is in the top 8 bits, tag is the bottom 24 bits */
child->asn1tag = asn1tagclass & 0xffffff;
child->asn1class = (asn1tagclass >> 24) & 0xff;
@@ -88,12 +93,9 @@
verbose("<BOOLEAN value=%s/>\n", token_text());
- /* give our parent a UNIVERSAL type if it is synthetic */
- if(is_synthetic(parent->asn1tag))
- {
- parent->asn1tag = ASN1TAG_BOOLEAN;
- parent->asn1class = ASN1CLASS_UNIVERSAL;
- }
+ /* create an explicit UNIVERSAL type if necessary */
+ if(needs_tagging(parent->asn1tag, parent->asn1class))
+ parent = add_child(parent, ASN1TAGCLASS_BOOLEAN);
der_encode_BOOLEAN(&parent->value, &parent->length, strcmp(token_text(), "false"));
@@ -108,12 +110,9 @@
verbose("<INTEGER value=%s/>\n", token_text());
- /* give our parent a UNIVERSAL type if it is synthetic */
- if(is_synthetic(parent->asn1tag))
- {
- parent->asn1tag = ASN1TAG_INTEGER;
- parent->asn1class = ASN1CLASS_UNIVERSAL;
- }
+ /* create an explicit UNIVERSAL type if necessary */
+ if(needs_tagging(parent->asn1tag, parent->asn1class))
+ parent = add_child(parent, ASN1TAGCLASS_INTEGER);
der_encode_INTEGER(&parent->value, &parent->length, strtol(token_text(), NULL, 0));
@@ -123,17 +122,14 @@
void parse_OCTETSTRING(struct node *parent)
{
/*
- * give our parent's parent a UNIVERSAL type if it is synthetic
+ * create an explicit UNIVERSAL type if necessary
* need to look at our parent's parent because an OctetString in the grammar
* is a choice between a STRING, a QPRINTABLE or a BASE64
* so our parent will always be a choice node
- * the OCTETSTRING ASN1 type does not have this extra choice parent node
+ * the OCTET STRING ASN1 type does not have this extra choice parent node
*/
- if(is_synthetic(parent->parent->asn1tag))
- {
- parent->asn1tag = ASN1TAG_OCTETSTRING;
- parent->asn1class = ASN1CLASS_UNIVERSAL;
- }
+ if(needs_tagging(parent->parent->asn1tag, parent->parent->asn1class))
+ parent = add_child(parent, ASN1TAGCLASS_OCTETSTRING);
der_encode_OctetString(&parent->value, &parent->length, token_text());
@@ -187,12 +183,9 @@
if(parent->length != 0)
fatal("Null: length=%u", parent->length);
- /* give our parent a UNIVERSAL type if it is synthetic */
- if(is_synthetic(parent->asn1tag))
- {
- parent->asn1tag = ASN1TAG_NULL;
- parent->asn1class = ASN1CLASS_UNIVERSAL;
- }
+ /* create an explicit UNIVERSAL type if necessary */
+ if(needs_tagging(parent->asn1tag, parent->asn1class))
+ parent = add_child(parent, ASN1TAGCLASS_NULL);
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-20 13:05:10
|
Revision: 404
http://redbutton.svn.sourceforge.net/redbutton/?rev=404&view=rev
Author: skilvington
Date: 2007-09-20 06:05:06 -0700 (Thu, 20 Sep 2007)
Log Message:
-----------
clean up comments about synthetic types
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.c
redbutton-author/trunk/asn1tag.h
Modified: redbutton-author/trunk/asn1tag.c
===================================================================
--- redbutton-author/trunk/asn1tag.c 2007-09-20 12:49:08 UTC (rev 403)
+++ redbutton-author/trunk/asn1tag.c 2007-09-20 13:05:06 UTC (rev 404)
@@ -18,8 +18,7 @@
bool
is_synthetic(unsigned int asn1tag)
{
-/* TODO: only need one value for synthetic types (ie no need for separate ASN1TAG_CHOICE etc) */
- return (asn1tag >= ASN1TAG_SYNTHETIC);
+ return (asn1tag == ASN1TAG_SYNTHETIC || asn1tag == ASN1TAG_CHOICE);
}
/*
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-20 12:49:08 UTC (rev 403)
+++ redbutton-author/trunk/asn1tag.h 2007-09-20 13:05:06 UTC (rev 404)
@@ -572,7 +572,7 @@
#define ASN1TAGCLASS_SEQUENCE ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_SEQUENCE)
#define ASN1TAGCLASS_SET ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_SET)
-/* UNIVERSAL ASN1 types in the grammar */
+/* the ASN1 types in the grammar that are not CONTEXT class types */
#define ASN1TAGCLASS_JointIsoItuIdentifier ASN1TAGCLASS_INTEGER
#define ASN1TAGCLASS_MHEGStandardIdentifier ASN1TAGCLASS_INTEGER
#define ASN1TAGCLASS_DirectFont ASN1TAGCLASS_OctetString
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-20 16:10:43
|
Revision: 405
http://redbutton.svn.sourceforge.net/redbutton/?rev=405&view=rev
Author: skilvington
Date: 2007-09-20 09:10:41 -0700 (Thu, 20 Sep 2007)
Log Message:
-----------
add a token to the grammar to make ActionClass sequences get tagged correctly
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/asn1type.c
redbutton-author/trunk/grammar
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-20 13:05:06 UTC (rev 404)
+++ redbutton-author/trunk/asn1tag.h 2007-09-20 16:10:41 UTC (rev 405)
@@ -725,9 +725,11 @@
#define ASN1TAGCLASS_ActionSlots ASN1TAGCLASS_SEQUENCE
#define ASN1TAGCLASS_InVariables ASN1TAGCLASS_SEQUENCE
#define ASN1TAGCLASS_OutVariables ASN1TAGCLASS_SEQUENCE
-#define ASN1TAGCLASS_ActionClass ASN1TAGCLASS_SEQUENCE
+#define ASN1TAGCLASS_ActionClass ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_Parameters ASN1TAGCLASS_SEQUENCE
#define ASN1TAGCLASS_PointList ASN1TAGCLASS_SEQUENCE
+/* added by me to get an explicit SEQUENCE under NoTokenActionSlot */
+#define ASN1TAGCLASS_ActionClassSeq ASN1TAGCLASS_SEQUENCE
#endif /* __ASN1TAG_H__ */
Modified: redbutton-author/trunk/asn1type.c
===================================================================
--- redbutton-author/trunk/asn1type.c 2007-09-20 13:05:06 UTC (rev 404)
+++ redbutton-author/trunk/asn1type.c 2007-09-20 16:10:41 UTC (rev 405)
@@ -212,6 +212,7 @@
MATCH(GetFocusPosition, SEQUENCE)
MATCH(SetFocusPosition, SEQUENCE)
MATCH(OctetString, CHOICE);
+ MATCH(ActionSlotSeq, CHOICE);
fprintf(stderr, "Unknown ASN1 type: %s\n", name);
exit(EXIT_FAILURE);
Modified: redbutton-author/trunk/grammar
===================================================================
--- redbutton-author/trunk/grammar 2007-09-20 13:05:06 UTC (rev 404)
+++ redbutton-author/trunk/grammar 2007-09-20 16:10:41 UTC (rev 405)
@@ -250,9 +250,11 @@
AVisible ::= ObjectReference .
ActionSlots ::= ":ActionSlots" "(" ActionSlot+ ")" .
ActionSlot ::= ActionClass | Null .
-NoTokenActionSlots ::= ":NoTokenActionSlots" "(" ActionSlot+ ")" .
+NoTokenActionSlots ::= ":NoTokenActionSlots" "(" ActionSlotSeq+ ")" .
+// srk - to get an explicit SEQUENCE tag under NoTokenActionSlots
+ActionSlotSeq ::= ActionClassSeq | Null .
+ActionClassSeq ::= ActionClass .
-
// B.4.23 ListGroup Class
ListGroupClass ::= "{:ListGroup" TokenGroupBody
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-21 12:55:22
|
Revision: 406
http://redbutton.svn.sourceforge.net/redbutton/?rev=406&view=rev
Author: skilvington
Date: 2007-09-21 05:55:18 -0700 (Fri, 21 Sep 2007)
Log Message:
-----------
don't generate an object if there were any parsing errors
Modified Paths:
--------------
redbutton-author/trunk/mhegc.c
redbutton-author/trunk/parser.c.header
redbutton-author/trunk/parser.h.header
redbutton-author/trunk/parser.l.footer
redbutton-author/trunk/parser.l.header
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-09-20 16:10:41 UTC (rev 405)
+++ redbutton-author/trunk/mhegc.c 2007-09-21 12:55:18 UTC (rev 406)
@@ -43,6 +43,7 @@
char *prog_name = argv[0];
int arg;
struct node asn1obj;
+ unsigned int nerrs;
while((arg = getopt(argc, argv, "v")) != EOF)
{
@@ -79,6 +80,10 @@
if(next_token())
parse_error("Unexpected text after InterchangedObject");
+ /* don't generate an object if there were any errors */
+ if((nerrs = nparse_errors()) > 0)
+ fatal("%u parsing error%s", nerrs, (nerrs == 1) ? "" : "s");
+
/* assert */
if(asn1obj.siblings != NULL)
fatal("Top level object has siblings");
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-20 16:10:41 UTC (rev 405)
+++ redbutton-author/trunk/parser.c.header 2007-09-21 12:55:18 UTC (rev 406)
@@ -10,12 +10,17 @@
* lexer functions we need to provide
*/
-int yylineno = 1;
+unsigned int yylineno = 1;
+unsigned int yynerrs = 0;
void
yyerror(const char *str)
{
fprintf(stderr, "Error: %s at line %d\n", str, yylineno);
+
+ yynerrs ++;
+
+ return;
}
int
Modified: redbutton-author/trunk/parser.h.header
===================================================================
--- redbutton-author/trunk/parser.h.header 2007-09-20 16:10:41 UTC (rev 405)
+++ redbutton-author/trunk/parser.h.header 2007-09-21 12:55:18 UTC (rev 406)
@@ -40,6 +40,7 @@
char *token_text(void);
void parse_error(const char *, ...);
+unsigned int nparse_errors(void);
void verbose(const char *, ...);
void vverbose(const char *, ...);
Modified: redbutton-author/trunk/parser.l.footer
===================================================================
--- redbutton-author/trunk/parser.l.footer 2007-09-20 16:10:41 UTC (rev 405)
+++ redbutton-author/trunk/parser.l.footer 2007-09-21 12:55:18 UTC (rev 406)
@@ -87,3 +87,9 @@
return;
}
+unsigned int
+nparse_errors(void)
+{
+ return yynerrs;
+}
+
Modified: redbutton-author/trunk/parser.l.header
===================================================================
--- redbutton-author/trunk/parser.l.header 2007-09-20 16:10:41 UTC (rev 405)
+++ redbutton-author/trunk/parser.l.header 2007-09-21 12:55:18 UTC (rev 406)
@@ -5,7 +5,8 @@
#include <errno.h>
#include "parser.h"
#include "tokens.h"
-extern int yylineno;
+extern unsigned int yylineno;
+extern unsigned int yynerrs;
%}
%%
\/\/[^\n\r\f]* return COMMENT;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-21 15:52:37
|
Revision: 407
http://redbutton.svn.sourceforge.net/redbutton/?rev=407&view=rev
Author: skilvington
Date: 2007-09-21 08:52:33 -0700 (Fri, 21 Sep 2007)
Log Message:
-----------
ContentReference has different tags in different places
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/grammar
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-21 12:55:18 UTC (rev 406)
+++ redbutton-author/trunk/asn1tag.h 2007-09-21 15:52:33 UTC (rev 407)
@@ -123,7 +123,7 @@
#define ASN1TAG_ProgramConnectionTag 66
#define ASN1TAG_OriginalValue 67
#define ASN1TAG_ObjectReferenceValue 68
-#define ASN1TAG_ContentReferenceValue 69
+#define ASN1TAG_ContentReference69 69
#define ASN1TAG_MovementTable 70
#define ASN1TAG_TokenGroupItems 71
#define ASN1TAG_NoTokenActionSlots 72
@@ -374,7 +374,7 @@
#define ASN1TAGCLASS_ProgramConnectionTag ((ASN1CLASS_CONTEXT << 24) | ASN1TAG_ProgramConnectionTag)
#define ASN1TAGCLASS_OriginalValue ((ASN1CLASS_CONTEXT << 24) | ASN1TAG_OriginalValue)
#define ASN1TAGCLASS_ObjectReferenceValue ((ASN1CLASS_CONTEXT << 24) | ASN1TAG_ObjectReferenceValue)
-#define ASN1TAGCLASS_ContentReferenceValue ((ASN1CLASS_CONTEXT << 24) | ASN1TAG_ContentReferenceValue)
+#define ASN1TAGCLASS_ContentReference69 ((ASN1CLASS_CONTEXT << 24) | ASN1TAG_ContentReference69)
#define ASN1TAGCLASS_MovementTable ((ASN1CLASS_CONTEXT << 24) | ASN1TAG_MovementTable)
#define ASN1TAGCLASS_TokenGroupItems ((ASN1CLASS_CONTEXT << 24) | ASN1TAG_TokenGroupItems)
#define ASN1TAGCLASS_NoTokenActionSlots ((ASN1CLASS_CONTEXT << 24) | ASN1TAG_NoTokenActionSlots)
@@ -588,7 +588,7 @@
#define ASN1TAGCLASS_EventType ASN1TAGCLASS_ENUMERATED
#define ASN1TAGCLASS_EventData ASN1TAG_CHOICE
#define ASN1TAGCLASS_ObjectReference ASN1TAG_SYNTHETIC
-#define ASN1TAGCLASS_ContentReference ASN1TAG_SYNTHETIC
+#define ASN1TAGCLASS_ContentReferenceValue ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_TargetElement ASN1TAGCLASS_INTEGER
#define ASN1TAGCLASS_AVisible ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_Position ASN1TAGCLASS_SEQUENCE
@@ -730,6 +730,8 @@
#define ASN1TAGCLASS_PointList ASN1TAGCLASS_SEQUENCE
/* added by me to get an explicit SEQUENCE under NoTokenActionSlot */
#define ASN1TAGCLASS_ActionClassSeq ASN1TAGCLASS_SEQUENCE
+/* ContentReference is [69] except in ReferencedContent */
+#define ASN1TAGCLASS_ContentReference ASN1TAG_SYNTHETIC
#endif /* __ASN1TAG_H__ */
Modified: redbutton-author/trunk/grammar
===================================================================
--- redbutton-author/trunk/grammar 2007-09-21 12:55:18 UTC (rev 406)
+++ redbutton-author/trunk/grammar 2007-09-21 15:52:33 UTC (rev 407)
@@ -199,7 +199,7 @@
| ObjectReferenceValue
| ContentReferenceValue .
ObjectReferenceValue ::= ":ObjectRef" ObjectReference .
-ContentReferenceValue ::= ":ContentRef" ContentReference .
+ContentReferenceValue ::= ":ContentRef" ContentReference69 .
// B.4.15 BooleanVariable Class
@@ -905,12 +905,14 @@
ObjectNumber ::= INTEGER .
ContentReference ::= OctetString .
+// srk - ContentReference is [69] except in ReferencedContent
+ContentReference69 ::= OctetString .
GenericObjectReference ::= DirectReference | IndirectReference .
DirectReference ::= ObjectReference .
IndirectReference ::= ":IndirectRef" ObjectReference .
-GenericContentReference ::= ContentReference | IndirectReference .
+GenericContentReference ::= ContentReference69 | IndirectReference .
GenericInteger ::= INTEGER | IndirectReference .
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-22 16:55:39
|
Revision: 411
http://redbutton.svn.sourceforge.net/redbutton/?rev=411&view=rev
Author: skilvington
Date: 2007-09-22 09:55:38 -0700 (Sat, 22 Sep 2007)
Log Message:
-----------
the skeleton needed to start generating complete DER objects
Modified Paths:
--------------
redbutton-author/trunk/der_encode.c
redbutton-author/trunk/der_encode.h
redbutton-author/trunk/mhegc.c
redbutton-author/trunk/parser.c.header
redbutton-author/trunk/parser.h.header
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-22 16:49:21 UTC (rev 410)
+++ redbutton-author/trunk/der_encode.c 2007-09-22 16:55:38 UTC (rev 411)
@@ -210,5 +210,20 @@
void
convert_BASE64(unsigned char **out, unsigned int *len, const unsigned char *str)
{
+/* TODO */
+printf("TODO: convert_BASE64\n");
}
+/*
+ * recursively generate the DER tag/length header for the tree of nodes
+ */
+
+unsigned int
+gen_der_header(struct node *n)
+{
+/* TODO */
+printf("TODO: gen_der_header\n");
+
+ return n->hdr_length + n->length;
+}
+
Modified: redbutton-author/trunk/der_encode.h
===================================================================
--- redbutton-author/trunk/der_encode.h 2007-09-22 16:49:21 UTC (rev 410)
+++ redbutton-author/trunk/der_encode.h 2007-09-22 16:55:38 UTC (rev 411)
@@ -5,6 +5,8 @@
#ifndef __DER_ENCODE_H__
#define __DER_ENCODE_H__
+#include "parser.h"
+
#include <stdbool.h>
void der_encode_BOOLEAN(unsigned char **, unsigned int *, bool);
@@ -15,5 +17,7 @@
void convert_QPRINTABLE(unsigned char **, unsigned int *, const unsigned char *);
void convert_BASE64(unsigned char **, unsigned int *, const unsigned char *);
+unsigned int gen_der_header(struct node *);
+
#endif /* __DER_ENCODE_H__ */
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-09-22 16:49:21 UTC (rev 410)
+++ redbutton-author/trunk/mhegc.c 2007-09-22 16:55:38 UTC (rev 411)
@@ -27,6 +27,7 @@
#include <strings.h>
#include "parser.h"
+#include "der_encode.h"
#include "asn1tag.h"
#include "utils.h"
@@ -44,6 +45,7 @@
int arg;
struct node asn1obj;
unsigned int nerrs;
+ unsigned int filesize;
while((arg = getopt(argc, argv, "v")) != EOF)
{
@@ -94,6 +96,10 @@
print_node(&asn1obj, 0);
}
+ /* create the DER tag/length header for each node */
+ filesize = gen_der_header(&asn1obj);
+ verbose("\nDER Object size: %u bytes\n", filesize);
+
return EXIT_SUCCESS;
}
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-22 16:49:21 UTC (rev 410)
+++ redbutton-author/trunk/parser.c.header 2007-09-22 16:55:38 UTC (rev 411)
@@ -46,8 +46,13 @@
/* class is in the top 8 bits, tag is the bottom 24 bits */
child->asn1tag = asn1tagclass & 0xffffff;
child->asn1class = (asn1tagclass >> 24) & 0xff;
+ /* DER tag/length header */
+ child->hdr_length = 0;
+ child->hdr_value = NULL;
+ /* DER value */
child->length = 0;
child->value = NULL;
+ /* the tree of nodes */
child->parent = parent;
child->children = NULL;
child->siblings = NULL;
Modified: redbutton-author/trunk/parser.h.header
===================================================================
--- redbutton-author/trunk/parser.h.header 2007-09-22 16:49:21 UTC (rev 410)
+++ redbutton-author/trunk/parser.h.header 2007-09-22 16:55:38 UTC (rev 411)
@@ -13,6 +13,9 @@
/* DER type */
unsigned int asn1tag; /* ASN1 tag number */
unsigned int asn1class; /* only UNIVERSAL or CONTEXT */
+ /* DER tag/length header */
+ unsigned int hdr_length;
+ unsigned char *hdr_value;
/* DER value */
unsigned int length; /* length of the value data */
unsigned char *value; /* DER encoded value */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-23 19:16:36
|
Revision: 415
http://redbutton.svn.sourceforge.net/redbutton/?rev=415&view=rev
Author: skilvington
Date: 2007-09-23 12:16:23 -0700 (Sun, 23 Sep 2007)
Log Message:
-----------
pull out whole unknown words, rather than a char at a time
Modified Paths:
--------------
redbutton-author/trunk/parser.l.footer
redbutton-author/trunk/tokens.h.header
Modified: redbutton-author/trunk/parser.l.footer
===================================================================
--- redbutton-author/trunk/parser.l.footer 2007-09-22 18:35:40 UTC (rev 414)
+++ redbutton-author/trunk/parser.l.footer 2007-09-23 19:16:23 UTC (rev 415)
@@ -1,4 +1,5 @@
-. return INVALID;
+[a-z0-9:]+ return UNKNOWN_WORD;
+. return INVALID_CHAR;
%%
void
Modified: redbutton-author/trunk/tokens.h.header
===================================================================
--- redbutton-author/trunk/tokens.h.header 2007-09-22 18:35:40 UTC (rev 414)
+++ redbutton-author/trunk/tokens.h.header 2007-09-23 19:16:23 UTC (rev 415)
@@ -1,9 +1,10 @@
#define END_OF_SRC 0 /* must be 0 */
#define COMMENT 1
-#define INVALID 2
-#define INTEGER 3
-#define BOOLEAN 4
-#define STRING 5
-#define QPRINTABLE 6
-#define BASE64 7
-#define Null 8
+#define UNKNOWN_WORD 2
+#define INVALID_CHAR 3
+#define INTEGER 4
+#define BOOLEAN 5
+#define STRING 6
+#define QPRINTABLE 7
+#define BASE64 8
+#define Null 9
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 11:09:27
|
Revision: 418
http://redbutton.svn.sourceforge.net/redbutton/?rev=418&view=rev
Author: skilvington
Date: 2007-09-24 04:09:12 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
keep RMS happy
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.c
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/asn1type.c
redbutton-author/trunk/asn1type.h
redbutton-author/trunk/der_encode.c
redbutton-author/trunk/der_encode.h
redbutton-author/trunk/parser.c.header
redbutton-author/trunk/parser.h.header
redbutton-author/trunk/tokens.h.header
Added Paths:
-----------
redbutton-author/trunk/COPYING
Added: redbutton-author/trunk/COPYING
===================================================================
--- redbutton-author/trunk/COPYING (rev 0)
+++ redbutton-author/trunk/COPYING 2007-09-24 11:09:12 UTC (rev 418)
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
Modified: redbutton-author/trunk/asn1tag.c
===================================================================
--- redbutton-author/trunk/asn1tag.c 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/asn1tag.c 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* asn1tag.c
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include "asn1tag.h"
char *
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/asn1tag.h 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* asn1tag.h
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#ifndef __ASN1TAG_H__
#define __ASN1TAG_H__
Modified: redbutton-author/trunk/asn1type.c
===================================================================
--- redbutton-author/trunk/asn1type.c 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/asn1type.c 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* asn1type.c
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Modified: redbutton-author/trunk/asn1type.h
===================================================================
--- redbutton-author/trunk/asn1type.h 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/asn1type.h 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* asn1type.h
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#ifndef __ASN1TYPE_H__
#define __ASN1TYPE_H__
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/der_encode.c 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* der_encode.c
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
Modified: redbutton-author/trunk/der_encode.h
===================================================================
--- redbutton-author/trunk/der_encode.h 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/der_encode.h 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* der_encode.h
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#ifndef __DER_ENCODE_H__
#define __DER_ENCODE_H__
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/parser.c.header 2007-09-24 11:09:12 UTC (rev 418)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include <stdio.h>
#include <string.h>
Modified: redbutton-author/trunk/parser.h.header
===================================================================
--- redbutton-author/trunk/parser.h.header 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/parser.h.header 2007-09-24 11:09:12 UTC (rev 418)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#ifndef __PARSER_H__
#define __PARSER_H__
Modified: redbutton-author/trunk/tokens.h.header
===================================================================
--- redbutton-author/trunk/tokens.h.header 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/tokens.h.header 2007-09-24 11:09:12 UTC (rev 418)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#define END_OF_SRC 0 /* must be 0 */
#define COMMENT 1
#define UNKNOWN_WORD 2
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 12:47:40
|
Revision: 419
http://redbutton.svn.sourceforge.net/redbutton/?rev=419&view=rev
Author: skilvington
Date: 2007-09-24 05:47:39 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
generate the DER type/length header
Modified Paths:
--------------
redbutton-author/trunk/der_encode.c
redbutton-author/trunk/der_encode.h
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-24 11:09:12 UTC (rev 418)
+++ redbutton-author/trunk/der_encode.c 2007-09-24 12:47:39 UTC (rev 419)
@@ -261,7 +261,85 @@
/* we don't need a header if we are a synthetic object */
if(!is_synthetic(n->asn1tag))
{
-printf("TODO: gen_der_header: tag=%u class=%s len=%u\n", n->asn1tag, asn1class_name(n->asn1class), val_length);
+ /* allocate more than we will need */
+ n->hdr_value = safe_malloc(MAX_DER_HDR_LENGTH);
+ /*
+ * first DER type byte is:
+ * AABCCCCC
+ * AA = ASN1 class (UNIVERSAL, CONTEXT, etc)
+ * B = 1 if it is a constructed type (ie has children)
+ * CCCCC = tag value (0-30)
+ * if the tag is set to 31, then:
+ * while the next byte has its top-bit set,
+ * the big-endian tag value is encoded in the bottom 7-bits
+ */
+ n->hdr_value[0] = n->asn1class;
+ if(n->children)
+ n->hdr_value[0] |= 0x20;
+ if(n->asn1tag < 31)
+ {
+ n->hdr_value[0] |= n->asn1tag;
+ n->hdr_length = 1;
+ }
+ else
+ {
+ n->hdr_value[0] |= 0x1f;
+ /* cheat - we know it is < 0x3fff (16383) */
+ if(n->asn1tag <= 0x7f)
+ {
+ n->hdr_value[1] = n->asn1tag & 0x7f;
+ n->hdr_length = 2;
+ }
+ else if(n->asn1tag <= 0x3fff)
+ {
+ n->hdr_value[1] = (n->asn1tag >> 7) & 0x7f;
+ n->hdr_value[2] = n->asn1tag & 0x7f;
+ n->hdr_length = 3;
+ }
+ else
+ {
+ /* assert */
+ fatal("gen_der_header: tag=%u class=%s", n->asn1tag, asn1class_name(n->asn1class));
+ }
+ }
+ /*
+ * if DER length is <128, then it is encoded as:
+ * 0LLLLLLL, where LLLLLLL is the 7-bit length
+ * if DER length is >=128, then it is encoded as:
+ * 1LLLLLLL, where LLLLLLL are the number of following bytes
+ * encoding the big-endian length
+ */
+ if(val_length < 128)
+ {
+ n->hdr_value[n->hdr_length] = val_length;
+ n->hdr_length ++;
+ }
+ else
+ {
+ unsigned int nlens = 1;
+ unsigned int len = val_length;
+ unsigned int i;
+ while(len > 255)
+ {
+ len >>= 8;
+ nlens ++;
+ }
+ /* assert */
+ if(n->hdr_length + nlens > MAX_DER_HDR_LENGTH)
+ fatal("gen_der_header: tag=%u class=%s nlens=%u", n->asn1tag, asn1class_name(n->asn1class), nlens);
+ n->hdr_value[n->hdr_length] = 0x80 | nlens;
+ n->hdr_length ++;
+ for(i=nlens; i>0; i--)
+ {
+ n->hdr_value[n->hdr_length] = (val_length >> ((i - 1) * 8)) & 0xff;
+ n->hdr_length ++;
+ }
+ }
+ /*
+ * this header is followed by the DER encoded value
+ * the value of constructed types is one or more DER types
+ * ie one or more DER header/value pairs
+ */
}
return n->hdr_length + val_length;
Modified: redbutton-author/trunk/der_encode.h
===================================================================
--- redbutton-author/trunk/der_encode.h 2007-09-24 11:09:12 UTC (rev 418)
+++ redbutton-author/trunk/der_encode.h 2007-09-24 12:47:39 UTC (rev 419)
@@ -27,6 +27,12 @@
#include <stdbool.h>
+/*
+ * max size a DER tag/length header could be
+ * (this is not the theoretical max, but it is big enough for us)
+ */
+#define MAX_DER_HDR_LENGTH 16
+
void der_encode_BOOLEAN(unsigned char **, unsigned int *, bool);
void der_encode_INTEGER(unsigned char **, unsigned int *, int);
void der_encode_OctetString(unsigned char **, unsigned int *, const unsigned char *);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 16:03:20
|
Revision: 420
http://redbutton.svn.sourceforge.net/redbutton/?rev=420&view=rev
Author: skilvington
Date: 2007-09-24 09:03:05 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
output the DER file
Modified Paths:
--------------
redbutton-author/trunk/der_encode.c
redbutton-author/trunk/der_encode.h
redbutton-author/trunk/mhegc.c
redbutton-author/trunk/utils.c
redbutton-author/trunk/utils.h
Added Paths:
-----------
redbutton-author/trunk/TODO
Added: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO (rev 0)
+++ redbutton-author/trunk/TODO 2007-09-24 16:03:05 UTC (rev 420)
@@ -0,0 +1,28 @@
+NewContentSize param in NewReferencedContent should compile to:
+[CONTEXT 234] { ... [UNIVERSAL 5] ... }
+not just [CONTEXT 234] { ... nothing ... }
+- ie need to add an explicit Null child node
+
+same with ConnectionTag param in TransitionTo
+
+temp fix - add "Null" to the relevent 2 places in the grammar?
+real fix - add "Identifier?" to the grammar => optional, but adds a Null if not
+ present (or perhaps "<Identifier>")
+
+---
+
+output filename should default to App/Scene GroupIdentifier rather than "a"
+(but warn if file exists - stops accidental overwrite of source!)
+
+---
+
+convert_BASE64() function
+
+---
+
+change fatal()'s to parse_error()'s in convert_STRING() et al.
+
+---
+
+clean up ccc.y
+
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/der_encode.c 2007-09-24 16:03:05 UTC (rev 420)
@@ -274,7 +274,7 @@
* the big-endian tag value is encoded in the bottom 7-bits
*/
n->hdr_value[0] = n->asn1class;
- if(n->children)
+ if(has_real_children(n))
n->hdr_value[0] |= 0x20;
if(n->asn1tag < 31)
{
@@ -292,7 +292,7 @@
}
else if(n->asn1tag <= 0x3fff)
{
- n->hdr_value[1] = (n->asn1tag >> 7) & 0x7f;
+ n->hdr_value[1] = 0x80 | ((n->asn1tag >> 7) & 0x7f);
n->hdr_value[2] = n->asn1tag & 0x7f;
n->hdr_length = 3;
}
@@ -345,3 +345,26 @@
return n->hdr_length + val_length;
}
+void
+write_der_object(FILE *out, struct node *n)
+{
+ struct node *kid;
+
+ /* write our tag/length header */
+ if(!is_synthetic(n->asn1tag))
+ write_all(out, n->hdr_value, n->hdr_length);
+
+ /* and our value */
+ if(n->children)
+ {
+ for(kid=n->children; kid; kid=kid->siblings)
+ write_der_object(out, kid);
+ }
+ else
+ {
+ write_all(out, n->value, n->length);
+ }
+
+ return;
+}
+
Modified: redbutton-author/trunk/der_encode.h
===================================================================
--- redbutton-author/trunk/der_encode.h 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/der_encode.h 2007-09-24 16:03:05 UTC (rev 420)
@@ -43,5 +43,7 @@
unsigned int gen_der_header(struct node *);
+void write_der_object(FILE *, struct node *);
+
#endif /* __DER_ENCODE_H__ */
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/mhegc.c 2007-09-24 16:03:05 UTC (rev 420)
@@ -24,14 +24,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
#include <strings.h>
+#include <errno.h>
#include "parser.h"
#include "der_encode.h"
#include "asn1tag.h"
#include "utils.h"
+/* default output name is 'a' */
+#define DEFAULT_OUT_NAME "a"
+
void print_node(struct node *, unsigned int);
+void print_der(struct node *, unsigned int);
void print_indent(unsigned int);
void usage(char *);
@@ -43,14 +49,20 @@
{
char *prog_name = argv[0];
int arg;
+ char *out_name = DEFAULT_OUT_NAME;
struct node asn1obj;
unsigned int nerrs;
unsigned int filesize;
+ FILE *out_file;
- while((arg = getopt(argc, argv, "v")) != EOF)
+ while((arg = getopt(argc, argv, "o:v")) != EOF)
{
switch(arg)
{
+ case 'o':
+ out_name = optarg;
+ break;
+
case 'v':
_verbose ++;
break;
@@ -100,6 +112,19 @@
filesize = gen_der_header(&asn1obj);
verbose("\nDER Object size: %u bytes\n", filesize);
+ /* write the output file */
+ if((out_file = fopen(out_name, "w")) == NULL)
+ fatal("Unable to open output file '%s': %s", out_name, strerror(errno));
+ verbose("Writing '%s'\n", out_name);
+ write_der_object(out_file, &asn1obj);
+ fclose(out_file);
+
+ if(_verbose > 1)
+ {
+ vverbose("\nDER file:\n");
+ print_der(&asn1obj, 0);
+ }
+
return EXIT_SUCCESS;
}
@@ -149,6 +174,37 @@
}
void
+print_der(struct node *n, unsigned int indent)
+{
+ struct node *kid;
+
+ /* write our tag/length header */
+ if(!is_synthetic(n->asn1tag))
+ {
+ print_indent(indent);
+ fprintf(stderr, "[%s %u]\n", asn1class_name(n->asn1class), n->asn1tag);
+ hexdump(stderr, n->hdr_value, n->hdr_length);
+ }
+
+ /* and our value */
+ if(has_real_children(n))
+ {
+ print_indent(indent);
+ fprintf(stderr, "{\n");
+ for(kid=n->children; kid; kid=kid->siblings)
+ print_der(kid, indent + 1);
+ print_indent(indent);
+ fprintf(stderr, "}\n");
+ }
+ else
+ {
+ hexdump(stderr, n->value, n->length);
+ }
+
+ return;
+}
+
+void
print_indent(unsigned int indent)
{
while(indent > 0)
@@ -193,7 +249,7 @@
void
usage(char *prog_name)
{
- fprintf(stderr, "Usage: %s [-vv] [<input_file>]\n", prog_name);
+ fprintf(stderr, "Usage: %s [-vv] [-o <output_file>] [<input_file>]\n", prog_name);
exit(EXIT_FAILURE);
}
Modified: redbutton-author/trunk/utils.c
===================================================================
--- redbutton-author/trunk/utils.c 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/utils.c 2007-09-24 16:03:05 UTC (rev 420)
@@ -24,9 +24,20 @@
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
+#include <string.h>
+#include <errno.h>
#include "utils.h"
+void
+write_all(FILE *out, unsigned char *buf, size_t len)
+{
+ if(fwrite(buf, 1, len, out) != len)
+ fatal("Error writing to file: %s", strerror(errno));
+
+ return;
+}
+
/*
* returns 15 for 'f' etc
*/
Modified: redbutton-author/trunk/utils.h
===================================================================
--- redbutton-author/trunk/utils.h 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/utils.h 2007-09-24 16:03:05 UTC (rev 420)
@@ -27,6 +27,8 @@
#include <stdarg.h>
#include <stdio.h>
+void write_all(FILE *, unsigned char *, size_t);
+
unsigned int char2hex(unsigned char);
void *safe_malloc(size_t);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 16:15:51
|
Revision: 421
http://redbutton.svn.sourceforge.net/redbutton/?rev=421&view=rev
Author: skilvington
Date: 2007-09-24 09:15:46 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
fix ConnectionTag Null issue
Modified Paths:
--------------
redbutton-author/trunk/TODO
redbutton-author/trunk/ccc.l
redbutton-author/trunk/ccc.y
redbutton-author/trunk/grammar
Modified: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO 2007-09-24 16:03:05 UTC (rev 420)
+++ redbutton-author/trunk/TODO 2007-09-24 16:15:46 UTC (rev 421)
@@ -1,14 +1,5 @@
-NewContentSize param in NewReferencedContent should compile to:
-[CONTEXT 234] { ... [UNIVERSAL 5] ... }
-not just [CONTEXT 234] { ... nothing ... }
-- ie need to add an explicit Null child node
+NewReferencedContent Null is in the wrong place
-same with ConnectionTag param in TransitionTo
-
-temp fix - add "Null" to the relevent 2 places in the grammar?
-real fix - add "Identifier?" to the grammar => optional, but adds a Null if not
- present (or perhaps "<Identifier>")
-
---
output filename should default to App/Scene GroupIdentifier rather than "a"
Modified: redbutton-author/trunk/ccc.l
===================================================================
--- redbutton-author/trunk/ccc.l 2007-09-24 16:03:05 UTC (rev 420)
+++ redbutton-author/trunk/ccc.l 2007-09-24 16:15:46 UTC (rev 421)
@@ -13,6 +13,7 @@
"[" return LBRACKET;
"]" return RBRACKET;
"+" return ONEORMORE;
+"?" return IDENTORNULL;
"." return ENDCLAUSE;
[\n\r\f] yylineno ++;
[ \t]+ /* ignore whitespace */
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-09-24 16:03:05 UTC (rev 420)
+++ redbutton-author/trunk/ccc.y 2007-09-24 16:15:46 UTC (rev 421)
@@ -19,7 +19,8 @@
IT_LITERAL, /* "LiteralString" */
IT_IDENTIFIER, /* NormalIdentifier */
IT_OPTIONAL, /* [OptionalIdentifier] */
- IT_ONEORMORE /* OneOrMoreIdentifier+ */
+ IT_ONEORMORE, /* OneOrMoreIdentifier+ */
+ IT_IDENTORNULL /* IdentifierOrNull? */
};
struct item
@@ -109,6 +110,7 @@
%token LBRACKET
%token RBRACKET
%token ONEORMORE
+%token IDENTORNULL
%token ENDCLAUSE
%token INVALID
@@ -172,6 +174,11 @@
{
add_item(IT_ONEORMORE, $1);
}
+ |
+ IDENTIFIER IDENTORNULL
+ {
+ add_item(IT_IDENTORNULL, $1);
+ }
;
%%
@@ -565,8 +572,8 @@
for(item=state.items; item; item=item->next)
{
/* assert */
- if(item->type != IT_IDENTIFIER && item->type != IT_LITERAL && item->type != IT_OPTIONAL)
- fatal("SEQUENCE but not Identifier, Literal or Optional");
+ if(item->type == IT_ONEORMORE)
+ fatal("SEQUENCE contains OneOrMore+");
/* eat literals, parse [optional] identifiers */
buf_append(&state.parse_fns, "\n\t/* %s */\n", item->name);
if(item->type == IT_LITERAL)
@@ -580,11 +587,19 @@
buf_append(&state.parse_fns, "\tnext = peek_token();\n");
buf_append(&state.parse_fns, "\tif(is_%s(next))\n", item->name);
buf_append(&state.parse_fns, "\t\tparse_%s(parent);\n", item->name);
- if(item->type != IT_OPTIONAL)
+ /* not optional => generate an error if it is not present */
+ if(item->type == IT_IDENTIFIER)
{
buf_append(&state.parse_fns, "\telse\n");
buf_append(&state.parse_fns, "\t\tparse_error(\"Expecting %s\");\n", item->name);
}
+ /* not optional - if it is not present, add a Null instead */
+ else if(item->type == IT_IDENTORNULL)
+ {
+ buf_append(&state.parse_fns, "\telse\n");
+ buf_append(&state.parse_fns, "\t\t(void) add_child(parent, ASN1TAGCLASS_NULL);\n");
+ }
+ /* else { optional - don't care if it is not present } */
}
}
break;
Modified: redbutton-author/trunk/grammar
===================================================================
--- redbutton-author/trunk/grammar 2007-09-24 16:03:05 UTC (rev 420)
+++ redbutton-author/trunk/grammar 2007-09-24 16:15:46 UTC (rev 421)
@@ -729,7 +729,7 @@
ComparisonValue ")" .
Toggle ::= ":Toggle" "(" Target ")" .
ToggleItem ::= ":ToggleItem" "(" Target ItemIndex ")" .
-TransitionTo ::= ":TransitionTo" "(" Target [ConnectionTag]
+TransitionTo ::= ":TransitionTo" "(" Target ConnectionTag?
[TransitionEffect] ")" .
Unload ::= ":Unload" "(" Target ")" .
UnlockScreen ::= ":UnlockScreen" "(" Target ")" .
@@ -820,7 +820,7 @@
NewPaletteRef ::= GenericObjectReference .
NewPortion ::= GenericInteger .
NewReferencedContent ::= ":NewRefContent" "(" GenericContentReference
- [NewContentSize]
+ NewContentSize?
[NewContentCachePriority] ")" .
NewSliderValue ::= GenericInteger .
NewSpeed ::= Rational .
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 16:29:30
|
Revision: 422
http://redbutton.svn.sourceforge.net/redbutton/?rev=422&view=rev
Author: skilvington
Date: 2007-09-24 09:29:26 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
fix NewReferencedContent Null issue. In theory the compiler is now fully working.
Modified Paths:
--------------
redbutton-author/trunk/TODO
redbutton-author/trunk/ccc.y
redbutton-author/trunk/parser.c.header
redbutton-author/trunk/parser.h.header
Modified: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO 2007-09-24 16:15:46 UTC (rev 421)
+++ redbutton-author/trunk/TODO 2007-09-24 16:29:26 UTC (rev 422)
@@ -1,7 +1,3 @@
-NewReferencedContent Null is in the wrong place
-
----
-
output filename should default to App/Scene GroupIdentifier rather than "a"
(but warn if file exists - stops accidental overwrite of source!)
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-09-24 16:15:46 UTC (rev 421)
+++ redbutton-author/trunk/ccc.y 2007-09-24 16:29:26 UTC (rev 422)
@@ -597,7 +597,7 @@
else if(item->type == IT_IDENTORNULL)
{
buf_append(&state.parse_fns, "\telse\n");
- buf_append(&state.parse_fns, "\t\t(void) add_child(parent, ASN1TAGCLASS_NULL);\n");
+ buf_append(&state.parse_fns, "\t\tadd_null_child(parent, ASN1TAGCLASS_%s);\n", item->name);
}
/* else { optional - don't care if it is not present } */
}
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-24 16:15:46 UTC (rev 421)
+++ redbutton-author/trunk/parser.c.header 2007-09-24 16:29:26 UTC (rev 422)
@@ -93,6 +93,20 @@
}
/*
+ * add this child and add a Null below it
+ */
+
+void
+add_null_child(struct node *parent, uint32_t asn1tagclass)
+{
+ parent = add_child(parent, asn1tagclass);
+
+ (void) add_child(parent, ASN1TAGCLASS_NULL);
+
+ return;
+}
+
+/*
* return true if any of the node's descendants are not synthetic
*/
Modified: redbutton-author/trunk/parser.h.header
===================================================================
--- redbutton-author/trunk/parser.h.header 2007-09-24 16:15:46 UTC (rev 421)
+++ redbutton-author/trunk/parser.h.header 2007-09-24 16:29:26 UTC (rev 422)
@@ -46,6 +46,9 @@
/* add a child to a node */
struct node *add_child(struct node *, uint32_t);
+/* add a Null ASN1 object child to a node */
+void add_null_child(struct node *, uint32_t);
+
/* return true if any of the node's descendants are not synthetic */
bool has_real_children(struct node *);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-25 11:59:43
|
Revision: 424
http://redbutton.svn.sourceforge.net/redbutton/?rev=424&view=rev
Author: skilvington
Date: 2007-09-25 04:59:39 -0700 (Tue, 25 Sep 2007)
Log Message:
-----------
report line number if STRINGs or QPRINTABLEs are invalid
Modified Paths:
--------------
redbutton-author/trunk/TODO
redbutton-author/trunk/der_encode.c
Modified: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO 2007-09-24 18:35:05 UTC (rev 423)
+++ redbutton-author/trunk/TODO 2007-09-25 11:59:39 UTC (rev 424)
@@ -7,9 +7,5 @@
---
-change fatal()'s to parse_error()'s in convert_STRING() et al.
-
----
-
clean up ccc.y
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-24 18:35:05 UTC (rev 423)
+++ redbutton-author/trunk/der_encode.c 2007-09-25 11:59:39 UTC (rev 424)
@@ -127,6 +127,7 @@
{
const unsigned char *whole_str = str;
unsigned char *p;
+ bool err;
/* max size it could be */
*out = safe_malloc(strlen(str));
@@ -134,11 +135,13 @@
/* skip the initial " */
str ++;
p = *out;
- while(*str != '"')
+ err = false;
+ while(!err && *str != '"')
{
if(*str < 0x20 || *str > 0x7e)
{
- fatal("Invalid character (0x%02x) in STRING: %s", *str, whole_str);
+ parse_error("Invalid character (0x%02x) in STRING: %s", *str, whole_str);
+ err = true;
}
else if(*str != '\\')
{
@@ -160,17 +163,30 @@
}
else
{
- /* TODO: show the line number */
- fatal("Invalid escape sequence in STRING: %s", whole_str);
+ parse_error("Invalid escape sequence in STRING: %s", whole_str);
+ err = true;
}
}
/* check we got to the closing quote */
- if(*(str + 1) != '\0')
- fatal("Unquoted \" in STRING: %s", whole_str);
+ if(!err && *(str + 1) != '\0')
+ {
+ parse_error("Unquoted \" in STRING: %s", whole_str);
+ err = true;
+ }
- /* return the length (note: no \0 terminator) */
- *len = (p - *out);
+ if(!err)
+ {
+ /* return the length (note: no \0 terminator) */
+ *len = (p - *out);
+ }
+ else
+ {
+ /* clean up */
+ safe_free(*out);
+ *out = NULL;
+ *len = 0;
+ }
return;
}
@@ -187,6 +203,7 @@
{
const unsigned char *whole_str = str;
unsigned char *p;
+ bool err;
/* max size it could be */
*out = safe_malloc(strlen(str));
@@ -194,7 +211,8 @@
/* skip the initial ' */
str ++;
p = *out;
- while(*str != '\'')
+ err = false;
+ while(!err && *str != '\'')
{
if(*str != '=')
{
@@ -210,17 +228,30 @@
}
else
{
- /* TODO: show the line number */
- fatal("Invalid escape sequence in QPRINTABLE: %s", whole_str);
+ parse_error("Invalid escape sequence in QPRINTABLE: %s", whole_str);
+ err = true;
}
}
/* check we got to the closing quote */
- if(*(str + 1) != '\0')
- fatal("Unquoted ' in QPRINTABLE: %s", whole_str);
+ if(!err && *(str + 1) != '\0')
+ {
+ parse_error("Unquoted ' in QPRINTABLE: %s", whole_str);
+ err = true;
+ }
- /* return the length (note: no \0 terminator) */
- *len = (p - *out);
+ if(!err)
+ {
+ /* return the length (note: no \0 terminator) */
+ *len = (p - *out);
+ }
+ else
+ {
+ /* clean up */
+ safe_free(*out);
+ *out = NULL;
+ *len = 0;
+ }
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-10-15 08:50:55
|
Revision: 436
http://redbutton.svn.sourceforge.net/redbutton/?rev=436&view=rev
Author: skilvington
Date: 2007-10-15 01:50:51 -0700 (Mon, 15 Oct 2007)
Log Message:
-----------
initial import of mhegd (opposite of mhegc) not finished yet
Modified Paths:
--------------
redbutton-author/trunk/Makefile
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/ccc.y
Added Paths:
-----------
redbutton-author/trunk/der_decode.c
redbutton-author/trunk/der_decode.h
redbutton-author/trunk/mhegd.c
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-10-15 08:49:09 UTC (rev 435)
+++ redbutton-author/trunk/Makefile 2007-10-15 08:50:51 UTC (rev 436)
@@ -4,6 +4,8 @@
# for vasprintf
DEFS=-D_GNU_SOURCE
+LIBS=
+
LEX=flex
YACC=bison
#LEX=lex
@@ -11,18 +13,29 @@
DESTDIR=/usr/local
-OBJS= mhegc.o \
- lex.parser.o \
- parser.o \
- der_encode.o \
- asn1tag.o \
- utils.o
+MHEGC_OBJS= mhegc.o \
+ lex.parser.o \
+ parser.o \
+ der_encode.o \
+ asn1tag.o \
+ utils.o
+MHEGD_OBJS= mhegd.o \
+ asn1decode.o \
+ der_decode.o \
+ asn1tag.o \
+ utils.o
+
TARDIR=`basename ${PWD}`
-mhegc: parser.h ${OBJS}
- ${CC} ${CFLAGS} ${DEFS} -o mhegc ${OBJS} ${LIBS}
+all: mhegc mhegd
+mhegc: parser.h ${MHEGC_OBJS}
+ ${CC} ${CFLAGS} ${DEFS} -o mhegc ${MHEGC_OBJS} ${LIBS}
+
+mhegd: asn1decode.h ${MHEGD_OBJS}
+ ${CC} ${CFLAGS} ${DEFS} -o mhegd ${MHEGD_OBJS} ${LIBS}
+
ccc: ccc.y ccc.l asn1type.o
${LEX} -i -t ccc.l > lex.ccc.c
${YACC} -b ccc -d ccc.y
@@ -32,17 +45,21 @@
cat grammar | ./ccc -l parser.l -p parser.c -h parser.h -t tokens.h
${LEX} -i -t parser.l > lex.parser.c
+asn1decode.c asn1decode.h: asn1decode.c.* asn1decode.h.* grammar asn1tag.h ccc
+ cat grammar | ./ccc -d asn1decode.c -e asn1decode.h
+
.c.o:
${CC} ${CFLAGS} ${DEFS} -c $<
berdecode: berdecode.c
${CC} ${CFLAGS} ${DEFS} -o berdecode berdecode.c
-install: mhegc
+install: mhegc mhegd
install -m 755 mhegc ${DESTDIR}/bin
+ install -m 755 mhegd ${DESTDIR}/bin
clean:
- rm -f mhegc ccc lex.ccc.c ccc.tab.[ch] lex.parser.c parser.[lch] tokens.h *.o berdecode core
+ rm -f mhegc mhegd ccc lex.ccc.c ccc.tab.[ch] lex.parser.c parser.[lch] tokens.h asn1decode.[ch] *.o berdecode core
tar:
make clean
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-10-15 08:49:09 UTC (rev 435)
+++ redbutton-author/trunk/asn1tag.h 2007-10-15 08:50:51 UTC (rev 436)
@@ -589,6 +589,8 @@
#define ASN1TAGCLASS_ENUMERATED ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_ENUMERATED)
#define ASN1TAGCLASS_SEQUENCE ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_SEQUENCE)
#define ASN1TAGCLASS_SET ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_SET)
+/* alias */
+#define ASN1TAGCLASS_Null ASN1TAGCLASS_NULL
/* the ASN1 types in the grammar that are not CONTEXT class types */
#define ASN1TAGCLASS_JointIsoItuIdentifier ASN1TAGCLASS_INTEGER
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-10-15 08:49:09 UTC (rev 435)
+++ redbutton-author/trunk/ccc.y 2007-10-15 08:50:51 UTC (rev 436)
@@ -58,6 +58,9 @@
struct buf parse_hdr; /* parse_Xxx() prototypes for the parser */
struct buf parse_enum_hdr; /* parse_Xxx() prototypes for enum values */
struct buf is_hdr; /* is_Xxx() prototypes for the parser */
+ struct buf decode_fns; /* asn1decode_Xxx() C functions for mhegd */
+ struct buf decode_is_fns; /* is_Xxx() C functions for mhegd */
+ struct buf decode_hdr; /* asn1decode_Xxx() prototypes for mhegd */
} state;
/* header for files we generate */
@@ -191,12 +194,14 @@
char *parser_name = NULL;
char *header_name = NULL;
char *tokens_name = NULL;
+ char *decode_name = NULL;
+ char *decode_hdr_name = NULL;
int arg;
struct str_list *t;
char header[PATH_MAX];
char footer[PATH_MAX];
- while((arg = getopt(argc, argv, "l:p:h:t:")) != EOF)
+ while((arg = getopt(argc, argv, "l:p:h:t:d:e:")) != EOF)
{
switch(arg)
{
@@ -216,6 +221,14 @@
tokens_name = optarg;
break;
+ case 'd':
+ decode_name = optarg;
+ break;
+
+ case 'e':
+ decode_hdr_name = optarg;
+ break;
+
default:
usage(prog_name);
break;
@@ -234,6 +247,9 @@
buf_init(&state.parse_hdr);
buf_init(&state.parse_enum_hdr);
buf_init(&state.is_hdr);
+ buf_init(&state.decode_fns);
+ buf_init(&state.decode_is_fns);
+ buf_init(&state.decode_hdr);
yyparse();
@@ -312,13 +328,46 @@
fclose(tokens_file);
}
+ /* output ASN1 decoder file */
+ if(decode_name != NULL)
+ {
+ FILE *decode_file = safe_fopen(decode_name, "w");
+ fprintf(decode_file, STANDARD_HEADER);
+ /* output the header if there is one */
+ snprintf(header, sizeof(header), "%s.header", decode_name);
+ file_append(decode_file, header);
+ /* output our stuff */
+ fprintf(decode_file, "%s", state.decode_fns.str);
+ fprintf(decode_file, "%s", state.decode_is_fns.str);
+ /* output the footer if there is one */
+ snprintf(footer, sizeof(footer), "%s.footer", decode_name);
+ file_append(decode_file, footer);
+ fclose(decode_file);
+ }
+
+ /* output ASN1 decoder header file */
+ if(decode_hdr_name != NULL)
+ {
+ FILE *decode_hdr_file = safe_fopen(decode_hdr_name, "w");
+ fprintf(decode_hdr_file, STANDARD_HEADER);
+ /* output the header if there is one */
+ snprintf(header, sizeof(header), "%s.header", decode_hdr_name);
+ file_append(decode_hdr_file, header);
+ /* output our stuff */
+ fprintf(decode_hdr_file, "%s", state.decode_hdr.str);
+ /* output the footer if there is one */
+ snprintf(footer, sizeof(footer), "%s.footer", decode_hdr_name);
+ file_append(decode_hdr_file, footer);
+ fclose(decode_hdr_file);
+ }
+
return EXIT_SUCCESS;
}
void
usage(char *prog_name)
{
- fprintf(stderr, "Syntax: %s [-l <lexer-file>] [-p <parser-c-file>] [-h <parser-h-file>] [-t <tokens-file>]\n", prog_name);
+ fprintf(stderr, "Syntax: %s [-l <lexer-file>] [-p <parser-c-file>] [-h <parser-h-file>] [-t <tokens-file>] [-d <decode-c-file>] [-e <decode-h-file>]\n", prog_name);
exit(EXIT_FAILURE);
}
@@ -371,6 +420,7 @@
struct item *next;
unsigned int nitems;
unsigned int enum_val;
+ bool first;
/* prototype for the parse_Xxx function */
buf_append(&state.parse_hdr, "void parse_%s(struct node *);\n", name);
@@ -727,6 +777,217 @@
}
buf_append(&state.is_fns, "}\n\n");
+ /* ASN1 decode prototypes */
+ buf_append(&state.decode_hdr, "int asn1decode_%s(FILE *, FILE *, int);\n", name);
+ buf_append(&state.decode_hdr, "bool is_%s(unsigned char, unsigned int);\n\n", name);
+
+ /* ASN1 decode_Xxx() functions */
+ buf_append(&state.decode_fns, "int asn1decode_%s(FILE *der, FILE *out, int length)\n{\n", name);
+ buf_append(&state.decode_fns, "\tint left = length;\n");
+ buf_append(&state.decode_fns, "\tint sublen;\n");
+ buf_append(&state.decode_fns, "\tstruct der_tag tag;\n\n");
+ buf_append(&state.decode_fns, "\tverbose(\"<%s>\\n\");\n\n", name);
+
+ /* ASN1 is_Xxx() functions */
+ buf_append(&state.decode_is_fns, "bool is_%s(unsigned char class, unsigned int number)\n{\n", name);
+
+ /* count how many non-literal items there are */
+ nitems = 0;
+ for(item=state.items; item; item=item->next)
+ if(item->type != IT_LITERAL)
+ nitems ++;
+
+ /* is it the special case */
+ if(strcmp(name, "OctetString") == 0)
+ {
+ /* decode_Xxx() function */
+ 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, "\tleft -= sublen;\n\n");
+ buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", name);
+ buf_append(&state.decode_fns, "\t\tder_decode_%s(der, out, tag.length);\n", name);
+ buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
+ buf_append(&state.decode_fns, "\t}\n\telse\n");
+ buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n\n", name);
+ /* is_Xxx() function */
+ buf_append(&state.decode_is_fns, "\treturn MATCH_TAGCLASS(class, number, ASN1TAGCLASS_OCTETSTRING);\n");
+ }
+ /* has it got only 1 non-literal item */
+ else if(nitems == 1)
+ {
+ /* output any literals at the start */
+ for(item=state.items; item && item->type==IT_LITERAL; item=item->next)
+ buf_append(&state.decode_fns, "\tfprintf(out, \"%%s \", %s);\n\n", item->name);
+ /* 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, "\tleft -= sublen;\n\n");
+ buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", item->name);
+ buf_append(&state.decode_fns, "\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
+ buf_append(&state.decode_fns, "\t}\n\telse\n");
+ buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n\n", name);
+ /* is_Xxx() function */
+ buf_append(&state.decode_is_fns, "\treturn is_%s(class, number);\n", item->name);
+ /* output any literals at the end */
+ item = item->next;
+ while(item)
+ {
+ /* assert */
+ if(item->type != IT_LITERAL)
+ fatal("Trailing non-literal");
+ buf_append(&state.decode_fns, "\tfprintf(out, %s);\n\n", item->name);
+ item = item->next;
+ }
+ }
+ /* is it a SEQUENCE or SET */
+ else if(state.and_items)
+ {
+ /* output any literals at the start */
+ for(item=state.items; item && item->type==IT_LITERAL; item=item->next)
+ buf_append(&state.decode_fns, "\tfprintf(out, \"%%s \", %s);\n\n", item->name);
+ /* items must be in the order they are defined for SEQUENCE types */
+ switch(asn1type(name))
+ {
+ case ASN1TYPE_SEQUENCE:
+ /* assert */
+ if(item->type != IT_IDENTIFIER)
+ fatal("not Identifier");
+ /* is_Xxx() - just match the first item */
+ buf_append(&state.decode_is_fns, "\treturn is_%s(class, number);\n", item->name);
+ /* decode_Xxx() - examine each non-literal item in turn */
+ while(item && item->type != IT_LITERAL)
+ {
+/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+ item = item->next;
+ }
+ break;
+
+ case ASN1TYPE_SET:
+ /* while there is data left in the current object */
+ buf_append(&state.decode_fns, "\twhile(left > 0)\n\t{\n");
+ /* decode the next tag */
+ 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");
+ /* the non-literal items may appear in any order */
+ first = true;
+ while(item && item->type != IT_LITERAL)
+ {
+ /* is_Xxx() */
+ if(first)
+ buf_append(&state.decode_is_fns, "\treturn ");
+ else
+ buf_append(&state.decode_is_fns, "\t || ");
+ buf_append(&state.decode_is_fns, "is_%s(class, number)", item->name);
+ /* is it the last */
+ if(item->next == NULL || item->next->type == IT_LITERAL)
+ buf_append(&state.decode_is_fns, ";");
+ buf_append(&state.decode_is_fns, "\n");
+ /* decode_Xxx() */
+ if(first)
+ buf_append(&state.decode_fns, "\t\t");
+ else
+ buf_append(&state.decode_fns, "\t\telse ");
+ first = false;
+ buf_append(&state.decode_fns, "if(is_%s(tag.class, tag.number))\n\t\t{\n", item->name);
+ buf_append(&state.decode_fns, "\t\t\tasn1decode_%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");
+ item = item->next;
+ }
+ /* decode_Xxx() */
+ buf_append(&state.decode_fns, "\t\telse\n");
+ buf_append(&state.decode_fns, "\t\t{\n\t\t\treturn der_error(\"%s: unexpected tag [%%s %%u]\", asn1class_name(tag.class), tag.number);\n\t}\n", name);
+ buf_append(&state.decode_fns, "\t\t}\n\n");
+ break;
+
+ default:
+ /* assert */
+ fatal("and_items set but not a SEQUENCE or SET");
+ break;
+ }
+ /* output any literals at the end */
+ while(item)
+ {
+ /* assert */
+ if(item->type != IT_LITERAL)
+ fatal("Trailing non-literal");
+ buf_append(&state.decode_fns, "\tfprintf(out, %s);\n\n", item->name);
+ item = item->next;
+ }
+ }
+ /* is it ENUMERATED */
+ else if(asn1type(name) == ASN1TYPE_ENUMERATED)
+ {
+ /* an ENUMERATED type */
+ buf_append(&state.decode_fns, "\t/* ENUMERATED */\n");
+ buf_append(&state.decode_fns, "\tchar *enum_names[] = {\n");
+ enum_val = 0;
+ for(item=state.items; item; item=item->next)
+ {
+ buf_append(&state.decode_fns, "\t\t%s,\n", item->name);
+ enum_val ++;
+ }
+ buf_append(&state.decode_fns, "\t};\n\n");
+ 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, "\tleft -= sublen;\n\n");
+ /* the ENUMERATED value is encoded as an INTEGER */
+ buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", name);
+ buf_append(&state.decode_fns, "\t\tder_decode_ENUMERATED(der, out, tag.length, %u, enum_names);\n", enum_val);
+ buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
+ buf_append(&state.decode_fns, "\t}\n\telse\n");
+ buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n\n", name);
+ /* is_Xxx() function */
+ buf_append(&state.decode_is_fns, "\treturn MATCH_TAGCLASS(class, number, ASN1TAGCLASS_ENUMERATED);\n");
+ }
+ /* must be a CHOICE */
+ else
+ {
+ /* a CHOICE type */
+ buf_append(&state.decode_fns, "\t/* CHOICE */\n");
+ 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, "\tleft -= sublen;\n\n");
+ /* see which item we chose */
+ for(item=state.items; item; item=item->next)
+ {
+ /* is_Xxx() function */
+ if(item == state.items)
+ buf_append(&state.decode_is_fns, "\treturn ");
+ else
+ buf_append(&state.decode_is_fns, "\t || ");
+ buf_append(&state.decode_is_fns, "MATCH_TAGCLASS(class, number, ASN1TAGCLASS_%s)", item->name);
+ /* is it the last */
+ if(item->next == NULL)
+ buf_append(&state.decode_is_fns, ";");
+ buf_append(&state.decode_is_fns, "\n");
+ /* decode_Xxx() function */
+ if(item == state.items)
+ buf_append(&state.decode_fns, "\t");
+ else
+ buf_append(&state.decode_fns, "\telse ");
+ buf_append(&state.decode_fns, "if(MATCH_TAGCLASS(tag.class, tag.number, ASN1TAGCLASS_%s))\n\t{\n", item->name);
+ buf_append(&state.decode_fns, "\t\tif((sublen = asn1decode_%s(der, out, tag.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");
+ buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n\n", name);
+ }
+
+ /* end decode_Xxx() function */
+ buf_append(&state.decode_fns, "\tfprintf(out, \"\\n\");\n\n");
+ buf_append(&state.decode_fns, "\tif(left != 0)\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s: %%d bytes left\", left);\n\n", name);
+ buf_append(&state.decode_fns, "\tverbose(\"</%s>\\n\");\n\n", name);
+ buf_append(&state.decode_fns, "\treturn length;\n}\n\n");
+
+ /* end is_Xxx() function */
+ buf_append(&state.decode_is_fns, "}\n\n");
+
/* free the items */
item = state.items;
while(item)
@@ -850,6 +1111,9 @@
if((b->str = malloc(b->nalloced)) == NULL)
fatal("Out of memory");
+ /* in case it never gets any data put in it */
+ b->str[0] = '\0';
+
return;
}
Added: redbutton-author/trunk/der_decode.c
===================================================================
--- redbutton-author/trunk/der_decode.c (rev 0)
+++ redbutton-author/trunk/der_decode.c 2007-10-15 08:50:51 UTC (rev 436)
@@ -0,0 +1,240 @@
+/*
+ * der_decode.c
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <ctype.h>
+
+#include "der_decode.h"
+
+void verbose(char *, ...);
+char hexdigit(unsigned char);
+
+/* DER does not allow indefinite lengths */
+
+int
+der_decode_Tag(FILE *der, struct der_tag *tag)
+{
+ unsigned int type;
+ unsigned int len;
+ unsigned char byte;
+ unsigned int longtype;
+ int nlens;
+ int nbytes = 0;
+
+ /* type */
+ if(der_read_file(der, 1, &byte) != 1)
+ return der_error("DER tag");
+ nbytes ++;
+ type = byte;
+ longtype = 0;
+ if((type & 0x1f) == 0x1f)
+ {
+ /* multi byte type */
+ do
+ {
+ if(der_read_file(der, 1, &byte) != 1)
+ return der_error("DER tag");
+ nbytes ++;
+ longtype <<= 7;
+ longtype += byte & 0x7f;
+ }
+ while((byte & 0x80) != 0);
+ }
+ tag->class = type & 0xc0;
+ tag->number = ((type & 0x1f) == 0x1f) ? longtype : type & 0x1f;
+
+ /* length */
+ if(der_read_file(der, 1, &byte) != 1)
+ return der_error("DER tag");
+ nbytes ++;
+ len = byte;
+ if(len == 0 && type == 0)
+ {
+ return der_error("Found EOC; indefinite lengths not allowed in DER");
+ }
+ else if(len == 0x80)
+ {
+ return der_error("Indefinite lengths not allowed in DER");
+ }
+ else if((len & 0x80) == 0x80)
+ {
+ /* multibyte length field */
+ nlens = len & 0x7f;
+ len = 0;
+ while(nlens > 0)
+ {
+ if(der_read_file(der, 1, &byte) != 1)
+ return der_error("DER tag");
+ nbytes ++;
+ len <<= 8;
+ len += byte;
+ nlens --;
+ }
+ }
+ tag->length = len;
+
+ return nbytes;
+}
+
+int
+der_decode_BOOLEAN(FILE *der, FILE *out, int length)
+{
+ unsigned char val;
+
+ if(length != 1)
+ return der_error("Boolean: length=%d", length);
+
+ if(der_read_file(der, length, &val) < 0)
+ return der_error("Boolean");
+
+ verbose("<Boolean value=\"%s\"/>\n", val ? "true" : "false");
+
+ fprintf(out, "%s", val ? "true" : "false");
+
+ return length;
+}
+
+int
+der_decode_INTEGER(FILE *der, FILE *out, int length)
+{
+ int val = get_der_int(der, length);
+
+ verbose("<Integer value=\"%d\"/>\n", val);
+
+ fprintf(out, "%d", val);
+
+ return length;
+}
+
+/* DER does not allow constructed OCTET-STRINGs */
+
+int
+der_decode_OctetString(FILE *der, FILE *out, int length)
+{
+ int left = length;
+ unsigned char byte;
+
+ verbose("<OctetString size=\"%d\">\n", length);
+
+ fprintf(out, "'");
+ while(left > 0)
+ {
+ if(der_read_file(der, 1, &byte) < 0)
+ return der_error("OctetString");
+ if(byte != '\'' && byte >= 0x20 && byte < 0x7f)
+ fprintf(out, "%c", byte);
+ else
+ fprintf(out, "=%c%c", hexdigit((byte >> 4) & 0xf), hexdigit(byte & 0xf));
+ left --;
+ }
+ fprintf(out, "'");
+
+ verbose("</OctetString>\n");
+
+ return length;
+}
+
+int
+der_decode_Null(FILE *der, FILE *out, int length)
+{
+ if(length != 0)
+ return der_error("Null: length=%d", length);
+
+ verbose("<Null/>");
+
+ return length;
+}
+
+int
+der_decode_ENUMERATED(FILE *der, FILE *out, int length, unsigned int max, char *names[])
+{
+ int val = get_der_int(der, length);
+
+ if(val < 1 || val > max)
+ return der_error("Enumerated: %d; not in range 1-%d", val, max);
+
+ verbose("<Enumerated value=\"%d\"/>\n", val);
+
+ fprintf(out, "%s", names[val - 1]);
+
+ return length;
+}
+
+char
+hexdigit(unsigned char nibble)
+{
+ if(nibble < 10)
+ return '0' + nibble;
+ else if(nibble < 16)
+ return 'a' + nibble;
+ else
+ return '?';
+}
+
+int
+get_der_int(FILE *der, int length)
+{
+ unsigned char byte;
+ unsigned int uval;
+ int val;
+ bool negative;
+ int i;
+
+ if(length > sizeof(int))
+ fatal("Integer: length=%d", length);
+
+ /* is it -ve */
+ if(der_read_file(der, 1, &byte) < 0)
+ fatal("Integer: EOF");
+ negative = ((byte & 0x80) == 0x80);
+
+ /* big endian */
+ uval = byte;
+ for(i=1; i<length; i++)
+ {
+ if(der_read_file(der, 1, &byte) < 0)
+ fatal("Integer: EOF");
+ uval <<= 8;
+ uval += byte;
+ }
+
+ /* sign extend if negative */
+ if(negative)
+ {
+ /* byte order neutral */
+ for(i=length; i<sizeof(int); i++)
+ uval += (0xff << (i * 8));
+ }
+
+ val = (int) uval;
+
+ return val;
+}
+
+int
+der_read_file(FILE *in, unsigned int nbytes, void *buf)
+{
+ int nread;
+
+ if((nread = fread(buf, 1, nbytes, in)) != nbytes)
+ return der_error("Unexpected EOF");
+
+ return nread;
+}
+
+int
+der_error(char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+ va_end(args);
+
+ return -1;
+}
+
Added: redbutton-author/trunk/der_decode.h
===================================================================
--- redbutton-author/trunk/der_decode.h (rev 0)
+++ redbutton-author/trunk/der_decode.h 2007-10-15 08:50:51 UTC (rev 436)
@@ -0,0 +1,47 @@
+/*
+ * der_decode.h
+ */
+
+#ifndef __DER_DECODE_H__
+#define __DER_DECODE_H__
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "utils.h"
+
+#define der_alloc(N) safe_malloc(N)
+#define der_realloc(P, N) safe_realloc(P, N)
+#define der_free(P) safe_free(P)
+
+struct der_tag
+{
+ unsigned char class;
+ unsigned int number;
+ unsigned int length;
+};
+
+#define DER_CLASS_UNIVERSAL 0x00
+#define DER_CLASS_APPLICATION 0x40
+#define DER_CLASS_CONTEXT 0x80
+#define DER_CLASS_PRIVATE 0xc0
+
+/* top 8 bits are class, bottom 24 are the tag number */
+#define MATCH_TAGCLASS(CLASS, NUMBER, TAGCLASS) ((CLASS == ((TAGCLASS >> 24) & 0xff)) && (NUMBER == (TAGCLASS & 0xffffff)))
+
+int der_decode_Tag(FILE *, struct der_tag *);
+
+int der_decode_BOOLEAN(FILE *, FILE *, int);
+int der_decode_INTEGER(FILE *, FILE *, int);
+int der_decode_OctetString(FILE *, FILE *, int);
+int der_decode_Null(FILE *, FILE *, int);
+int der_decode_ENUMERATED(FILE *, FILE *, int, unsigned int, char **);
+
+int get_der_int(FILE *, int);
+
+int der_read_file(FILE *, unsigned int, void *);
+
+int der_error(char *, ...);
+
+#endif /* __DER_DECODE_H__ */
+
Added: redbutton-author/trunk/mhegd.c
===================================================================
--- redbutton-author/trunk/mhegd.c (rev 0)
+++ redbutton-author/trunk/mhegd.c 2007-10-15 08:50:51 UTC (rev 436)
@@ -0,0 +1,131 @@
+/*
+ * mhegd.c
+ */
+
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "asn1decode.h"
+#include "der_decode.h"
+#include "utils.h"
+
+void verbose(const char *, ...);
+void vverbose(const char *, ...);
+
+void usage(char *);
+
+static int _verbose = 0;
+
+int
+main(int argc, char *argv[])
+{
+ char *prog_name = argv[0];
+ int arg;
+ FILE *in_file;
+ FILE *out_file = stdout;
+ int filesize;
+
+ while((arg = getopt(argc, argv, "o:v")) != EOF)
+ {
+ switch(arg)
+ {
+ case 'o':
+ if((out_file = fopen(optarg, "w")) == NULL)
+ fatal("Unable to write '%s': %s", optarg, strerror(errno));
+ break;
+
+ case 'v':
+ _verbose ++;
+ break;
+
+ default:
+ usage(prog_name);
+ break;
+ }
+ }
+
+ /* the single param is the name of a DER file */
+ if(optind != argc - 1)
+ usage(prog_name);
+
+ if((in_file = fopen(argv[optind], "r")) == NULL)
+ fatal("Unable to open '%s': %s", argv[optind], strerror(errno));
+
+ verbose("Reading '%s':\n", argv[optind]);
+
+ /* see how long the file is */
+ fseek(in_file, 0, SEEK_END);
+ filesize = (int) ftell(in_file);
+ rewind(in_file);
+
+ /* write text form of DER encoded in_file to out_file */
+ if(asn1decode_InterchangedObject(in_file, out_file, filesize) != filesize)
+ fatal("Unexpected data after InterchangedObject");
+
+ return EXIT_SUCCESS;
+}
+
+/*
+ * verbose functions send output to stderr so error messages get interleaved correctly
+ */
+
+void
+verbose(const char *fmt, ...)
+{
+ va_list ap;
+
+ if(_verbose)
+ {
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ }
+
+ return;
+}
+
+void
+vverbose(const char *fmt, ...)
+{
+ va_list ap;
+
+ if(_verbose > 1)
+ {
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ }
+
+ return;
+}
+
+void
+usage(char *prog_name)
+{
+ fprintf(stderr, "Usage: %s [-vv] [-o <output_file>] <input_file>\n", prog_name);
+
+ exit(EXIT_FAILURE);
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-10-15 08:52:30
|
Revision: 437
http://redbutton.svn.sourceforge.net/redbutton/?rev=437&view=rev
Author: skilvington
Date: 2007-10-15 01:52:29 -0700 (Mon, 15 Oct 2007)
Log Message:
-----------
forgot these files
Added Paths:
-----------
redbutton-author/trunk/asn1decode.c.header
redbutton-author/trunk/asn1decode.h.footer
redbutton-author/trunk/asn1decode.h.header
Added: redbutton-author/trunk/asn1decode.c.header
===================================================================
--- redbutton-author/trunk/asn1decode.c.header (rev 0)
+++ redbutton-author/trunk/asn1decode.c.header 2007-10-15 08:52:29 UTC (rev 437)
@@ -0,0 +1,111 @@
+#include "asn1decode.h"
+#include "der_decode.h"
+#include "asn1tag.h"
+
+void verbose(char *, ...);
+
+int asn1decode_BOOLEAN(FILE *der, FILE *out, int length)
+{
+ int left = length;
+ int sublen;
+ struct der_tag tag;
+
+ verbose("<BOOLEAN>\n");
+
+ if((sublen = der_decode_Tag(der, &tag)) < 0)
+ return der_error("BOOLEAN");
+ left -= sublen;
+
+ if(is_BOOLEAN(tag.class, tag.number))
+ {
+ der_decode_BOOLEAN(der, out, tag.length);
+ left -= tag.length;
+ }
+ else
+ {
+ return der_error("BOOLEAN");
+ }
+
+ if(left != 0)
+ return der_error("BOOLEAN: %d bytes left", left);
+
+ verbose("</BOOLEAN>\n");
+
+ return length;
+}
+
+bool is_BOOLEAN(unsigned char class, unsigned int number)
+{
+ return MATCH_TAGCLASS(class, number, ASN1TAGCLASS_BOOLEAN);
+}
+
+int asn1decode_INTEGER(FILE *der, FILE *out, int length)
+{
+ int left = length;
+ int sublen;
+ struct der_tag tag;
+
+ verbose("<INTEGER>\n");
+
+ if((sublen = der_decode_Tag(der, &tag)) < 0)
+ return der_error("INTEGER");
+ left -= sublen;
+
+ if(is_INTEGER(tag.class, tag.number))
+ {
+ der_decode_INTEGER(der, out, tag.length);
+ left -= tag.length;
+ }
+ else
+ {
+ return der_error("INTEGER");
+ }
+
+ if(left != 0)
+ return der_error("INTEGER: %d bytes left", left);
+
+ verbose("</INTEGER>\n");
+
+ return length;
+}
+
+bool is_INTEGER(unsigned char class, unsigned int number)
+{
+ return MATCH_TAGCLASS(class, number, ASN1TAGCLASS_INTEGER);
+}
+
+int asn1decode_Null(FILE *der, FILE *out, int length)
+{
+ int left = length;
+ int sublen;
+ struct der_tag tag;
+
+ verbose("<Null>\n");
+
+ if((sublen = der_decode_Tag(der, &tag)) < 0)
+ return der_error("Null");
+ left -= sublen;
+
+ if(is_Null(tag.class, tag.number))
+ {
+ der_decode_Null(der, out, tag.length);
+ left -= tag.length;
+ }
+ else
+ {
+ return der_error("Null");
+ }
+
+ if(left != 0)
+ return der_error("Null: %d bytes left", left);
+
+ verbose("</Null>\n");
+
+ return length;
+}
+
+bool is_Null(unsigned char class, unsigned int number)
+{
+ return MATCH_TAGCLASS(class, number, ASN1TAGCLASS_NULL);
+}
+
Added: redbutton-author/trunk/asn1decode.h.footer
===================================================================
--- redbutton-author/trunk/asn1decode.h.footer (rev 0)
+++ redbutton-author/trunk/asn1decode.h.footer 2007-10-15 08:52:29 UTC (rev 437)
@@ -0,0 +1,2 @@
+#endif /* __ASN1DECODE_H__ */
+
Added: redbutton-author/trunk/asn1decode.h.header
===================================================================
--- redbutton-author/trunk/asn1decode.h.header (rev 0)
+++ redbutton-author/trunk/asn1decode.h.header 2007-10-15 08:52:29 UTC (rev 437)
@@ -0,0 +1,15 @@
+#ifndef __ASN1DECODE_H__
+#define __ASN1DECODE_H__
+
+#include <stdio.h>
+#include <stdbool.h>
+
+int asn1decode_BOOLEAN(FILE *, FILE *, int);
+bool is_BOOLEAN(unsigned char, unsigned int);
+
+int asn1decode_INTEGER(FILE *, FILE *, int);
+bool is_INTEGER(unsigned char, unsigned int);
+
+int asn1decode_Null(FILE *, FILE *, int);
+bool is_Null(unsigned char, unsigned int);
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-10-16 13:01:42
|
Revision: 441
http://redbutton.svn.sourceforge.net/redbutton/?rev=441&view=rev
Author: skilvington
Date: 2007-10-16 06:01:37 -0700 (Tue, 16 Oct 2007)
Log Message:
-----------
propogate the current tag to ENUMERATED types
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-10-16 11:27:20 UTC (rev 440)
+++ redbutton-author/trunk/asn1tag.h 2007-10-16 13:01:37 UTC (rev 441)
@@ -753,5 +753,34 @@
/* ContentReference is [69] except in ReferencedContent */
#define ASN1TAGCLASS_ContentReference ASN1TAG_SYNTHETIC
+/* needed by mhegd */
+#define FIXME 9999
+#define ASN1TAGCLASS_ActionSlot FIXME
+#define ASN1TAGCLASS_ActionSlotSeq FIXME
+#define ASN1TAGCLASS_ButtonStyleEnum ASN1TAGCLASS_ENUMERATED
+#define ASN1TAGCLASS_Colour FIXME
+#define ASN1TAGCLASS_ContentBody FIXME
+#define ASN1TAGCLASS_DefaultAttribute FIXME
+#define ASN1TAGCLASS_ElementaryAction FIXME
+#define ASN1TAGCLASS_EventDataBody FIXME
+#define ASN1TAGCLASS_EventTypeEnum ASN1TAGCLASS_ENUMERATED
+#define ASN1TAGCLASS_FontBody FIXME
+#define ASN1TAGCLASS_GenericBoolean FIXME
+#define ASN1TAGCLASS_GenericContentReference FIXME
+#define ASN1TAGCLASS_GenericInteger FIXME
+#define ASN1TAGCLASS_GenericObjectReference FIXME
+#define ASN1TAGCLASS_GenericOctetString FIXME
+#define ASN1TAGCLASS_GroupItem FIXME
+#define ASN1TAGCLASS_InputTypeEnum ASN1TAGCLASS_ENUMERATED
+#define ASN1TAGCLASS_JustificationEnum ASN1TAGCLASS_ENUMERATED
+#define ASN1TAGCLASS_LineOrientationEnum ASN1TAGCLASS_ENUMERATED
+#define ASN1TAGCLASS_OrientationEnum ASN1TAGCLASS_ENUMERATED
+#define ASN1TAGCLASS_OriginalValueBody FIXME
+#define ASN1TAGCLASS_Parameter FIXME
+#define ASN1TAGCLASS_SliderStyleEnum ASN1TAGCLASS_ENUMERATED
+#define ASN1TAGCLASS_StartCornerEnum ASN1TAGCLASS_ENUMERATED
+#define ASN1TAGCLASS_StorageEnum ASN1TAGCLASS_ENUMERATED
+#define ASN1TAGCLASS_StreamComponent FIXME
+#define ASN1TAGCLASS_TerminationEnum ASN1TAGCLASS_ENUMERATED
+
#endif /* __ASN1TAG_H__ */
-
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-10-16 11:27:20 UTC (rev 440)
+++ redbutton-author/trunk/ccc.y 2007-10-16 13:01:37 UTC (rev 441)
@@ -819,11 +819,22 @@
for(item=state.items; item && item->type==IT_LITERAL; item=item->next)
buf_append(&state.decode_fns, "\tfprintf(out, \"%%s \", %s);\n\n", item->name);
/* decode the item */
+ buf_append(&state.decode_fns, "\tlong pretag = ftell(der);\n");
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, "\tleft -= sublen;\n\n");
buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", item->name);
- buf_append(&state.decode_fns, "\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
+ /* if it is a synthetic or ENUMERATED type, we still need the current tag */
+ buf_append(&state.decode_fns, "\t\tif(ASN1TAGCLASS_%s == ASN1TAG_SYNTHETIC\n", item->name);
+ buf_append(&state.decode_fns, "\t\t|| ASN1TAGCLASS_%s == ASN1TAGCLASS_ENUMERATED)\n", item->name);
+ buf_append(&state.decode_fns, "\t\t{\n");
+ buf_append(&state.decode_fns, "\t\t\tfseek(der, pretag, SEEK_SET);\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}\n");
+ buf_append(&state.decode_fns, "\t\telse\n");
+ buf_append(&state.decode_fns, "\t\t{\n");
+ buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\t}\n");
buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
buf_append(&state.decode_fns, "\t}\n\telse\n");
buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n\n", name);
@@ -892,8 +903,9 @@
buf_append(&state.decode_fns, "\t\telse ");
first = false;
buf_append(&state.decode_fns, "if(is_%s(tag.class, tag.number))\n\t\t{\n", item->name);
- /* if it is a synthetic type, we still need the current tag */
- buf_append(&state.decode_fns, "\t\t\tif(ASN1TAGCLASS_%s == ASN1TAG_SYNTHETIC)\n", item->name);
+ /* if it is a synthetic or ENUMERATED type, we still need the current tag */
+ buf_append(&state.decode_fns, "\t\t\tif(ASN1TAGCLASS_%s == ASN1TAG_SYNTHETIC\n", item->name);
+ buf_append(&state.decode_fns, "\t\t\t|| ASN1TAGCLASS_%s == ASN1TAGCLASS_ENUMERATED)\n", item->name);
buf_append(&state.decode_fns, "\t\t\t{\n");
buf_append(&state.decode_fns, "\t\t\t\tfseek(der, pretag, SEEK_SET);\n");
buf_append(&state.decode_fns, "\t\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-10-16 16:12:52
|
Revision: 442
http://redbutton.svn.sourceforge.net/redbutton/?rev=442&view=rev
Author: skilvington
Date: 2007-10-16 09:12:48 -0700 (Tue, 16 Oct 2007)
Log Message:
-----------
decode SEQUENCE types
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-10-16 13:01:37 UTC (rev 441)
+++ redbutton-author/trunk/asn1tag.h 2007-10-16 16:12:48 UTC (rev 442)
@@ -782,5 +782,11 @@
#define ASN1TAGCLASS_StorageEnum ASN1TAGCLASS_ENUMERATED
#define ASN1TAGCLASS_StreamComponent FIXME
#define ASN1TAGCLASS_TerminationEnum ASN1TAGCLASS_ENUMERATED
+#define ASN1TAGCLASS_ComparisonValue FIXME
+#define ASN1TAGCLASS_EmulatedEventData FIXME
+#define ASN1TAGCLASS_NewColour FIXME
+#define ASN1TAGCLASS_NewContent FIXME
+#define ASN1TAGCLASS_NewFont FIXME
+#define ASN1TAGCLASS_NewVariableValue FIXME
#endif /* __ASN1TAG_H__ */
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-10-16 13:01:37 UTC (rev 441)
+++ redbutton-author/trunk/ccc.y 2007-10-16 16:12:48 UTC (rev 442)
@@ -854,6 +854,10 @@
/* is it a SEQUENCE or SET */
else if(state.and_items)
{
+ if(asn1type(name) == ASN1TYPE_SEQUENCE)
+ buf_append(&state.decode_fns, "\t/* SEQUENCE */\n");
+ else
+ buf_append(&state.decode_fns, "\t/* SET */\n");
/* output any literals at the start */
for(item=state.items; item && item->type==IT_LITERAL; item=item->next)
buf_append(&state.decode_fns, "\tfprintf(out, \"%%s \", %s);\n\n", item->name);
@@ -867,9 +871,33 @@
/* is_Xxx() - just match the first item */
buf_append(&state.decode_is_fns, "\treturn is_%s(class, number);\n", item->name);
/* decode_Xxx() - examine each non-literal item in turn */
+ buf_append(&state.decode_fns, "\tlong pretag;\n\n");
while(item && item->type != IT_LITERAL)
{
-/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+ /* decode the next tag */
+ buf_append(&state.decode_fns, "\tpretag = ftell(der);\n");
+ 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, "\tleft -= sublen;\n\n");
+ /* is it what we expect */
+ buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", item->name);
+ /* if it is a synthetic or ENUMERATED type, we still need the current tag */
+ buf_append(&state.decode_fns, "\t\tif(ASN1TAGCLASS_%s == ASN1TAG_SYNTHETIC\n", item->name);
+ buf_append(&state.decode_fns, "\t\t|| ASN1TAGCLASS_%s == ASN1TAGCLASS_ENUMERATED)\n", item->name);
+ buf_append(&state.decode_fns, "\t\t{\n");
+ buf_append(&state.decode_fns, "\t\t\tfseek(der, pretag, SEEK_SET);\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}\n");
+ buf_append(&state.decode_fns, "\t\telse\n");
+ buf_append(&state.decode_fns, "\t\t{\n");
+ buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\t}\n");
+ buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
+ buf_append(&state.decode_fns, "\t}\n\n");
+ /* if it is not optional, raise an error if it is not present */
+/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+ /* if it is optional and not present, seek back to the start of the tag */
+/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
item = item->next;
}
break;
@@ -935,7 +963,7 @@
/* assert */
if(item->type != IT_LITERAL)
fatal("Trailing non-literal");
- buf_append(&state.decode_fns, "\tfprintf(out, %s);\n\n", item->name);
+ buf_append(&state.decode_fns, "\tfprintf(out, \"%%s \", %s);\n\n", item->name);
item = item->next;
}
}
@@ -990,6 +1018,7 @@
buf_append(&state.decode_fns, "\t");
else
buf_append(&state.decode_fns, "\telse ");
+/* TODO: does GenericObjectReference_direct_reference need a fseek(pretag) */
buf_append(&state.decode_fns, "if(MATCH_TAGCLASS(tag.class, tag.number, ASN1TAGCLASS_%s))\n\t{\n", item->name);
buf_append(&state.decode_fns, "\t\tif((sublen = asn1decode_%s(der, out, tag.length)) < 0)\n", item->name);
buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n", name);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-10-17 16:07:34
|
Revision: 443
http://redbutton.svn.sourceforge.net/redbutton/?rev=443&view=rev
Author: skilvington
Date: 2007-10-17 09:07:23 -0700 (Wed, 17 Oct 2007)
Log Message:
-----------
don't think we are going to need this
Modified Paths:
--------------
redbutton-author/trunk/asn1decode.c.header
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/asn1decode.c.header
===================================================================
--- redbutton-author/trunk/asn1decode.c.header 2007-10-16 16:12:48 UTC (rev 442)
+++ redbutton-author/trunk/asn1decode.c.header 2007-10-17 16:07:23 UTC (rev 443)
@@ -1,3 +1,6 @@
+#include <stdio.h>
+#include <stdbool.h>
+
#include "asn1decode.h"
#include "der_decode.h"
#include "asn1tag.h"
@@ -4,6 +7,17 @@
void verbose(char *, ...);
+bool keep_tag(unsigned int tagclass)
+{
+/* TODO: is this function needed? */
+return true;
+ if(ASN1TAGCLASS_GroupIdentifier == ASN1TAG_SYNTHETIC
+ || ASN1TAGCLASS_GroupIdentifier == ASN1TAGCLASS_ENUMERATED)
+ return true;
+ else
+ return false;
+}
+
int asn1decode_BOOLEAN(FILE *der, FILE *out, int length)
{
int left = length;
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-10-16 16:12:48 UTC (rev 442)
+++ redbutton-author/trunk/ccc.y 2007-10-17 16:07:23 UTC (rev 443)
@@ -825,8 +825,7 @@
buf_append(&state.decode_fns, "\tleft -= sublen;\n\n");
buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", item->name);
/* if it is a synthetic or ENUMERATED type, we still need the current tag */
- buf_append(&state.decode_fns, "\t\tif(ASN1TAGCLASS_%s == ASN1TAG_SYNTHETIC\n", item->name);
- buf_append(&state.decode_fns, "\t\t|| ASN1TAGCLASS_%s == ASN1TAGCLASS_ENUMERATED)\n", item->name);
+ buf_append(&state.decode_fns, "\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
buf_append(&state.decode_fns, "\t\t{\n");
buf_append(&state.decode_fns, "\t\t\tfseek(der, pretag, SEEK_SET);\n");
buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
@@ -882,8 +881,7 @@
/* is it what we expect */
buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", item->name);
/* if it is a synthetic or ENUMERATED type, we still need the current tag */
- buf_append(&state.decode_fns, "\t\tif(ASN1TAGCLASS_%s == ASN1TAG_SYNTHETIC\n", item->name);
- buf_append(&state.decode_fns, "\t\t|| ASN1TAGCLASS_%s == ASN1TAGCLASS_ENUMERATED)\n", item->name);
+ buf_append(&state.decode_fns, "\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
buf_append(&state.decode_fns, "\t\t{\n");
buf_append(&state.decode_fns, "\t\t\tfseek(der, pretag, SEEK_SET);\n");
buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
@@ -932,8 +930,7 @@
first = false;
buf_append(&state.decode_fns, "if(is_%s(tag.class, tag.number))\n\t\t{\n", item->name);
/* if it is a synthetic or ENUMERATED type, we still need the current tag */
- buf_append(&state.decode_fns, "\t\t\tif(ASN1TAGCLASS_%s == ASN1TAG_SYNTHETIC\n", item->name);
- buf_append(&state.decode_fns, "\t\t\t|| ASN1TAGCLASS_%s == ASN1TAGCLASS_ENUMERATED)\n", item->name);
+ buf_append(&state.decode_fns, "\t\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
buf_append(&state.decode_fns, "\t\t\t{\n");
buf_append(&state.decode_fns, "\t\t\t\tfseek(der, pretag, SEEK_SET);\n");
buf_append(&state.decode_fns, "\t\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-10-18 07:24:49
|
Revision: 444
http://redbutton.svn.sourceforge.net/redbutton/?rev=444&view=rev
Author: skilvington
Date: 2007-10-18 00:24:42 -0700 (Thu, 18 Oct 2007)
Log Message:
-----------
check for synthetic types in the is_Xxx() functions
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-10-17 16:07:23 UTC (rev 443)
+++ redbutton-author/trunk/asn1tag.h 2007-10-18 07:24:42 UTC (rev 444)
@@ -755,6 +755,7 @@
/* needed by mhegd */
#define FIXME 9999
+#define ASN1TAGCLASS_InterchangedObject ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_ActionSlot FIXME
#define ASN1TAGCLASS_ActionSlotSeq FIXME
#define ASN1TAGCLASS_ButtonStyleEnum ASN1TAGCLASS_ENUMERATED
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-10-17 16:07:23 UTC (rev 443)
+++ redbutton-author/trunk/ccc.y 2007-10-18 07:24:42 UTC (rev 444)
@@ -790,6 +790,9 @@
/* ASN1 is_Xxx() functions */
buf_append(&state.decode_is_fns, "bool is_%s(unsigned char class, unsigned int number)\n{\n", name);
+ buf_append(&state.decode_is_fns, "\tif(!is_synthetic(ASN1TAGCLASS_%s))\n", name);
+ buf_append(&state.decode_is_fns, "\t\treturn MATCH_TAGCLASS(class, number, ASN1TAGCLASS_%s);\n", name);
+ buf_append(&state.decode_is_fns, "\telse\n");
/* count how many non-literal items there are */
nitems = 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-10-18 08:34:57
|
Revision: 445
http://redbutton.svn.sourceforge.net/redbutton/?rev=445&view=rev
Author: skilvington
Date: 2007-10-18 01:34:54 -0700 (Thu, 18 Oct 2007)
Log Message:
-----------
fix error spotted by Mario Rossi
Modified Paths:
--------------
redbutton-author/trunk/ccc.l
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.l
===================================================================
--- redbutton-author/trunk/ccc.l 2007-10-18 07:24:42 UTC (rev 444)
+++ redbutton-author/trunk/ccc.l 2007-10-18 08:34:54 UTC (rev 445)
@@ -2,7 +2,7 @@
#include <string.h>
#define YYSTYPE char *
#include "ccc.tab.h"
-extern int yylineno;
+extern unsigned int yylineno;
%}
%%
\/\/[^\n\r\f]* return COMMENT;
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-10-18 07:24:42 UTC (rev 444)
+++ redbutton-author/trunk/ccc.y 2007-10-18 08:34:54 UTC (rev 445)
@@ -86,7 +86,7 @@
void file_append(FILE *, char *);
/* input line we are currently parsing */
-int yylineno = 1;
+unsigned int yylineno = 1;
/* yacc functions we need to provide */
void
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-10-18 08:41:16
|
Revision: 446
http://redbutton.svn.sourceforge.net/redbutton/?rev=446&view=rev
Author: skilvington
Date: 2007-10-18 01:41:14 -0700 (Thu, 18 Oct 2007)
Log Message:
-----------
these should be unsigned too
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
redbutton-author/trunk/parser.c.header
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-10-18 08:34:54 UTC (rev 445)
+++ redbutton-author/trunk/ccc.y 2007-10-18 08:41:14 UTC (rev 446)
@@ -92,7 +92,7 @@
void
yyerror(const char *str)
{
- fprintf(stderr, "Error: %s at line %d\n", str, yylineno);
+ fprintf(stderr, "Error: %s at line %u\n", str, yylineno);
return;
}
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-10-18 08:34:54 UTC (rev 445)
+++ redbutton-author/trunk/parser.c.header 2007-10-18 08:41:14 UTC (rev 446)
@@ -34,7 +34,7 @@
void
yyerror(const char *str)
{
- fprintf(stderr, "Error: %s at line %d\n", str, yylineno);
+ fprintf(stderr, "Error: %s at line %u\n", str, yylineno);
yynerrs ++;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|