[Redbutton-devel] SF.net SVN: redbutton: [403] redbutton-author/trunk
Brought to you by:
skilvington
|
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.
|