r14198: Update Samba4 to current lorikeet-heimdal.
[samba.git] / source4 / heimdal / lib / asn1 / parse.y
index 51dc51ed8835869f70cd3e791347d4f4130b970b..223847828476502ead6ea7e0f66882315d189bd1 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE. 
  */
 
-/* $Id: parse.y,v 1.25 2005/08/23 10:52:31 lha Exp $ */
+/* $Id: parse.y,v 1.27 2005/12/14 09:44:36 lha Exp $ */
 
 %{
 #ifdef HAVE_CONFIG_H
 #include "gen_locl.h"
 #include "der.h"
 
-RCSID("$Id: parse.y,v 1.25 2005/08/23 10:52:31 lha Exp $");
+RCSID("$Id: parse.y,v 1.27 2005/12/14 09:44:36 lha Exp $");
 
 static Type *new_type (Typetype t);
+static struct constraint_spec *new_constraint_spec(enum ctype);
 static Type *new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype);
 void yyerror (const char *);
 static struct objid *new_objid(const char *label, int value);
@@ -73,6 +74,7 @@ struct string_list {
     struct string_list *sl;
     struct tagtype tag;
     struct memhead *members;
+    struct constraint_spec *constraint_spec;
 }
 
 %token kw_ABSENT
@@ -183,6 +185,7 @@ struct string_list {
 %type <type> BitStringType
 %type <type> BooleanType
 %type <type> ChoiceType
+%type <type> ConstrainedType
 %type <type> EnumeratedType
 %type <type> IntegerType
 %type <type> NullType
@@ -215,6 +218,12 @@ struct string_list {
 
 %type <sl> referencenames
 
+%type <constraint_spec> Constraint
+%type <constraint_spec> ConstraintSpec
+%type <constraint_spec> GeneralConstraint
+%type <constraint_spec> ContentsConstraint
+%type <constraint_spec> UserDefinedConstraint
+
 %start ModuleDefinition
 
 %%
@@ -300,6 +309,7 @@ TypeAssignment      : IDENTIFIER EEQUAL Type
 
 Type           : BuiltinType
                | ReferencedType
+               | ConstrainedType
                ;
 
 BuiltinType    : BitStringType
@@ -507,6 +517,63 @@ UsefulType : kw_GeneralizedTime
                }
                ;
 
+ConstrainedType        : Type Constraint
+               {
+                   /* if (Constraint.type == contentConstrant) {
+                      assert(Constraint.u.constraint.type == octetstring|bitstring-w/o-NamedBitList); // remember to check type reference too
+                      if (Constraint.u.constraint.type) {
+                        assert((Constraint.u.constraint.type.length % 8) == 0);
+                      }
+                     }
+                     if (Constraint.u.constraint.encoding) {
+                       type == der-oid|ber-oid
+                     }
+                   */
+               }
+               ;
+
+
+Constraint     : '(' ConstraintSpec ')'
+               {
+                   $$ = $2;
+               }
+
+ConstraintSpec : GeneralConstraint
+
+GeneralConstraint: ContentsConstraint
+               | UserDefinedConstraint
+               ;
+
+ContentsConstraint: kw_CONTAINING Type
+               {
+                   $$ = new_constraint_spec(CT_CONTENTS);
+                   $$->u.content.type = $2;
+                   $$->u.content.encoding = NULL;
+               }
+               | kw_ENCODED kw_BY Value
+               {
+                   if ($3->type != objectidentifiervalue)
+                       error_message("Non-OID used in ENCODED BY constraint");
+                   $$ = new_constraint_spec(CT_CONTENTS);
+                   $$->u.content.type = NULL;
+                   $$->u.content.encoding = $3;
+               }
+               | kw_CONTAINING Type kw_ENCODED kw_BY Value
+               {
+                   if ($5->type != objectidentifiervalue)
+                       error_message("Non-OID used in ENCODED BY constraint");
+                   $$ = new_constraint_spec(CT_CONTENTS);
+                   $$->u.content.type = $2;
+                   $$->u.content.encoding = $5;
+               }
+               ;
+
+UserDefinedConstraint: kw_CONSTRAINED kw_BY '{' '}'
+               {
+                   $$ = new_constraint_spec(CT_USER);
+               }
+               ;
+
 TaggedType     : Tag tagenv Type
                {
                        $$ = new_type(TTag);
@@ -861,6 +928,14 @@ new_type (Typetype tt)
     return t;
 }
 
+static struct constraint_spec *
+new_constraint_spec(enum ctype ct)
+{
+    struct constraint_spec *c = ecalloc(1, sizeof(*c));
+    c->ctype = ct;
+    return c;
+}
+
 static void fix_labels2(Type *t, const char *prefix);
 static void fix_labels1(struct memhead *members, const char *prefix)
 {