Remove ASN1_TFLG_COMBINE.

This feature is unused and, if I recall, doesn't actually work. (OpenSSL
1.1.0 or so had to rework the feature significantly.) It would actually
be nice to embed some fields, but I think that's better done by just
switching the parsers to imperative CBS/CBB calls.

One less feature to support in the new parsers.

Bug: 548
Change-Id: If10a0d9f1ba5eb09c7e570ab7327fb42fa2bd987
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/56189
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/asn1/internal.h b/crypto/asn1/internal.h
index 0631861..49286ea 100644
--- a/crypto/asn1/internal.h
+++ b/crypto/asn1/internal.h
@@ -143,9 +143,6 @@
 OPENSSL_EXPORT int asn1_generalizedtime_to_tm(struct tm *tm,
                                               const ASN1_GENERALIZEDTIME *d);
 
-void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
-                            int combine);
-
 int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
 void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
 
diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c
index 54e9a99..0fb7344 100644
--- a/crypto/asn1/tasn_dec.c
+++ b/crypto/asn1/tasn_dec.c
@@ -168,8 +168,6 @@
   int otag;
   int ret = 0;
   ASN1_VALUE **pchptr;
-  int combine = aclass & ASN1_TFLG_COMBINE;
-  aclass &= ~ASN1_TFLG_COMBINE;
   if (!pval) {
     return 0;
   }
@@ -440,9 +438,7 @@
 auxerr:
   OPENSSL_PUT_ERROR(ASN1, ASN1_R_AUX_ERROR);
 err:
-  if (combine == 0) {
-    ASN1_item_ex_free(pval, it);
-  }
+  ASN1_item_ex_free(pval, it);
   if (errtt) {
     ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname);
   } else {
@@ -602,8 +598,8 @@
     }
   } else {
     // Nothing special
-    ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1,
-                           tt->flags & ASN1_TFLG_COMBINE, opt, depth);
+    ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, opt,
+                           depth);
     if (!ret) {
       OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
       goto err;
diff --git a/crypto/asn1/tasn_fre.c b/crypto/asn1/tasn_fre.c
index 82c0a0c..ebfd3d6 100644
--- a/crypto/asn1/tasn_fre.c
+++ b/crypto/asn1/tasn_fre.c
@@ -66,15 +66,10 @@
 // Free up an ASN1 structure
 
 void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) {
-  asn1_item_combine_free(&val, it, 0);
+  ASN1_item_ex_free(&val, it);
 }
 
 void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
-  asn1_item_combine_free(pval, it, 0);
-}
-
-void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
-                            int combine) {
   const ASN1_TEMPLATE *tt = NULL, *seqtt;
   const ASN1_EXTERN_FUNCS *ef;
   int i;
@@ -117,10 +112,8 @@
       if (asn1_cb) {
         asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
       }
-      if (!combine) {
-        OPENSSL_free(*pval);
-        *pval = NULL;
-      }
+      OPENSSL_free(*pval);
+      *pval = NULL;
       break;
     }
 
@@ -160,10 +153,8 @@
       if (asn1_cb) {
         asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
       }
-      if (!combine) {
-        OPENSSL_free(*pval);
-        *pval = NULL;
-      }
+      OPENSSL_free(*pval);
+      *pval = NULL;
       break;
     }
   }
@@ -176,13 +167,12 @@
     for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
       ASN1_VALUE *vtmp;
       vtmp = sk_ASN1_VALUE_value(sk, i);
-      asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0);
+      ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
     }
     sk_ASN1_VALUE_free(sk);
     *pval = NULL;
   } else {
-    asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
-                           tt->flags & ASN1_TFLG_COMBINE);
+    ASN1_item_ex_free(pval, ASN1_ITEM_ptr(tt->item));
   }
 }
 
diff --git a/crypto/asn1/tasn_new.c b/crypto/asn1/tasn_new.c
index 563674d..3727b9b 100644
--- a/crypto/asn1/tasn_new.c
+++ b/crypto/asn1/tasn_new.c
@@ -67,8 +67,6 @@
 #include "internal.h"
 
 
-static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
-                                    int combine);
 static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
 static int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
 static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
@@ -86,11 +84,6 @@
 // Allocate an ASN1 structure
 
 int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
