asn1_encode.{c,h}: support DEFOCTETWRAPTYPE
authorSam Hartman <hartmans@mit.edu>
Mon, 19 Sep 2011 00:34:40 +0000 (00:34 +0000)
committerSam Hartman <hartmans@mit.edu>
Mon, 19 Sep 2011 00:34:40 +0000 (00:34 +0000)
Support a way of defining a type that indicates that the DER encoding
of some other type is wrapped inside an octet string in a produced
encoding.  To support this, support encoding of tagged things where
the class is not constructed; in this case it will be primitive.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25187 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/asn.1/asn1_encode.c
src/lib/krb5/asn.1/asn1_encode.h

index a9077093dc18d56492de9d2393d728d92e25ff7a..d31cefa5ff001285b5d1402185ffdf289c551b87 100644 (file)
@@ -408,7 +408,7 @@ krb5int_asn1_encode_a_thing(asn1buf *buf, const void *val,
         retval = krb5int_asn1_encode_a_thing(buf, val, a->basetype, &length);
         if (retval) return retval;
         sum = length;
-        retval = asn1_make_etag(buf, a->tagtype, a->tagval, sum, &length);
+        retval = asn1_make_tag(buf, a->tagtype, a->construction, a->tagval, sum, &length);
         if (retval) return retval;
         sum += length;
         *retlen = sum;
index a17a20cb2f42bbe1c128fc3b718de65c253b042c..04d92fc90a70225ab903b9ec6c8835d512e86b72 100644 (file)
@@ -294,8 +294,8 @@ struct atype_info {
     /* atype_field */
     const struct field_info *field;
     /* atype_tagged_thing */
-    unsigned int tagval : 8, tagtype : 8;
-    /* atype_[u]int */
+    unsigned int tagval : 8, tagtype : 8, construction:8;
+        /* atype_[u]int */
     asn1_intmax (*loadint)(const void *);
     asn1_uintmax (*loaduint)(const void *);
 };
@@ -404,7 +404,7 @@ struct atype_info {
         return *(const aux_typedefname_##DESCNAME *)p;          \
     }                                                           \
     const struct atype_info krb5int_asn1type_##DESCNAME = {     \
-        atype_int, sizeof(CTYPENAME), 0, 0, 0, 0, 0, 0, 0, 0,   \
+        atype_int, sizeof(CTYPENAME), 0, 0, 0, 0, 0, 0, 0, 0, 0,        \
         loadint_##DESCNAME, 0,                                  \
     }
 #define DEFUINTTYPE(DESCNAME, CTYPENAME)                        \
@@ -416,7 +416,7 @@ struct atype_info {
     }                                                           \
     const struct atype_info krb5int_asn1type_##DESCNAME = {     \
         atype_uint, sizeof(CTYPENAME), 0, 0, 0, 0, 0, 0, 0, 0,  \
-        0, loaduint_##DESCNAME,                                 \
+        0, 0, loaduint_##DESCNAME,                               \
     }
 /* Pointers to other types, to be encoded as those other types.  */
 #ifdef POINTERS_ARE_ALL_THE_SAME
@@ -488,7 +488,17 @@ struct atype_info {
     typedef aux_typedefname_##BASEDESC aux_typedefname_##DESCNAME;      \
     const struct atype_info krb5int_asn1type_##DESCNAME = {             \
         atype_tagged_thing, sizeof(aux_typedefname_##DESCNAME),         \
-        0, 0, 0, &krb5int_asn1type_##BASEDESC, 0, 0, TAG, APPLICATION   \
+        0, 0, 0, &krb5int_asn1type_##BASEDESC, 0, 0, TAG, APPLICATION, CONSTRUCTED \
+    }
+
+/**
+ * An encoding wrapped in an octet string
+ */
+#define DEFOCTETWRAPTYPE(DESCNAME, BASEDESC)                           \
+    typedef aux_typedefname_##BASEDESC aux_typedefname_##DESCNAME;      \
+    const struct atype_info krb5int_asn1type_##DESCNAME = {             \
+        atype_tagged_thing, sizeof(aux_typedefname_##DESCNAME),         \
+        0, 0, 0, &krb5int_asn1type_##BASEDESC, 0, 0, ASN1_OCTETSTRING, UNIVERSAL, PRIMITIVE \
     }
 
 /*