Use a sized type for asn1t.h flags.

We currently shift between unsigned long and int.

Bug: 516
Change-Id: I9e3fcc9393e24a352a2c08b9df0650a508d7a60b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/55448
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c
index de87791..5eb6e6e 100644
--- a/crypto/asn1/tasn_dec.c
+++ b/crypto/asn1/tasn_dec.c
@@ -377,7 +377,7 @@
         if (i == (it->tcount - 1)) {
           isopt = 0;
         } else {
-          isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
+          isopt = (seqtt->flags & ASN1_TFLG_OPTIONAL) != 0;
         }
         // attempt to read in field, allowing each to be OPTIONAL
 
@@ -459,14 +459,14 @@
 static int asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in,
                                 long inlen, const ASN1_TEMPLATE *tt, char opt,
                                 int depth) {
-  int flags, aclass;
+  int aclass;
   int ret;
   long len;
   const unsigned char *p, *q;
   if (!val) {
     return 0;
   }
-  flags = tt->flags;
+  uint32_t flags = tt->flags;
   aclass = flags & ASN1_TFLG_TAG_CLASS;
 
   p = *in;
@@ -517,13 +517,13 @@
 static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
                                    long len, const ASN1_TEMPLATE *tt, char opt,
                                    int depth) {
-  int flags, aclass;
+  int aclass;
   int ret;
   const unsigned char *p;
   if (!val) {
     return 0;
   }
-  flags = tt->flags;
+  uint32_t flags = tt->flags;
   aclass = flags & ASN1_TFLG_TAG_CLASS;
 
   p = *in;
diff --git a/crypto/asn1/tasn_enc.c b/crypto/asn1/tasn_enc.c
index 39a3d52..5b9a8d4 100644
--- a/crypto/asn1/tasn_enc.c
+++ b/crypto/asn1/tasn_enc.c
@@ -263,9 +263,9 @@
 // taking an |optional| parameter, it uses the |ASN1_TFLG_OPTIONAL| flag.
 static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                                 const ASN1_TEMPLATE *tt, int tag, int iclass) {
-  int i, ret, flags, ttag, tclass;
+  int i, ret, ttag, tclass;
   size_t j;
-  flags = tt->flags;
+  uint32_t flags = tt->flags;
 
   // Historically, |iclass| was repurposed to pass additional flags into the
   // encoding process.
diff --git a/include/openssl/asn1t.h b/include/openssl/asn1t.h
index 105cee8..b32fe34 100644
--- a/include/openssl/asn1t.h
+++ b/include/openssl/asn1t.h
@@ -348,7 +348,7 @@
  */
 
 struct ASN1_TEMPLATE_st {
-unsigned long flags;		/* Various flags */
+uint32_t flags;		/* Various flags */
 long tag;			/* tag, not used if no tagging */
 unsigned long offset;		/* Offset of this field in structure */
 const char *field_name;		/* Field name */
@@ -366,7 +366,7 @@
 typedef struct asn1_must_be_null_st ASN1_MUST_BE_NULL;
 
 struct ASN1_ADB_st {
-	unsigned long flags;	/* Various flags */
+	uint32_t flags;	/* Various flags */
 	unsigned long offset;	/* Offset of selector field */
 	ASN1_MUST_BE_NULL *unused;
 	const ASN1_ADB_TABLE *tbl;	/* Table of possible types */
@@ -563,7 +563,7 @@
 
 typedef struct ASN1_AUX_st {
 	void *app_data;
-	int flags;
+	uint32_t flags;
 	int ref_offset;		/* Offset of reference value */
 	ASN1_aux_cb *asn1_cb;
 	int enc_offset;		/* Offset of ASN1_ENCODING structure */