-  return asn1_item_ex_combine_new(pval, it, 0);
-}
-
-static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
-                                    int combine) {
   const ASN1_TEMPLATE *tt = NULL;
   const ASN1_EXTERN_FUNCS *ef;
   ASN1_VALUE **pseqval;
@@ -134,13 +127,11 @@
           return 1;
         }
       }
-      if (!combine) {
-        *pval = OPENSSL_malloc(it->size);
-        if (!*pval) {
-          goto memerr;
-        }
-        OPENSSL_memset(*pval, 0, it->size);
+      *pval = OPENSSL_malloc(it->size);
+      if (!*pval) {
+        goto memerr;
       }
+      OPENSSL_memset(*pval, 0, it->size);
       asn1_set_choice_selector(pval, -1, it);
       if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) {
         goto auxerr2;
@@ -160,15 +151,13 @@
           return 1;
         }
       }
-      if (!combine) {
-        *pval = OPENSSL_malloc(it->size);
-        if (!*pval) {
-          goto memerr;
-        }
-        OPENSSL_memset(*pval, 0, it->size);
-        asn1_refcount_set_one(pval, it);
-        asn1_enc_init(pval, it);
+      *pval = OPENSSL_malloc(it->size);
+      if (!*pval) {
+        goto memerr;
       }
+      OPENSSL_memset(*pval, 0, it->size);
+      asn1_refcount_set_one(pval, it);
+      asn1_enc_init(pval, it);
       for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
         pseqval = asn1_get_field_ptr(pval, tt);
         if (!ASN1_template_new(pseqval, tt)) {
@@ -184,13 +173,13 @@
   return 1;
 
 memerr2:
-  asn1_item_combine_free(pval, it, combine);
+  ASN1_item_ex_free(pval, it);
 memerr:
   OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
   return 0;
 
 auxerr2:
-  asn1_item_combine_free(pval, it, combine);
+  ASN1_item_ex_free(pval, it);
 auxerr:
   OPENSSL_PUT_ERROR(ASN1, ASN1_R_AUX_ERROR);
   return 0;
@@ -255,7 +244,7 @@
     goto done;
   }
   // Otherwise pass it back to the item routine
-  ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
+  ret = ASN1_item_ex_new(pval, it);
 done:
   return ret;
 }
diff --git a/crypto/asn1/tasn_utl.c b/crypto/asn1/tasn_utl.c
index 9316c22..741ce17 100644
--- a/crypto/asn1/tasn_utl.c
+++ b/crypto/asn1/tasn_utl.c
@@ -203,11 +203,7 @@
 
 // Given an ASN1_TEMPLATE get a pointer to a field
 ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) {
-  ASN1_VALUE **pvaltmp;
-  if (tt->flags & ASN1_TFLG_COMBINE) {
-    return pval;
-  }
-  pvaltmp = offset2ptr(*pval, tt->offset);
+  ASN1_VALUE **pvaltmp = offset2ptr(*pval, tt->offset);
   // NOTE for BOOLEAN types the field is just a plain int so we can't return
   // int **, so settle for (int *).
   return pvaltmp;
diff --git a/include/openssl/asn1t.h b/include/openssl/asn1t.h
index f655193..f3c4b7f 100644
--- a/include/openssl/asn1t.h
+++ b/include/openssl/asn1t.h
@@ -244,11 +244,6 @@
 	(flags), (tag), offsetof(stname, field),\
 	#field, ASN1_ITEM_ref(type) }
 
-/* used when the structure is combined with the parent */
-
-#define ASN1_EX_COMBINE(flags, tag, type) { \
-	(flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }
-
 /* implicit and explicit helper macros */
 
 #define ASN1_IMP_EX(stname, field, type, tag, ex) \
@@ -441,16 +436,6 @@
 
 #define ASN1_TFLG_ADB_OID	(0x1<<8)
 
-/* This flag means a parent structure is passed
- * instead of the field: this is useful is a
- * SEQUENCE is being combined with a CHOICE for
- * example. Since this means the structure and
- * item name will differ we need to use the
- * ASN1_CHOICE_END_name() macro for example.
- */
-
-#define ASN1_TFLG_COMBINE	(0x1<<10)
-
 /* This is the actual ASN1 item itself */
 
 struct ASN1_ITEM_st {