More KNF.
authorjsing <jsing@openbsd.org>
Fri, 18 Apr 2014 12:15:48 +0000 (12:15 +0000)
committerjsing <jsing@openbsd.org>
Fri, 18 Apr 2014 12:15:48 +0000 (12:15 +0000)
14 files changed:
lib/libcrypto/asn1/tasn_dec.c
lib/libcrypto/asn1/tasn_enc.c
lib/libcrypto/asn1/tasn_fre.c
lib/libcrypto/asn1/tasn_new.c
lib/libcrypto/asn1/tasn_prn.c
lib/libcrypto/asn1/tasn_typ.c
lib/libcrypto/asn1/tasn_utl.c
lib/libssl/src/crypto/asn1/tasn_dec.c
lib/libssl/src/crypto/asn1/tasn_enc.c
lib/libssl/src/crypto/asn1/tasn_fre.c
lib/libssl/src/crypto/asn1/tasn_new.c
lib/libssl/src/crypto/asn1/tasn_prn.c
lib/libssl/src/crypto/asn1/tasn_typ.c
lib/libssl/src/crypto/asn1/tasn_utl.c

index 1a06ddc..e9059df 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -69,45 +69,40 @@ static int asn1_check_eoc(const unsigned char **in, long len);
 static int asn1_find_end(const unsigned char **in, long len, char inf);
 
 static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
-                       char inf, int tag, int aclass, int depth);
+    char inf, int tag, int aclass, int depth);
 
 static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen);
 
 static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
-                               char *inf, char *cst,
-                               const unsigned char **in, long len,
-                               int exptag, int expclass, char opt,
-                               ASN1_TLC *ctx);
-
-static int asn1_template_ex_d2i(ASN1_VALUE **pval,
-                               const unsigned char **in, long len,
-                               const ASN1_TEMPLATE *tt, char opt,
-                               ASN1_TLC *ctx);
-static int asn1_template_noexp_d2i(ASN1_VALUE **val,
-                               const unsigned char **in, long len,
-                               const ASN1_TEMPLATE *tt, char opt,
-                               ASN1_TLC *ctx);
-static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
-                               const unsigned char **in, long len,
-                               const ASN1_ITEM *it,
-                               int tag, int aclass, char opt, ASN1_TLC *ctx);
+    char *inf, char *cst, const unsigned char **in, long len, int exptag,
+    int expclass, char opt, ASN1_TLC *ctx);
+
+static int asn1_template_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
+    long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
+static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
+    long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
+static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
+    long len, const ASN1_ITEM *it, int tag, int aclass, char opt,
+    ASN1_TLC *ctx);
 
 /* Table to convert tags to bit values, used for MSTRING type */
 static const unsigned long tag2bit[32] = {
-0,     0,      0,      B_ASN1_BIT_STRING,      /* tags  0 -  3 */
-B_ASN1_OCTET_STRING,   0,      0,              B_ASN1_UNKNOWN,/* tags  4- 7 */
-B_ASN1_UNKNOWN,        B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags  8-11 */
-B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
-B_ASN1_SEQUENCE,0,B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */
-B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,       /* tags 20-22 */
-B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME,                               /* tags 23-24 */ 
-B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING,  /* tags 25-27 */
-B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */
+       0,      0,      0,      B_ASN1_BIT_STRING,      /* tags  0 -  3 */
+       B_ASN1_OCTET_STRING,    0,      0,              B_ASN1_UNKNOWN,/* tags  4- 7 */
+       B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags  8-11 */
+       B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
+       B_ASN1_SEQUENCE,0,B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */
+       B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,       /* tags 20-22 */
+       B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME,                        /* tags 23-24 */
+       B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING,  /* tags 25-27 */
+       B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */
 };
 
-unsigned long ASN1_tag2bit(int tag)
+unsigned long
+ASN1_tag2bit(int tag)
 {
-       if ((tag < 0) || (tag > 30)) return 0;
+       if ((tag < 0) || (tag > 30))
+               return 0;
        return tag2bit[tag];
 }
 
@@ -117,29 +112,31 @@ unsigned long ASN1_tag2bit(int tag)
 /* Version to avoid compiler warning about 'c' always non-NULL */
 #define asn1_tlc_clear_nc(c)   (c)->valid = 0
 
-/* Decode an ASN1 item, this currently behaves just 
- * like a standard 'd2i' function. 'in' points to 
+/* Decode an ASN1 item, this currently behaves just
+ * like a standard 'd2i' function. 'in' points to
  * a buffer to read the data from, in future we will
  * have more advanced versions that can input data
  * a piece at a time and this will simply be a special
  * case.
  */
 
-ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval,
-               const unsigned char **in, long len, const ASN1_ITEM *it)
+ASN1_VALUE *
+ASN1_item_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
+    const ASN1_ITEM *it)
 {
        ASN1_TLC c;
        ASN1_VALUE *ptmpval = NULL;
        if (!pval)
                pval = &ptmpval;
        asn1_tlc_clear_nc(&c);
-       if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0) 
+       if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
                return *pval;
        return NULL;
 }
 
-int ASN1_template_d2i(ASN1_VALUE **pval,
-               const unsigned char **in, long len, const ASN1_TEMPLATE *tt)
+int
+ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
+    const ASN1_TEMPLATE *tt)
 {
        ASN1_TLC c;
        asn1_tlc_clear_nc(&c);
@@ -151,9 +148,9 @@ int ASN1_template_d2i(ASN1_VALUE **pval,
  * If 'opt' set and tag mismatch return -1 to handle OPTIONAL
  */
 
-int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
-                       const ASN1_ITEM *it,
-                       int tag, int aclass, char opt, ASN1_TLC *ctx)
+int
+ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
+    const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
 {
        const ASN1_TEMPLATE *tt, *errtt = NULL;
        const ASN1_COMPAT_FUNCS *cf;
@@ -161,7 +158,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
        const ASN1_AUX *aux = it->funcs;
        ASN1_aux_cb *asn1_cb;
        const unsigned char *p = NULL, *q;
-       unsigned char *wp=NULL; /* BIG FAT WARNING!  BREAKS CONST WHERE USED */
+       unsigned char *wp = NULL;       /* BIG FAT WARNING!  BREAKS CONST WHERE USED */
        unsigned char imphack = 0, oclass;
        char seq_eoc, seq_nolen, cst, isopt;
        long tmplen;
@@ -173,9 +170,10 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                return 0;
        if (aux && aux->asn1_cb)
                asn1_cb = aux->asn1_cb;
-       else asn1_cb = 0;
+       else
+               asn1_cb = 0;
 
-       switch(it->itype) {
+       switch (it->itype) {
        case ASN1_ITYPE_PRIMITIVE:
                if (it->templates) {
                        /* tagging or OPTIONAL is currently illegal on an item
@@ -186,33 +184,34 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                         */
                        if ((tag != -1) || opt) {
                                ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                               ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
+                                   ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
                                goto err;
                        }
                        return asn1_template_ex_d2i(pval, in, len,
-                                       it->templates, opt, ctx);
-       }
+                           it->templates, opt, ctx);
+               }
                return asn1_d2i_ex_primitive(pval, in, len, it,
-                                               tag, aclass, opt, ctx);
+                   tag, aclass, opt, ctx);
                break;
 
        case ASN1_ITYPE_MSTRING:
                p = *in;
                /* Just read in tag and class */
                ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
-                                               &p, len, -1, 0, 1, ctx);
+                   &p, len, -1, 0, 1, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
                }
 
                /* Must be UNIVERSAL class */
                if (oclass != V_ASN1_UNIVERSAL) {
                        /* If OPTIONAL, assume this is OK */
-                       if (opt) return -1;
+                       if (opt)
+                               return -1;
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ASN1_R_MSTRING_NOT_UNIVERSAL);
+                           ASN1_R_MSTRING_NOT_UNIVERSAL);
                        goto err;
                }
                /* Check tag matches bit map */
@@ -221,17 +220,17 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        if (opt)
                                return -1;
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ASN1_R_MSTRING_WRONG_TAG);
+                           ASN1_R_MSTRING_WRONG_TAG);
                        goto err;
                }
                return asn1_d2i_ex_primitive(pval, in, len,
-                                               it, otag, 0, 0, ctx);
+                   it, otag, 0, 0, ctx);
 
        case ASN1_ITYPE_EXTERN:
                /* Use new style d2i */
                ef = it->funcs;
                return ef->asn1_ex_d2i(pval, in, len,
-                                               it, tag, aclass, opt, ctx);
+                   it, tag, aclass, opt, ctx);
 
        case ASN1_ITYPE_COMPAT:
                /* we must resort to old style evil hackery */
@@ -243,15 +242,16 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        p = *in;
                        if (tag == -1)
                                exptag = it->utype;
-                       else exptag = tag;
+                       else
+                               exptag = tag;
                        /* Don't care about anything other than presence
                         * of expected tag */
 
                        ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL,
-                                       &p, len, exptag, aclass, 1, ctx);
+                           &p, len, exptag, aclass, 1, ctx);
                        if (!ret) {
                                ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                                   ERR_R_NESTED_ASN1_ERROR);
                                goto err;
                        }
                        if (ret == -1)
@@ -278,11 +278,11 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        imphack = *wp;
                        if (p == NULL) {
                                ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                                   ERR_R_NESTED_ASN1_ERROR);
                                goto err;
                        }
-                       *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED)
-                                                               | it->utype);
+                       *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED) |
+                           it->utype);
                }
 
                ptmpval = cf->asn1_d2i(pval, in, len);
@@ -296,20 +296,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
                goto err;
 
-
        case ASN1_ITYPE_CHOICE:
                if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
 
                /* Allocate structure */
                if (!*pval && !ASN1_item_ex_new(pval, it)) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                               ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
                }
                /* CHOICE type, try each possibility in turn */
                p = *in;
-               for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) {
+               for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
                        pchptr = asn1_get_field_ptr(pval, tt);
                        /* We mark field as OPTIONAL so its absence
                         * can be recognised.
@@ -324,7 +323,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        /* Otherwise must be an ASN1 parsing error */
                        errtt = tt;
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                               ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
                }
 
@@ -337,14 +336,14 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                                return -1;
                        }
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ASN1_R_NO_MATCHING_CHOICE_TYPE);
+                           ASN1_R_NO_MATCHING_CHOICE_TYPE);
                        goto err;
                }
 
                asn1_set_choice_selector(pval, i, it);
                *in = p;
                if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
                return 1;
 
        case ASN1_ITYPE_NDEF_SEQUENCE:
@@ -359,34 +358,34 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                }
                /* Get SEQUENCE length and update len, p */
                ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,
-                                       &p, len, tag, aclass, opt, ctx);
+                   &p, len, tag, aclass, opt, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
-               }
-               else if (ret == -1)
+               } else if (ret == -1)
                        return -1;
                if (aux && (aux->flags & ASN1_AFLG_BROKEN)) {
                        len = tmplen - (p - *in);
                        seq_nolen = 1;
                }
                /* If indefinite we don't do a length check */
-               else seq_nolen = seq_eoc;
+               else
+                       seq_nolen = seq_eoc;
                if (!cst) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                               ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
+                           ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
                        goto err;
                }
 
                if (!*pval && !ASN1_item_ex_new(pval, it)) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                               ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
                }
 
                if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
 
                /* Get each field entry */
                for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
@@ -403,7 +402,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        if (asn1_check_eoc(&p, len)) {
                                if (!seq_eoc) {
                                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                                       ASN1_R_UNEXPECTED_EOC);
+                                           ASN1_R_UNEXPECTED_EOC);
                                        goto err;
                                }
                                len -= p - q;
@@ -419,12 +418,13 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                         */
                        if (i == (it->tcount - 1))
                                isopt = 0;
-                       else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
+                       else
+                               isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
                        /* attempt to read in field, allowing each to be
                         * OPTIONAL */
 
                        ret = asn1_template_ex_d2i(pseqval, &p, len,
-                                                       seqtt, isopt, ctx);
+                           seqtt, isopt, ctx);
                        if (!ret) {
                                errtt = seqtt;
                                goto err;
@@ -447,7 +447,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                /* Check all data read */
                if (!seq_nolen && len) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ASN1_R_SEQUENCE_LENGTH_MISMATCH);
+                           ASN1_R_SEQUENCE_LENGTH_MISMATCH);
                        goto err;
                }
 
@@ -467,7 +467,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        } else {
                                errtt = seqtt;
                                ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                                       ASN1_R_FIELD_MISSING);
+                                   ASN1_R_FIELD_MISSING);
                                goto err;
                        }
                }
@@ -476,19 +476,20 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        goto auxerr;
                *in = p;
                if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
                return 1;
 
-               default:
+       default:
                return 0;
        }
-       auxerr:
+
+auxerr:
        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);
-       err:
+err:
        ASN1_item_ex_free(pval, it);
        if (errtt)
                ERR_add_error_data(4, "Field=", errtt->field_name,
-                                       ", Type=", it->sname);
+                   ", Type=", it->sname);
        else
                ERR_add_error_data(2, "Type=", it->sname);
        return 0;
@@ -498,16 +499,16 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
  * One handles any EXPLICIT tag and the other handles the rest.
  */
 
-static int asn1_template_ex_d2i(ASN1_VALUE **val,
-                               const unsigned char **in, long inlen,
-                               const ASN1_TEMPLATE *tt, char opt,
-                                                       ASN1_TLC *ctx)
+static int
+asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long inlen,
+    const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
 {
        int flags, aclass;
        int ret;
        long len;
        const unsigned char *p, *q;
        char exp_eoc;
+
        if (!val)
                return 0;
        flags = tt->flags;
@@ -523,24 +524,24 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
                 * get the info.
                 */
                ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst,
-                                       &p, inlen, tt->tag, aclass, opt, ctx);
+                   &p, inlen, tt->tag, aclass, opt, ctx);
                q = p;
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        return 0;
                } else if (ret == -1)
                        return -1;
                if (!cst) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
-                                       ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
+                           ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
                        return 0;
                }
                /* We've found the field so it can't be OPTIONAL now */
                ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        return 0;
                }
                /* We read the field in OK so update length */
@@ -549,7 +550,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
                        /* If NDEF we must have an EOC here */
                        if (!asn1_check_eoc(&p, len)) {
                                ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
-                                               ASN1_R_MISSING_EOC);
+                                   ASN1_R_MISSING_EOC);
                                goto err;
                        }
                } else {
@@ -557,31 +558,29 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
                         * an error */
                        if (len) {
                                ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
-                                       ASN1_R_EXPLICIT_LENGTH_MISMATCH);
+                                   ASN1_R_EXPLICIT_LENGTH_MISMATCH);
                                goto err;
                        }
                }
-       }
-               else 
-                       return asn1_template_noexp_d2i(val, in, inlen,
-                                                               tt, opt, ctx);
+       } else
+               return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx);
 
        *in = p;
        return 1;
 
-       err:
+err:
        ASN1_template_free(val, tt);
        return 0;
 }
 
-static int asn1_template_noexp_d2i(ASN1_VALUE **val,
-                               const unsigned char **in, long len,
-                               const ASN1_TEMPLATE *tt, char opt,
-                               ASN1_TLC *ctx)
+static int
+asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
+    const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
 {
        int flags, aclass;
        int ret;
        const unsigned char *p, *q;
+
        if (!val)
                return 0;
        flags = tt->flags;
@@ -607,43 +606,42 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
                }
                /* Get the tag */
                ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL,
-                                       &p, len, sktag, skaclass, opt, ctx);
+                   &p, len, sktag, skaclass, opt, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                               ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        return 0;
-               }
-               else if (ret == -1)
+               } else if (ret == -1)
                        return -1;
                if (!*val)
                        *val = (ASN1_VALUE *)sk_new_null();
                else {
                        /* We've got a valid STACK: free up any items present */
-                       STACK_OF(ASN1_VALUE) *sktmp
-                           (STACK_OF(ASN1_VALUE) *)*val;
+                       STACK_OF(ASN1_VALUE) *sktmp =
+                           (STACK_OF(ASN1_VALUE) *)*val;
                        ASN1_VALUE *vtmp;
-                       while(sk_ASN1_VALUE_num(sktmp) > 0) {
+                       while (sk_ASN1_VALUE_num(sktmp) > 0) {
                                vtmp = sk_ASN1_VALUE_pop(sktmp);
                                ASN1_item_ex_free(&vtmp,
-                                               ASN1_ITEM_ptr(tt->item));
+                                   ASN1_ITEM_ptr(tt->item));
                        }
                }
-                               
+
                if (!*val) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                               ERR_R_MALLOC_FAILURE);
+                           ERR_R_MALLOC_FAILURE);
                        goto err;
                }
 
                /* Read as many items as we can */
-               while(len > 0) {
+               while (len > 0) {
                        ASN1_VALUE *skfield;
                        q = p;
                        /* See if EOC found */
                        if (asn1_check_eoc(&p, len)) {
                                if (!sk_eoc) {
                                        ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                                       ASN1_R_UNEXPECTED_EOC);
+                                           ASN1_R_UNEXPECTED_EOC);
                                        goto err;
                                }
                                len -= p - q;
@@ -652,60 +650,57 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
                        }
                        skfield = NULL;
                        if (!ASN1_item_ex_d2i(&skfield, &p, len,
-                                               ASN1_ITEM_ptr(tt->item),
-                                               -1, 0, 0, ctx)) {
+                           ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) {
                                ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                                   ERR_R_NESTED_ASN1_ERROR);
                                goto err;
                        }
                        len -= p - q;
                        if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val,
-                                               skfield)) {
+                           skfield)) {
                                ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                               ERR_R_MALLOC_FAILURE);
+                                   ERR_R_MALLOC_FAILURE);
                                goto err;
                        }
                }
                if (sk_eoc) {
-                       ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC);
+                       ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
+                           ASN1_R_MISSING_EOC);
                        goto err;
                }
        } else if (flags & ASN1_TFLG_IMPTAG) {
                /* IMPLICIT tagging */
                ret = ASN1_item_ex_d2i(val, &p, len,
-                       ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
+                   ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                               ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
-               }
-               else if (ret == -1)
+               } else if (ret == -1)
                        return -1;
        } else {
                /* Nothing special */
                ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),
-                                                       -1, 0, opt, ctx);
+                   -1, 0, opt, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
-               }
-               else if (ret == -1)
+               } else if (ret == -1)
                        return -1;
        }
 
        *in = p;
        return 1;
 
-       err:
+err:
        ASN1_template_free(val, tt);
        return 0;
 }
 
-static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
-                               const unsigned char **in, long inlen, 
-                               const ASN1_ITEM *it,
-                               int tag, int aclass, char opt, ASN1_TLC *ctx)
+static int
+asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long inlen,
+    const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
 {
        int ret = 0, utype;
        long plen;
@@ -713,7 +708,8 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
        const unsigned char *p;
        BUF_MEM buf;
        const unsigned char *cont = NULL;
-       long len; 
+       long len;
+
        if (!pval) {
                ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL);
                return 0; /* Should never happen */
@@ -722,8 +718,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
        if (it->itype == ASN1_ITYPE_MSTRING) {
                utype = tag;
                tag = -1;
-       }
-       else
+       } else
                utype = it->utype;
 
        if (utype == V_ASN1_ANY) {
@@ -731,20 +726,20 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
                unsigned char oclass;
                if (tag >= 0) {
                        ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
-                                       ASN1_R_ILLEGAL_TAGGED_ANY);
+                           ASN1_R_ILLEGAL_TAGGED_ANY);
                        return 0;
                }
                if (opt) {
                        ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
-                                       ASN1_R_ILLEGAL_OPTIONAL_ANY);
+                           ASN1_R_ILLEGAL_OPTIONAL_ANY);
                        return 0;
                }
                p = *in;
                ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL,
-                                       &p, inlen, -1, 0, 0, ctx);
+                   &p, inlen, -1, 0, 0, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        return 0;
                }
                if (oclass != V_ASN1_UNIVERSAL)
@@ -757,17 +752,16 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
        p = *in;
        /* Check header */
        ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst,
-                               &p, inlen, tag, aclass, opt, ctx);
+           &p, inlen, tag, aclass, opt, ctx);
        if (!ret) {
                ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
                return 0;
-       }
-       else if (ret == -1)
+       } else if (ret == -1)
                return -1;
-        ret = 0;
+       ret = 0;
        /* SEQUENCE, SET and "OTHER" are left in encoded form */
-       if ((utype == V_ASN1_SEQUENCE)
-               || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
+       if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
+           (utype == V_ASN1_OTHER)) {
                /* Clear context cache for type OTHER because the auto clear
                 * when we have a exact match wont work
                 */
@@ -777,7 +771,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
                /* SEQUENCE and SET must be constructed */
                else if (!cst) {
                        ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
-                               ASN1_R_TYPE_NOT_CONSTRUCTED);
+                           ASN1_R_TYPE_NOT_CONSTRUCTED);
                        return 0;
                }
 
@@ -785,7 +779,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
                /* If indefinite length constructed find the real end */
                if (inf) {
                        if (!asn1_find_end(&p, plen, inf))
-                                goto err;
+                               goto err;
                        len = p - cont;
                } else {
                        len = p - cont + plen;
@@ -810,7 +804,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
                /* Append a final null to string */
                if (!BUF_MEM_grow_clean(&buf, len + 1)) {
                        ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
-                                               ERR_R_MALLOC_FAILURE);
+                           ERR_R_MALLOC_FAILURE);
                        return 0;
                }
                buf.data[len] = 0;
@@ -828,15 +822,18 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
 
        *in = p;
        ret = 1;
-       err:
-       if (free_cont && buf.data) free(buf.data);
+
+err:
+       if (free_cont && buf.data)
+               free(buf.data);
        return ret;
 }
 
 /* Translate ASN1 content octets into a structure */
 
-int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
-                       int utype, char *free_cont, const ASN1_ITEM *it)
+int
+asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
+    char *free_cont, const ASN1_ITEM *it)
 {
        ASN1_VALUE **opval = NULL;
        ASN1_STRING *stmp;
@@ -855,8 +852,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
                        if (typ == NULL)
                                goto err;
                        *pval = (ASN1_VALUE *)typ;
-               }
-               else
+               } else
                        typ = (ASN1_TYPE *)*pval;
 
                if (utype != typ->type)
@@ -864,7 +860,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
                opval = pval;
                pval = &typ->value.asn1_value;
        }
-       switch(utype) {
+       switch (utype) {
        case V_ASN1_OBJECT:
                if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len))
                        goto err;
@@ -873,7 +869,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
        case V_ASN1_NULL:
                if (len) {
                        ASN1err(ASN1_F_ASN1_EX_C2I,
-                                               ASN1_R_NULL_IS_WRONG_LENGTH);
+                           ASN1_R_NULL_IS_WRONG_LENGTH);
                        goto err;
                }
                *pval = (ASN1_VALUE *)1;
@@ -882,7 +878,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
        case V_ASN1_BOOLEAN:
                if (len != 1) {
                        ASN1err(ASN1_F_ASN1_EX_C2I,
-                                               ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
+                           ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
                        goto err;
                } else {
                        ASN1_BOOLEAN *tbool;
@@ -927,12 +923,12 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
        default:
                if (utype == V_ASN1_BMPSTRING && (len & 1)) {
                        ASN1err(ASN1_F_ASN1_EX_C2I,
-                                       ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
+                           ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
                        goto err;
                }
                if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) {
                        ASN1err(ASN1_F_ASN1_EX_C2I,
-                                       ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
+                           ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
                        goto err;
                }
                /* All based on ASN1_STRING and handled the same */
@@ -940,7 +936,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
                        stmp = ASN1_STRING_type_new(utype);
                        if (!stmp) {
                                ASN1err(ASN1_F_ASN1_EX_C2I,
-                                                       ERR_R_MALLOC_FAILURE);
+                                   ERR_R_MALLOC_FAILURE);
                                goto err;
                        }
                        *pval = (ASN1_VALUE *)stmp;
@@ -958,8 +954,8 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
                } else {
                        if (!ASN1_STRING_set(stmp, cont, len)) {
                                ASN1err(ASN1_F_ASN1_EX_C2I,
-                                                       ERR_R_MALLOC_FAILURE);
-                               ASN1_STRING_free(stmp); 
+                                   ERR_R_MALLOC_FAILURE);
+                               ASN1_STRING_free(stmp);
                                *pval = NULL;
                                goto err;
                        }
@@ -968,10 +964,11 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
        }
        /* If ASN1_ANY and NULL type fix up value */
        if (typ && (utype == V_ASN1_NULL))
-                typ->value.ptr = NULL;
+               typ->value.ptr = NULL;
 
        ret = 1;
-       err:
+
+err:
        if (!ret) {
                ASN1_TYPE_free(typ);
                if (opval)
@@ -987,11 +984,13 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
  * recurse on each indefinite length header.
  */
 
-static int asn1_find_end(const unsigned char **in, long len, char inf)
+static int
+asn1_find_end(const unsigned char **in, long len, char inf)
 {
        int expected_eoc;
        long plen;
        const unsigned char *p = *in, *q;
+
        /* If not indefinite length constructed just add length */
        if (inf == 0) {
                *in += len;
@@ -1004,7 +1003,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
         * skip to the end of the data.
         */
        while (len > 0) {
-               if(asn1_check_eoc(&p, len)) {
+               if (asn1_check_eoc(&p, len)) {
                        expected_eoc--;
                        if (expected_eoc == 0)
                                break;
@@ -1013,8 +1012,8 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
                }
                q = p;
                /* Just read in a header: only care about the length */
-               if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
-                               -1, 0, 0, NULL)) {
+               if (!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
+                   -1, 0, 0, NULL)) {
                        ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR);
                        return 0;
                }
@@ -1046,13 +1045,14 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
 #define ASN1_MAX_STRING_NEST 5
 #endif
 
-
-static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
-                       char inf, int tag, int aclass, int depth)
+static int
+asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, char inf,
+    int tag, int aclass, int depth)
 {
        const unsigned char *p, *q;
        long plen;
        char cst, ininf;
+
        p = *in;
        inf &= 1;
        /* If no buffer and not indefinite length constructed just pass over
@@ -1061,7 +1061,7 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
                *in += len;
                return 1;
        }
-       while(len > 0) {
+       while (len > 0) {
                q = p;
                /* Check for EOC */
                if (asn1_check_eoc(&p, len)) {
@@ -1069,7 +1069,7 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
                         * constructed form */
                        if (!inf) {
                                ASN1err(ASN1_F_ASN1_COLLECT,
-                                       ASN1_R_UNEXPECTED_EOC);
+                                   ASN1_R_UNEXPECTED_EOC);
                                return 0;
                        }
                        inf = 0;
@@ -1077,7 +1077,7 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
                }
 
                if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p,
-                                       len, tag, aclass, 0, NULL)) {
+                   len, tag, aclass, 0, NULL)) {
                        ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR);
                        return 0;
                }
@@ -1086,14 +1086,13 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
                if (cst) {
                        if (depth >= ASN1_MAX_STRING_NEST) {
                                ASN1err(ASN1_F_ASN1_COLLECT,
-                                       ASN1_R_NESTED_ASN1_STRING);
+                                   ASN1_R_NESTED_ASN1_STRING);
                                return 0;
                        }
                        if (!asn1_collect(buf, &p, plen, ininf, tag, aclass,
-                                               depth + 1))
+                           depth + 1))
                                return 0;
-               }
-               else if (plen && !collect_data(buf, &p, plen))
+               } else if (plen && !collect_data(buf, &p, plen))
                        return 0;
                len -= p - q;
        }
@@ -1105,7 +1104,8 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
        return 1;
 }
 
-static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
+static int
+collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
 {
        int len;
        if (buf) {
@@ -1122,10 +1122,13 @@ static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
 
 /* Check for ASN1 EOC and swallow it if found */
 
-static int asn1_check_eoc(const unsigned char **in, long len)
+static int
+asn1_check_eoc(const unsigned char **in, long len)
 {
        const unsigned char *p;
-       if (len < 2) return 0;
+
+       if (len < 2)
+               return 0;
        p = *in;
        if (!p[0] && !p[1]) {
                *in += 2;
@@ -1141,11 +1144,10 @@ static int asn1_check_eoc(const unsigned char **in, long len)
  * header length just read.
  */
 
-static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
-                               char *inf, char *cst,
-                               const unsigned char **in, long len,
-                               int exptag, int expclass, char opt,
-                               ASN1_TLC *ctx)
+static int
+asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf,
+    char *cst, const unsigned char **in, long len, int exptag, int expclass,
+    char opt, ASN1_TLC *ctx)
 {
        int i;
        int ptag, pclass;
@@ -1170,11 +1172,11 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
                        ctx->hdrlen = p - q;
                        ctx->valid = 1;
                        /* If definite length, and no error, length +
-                        * header can't exceed total amount of data available. 
+                        * header can't exceed total amount of data available.
                         */
                        if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
                                ASN1err(ASN1_F_ASN1_CHECK_TLEN,
-                                                       ASN1_R_TOO_LONG);
+                                   ASN1_R_TOO_LONG);
                                asn1_tlc_clear(ctx);
                                return 0;
                        }
@@ -1191,7 +1193,8 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
                        /* If type is OPTIONAL, not an error:
                         * indicate missing type.
                         */
-                       if (opt) return -1;
+                       if (opt)
+                               return -1;
                        asn1_tlc_clear(ctx);
                        ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG);
                        return 0;
@@ -1203,19 +1206,14 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
 
        if (i & 1)
                plen = len - (p - q);
-
        if (inf)
                *inf = i & 1;
-
        if (cst)
                *cst = i & V_ASN1_CONSTRUCTED;
-
        if (olen)
                *olen = plen;
-
        if (oclass)
                *oclass = pclass;
-
        if (otag)
                *otag = ptag;
 
index c9131cd..f5fc882 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -56,7 +56,6 @@
  *
  */
 
-
 #include <stddef.h>
 #include <string.h>
 #include "cryptlib.h"
 #include <openssl/objects.h>
 
 static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
-                                       const ASN1_ITEM *it,
-                                       int tag, int aclass);
+    const ASN1_ITEM *it, int tag, int aclass);
 static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
-                                       int skcontlen, const ASN1_ITEM *item,
-                                       int do_sort, int iclass);
+    int skcontlen, const ASN1_ITEM *item, int do_sort, int iclass);
 static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
-                                       const ASN1_TEMPLATE *tt,
-                                       int tag, int aclass);
+    const ASN1_TEMPLATE *tt, int tag, int aclass);
 static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
-                                       const ASN1_ITEM *it, int flags);
+    const ASN1_ITEM *it, int flags);
 
 /* Top level i2d equivalents: the 'ndef' variant instructs the encoder
  * to use indefinite length constructed encoding, where appropriate
  */
 
-int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out,
-                                               const ASN1_ITEM *it)
+int
+ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
 {
        return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF);
 }
 
-int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
+int
+ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
 {
        return asn1_item_flags_i2d(val, out, it, 0);
 }
 
 /* Encode an ASN1 item, this is use by the
- * standard 'i2d' function. 'out' points to 
+ * standard 'i2d' function. 'out' points to
  * a buffer to output the data to.
  *
  * The new i2d has one additional feature. If the output
@@ -100,8 +97,9 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
  * allocated and populated with the encoding.
  */
 
-static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
-                                       const ASN1_ITEM *it, int flags)
+static int
+asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it,
+    int flags)
 {
        if (out && !*out) {
                unsigned char *p, *buf;
@@ -126,8 +124,9 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
  * used in external types.
  */
 
-int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
-                       const ASN1_ITEM *it, int tag, int aclass)
+int
+ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
+    int tag, int aclass)
 {
        const ASN1_TEMPLATE *tt = NULL;
        unsigned char *p = NULL;
@@ -141,14 +140,14 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                return 0;
 
        if (aux && aux->asn1_cb)
-                asn1_cb = aux->asn1_cb;
+               asn1_cb = aux->asn1_cb;
 
-       switch(it->itype) {
+       switch (it->itype) {
 
        case ASN1_ITYPE_PRIMITIVE:
                if (it->templates)
                        return asn1_template_ex_i2d(pval, out, it->templates,
-                                                               tag, aclass);
+                           tag, aclass);
                return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
                break;
 
@@ -157,7 +156,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
 
        case ASN1_ITYPE_CHOICE:
                if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
-                               return 0;
+                       return 0;
                i = asn1_get_choice_selector(pval, it);
                if ((i >= 0) && (i < it->tcount)) {
                        ASN1_VALUE **pchval;
@@ -165,11 +164,11 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        chtt = it->templates + i;
                        pchval = asn1_get_field_ptr(pval, chtt);
                        return asn1_template_ex_i2d(pchval, out, chtt,
-                                                               -1, aclass);
+                           -1, aclass);
                }
                /* Fixme: error condition if selector out of range */
                if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
-                               return 0;
+                       return 0;
                break;
 
        case ASN1_ITYPE_EXTERN:
@@ -189,10 +188,11 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                if (out && (tag != -1))
                        *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
                return i;
-               
+
        case ASN1_ITYPE_NDEF_SEQUENCE:
                /* Use indefinite length constructed if requested */
-               if (aclass & ASN1_TFLG_NDEF) ndef = 2;
+               if (aclass & ASN1_TFLG_NDEF)
+                       ndef = 2;
                /* fall through */
 
        case ASN1_ITYPE_SEQUENCE:
@@ -209,11 +209,11 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                if (tag == -1) {
                        tag = V_ASN1_SEQUENCE;
                        /* Retain any other flags in aclass */
-                       aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)
-                                       | V_ASN1_UNIVERSAL;
+                       aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) |
+                           V_ASN1_UNIVERSAL;
                }
                if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
-                               return 0;
+                       return 0;
                /* First work out sequence content length */
                for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
                        const ASN1_TEMPLATE *seqtt;
@@ -224,7 +224,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        pseqval = asn1_get_field_ptr(pval, seqtt);
                        /* FIXME: check for errors in enhanced version */
                        seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt,
-                                                               -1, aclass);
+                           -1, aclass);
                }
 
                seqlen = ASN1_object_size(ndef, seqcontlen, tag);
@@ -245,24 +245,26 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                if (ndef == 2)
                        ASN1_put_eoc(out);
                if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
-                               return 0;
+                       return 0;
                return seqlen;
 
-               default:
+       default:
                return 0;
 
        }
        return 0;
 }
 
-int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out,
-                                                       const ASN1_TEMPLATE *tt)
+int
+ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out,
+    const ASN1_TEMPLATE *tt)
 {
        return asn1_template_ex_i2d(pval, out, tt, -1, 0);
 }
 
-static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
-                               const ASN1_TEMPLATE *tt, int tag, int iclass)
+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, ndef;
        flags = tt->flags;
@@ -288,7 +290,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                ttag = -1;
                tclass = 0;
        }
-       /* 
+       /*
         * Remove any class mask from iflag.
         */
        iclass &= ~ASN1_TFLG_TAG_CLASS;
@@ -301,7 +303,8 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
        /* if template and arguments require ndef, use it */
        if ((flags & ASN1_TFLG_NDEF) && (iclass & ASN1_TFLG_NDEF))
                ndef = 2;
-       else ndef = 1;
+       else
+               ndef = 1;
 
        if (flags & ASN1_TFLG_SK_MASK) {
                /* SET OF, SEQUENCE OF */
@@ -318,8 +321,8 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        /* 2 means we reorder */
                        if (flags & ASN1_TFLG_SEQUENCE_OF)
                                isset = 2;
-               }
-               else isset = 0;
+               } else
+                       isset = 0;
 
                /* Work out inner tag value: if EXPLICIT
                 * or no tagging use underlying type.
@@ -331,7 +334,8 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        skaclass = V_ASN1_UNIVERSAL;
                        if (isset)
                                sktag = V_ASN1_SET;
-                       else sktag = V_ASN1_SEQUENCE;
+                       else
+                               sktag = V_ASN1_SEQUENCE;
                }
 
                /* Determine total length of items */
@@ -339,14 +343,14 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
                        skitem = sk_ASN1_VALUE_value(sk, i);
                        skcontlen += ASN1_item_ex_i2d(&skitem, NULL,
-                                               ASN1_ITEM_ptr(tt->item),
-                                                       -1, iclass);
+                           ASN1_ITEM_ptr(tt->item), -1, iclass);
                }
                sklen = ASN1_object_size(ndef, skcontlen, sktag);
                /* If EXPLICIT need length of surrounding tag */
                if (flags & ASN1_TFLG_EXPTAG)
                        ret = ASN1_object_size(ndef, sklen, ttag);
-               else ret = sklen;
+               else
+                       ret = sklen;
 
                if (!out)
                        return ret;
@@ -359,7 +363,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                ASN1_put_object(out, ndef, skcontlen, sktag, skaclass);
                /* And the stuff itself */
                asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),
-                                                               isset, iclass);
+                   isset, iclass);
                if (ndef == 2) {
                        ASN1_put_eoc(out);
                        if (flags & ASN1_TFLG_EXPTAG)
@@ -373,7 +377,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                /* EXPLICIT tagging */
                /* Find length of tagged item */
                i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item),
-                                                               -1, iclass);
+                   -1, iclass);
                if (!i)
                        return 0;
                /* Find length of EXPLICIT tag */
@@ -382,7 +386,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        /* Output tag and item */
                        ASN1_put_object(out, ndef, i, ttag, tclass);
                        ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
-                                                               -1, iclass);
+                           -1, iclass);
                        if (ndef == 2)
                                ASN1_put_eoc(out);
                }
@@ -391,8 +395,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
 
        /* Either normal or IMPLICIT tagging: combine class and flags */
        return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
-                                               ttag, tclass | iclass);
-
+           ttag, tclass | iclass);
 }
 
 /* Temporary structure used to hold DER encoding of items for SET OF */
@@ -403,10 +406,12 @@ typedef   struct {
        ASN1_VALUE *field;
 } DER_ENC;
 
-static int der_cmp(const void *a, const void *b)
+static int
+der_cmp(const void *a, const void *b)
 {
        const DER_ENC *d1 = a, *d2 = b;
        int cmplen, i;
+
        cmplen = (d1->length < d2->length) ? d1->length : d2->length;
        i = memcmp(d1->data, d2->data, cmplen);
        if (i)
@@ -416,22 +421,22 @@ static int der_cmp(const void *a, const void *b)
 
 /* Output the content octets of SET OF or SEQUENCE OF */
 
-static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
-                                       int skcontlen, const ASN1_ITEM *item,
-                                       int do_sort, int iclass)
+static int
+asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen,
+    const ASN1_ITEM *item, int do_sort, int iclass)
 {
        int i;
        ASN1_VALUE *skitem;
        unsigned char *tmpdat = NULL, *p = NULL;
        DER_ENC *derlst = NULL, *tder;
-       if (do_sort)
-                {
+
+       if (do_sort) {
                /* Don't need to sort less than 2 items */
                if (sk_ASN1_VALUE_num(sk) < 2)
                        do_sort = 0;
                else {
-                       derlst = malloc(sk_ASN1_VALUE_num(sk)
-                                               * sizeof(*derlst));
+                       derlst = malloc(sk_ASN1_VALUE_num(sk) *
+                           sizeof(*derlst));
                        tmpdat = malloc(skcontlen);
                        if (!derlst || !tmpdat) {
                                free(derlst);
@@ -460,7 +465,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
 
        /* Now sort them */
        qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
-       /* Output sorted DER encoding */        
+       /* Output sorted DER encoding */
        p = *out;
        for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
                memcpy(p, tder->data, tder->length);
@@ -477,8 +482,9 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
        return 1;
 }
 
-static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
-                               const ASN1_ITEM *it, int tag, int aclass)
+static int
+asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
+    const ASN1_ITEM *it, int tag, int aclass)
 {
        int len;
        int utype;
@@ -500,12 +506,12 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
         * utype.
         */
        if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
-          (utype == V_ASN1_OTHER))
+           (utype == V_ASN1_OTHER))
                usetag = 0;
-       else usetag = 1;
+       else
+               usetag = 1;
 
        /* -1 means omit type */
-
        if (len == -1)
                return 0;
 
@@ -516,7 +522,8 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
        }
 
        /* If not implicitly tagged get tag from underlying type */
-       if (tag == -1) tag = utype;
+       if (tag == -1)
+               tag = utype;
 
        /* Output tag+length followed by content octets */
        if (out) {
@@ -536,8 +543,9 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
 
 /* Produce content octets from a structure */
 
-int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
-                               const ASN1_ITEM *it)
+int
+asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
+    const ASN1_ITEM *it)
 {
        ASN1_BOOLEAN *tbool = NULL;
        ASN1_STRING *strtmp;
@@ -547,13 +555,16 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
        unsigned char c;
        int len;
        const ASN1_PRIMITIVE_FUNCS *pf;
+
        pf = it->funcs;
        if (pf && pf->prim_i2c)
                return pf->prim_i2c(pval, cout, putype, it);
 
        /* Should type be omitted? */
-       if ((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
-               if (!*pval) return -1;
+       if ((it->itype != ASN1_ITYPE_PRIMITIVE) ||
+           (it->utype != V_ASN1_BOOLEAN)) {
+               if (!*pval)
+                       return -1;
        }
 
        if (it->itype == ASN1_ITYPE_MSTRING) {
@@ -568,10 +579,10 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
                utype = typ->type;
                *putype = utype;
                pval = &typ->value.asn1_value;
-       }
-       else utype = *putype;
+       } else
+               utype = *putype;
 
-       switch(utype) {
+       switch (utype) {
        case V_ASN1_OBJECT:
                otmp = (ASN1_OBJECT *)*pval;
                cont = otmp->data;
@@ -601,7 +612,7 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
 
        case V_ASN1_BIT_STRING:
                return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval,
-                                                       cout ? &cout : NULL);
+                   cout ? &cout : NULL);
                break;
 
        case V_ASN1_INTEGER:
@@ -612,7 +623,7 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
                 * as ASN1_INTEGER
                 */
                return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval,
-                                                       cout ? &cout : NULL);
+                   cout ? &cout : NULL);
                break;
 
        case V_ASN1_OCTET_STRING:
@@ -635,8 +646,8 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
                /* All based on ASN1_STRING and handled the same */
                strtmp = (ASN1_STRING *)*pval;
                /* Special handling for NDEF */
-               if ((it->size == ASN1_TFLG_NDEF)
-                       && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) {
+               if ((it->size == ASN1_TFLG_NDEF) &&
+                   (strtmp->flags & ASN1_STRING_FLAG_NDEF)) {
                        if (cout) {
                                strtmp->data = cout;
                                strtmp->length = 0;
index 5211276..9e6e757 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
 #include <openssl/asn1t.h>
 #include <openssl/objects.h>
 
-static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
+static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
+    int combine);
 
 /* Free up an ASN1 structure */
 
-void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
+void
+ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
 {
        asn1_item_combine_free(&val, it, 0);
 }
 
-void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
+void
+ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        asn1_item_combine_free(pval, it, 0);
 }
 
-static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
+static 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;
@@ -84,6 +88,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
        const ASN1_AUX *aux = it->funcs;
        ASN1_aux_cb *asn1_cb;
        int i;
+
        if (!pval)
                return;
        if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
@@ -93,8 +98,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
        else
                asn1_cb = 0;
 
-       switch(it->itype) {
-
+       switch (it->itype) {
        case ASN1_ITYPE_PRIMITIVE:
                if (it->templates)
                        ASN1_template_free(pval, it->templates);
@@ -147,10 +151,10 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
                        i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
                        if (i == 2)
                                return;
-               }               
+               }
                asn1_enc_free(pval, it);
                /* If we free up as normal we will invalidate any
-                * ANY DEFINED BY field and we wont be able to 
+                * ANY DEFINED BY field and we wont be able to
                 * determine the type of the field it defines. So
                 * free up in reverse order.
                 */
@@ -173,7 +177,8 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
        }
 }
 
-void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
+void
+ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
 {
        int i;
        if (tt->flags & ASN1_TFLG_SK_MASK) {
@@ -182,17 +187,17 @@ void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
                        ASN1_VALUE *vtmp;
                        vtmp = sk_ASN1_VALUE_value(sk, i);
                        asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item),
-                                                                       0);
+                           0);
                }
                sk_ASN1_VALUE_free(sk);
                *pval = NULL;
-       }
-       else
+       } else
                asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
-                                               tt->flags & ASN1_TFLG_COMBINE);
+                   tt->flags & ASN1_TFLG_COMBINE);
 }
 
-void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
+void
+ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        int utype;
        if (it) {
@@ -220,7 +225,7 @@ void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
                        return;
        }
 
-       switch(utype) {
+       switch (utype) {
        case V_ASN1_OBJECT:
                ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
                break;
index 00aa31d..dc9ddc4 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
 #include <string.h>
 
 static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
-                                                               int combine);
+    int combine);
 static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
 static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
 static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
 
-ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
+ASN1_VALUE *
+ASN1_item_new(const ASN1_ITEM *it)
 {
        ASN1_VALUE *ret = NULL;
        if (ASN1_item_ex_new(&ret, it) > 0)
@@ -80,13 +81,14 @@ ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
 
 /* Allocate an ASN1 structure */
 
-int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
+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)
+static int
+asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
 {
        const ASN1_TEMPLATE *tt = NULL;
        const ASN1_COMPAT_FUNCS *cf;
@@ -95,20 +97,21 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
        ASN1_aux_cb *asn1_cb;
        ASN1_VALUE **pseqval;
        int i;
+
        if (aux && aux->asn1_cb)
                asn1_cb = aux->asn1_cb;
        else
                asn1_cb = 0;
 
-       if (!combine) *pval = NULL;
+       if (!combine)
+               *pval = NULL;
 
 #ifdef CRYPTO_MDEBUG
        if (it->sname)
                CRYPTO_push_info(it->sname);
 #endif
 
-       switch(it->itype) {
-
+       switch (it->itype) {
        case ASN1_ITYPE_EXTERN:
                ef = it->funcs;
                if (ef && ef->asn1_ex_new) {
@@ -130,14 +133,13 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                if (it->templates) {
                        if (!ASN1_template_new(pval, it->templates))
                                goto memerr;
-               }
-               else if (!ASN1_primitive_new(pval, it))
-                               goto memerr;
+               } else if (!ASN1_primitive_new(pval, it))
+                       goto memerr;
                break;
 
        case ASN1_ITYPE_MSTRING:
                if (!ASN1_primitive_new(pval, it))
-                               goto memerr;
+                       goto memerr;
                break;
 
        case ASN1_ITYPE_CHOICE:
@@ -145,7 +147,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                        i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
                        if (!i)
                                goto auxerr;
-                       if (i==2) {
+                       if (i == 2) {
 #ifdef CRYPTO_MDEBUG
                                if (it->sname)
                                        CRYPTO_pop_info();
@@ -161,7 +163,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                }
                asn1_set_choice_selector(pval, -1, it);
                if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
                break;
 
        case ASN1_ITYPE_NDEF_SEQUENCE:
@@ -170,7 +172,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                        i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
                        if (!i)
                                goto auxerr;
-                       if (i==2) {
+                       if (i == 2) {
 #ifdef CRYPTO_MDEBUG
                                if (it->sname)
                                        CRYPTO_pop_info();
@@ -192,47 +194,50 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                                goto memerr;
                }
                if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
                break;
-}
+       }
 #ifdef CRYPTO_MDEBUG
-       if (it->sname) CRYPTO_pop_info();
+       if (it->sname)
+               CRYPTO_pop_info();
 #endif
        return 1;
 
-       memerr:
+memerr:
        ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE);
 #ifdef CRYPTO_MDEBUG
-       if (it->sname) CRYPTO_pop_info();
+       if (it->sname)
+               CRYPTO_pop_info();
 #endif
        return 0;
 
-       auxerr:
+auxerr:
        ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ASN1_R_AUX_ERROR);
        ASN1_item_ex_free(pval, it);
 #ifdef CRYPTO_MDEBUG
-       if (it->sname) CRYPTO_pop_info();
+       if (it->sname)
+               CRYPTO_pop_info();
 #endif
        return 0;
 
 }
 
-static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
+static void
+asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        const ASN1_EXTERN_FUNCS *ef;
 
-       switch(it->itype) {
-
+       switch (it->itype) {
        case ASN1_ITYPE_EXTERN:
                ef = it->funcs;
-               if (ef && ef->asn1_ex_clear) 
+               if (ef && ef->asn1_ex_clear)
                        ef->asn1_ex_clear(pval, it);
-               else *pval = NULL;
+               else
+                       *pval = NULL;
                break;
 
-
        case ASN1_ITYPE_PRIMITIVE:
-               if (it->templates) 
+               if (it->templates)
                        asn1_template_clear(pval, it->templates);
                else
                        asn1_primitive_clear(pval, it);
@@ -251,11 +256,12 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
        }
 }
 
-
-int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
+int
+ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
 {
        const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
        int ret;
+
        if (tt->flags & ASN1_TFLG_OPTIONAL) {
                asn1_template_clear(pval, tt);
                return 1;
@@ -285,7 +291,7 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
        }
        /* Otherwise pass it back to the item routine */
        ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
-       done:
+done:
 #ifdef CRYPTO_MDEBUG
        if (it->sname)
                CRYPTO_pop_info();
@@ -293,10 +299,11 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
        return ret;
 }
 
-static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
+static void
+asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
 {
        /* If ADB or STACK just NULL the field */
-       if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) 
+       if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
                *pval = NULL;
        else
                asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
@@ -307,7 +314,8 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
  * all the old functions.
  */
 
-int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
+int
+ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        ASN1_TYPE *typ;
        ASN1_STRING *str;
@@ -323,7 +331,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
                utype = -1;
        else
                utype = it->utype;
-       switch(utype) {
+       switch (utype) {
        case V_ASN1_OBJECT:
                *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
                return 1;
@@ -357,14 +365,15 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
        return 0;
 }
 
-static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
+static void
+asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        int utype;
        if (it && it->funcs) {
                const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
                if (pf->prim_clear)
                        pf->prim_clear(pval, it);
-               else 
+               else
                        *pval = NULL;
                return;
        }
@@ -374,5 +383,6 @@ static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
                utype = it->utype;
        if (utype == V_ASN1_BOOLEAN)
                *(ASN1_BOOLEAN *)pval = it->size;
-       else *pval = NULL;
+       else
+               *pval = NULL;
 }
index 345daeb..1362499 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -56,7 +56,6 @@
  *
  */
 
-
 #include <stddef.h>
 #include "cryptlib.h"
 #include <openssl/asn1.h>
 
 /* ASN1_PCTX routines */
 
-ASN1_PCTX default_pctx = 
-{
+ASN1_PCTX default_pctx = {
        ASN1_PCTX_FLAGS_SHOW_ABSENT,    /* flags */
-       0,      /* nm_flags */
-       0,      /* cert_flags */
-       0,      /* oid_flags */
-       0       /* str_flags */
+       0,                              /* nm_flags */
+       0,                              /* cert_flags */
+       0,                              /* oid_flags */
+       0                               /* str_flags */
 };
-       
 
-ASN1_PCTX *ASN1_PCTX_new(void)
+
+ASN1_PCTX *
+ASN1_PCTX_new(void)
 {
        ASN1_PCTX *ret;
        ret = malloc(sizeof(ASN1_PCTX));
@@ -98,57 +97,68 @@ ASN1_PCTX *ASN1_PCTX_new(void)
        return ret;
 }
 
-void ASN1_PCTX_free(ASN1_PCTX *p)
+void
+ASN1_PCTX_free(ASN1_PCTX *p)
 {
        free(p);
 }
 
-unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p)
+unsigned long
+ASN1_PCTX_get_flags(ASN1_PCTX *p)
 {
        return p->flags;
 }
 
-void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags)
+void
+ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags)
 {
        p->flags = flags;
 }
 
-unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p)
+unsigned long
+ASN1_PCTX_get_nm_flags(ASN1_PCTX *p)
 {
        return p->nm_flags;
 }
 
-void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags)
+void
+ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags)
 {
        p->nm_flags = flags;
 }
 
-unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p)
+unsigned long
+ASN1_PCTX_get_cert_flags(ASN1_PCTX *p)
 {
        return p->cert_flags;
 }
 
-void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags)
+void
+ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags)
 {
        p->cert_flags = flags;
 }
 
-unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p)
+unsigned long
+ASN1_PCTX_get_oid_flags(ASN1_PCTX *p)
 {
        return p->oid_flags;
 }
 
-void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags)
+void
+ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags)
 {
        p->oid_flags = flags;
 }
 
-unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p)
+unsigned long
+ASN1_PCTX_get_str_flags(ASN1_PCTX *p)
 {
        return p->str_flags;
 }
 
-void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
+void
+ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
 {
        p->str_flags = flags;
 }
@@ -156,40 +166,38 @@ void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
 /* Main print routines */
 
 static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
-                               const ASN1_ITEM *it,
-                               const char *fname, const char *sname,
-                               int nohdr, const ASN1_PCTX *pctx);
+    const ASN1_ITEM *it, const char *fname, const char *sname, int nohdr,
+    const ASN1_PCTX *pctx);
 
 int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
-                               const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx);
+    const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx);
 
 static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
-                               const ASN1_ITEM *it, int indent,
-                               const char *fname, const char *sname,
-                               const ASN1_PCTX *pctx);
+    const ASN1_ITEM *it, int indent, const char *fname, const char *sname,
+    const ASN1_PCTX *pctx);
 
-static int asn1_print_fsname(BIO *out, int indent,
-                       const char *fname, const char *sname,
-                       const ASN1_PCTX *pctx);
+static int asn1_print_fsname(BIO *out, int indent, const char *fname,
+    const char *sname, const ASN1_PCTX *pctx);
 
-int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent,
-                               const ASN1_ITEM *it, const ASN1_PCTX *pctx)
+int
+ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, const ASN1_ITEM *it,
+    const ASN1_PCTX *pctx)
 {
        const char *sname;
+
        if (pctx == NULL)
                pctx = &default_pctx;
        if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME)
                sname = NULL;
        else
                sname = it->sname;
-       return asn1_item_print_ctx(out, &ifld, indent, it,
-                                                       NULL, sname, 0, pctx);
+       return asn1_item_print_ctx(out, &ifld, indent, it, NULL, sname,
+           0, pctx);
 }
 
-static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
-                               const ASN1_ITEM *it,
-                               const char *fname, const char *sname,
-                               int nohdr, const ASN1_PCTX *pctx)
+static int
+asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, const ASN1_ITEM *it,
+    const char *fname, const char *sname, int nohdr, const ASN1_PCTX *pctx)
 {
        const ASN1_TEMPLATE *tt;
        const ASN1_EXTERN_FUNCS *ef;
@@ -198,18 +206,19 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
        ASN1_aux_cb *asn1_cb;
        ASN1_PRINT_ARG parg;
        int i;
+
        if (aux && aux->asn1_cb) {
                parg.out = out;
                parg.indent = indent;
                parg.pctx = pctx;
                asn1_cb = aux->asn1_cb;
-       }
-       else asn1_cb = 0;
+       } else
+               asn1_cb = 0;
 
-       if(*fld == NULL) {
+       if (*fld == NULL) {
                if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) {
-                       if (!nohdr && !asn1_print_fsname(out, indent,
-                                                       fname, sname, pctx))
+                       if (!nohdr &&
+                           !asn1_print_fsname(out, indent, fname, sname, pctx))
                                return 0;
                        if (BIO_puts(out, "<ABSENT>\n") <= 0)
                                return 0;
@@ -217,22 +226,23 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                return 1;
        }
 
-       switch(it->itype) {
+       switch (it->itype) {
        case ASN1_ITYPE_PRIMITIVE:
-               if(it->templates) {
+               if (it->templates) {
                        if (!asn1_template_print_ctx(out, fld, indent,
-                                                       it->templates, pctx))
+                           it->templates, pctx))
                                return 0;
                }
                /* fall thru */
        case ASN1_ITYPE_MSTRING:
                if (!asn1_primitive_print(out, fld, it,
-                               indent, fname, sname,pctx))
+                   indent, fname, sname, pctx))
                        return 0;
                break;
 
        case ASN1_ITYPE_EXTERN:
-               if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
+               if (!nohdr &&
+                   !asn1_print_fsname(out, indent, fname, sname, pctx))
                        return 0;
                /* Use new style print routine if possible */
                ef = it->funcs;
@@ -243,23 +253,23 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                        if ((i == 2) && (BIO_puts(out, "\n") <= 0))
                                return 0;
                        return 1;
-               }
-               else if (sname && 
-                       BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0)
+               } else if (sname &&
+                   BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0)
                        return 0;
                break;
 
        case ASN1_ITYPE_CHOICE:
 #if 0
-               if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
+               if (!nohdr &&
+                   !asn1_print_fsname(out, indent, fname, sname, pctx))
                        return 0;
 #endif
                /* CHOICE type, get selector */
                i = asn1_get_choice_selector(fld, it);
                /* This should never happen... */
-               if((i < 0) || (i >= it->tcount)) {
+               if ((i < 0) || (i >= it->tcount)) {
                        if (BIO_printf(out,
-                               "ERROR: selector [%d] invalid\n", i) <= 0)
+                           "ERROR: selector [%d] invalid\n", i) <= 0)
                                return 0;
                        return 1;
                }
@@ -271,7 +281,8 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
 
        case ASN1_ITYPE_SEQUENCE:
        case ASN1_ITYPE_NDEF_SEQUENCE:
-               if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
+               if (!nohdr &&
+                   !asn1_print_fsname(out, indent, fname, sname, pctx))
                        return 0;
                if (fname || sname) {
                        if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
@@ -292,12 +303,12 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                }
 
                /* Print each field entry */
-               for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
+               for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
                        const ASN1_TEMPLATE *seqtt;
                        seqtt = asn1_do_adb(fld, tt, 1);
                        tmpfld = asn1_get_field_ptr(fld, seqtt);
-                       if (!asn1_template_print_ctx(out, tmpfld,
-                                               indent + 2, seqtt, pctx))
+                       if (!asn1_template_print_ctx(out, tmpfld, indent + 2,
+                           seqtt, pctx))
                                return 0;
                }
                if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
@@ -312,7 +323,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                }
                break;
 
-               default:
+       default:
                BIO_printf(out, "Unprocessed type %d\n", it->itype);
                return 0;
        }
@@ -320,65 +331,65 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
        return 1;
 }
 
-int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
-                               const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx)
+int
+asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
+    const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx)
 {
        int i, flags;
        const char *sname, *fname;
+
        flags = tt->flags;
-       if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME)
+       if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME)
                sname = ASN1_ITEM_ptr(tt->item)->sname;
        else
                sname = NULL;
-       if(pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
+       if (pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
                fname = NULL;
        else
                fname = tt->field_name;
-       if(flags & ASN1_TFLG_SK_MASK) {
+       if (flags & ASN1_TFLG_SK_MASK) {
                char *tname;
                ASN1_VALUE *skitem;
                STACK_OF(ASN1_VALUE) *stack;
 
                /* SET OF, SEQUENCE OF */
                if (fname) {
-                       if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) {
-                               if(flags & ASN1_TFLG_SET_OF)
+                       if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) {
+                               if (flags & ASN1_TFLG_SET_OF)
                                        tname = "SET";
                                else
                                        tname = "SEQUENCE";
                                if (BIO_printf(out, "%*s%s OF %s {\n",
-                                       indent, "", tname, tt->field_name) <= 0)
+                                   indent, "", tname, tt->field_name) <= 0)
                                        return 0;
-                       }
-                       else if (BIO_printf(out, "%*s%s:\n", indent, "",
-                                       fname) <= 0)
+                       } else if (BIO_printf(out, "%*s%s:\n", indent, "",
+                           fname) <= 0)
                                return 0;
                }
                stack = (STACK_OF(ASN1_VALUE) *)*fld;
-               for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) {
+               for (i = 0; i < sk_ASN1_VALUE_num(stack); i++) {
                        if ((i > 0) && (BIO_puts(out, "\n") <= 0))
                                return 0;
-
                        skitem = sk_ASN1_VALUE_value(stack, i);
                        if (!asn1_item_print_ctx(out, &skitem, indent + 2,
-                               ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx))
+                           ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx))
                                return 0;
                }
                if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
-                               return 0;
-               if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
+                       return 0;
+               if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
                        if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
                                return 0;
                }
                return 1;
        }
        return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item),
-                                                       fname, sname, 0, pctx);
+           fname, sname, 0, pctx);
 }
 
-static int asn1_print_fsname(BIO *out, int indent,
-                       const char *fname, const char *sname,
-                       const ASN1_PCTX *pctx)
+static int
+asn1_print_fsname(BIO *out, int indent, const char *fname, const char *sname,
+    const ASN1_PCTX *pctx)
 {
        static char spaces[] = "                    ";
        const int nspaces = sizeof(spaces) - 1;
@@ -419,8 +430,8 @@ static int asn1_print_fsname(BIO *out, int indent,
        return 1;
 }
 
-static int asn1_print_boolean_ctx(BIO *out, int boolval,
-                                                       const ASN1_PCTX *pctx)
+static int
+asn1_print_boolean_ctx(BIO *out, int boolval, const ASN1_PCTX *pctx)
 {
        const char *str;
        switch (boolval) {
@@ -432,7 +443,7 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval,
                str = "FALSE";
                break;
 
-               default:
+       default:
                str = "TRUE";
                break;
 
@@ -444,8 +455,8 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval,
 
 }
 
-static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str,
-                                               const ASN1_PCTX *pctx)
+static int
+asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, const ASN1_PCTX *pctx)
 {
        char *s;
        int ret = 1;
@@ -456,13 +467,13 @@ static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str,
        return ret;
 }
 
-static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid,
-                                               const ASN1_PCTX *pctx)
+static int
+asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, const ASN1_PCTX *pctx)
 {
        char objbuf[80];
        const char *ln;
        ln = OBJ_nid2ln(OBJ_obj2nid(oid));
-       if(!ln)
+       if (!ln)
                ln = "";
        OBJ_obj2txt(objbuf, sizeof objbuf, oid, 1);
        if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0)
@@ -470,36 +481,36 @@ static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid,
        return 1;
 }
 
-static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
-                                               const ASN1_PCTX *pctx)
+static int
+asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
+    const ASN1_PCTX *pctx)
 {
        if (str->type == V_ASN1_BIT_STRING) {
                if (BIO_printf(out, " (%ld unused bits)\n",
-                                       str->flags & 0x7) <= 0)
-                               return 0;
-       }
-       else if (BIO_puts(out, "\n") <= 0)
+                   str->flags & 0x7) <= 0)
+                       return 0;
+       } else if (BIO_puts(out, "\n") <= 0)
                return 0;
-       if ((str->length > 0)
-               && BIO_dump_indent(out, (char *)str->data, str->length,
-                               indent + 2) <= 0)
+       if ((str->length > 0) &&
+           BIO_dump_indent(out, (char *)str->data, str->length,
+           indent + 2) <= 0)
                return 0;
        return 1;
 }
 
-static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
-                               const ASN1_ITEM *it, int indent,
-                               const char *fname, const char *sname,
-                               const ASN1_PCTX *pctx)
+static int
+asn1_primitive_print(BIO *out, ASN1_VALUE **fld, const ASN1_ITEM *it,
+    int indent, const char *fname, const char *sname, const ASN1_PCTX *pctx)
 {
        long utype;
        ASN1_STRING *str;
        int ret = 1, needlf = 1;
        const char *pname;
        const ASN1_PRIMITIVE_FUNCS *pf;
+
        pf = it->funcs;
        if (!asn1_print_fsname(out, indent, fname, sname, pctx))
-                       return 0;
+               return 0;
        if (pf && pf->prim_print)
                return pf->prim_print(out, fld, it, indent, pctx);
        str = (ASN1_STRING *)*fld;
@@ -514,12 +525,12 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
                str = (ASN1_STRING *)*fld;
                if (pctx->flags & ASN1_PCTX_FLAGS_NO_ANY_TYPE)
                        pname = NULL;
-               else 
+               else
                        pname = ASN1_tag2str(utype);
        } else {
                if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE)
                        pname = ASN1_tag2str(utype);
-               else 
+               else
                        pname = NULL;
        }
 
@@ -575,14 +586,13 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
                if (BIO_puts(out, "\n") <= 0)
                        return 0;
                if (ASN1_parse_dump(out, str->data, str->length,
-                                               indent, 0) <= 0)
+                   indent, 0) <= 0)
                        ret = 0;
                needlf = 0;
                break;
 
        default:
                ret = ASN1_STRING_print_ex(out, str, pctx->str_flags);
-
        }
        if (!ret)
                return 0;
index 6fb1c37..3399e74 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -136,12 +136,12 @@ IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
 
 IMPLEMENT_ASN1_TYPE_ex(ASN1_OCTET_STRING_NDEF, ASN1_OCTET_STRING, ASN1_TFLG_NDEF)
 
-ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) = 
-       ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY)
+ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) =
+    ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY)
 ASN1_ITEM_TEMPLATE_END(ASN1_SEQUENCE_ANY)
 
-ASN1_ITEM_TEMPLATE(ASN1_SET_ANY) = 
-       ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, ASN1_SET_ANY, ASN1_ANY)
+ASN1_ITEM_TEMPLATE(ASN1_SET_ANY) =
+    ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, ASN1_SET_ANY, ASN1_ANY)
 ASN1_ITEM_TEMPLATE_END(ASN1_SET_ANY)
 
 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
index 9715dac..e1051c2 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -56,7 +56,6 @@
  *
  */
 
-
 #include <stddef.h>
 #include <string.h>
 #include <openssl/asn1.h>
@@ -73,7 +72,8 @@
  * the selector value
  */
 
-int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
+int
+asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        int *sel = offset2ptr(*pval, it->utype);
        return *sel;
@@ -83,8 +83,9 @@ int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
  * the selector value, return old value.
  */
 
-int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
-{      
+int
+asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
+{
        int *sel, ret;
        sel = offset2ptr(*pval, it->utype);
        ret = *sel;
@@ -92,18 +93,20 @@ int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
        return ret;
 }
 
-/* Do reference counting. The value 'op' decides what to do. 
+/* Do reference counting. The value 'op' decides what to do.
  * if it is +1 then the count is incremented. If op is 0 count is
  * set to 1. If op is -1 count is decremented and the return value
  * is the current refrence count or 0 if no reference count exists.
  */
 
-int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
+int
+asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
 {
        const ASN1_AUX *aux;
        int *lck, ret;
-       if ((it->itype != ASN1_ITYPE_SEQUENCE)
-          && (it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
+
+       if ((it->itype != ASN1_ITYPE_SEQUENCE) &&
+           (it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
                return 0;
        aux = it->funcs;
        if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
@@ -117,9 +120,11 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
        return ret;
 }
 
-static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
+static ASN1_ENCODING *
+asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        const ASN1_AUX *aux;
+
        if (!pval || !*pval)
                return NULL;
        aux = it->funcs;
@@ -128,9 +133,11 @@ static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
        return offset2ptr(*pval, aux->enc_offset);
 }
 
-void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
+void
+asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        ASN1_ENCODING *enc;
+
        enc = asn1_get_enc_ptr(pval, it);
        if (enc) {
                enc->enc = NULL;
@@ -139,9 +146,11 @@ void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
        }
 }
 
-void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
+void
+asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        ASN1_ENCODING *enc;
+
        enc = asn1_get_enc_ptr(pval, it);
        if (enc) {
                if (enc->enc)
@@ -152,10 +161,12 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
        }
 }
 
-int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
-                                                        const ASN1_ITEM *it)
+int
+asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
+    const ASN1_ITEM *it)
 {
        ASN1_ENCODING *enc;
+
        enc = asn1_get_enc_ptr(pval, it);
        if (!enc)
                return 1;
@@ -171,11 +182,13 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
 
        return 1;
 }
-               
-int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
-                                                       const ASN1_ITEM *it)
+
+int
+asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
+    const ASN1_ITEM *it)
 {
        ASN1_ENCODING *enc;
+
        enc = asn1_get_enc_ptr(pval, it);
        if (!enc || enc->modified)
                return 0;
@@ -189,9 +202,11 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
 }
 
 /* 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 **
+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);
@@ -206,14 +221,15 @@ ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
  * the relevant ASN1_TEMPLATE in the table and return it.
  */
 
-const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
-                                                               int nullerr)
+const ASN1_TEMPLATE *
+asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
 {
        const ASN1_ADB *adb;
        const ASN1_ADB_TABLE *atbl;
        long selector;
        ASN1_VALUE **sfld;
        int i;
+
        if (!(tt->flags & ASN1_TFLG_ADB_MASK))
                return tt;
 
@@ -234,9 +250,9 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
         * NB: don't check for NID_undef here because it
         * might be a legitimate value in the table
         */
-       if (tt->flags & ASN1_TFLG_ADB_OID) 
+       if (tt->flags & ASN1_TFLG_ADB_OID)
                selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
-       else 
+       else
                selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
 
        /* Try to find matching entry in table
@@ -255,13 +271,13 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
 
        /* No match, return default type */
        if (!adb->default_tt)
-               goto err;               
+               goto err;
        return adb->default_tt;
-       
-       err:
+
+err:
        /* FIXME: should log the value or OID of unsupported type */
        if (nullerr)
                ASN1err(ASN1_F_ASN1_DO_ADB,
-                       ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
+                   ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
        return NULL;
 }
index 1a06ddc..e9059df 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -69,45 +69,40 @@ static int asn1_check_eoc(const unsigned char **in, long len);
 static int asn1_find_end(const unsigned char **in, long len, char inf);
 
 static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
-                       char inf, int tag, int aclass, int depth);
+    char inf, int tag, int aclass, int depth);
 
 static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen);
 
 static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
-                               char *inf, char *cst,
-                               const unsigned char **in, long len,
-                               int exptag, int expclass, char opt,
-                               ASN1_TLC *ctx);
-
-static int asn1_template_ex_d2i(ASN1_VALUE **pval,
-                               const unsigned char **in, long len,
-                               const ASN1_TEMPLATE *tt, char opt,
-                               ASN1_TLC *ctx);
-static int asn1_template_noexp_d2i(ASN1_VALUE **val,
-                               const unsigned char **in, long len,
-                               const ASN1_TEMPLATE *tt, char opt,
-                               ASN1_TLC *ctx);
-static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
-                               const unsigned char **in, long len,
-                               const ASN1_ITEM *it,
-                               int tag, int aclass, char opt, ASN1_TLC *ctx);
+    char *inf, char *cst, const unsigned char **in, long len, int exptag,
+    int expclass, char opt, ASN1_TLC *ctx);
+
+static int asn1_template_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
+    long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
+static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
+    long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
+static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
+    long len, const ASN1_ITEM *it, int tag, int aclass, char opt,
+    ASN1_TLC *ctx);
 
 /* Table to convert tags to bit values, used for MSTRING type */
 static const unsigned long tag2bit[32] = {
-0,     0,      0,      B_ASN1_BIT_STRING,      /* tags  0 -  3 */
-B_ASN1_OCTET_STRING,   0,      0,              B_ASN1_UNKNOWN,/* tags  4- 7 */
-B_ASN1_UNKNOWN,        B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags  8-11 */
-B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
-B_ASN1_SEQUENCE,0,B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */
-B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,       /* tags 20-22 */
-B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME,                               /* tags 23-24 */ 
-B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING,  /* tags 25-27 */
-B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */
+       0,      0,      0,      B_ASN1_BIT_STRING,      /* tags  0 -  3 */
+       B_ASN1_OCTET_STRING,    0,      0,              B_ASN1_UNKNOWN,/* tags  4- 7 */
+       B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags  8-11 */
+       B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
+       B_ASN1_SEQUENCE,0,B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */
+       B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,       /* tags 20-22 */
+       B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME,                        /* tags 23-24 */
+       B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING,  /* tags 25-27 */
+       B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */
 };
 
-unsigned long ASN1_tag2bit(int tag)
+unsigned long
+ASN1_tag2bit(int tag)
 {
-       if ((tag < 0) || (tag > 30)) return 0;
+       if ((tag < 0) || (tag > 30))
+               return 0;
        return tag2bit[tag];
 }
 
@@ -117,29 +112,31 @@ unsigned long ASN1_tag2bit(int tag)
 /* Version to avoid compiler warning about 'c' always non-NULL */
 #define asn1_tlc_clear_nc(c)   (c)->valid = 0
 
-/* Decode an ASN1 item, this currently behaves just 
- * like a standard 'd2i' function. 'in' points to 
+/* Decode an ASN1 item, this currently behaves just
+ * like a standard 'd2i' function. 'in' points to
  * a buffer to read the data from, in future we will
  * have more advanced versions that can input data
  * a piece at a time and this will simply be a special
  * case.
  */
 
-ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval,
-               const unsigned char **in, long len, const ASN1_ITEM *it)
+ASN1_VALUE *
+ASN1_item_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
+    const ASN1_ITEM *it)
 {
        ASN1_TLC c;
        ASN1_VALUE *ptmpval = NULL;
        if (!pval)
                pval = &ptmpval;
        asn1_tlc_clear_nc(&c);
-       if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0) 
+       if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
                return *pval;
        return NULL;
 }
 
-int ASN1_template_d2i(ASN1_VALUE **pval,
-               const unsigned char **in, long len, const ASN1_TEMPLATE *tt)
+int
+ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
+    const ASN1_TEMPLATE *tt)
 {
        ASN1_TLC c;
        asn1_tlc_clear_nc(&c);
@@ -151,9 +148,9 @@ int ASN1_template_d2i(ASN1_VALUE **pval,
  * If 'opt' set and tag mismatch return -1 to handle OPTIONAL
  */
 
-int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
-                       const ASN1_ITEM *it,
-                       int tag, int aclass, char opt, ASN1_TLC *ctx)
+int
+ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
+    const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
 {
        const ASN1_TEMPLATE *tt, *errtt = NULL;
        const ASN1_COMPAT_FUNCS *cf;
@@ -161,7 +158,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
        const ASN1_AUX *aux = it->funcs;
        ASN1_aux_cb *asn1_cb;
        const unsigned char *p = NULL, *q;
-       unsigned char *wp=NULL; /* BIG FAT WARNING!  BREAKS CONST WHERE USED */
+       unsigned char *wp = NULL;       /* BIG FAT WARNING!  BREAKS CONST WHERE USED */
        unsigned char imphack = 0, oclass;
        char seq_eoc, seq_nolen, cst, isopt;
        long tmplen;
@@ -173,9 +170,10 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                return 0;
        if (aux && aux->asn1_cb)
                asn1_cb = aux->asn1_cb;
-       else asn1_cb = 0;
+       else
+               asn1_cb = 0;
 
-       switch(it->itype) {
+       switch (it->itype) {
        case ASN1_ITYPE_PRIMITIVE:
                if (it->templates) {
                        /* tagging or OPTIONAL is currently illegal on an item
@@ -186,33 +184,34 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                         */
                        if ((tag != -1) || opt) {
                                ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                               ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
+                                   ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
                                goto err;
                        }
                        return asn1_template_ex_d2i(pval, in, len,
-                                       it->templates, opt, ctx);
-       }
+                           it->templates, opt, ctx);
+               }
                return asn1_d2i_ex_primitive(pval, in, len, it,
-                                               tag, aclass, opt, ctx);
+                   tag, aclass, opt, ctx);
                break;
 
        case ASN1_ITYPE_MSTRING:
                p = *in;
                /* Just read in tag and class */
                ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
-                                               &p, len, -1, 0, 1, ctx);
+                   &p, len, -1, 0, 1, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
                }
 
                /* Must be UNIVERSAL class */
                if (oclass != V_ASN1_UNIVERSAL) {
                        /* If OPTIONAL, assume this is OK */
-                       if (opt) return -1;
+                       if (opt)
+                               return -1;
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ASN1_R_MSTRING_NOT_UNIVERSAL);
+                           ASN1_R_MSTRING_NOT_UNIVERSAL);
                        goto err;
                }
                /* Check tag matches bit map */
@@ -221,17 +220,17 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        if (opt)
                                return -1;
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ASN1_R_MSTRING_WRONG_TAG);
+                           ASN1_R_MSTRING_WRONG_TAG);
                        goto err;
                }
                return asn1_d2i_ex_primitive(pval, in, len,
-                                               it, otag, 0, 0, ctx);
+                   it, otag, 0, 0, ctx);
 
        case ASN1_ITYPE_EXTERN:
                /* Use new style d2i */
                ef = it->funcs;
                return ef->asn1_ex_d2i(pval, in, len,
-                                               it, tag, aclass, opt, ctx);
+                   it, tag, aclass, opt, ctx);
 
        case ASN1_ITYPE_COMPAT:
                /* we must resort to old style evil hackery */
@@ -243,15 +242,16 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        p = *in;
                        if (tag == -1)
                                exptag = it->utype;
-                       else exptag = tag;
+                       else
+                               exptag = tag;
                        /* Don't care about anything other than presence
                         * of expected tag */
 
                        ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL,
-                                       &p, len, exptag, aclass, 1, ctx);
+                           &p, len, exptag, aclass, 1, ctx);
                        if (!ret) {
                                ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                                   ERR_R_NESTED_ASN1_ERROR);
                                goto err;
                        }
                        if (ret == -1)
@@ -278,11 +278,11 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        imphack = *wp;
                        if (p == NULL) {
                                ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                                   ERR_R_NESTED_ASN1_ERROR);
                                goto err;
                        }
-                       *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED)
-                                                               | it->utype);
+                       *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED) |
+                           it->utype);
                }
 
                ptmpval = cf->asn1_d2i(pval, in, len);
@@ -296,20 +296,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
                goto err;
 
-
        case ASN1_ITYPE_CHOICE:
                if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
 
                /* Allocate structure */
                if (!*pval && !ASN1_item_ex_new(pval, it)) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                               ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
                }
                /* CHOICE type, try each possibility in turn */
                p = *in;
-               for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) {
+               for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
                        pchptr = asn1_get_field_ptr(pval, tt);
                        /* We mark field as OPTIONAL so its absence
                         * can be recognised.
@@ -324,7 +323,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        /* Otherwise must be an ASN1 parsing error */
                        errtt = tt;
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                               ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
                }
 
@@ -337,14 +336,14 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                                return -1;
                        }
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ASN1_R_NO_MATCHING_CHOICE_TYPE);
+                           ASN1_R_NO_MATCHING_CHOICE_TYPE);
                        goto err;
                }
 
                asn1_set_choice_selector(pval, i, it);
                *in = p;
                if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
                return 1;
 
        case ASN1_ITYPE_NDEF_SEQUENCE:
@@ -359,34 +358,34 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                }
                /* Get SEQUENCE length and update len, p */
                ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,
-                                       &p, len, tag, aclass, opt, ctx);
+                   &p, len, tag, aclass, opt, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
-               }
-               else if (ret == -1)
+               } else if (ret == -1)
                        return -1;
                if (aux && (aux->flags & ASN1_AFLG_BROKEN)) {
                        len = tmplen - (p - *in);
                        seq_nolen = 1;
                }
                /* If indefinite we don't do a length check */
-               else seq_nolen = seq_eoc;
+               else
+                       seq_nolen = seq_eoc;
                if (!cst) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                               ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
+                           ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
                        goto err;
                }
 
                if (!*pval && !ASN1_item_ex_new(pval, it)) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                               ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
                }
 
                if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
 
                /* Get each field entry */
                for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
@@ -403,7 +402,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        if (asn1_check_eoc(&p, len)) {
                                if (!seq_eoc) {
                                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                                       ASN1_R_UNEXPECTED_EOC);
+                                           ASN1_R_UNEXPECTED_EOC);
                                        goto err;
                                }
                                len -= p - q;
@@ -419,12 +418,13 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                         */
                        if (i == (it->tcount - 1))
                                isopt = 0;
-                       else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
+                       else
+                               isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
                        /* attempt to read in field, allowing each to be
                         * OPTIONAL */
 
                        ret = asn1_template_ex_d2i(pseqval, &p, len,
-                                                       seqtt, isopt, ctx);
+                           seqtt, isopt, ctx);
                        if (!ret) {
                                errtt = seqtt;
                                goto err;
@@ -447,7 +447,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                /* Check all data read */
                if (!seq_nolen && len) {
                        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                       ASN1_R_SEQUENCE_LENGTH_MISMATCH);
+                           ASN1_R_SEQUENCE_LENGTH_MISMATCH);
                        goto err;
                }
 
@@ -467,7 +467,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        } else {
                                errtt = seqtt;
                                ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
-                                                       ASN1_R_FIELD_MISSING);
+                                   ASN1_R_FIELD_MISSING);
                                goto err;
                        }
                }
@@ -476,19 +476,20 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
                        goto auxerr;
                *in = p;
                if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
                return 1;
 
-               default:
+       default:
                return 0;
        }
-       auxerr:
+
+auxerr:
        ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);
-       err:
+err:
        ASN1_item_ex_free(pval, it);
        if (errtt)
                ERR_add_error_data(4, "Field=", errtt->field_name,
-                                       ", Type=", it->sname);
+                   ", Type=", it->sname);
        else
                ERR_add_error_data(2, "Type=", it->sname);
        return 0;
@@ -498,16 +499,16 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
  * One handles any EXPLICIT tag and the other handles the rest.
  */
 
-static int asn1_template_ex_d2i(ASN1_VALUE **val,
-                               const unsigned char **in, long inlen,
-                               const ASN1_TEMPLATE *tt, char opt,
-                                                       ASN1_TLC *ctx)
+static int
+asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long inlen,
+    const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
 {
        int flags, aclass;
        int ret;
        long len;
        const unsigned char *p, *q;
        char exp_eoc;
+
        if (!val)
                return 0;
        flags = tt->flags;
@@ -523,24 +524,24 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
                 * get the info.
                 */
                ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst,
-                                       &p, inlen, tt->tag, aclass, opt, ctx);
+                   &p, inlen, tt->tag, aclass, opt, ctx);
                q = p;
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        return 0;
                } else if (ret == -1)
                        return -1;
                if (!cst) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
-                                       ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
+                           ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
                        return 0;
                }
                /* We've found the field so it can't be OPTIONAL now */
                ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        return 0;
                }
                /* We read the field in OK so update length */
@@ -549,7 +550,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
                        /* If NDEF we must have an EOC here */
                        if (!asn1_check_eoc(&p, len)) {
                                ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
-                                               ASN1_R_MISSING_EOC);
+                                   ASN1_R_MISSING_EOC);
                                goto err;
                        }
                } else {
@@ -557,31 +558,29 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
                         * an error */
                        if (len) {
                                ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
-                                       ASN1_R_EXPLICIT_LENGTH_MISMATCH);
+                                   ASN1_R_EXPLICIT_LENGTH_MISMATCH);
                                goto err;
                        }
                }
-       }
-               else 
-                       return asn1_template_noexp_d2i(val, in, inlen,
-                                                               tt, opt, ctx);
+       } else
+               return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx);
 
        *in = p;
        return 1;
 
-       err:
+err:
        ASN1_template_free(val, tt);
        return 0;
 }
 
-static int asn1_template_noexp_d2i(ASN1_VALUE **val,
-                               const unsigned char **in, long len,
-                               const ASN1_TEMPLATE *tt, char opt,
-                               ASN1_TLC *ctx)
+static int
+asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
+    const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
 {
        int flags, aclass;
        int ret;
        const unsigned char *p, *q;
+
        if (!val)
                return 0;
        flags = tt->flags;
@@ -607,43 +606,42 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
                }
                /* Get the tag */
                ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL,
-                                       &p, len, sktag, skaclass, opt, ctx);
+                   &p, len, sktag, skaclass, opt, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                               ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        return 0;
-               }
-               else if (ret == -1)
+               } else if (ret == -1)
                        return -1;
                if (!*val)
                        *val = (ASN1_VALUE *)sk_new_null();
                else {
                        /* We've got a valid STACK: free up any items present */
-                       STACK_OF(ASN1_VALUE) *sktmp
-                           (STACK_OF(ASN1_VALUE) *)*val;
+                       STACK_OF(ASN1_VALUE) *sktmp =
+                           (STACK_OF(ASN1_VALUE) *)*val;
                        ASN1_VALUE *vtmp;
-                       while(sk_ASN1_VALUE_num(sktmp) > 0) {
+                       while (sk_ASN1_VALUE_num(sktmp) > 0) {
                                vtmp = sk_ASN1_VALUE_pop(sktmp);
                                ASN1_item_ex_free(&vtmp,
-                                               ASN1_ITEM_ptr(tt->item));
+                                   ASN1_ITEM_ptr(tt->item));
                        }
                }
-                               
+
                if (!*val) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                               ERR_R_MALLOC_FAILURE);
+                           ERR_R_MALLOC_FAILURE);
                        goto err;
                }
 
                /* Read as many items as we can */
-               while(len > 0) {
+               while (len > 0) {
                        ASN1_VALUE *skfield;
                        q = p;
                        /* See if EOC found */
                        if (asn1_check_eoc(&p, len)) {
                                if (!sk_eoc) {
                                        ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                                       ASN1_R_UNEXPECTED_EOC);
+                                           ASN1_R_UNEXPECTED_EOC);
                                        goto err;
                                }
                                len -= p - q;
@@ -652,60 +650,57 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
                        }
                        skfield = NULL;
                        if (!ASN1_item_ex_d2i(&skfield, &p, len,
-                                               ASN1_ITEM_ptr(tt->item),
-                                               -1, 0, 0, ctx)) {
+                           ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) {
                                ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                                   ERR_R_NESTED_ASN1_ERROR);
                                goto err;
                        }
                        len -= p - q;
                        if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val,
-                                               skfield)) {
+                           skfield)) {
                                ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                               ERR_R_MALLOC_FAILURE);
+                                   ERR_R_MALLOC_FAILURE);
                                goto err;
                        }
                }
                if (sk_eoc) {
-                       ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC);
+                       ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
+                           ASN1_R_MISSING_EOC);
                        goto err;
                }
        } else if (flags & ASN1_TFLG_IMPTAG) {
                /* IMPLICIT tagging */
                ret = ASN1_item_ex_d2i(val, &p, len,
-                       ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
+                   ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                               ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
-               }
-               else if (ret == -1)
+               } else if (ret == -1)
                        return -1;
        } else {
                /* Nothing special */
                ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),
-                                                       -1, 0, opt, ctx);
+                   -1, 0, opt, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        goto err;
-               }
-               else if (ret == -1)
+               } else if (ret == -1)
                        return -1;
        }
 
        *in = p;
        return 1;
 
-       err:
+err:
        ASN1_template_free(val, tt);
        return 0;
 }
 
-static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
-                               const unsigned char **in, long inlen, 
-                               const ASN1_ITEM *it,
-                               int tag, int aclass, char opt, ASN1_TLC *ctx)
+static int
+asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long inlen,
+    const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
 {
        int ret = 0, utype;
        long plen;
@@ -713,7 +708,8 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
        const unsigned char *p;
        BUF_MEM buf;
        const unsigned char *cont = NULL;
-       long len; 
+       long len;
+
        if (!pval) {
                ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL);
                return 0; /* Should never happen */
@@ -722,8 +718,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
        if (it->itype == ASN1_ITYPE_MSTRING) {
                utype = tag;
                tag = -1;
-       }
-       else
+       } else
                utype = it->utype;
 
        if (utype == V_ASN1_ANY) {
@@ -731,20 +726,20 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
                unsigned char oclass;
                if (tag >= 0) {
                        ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
-                                       ASN1_R_ILLEGAL_TAGGED_ANY);
+                           ASN1_R_ILLEGAL_TAGGED_ANY);
                        return 0;
                }
                if (opt) {
                        ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
-                                       ASN1_R_ILLEGAL_OPTIONAL_ANY);
+                           ASN1_R_ILLEGAL_OPTIONAL_ANY);
                        return 0;
                }
                p = *in;
                ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL,
-                                       &p, inlen, -1, 0, 0, ctx);
+                   &p, inlen, -1, 0, 0, ctx);
                if (!ret) {
                        ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
-                                       ERR_R_NESTED_ASN1_ERROR);
+                           ERR_R_NESTED_ASN1_ERROR);
                        return 0;
                }
                if (oclass != V_ASN1_UNIVERSAL)
@@ -757,17 +752,16 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
        p = *in;
        /* Check header */
        ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst,
-                               &p, inlen, tag, aclass, opt, ctx);
+           &p, inlen, tag, aclass, opt, ctx);
        if (!ret) {
                ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
                return 0;
-       }
-       else if (ret == -1)
+       } else if (ret == -1)
                return -1;
-        ret = 0;
+       ret = 0;
        /* SEQUENCE, SET and "OTHER" are left in encoded form */
-       if ((utype == V_ASN1_SEQUENCE)
-               || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
+       if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
+           (utype == V_ASN1_OTHER)) {
                /* Clear context cache for type OTHER because the auto clear
                 * when we have a exact match wont work
                 */
@@ -777,7 +771,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
                /* SEQUENCE and SET must be constructed */
                else if (!cst) {
                        ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
-                               ASN1_R_TYPE_NOT_CONSTRUCTED);
+                           ASN1_R_TYPE_NOT_CONSTRUCTED);
                        return 0;
                }
 
@@ -785,7 +779,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
                /* If indefinite length constructed find the real end */
                if (inf) {
                        if (!asn1_find_end(&p, plen, inf))
-                                goto err;
+                               goto err;
                        len = p - cont;
                } else {
                        len = p - cont + plen;
@@ -810,7 +804,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
                /* Append a final null to string */
                if (!BUF_MEM_grow_clean(&buf, len + 1)) {
                        ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
-                                               ERR_R_MALLOC_FAILURE);
+                           ERR_R_MALLOC_FAILURE);
                        return 0;
                }
                buf.data[len] = 0;
@@ -828,15 +822,18 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
 
        *in = p;
        ret = 1;
-       err:
-       if (free_cont && buf.data) free(buf.data);
+
+err:
+       if (free_cont && buf.data)
+               free(buf.data);
        return ret;
 }
 
 /* Translate ASN1 content octets into a structure */
 
-int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
-                       int utype, char *free_cont, const ASN1_ITEM *it)
+int
+asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
+    char *free_cont, const ASN1_ITEM *it)
 {
        ASN1_VALUE **opval = NULL;
        ASN1_STRING *stmp;
@@ -855,8 +852,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
                        if (typ == NULL)
                                goto err;
                        *pval = (ASN1_VALUE *)typ;
-               }
-               else
+               } else
                        typ = (ASN1_TYPE *)*pval;
 
                if (utype != typ->type)
@@ -864,7 +860,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
                opval = pval;
                pval = &typ->value.asn1_value;
        }
-       switch(utype) {
+       switch (utype) {
        case V_ASN1_OBJECT:
                if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len))
                        goto err;
@@ -873,7 +869,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
        case V_ASN1_NULL:
                if (len) {
                        ASN1err(ASN1_F_ASN1_EX_C2I,
-                                               ASN1_R_NULL_IS_WRONG_LENGTH);
+                           ASN1_R_NULL_IS_WRONG_LENGTH);
                        goto err;
                }
                *pval = (ASN1_VALUE *)1;
@@ -882,7 +878,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
        case V_ASN1_BOOLEAN:
                if (len != 1) {
                        ASN1err(ASN1_F_ASN1_EX_C2I,
-                                               ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
+                           ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
                        goto err;
                } else {
                        ASN1_BOOLEAN *tbool;
@@ -927,12 +923,12 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
        default:
                if (utype == V_ASN1_BMPSTRING && (len & 1)) {
                        ASN1err(ASN1_F_ASN1_EX_C2I,
-                                       ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
+                           ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
                        goto err;
                }
                if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) {
                        ASN1err(ASN1_F_ASN1_EX_C2I,
-                                       ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
+                           ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
                        goto err;
                }
                /* All based on ASN1_STRING and handled the same */
@@ -940,7 +936,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
                        stmp = ASN1_STRING_type_new(utype);
                        if (!stmp) {
                                ASN1err(ASN1_F_ASN1_EX_C2I,
-                                                       ERR_R_MALLOC_FAILURE);
+                                   ERR_R_MALLOC_FAILURE);
                                goto err;
                        }
                        *pval = (ASN1_VALUE *)stmp;
@@ -958,8 +954,8 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
                } else {
                        if (!ASN1_STRING_set(stmp, cont, len)) {
                                ASN1err(ASN1_F_ASN1_EX_C2I,
-                                                       ERR_R_MALLOC_FAILURE);
-                               ASN1_STRING_free(stmp); 
+                                   ERR_R_MALLOC_FAILURE);
+                               ASN1_STRING_free(stmp);
                                *pval = NULL;
                                goto err;
                        }
@@ -968,10 +964,11 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
        }
        /* If ASN1_ANY and NULL type fix up value */
        if (typ && (utype == V_ASN1_NULL))
-                typ->value.ptr = NULL;
+               typ->value.ptr = NULL;
 
        ret = 1;
-       err:
+
+err:
        if (!ret) {
                ASN1_TYPE_free(typ);
                if (opval)
@@ -987,11 +984,13 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
  * recurse on each indefinite length header.
  */
 
-static int asn1_find_end(const unsigned char **in, long len, char inf)
+static int
+asn1_find_end(const unsigned char **in, long len, char inf)
 {
        int expected_eoc;
        long plen;
        const unsigned char *p = *in, *q;
+
        /* If not indefinite length constructed just add length */
        if (inf == 0) {
                *in += len;
@@ -1004,7 +1003,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
         * skip to the end of the data.
         */
        while (len > 0) {
-               if(asn1_check_eoc(&p, len)) {
+               if (asn1_check_eoc(&p, len)) {
                        expected_eoc--;
                        if (expected_eoc == 0)
                                break;
@@ -1013,8 +1012,8 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
                }
                q = p;
                /* Just read in a header: only care about the length */
-               if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
-                               -1, 0, 0, NULL)) {
+               if (!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
+                   -1, 0, 0, NULL)) {
                        ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR);
                        return 0;
                }
@@ -1046,13 +1045,14 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
 #define ASN1_MAX_STRING_NEST 5
 #endif
 
-
-static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
-                       char inf, int tag, int aclass, int depth)
+static int
+asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, char inf,
+    int tag, int aclass, int depth)
 {
        const unsigned char *p, *q;
        long plen;
        char cst, ininf;
+
        p = *in;
        inf &= 1;
        /* If no buffer and not indefinite length constructed just pass over
@@ -1061,7 +1061,7 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
                *in += len;
                return 1;
        }
-       while(len > 0) {
+       while (len > 0) {
                q = p;
                /* Check for EOC */
                if (asn1_check_eoc(&p, len)) {
@@ -1069,7 +1069,7 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
                         * constructed form */
                        if (!inf) {
                                ASN1err(ASN1_F_ASN1_COLLECT,
-                                       ASN1_R_UNEXPECTED_EOC);
+                                   ASN1_R_UNEXPECTED_EOC);
                                return 0;
                        }
                        inf = 0;
@@ -1077,7 +1077,7 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
                }
 
                if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p,
-                                       len, tag, aclass, 0, NULL)) {
+                   len, tag, aclass, 0, NULL)) {
                        ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR);
                        return 0;
                }
@@ -1086,14 +1086,13 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
                if (cst) {
                        if (depth >= ASN1_MAX_STRING_NEST) {
                                ASN1err(ASN1_F_ASN1_COLLECT,
-                                       ASN1_R_NESTED_ASN1_STRING);
+                                   ASN1_R_NESTED_ASN1_STRING);
                                return 0;
                        }
                        if (!asn1_collect(buf, &p, plen, ininf, tag, aclass,
-                                               depth + 1))
+                           depth + 1))
                                return 0;
-               }
-               else if (plen && !collect_data(buf, &p, plen))
+               } else if (plen && !collect_data(buf, &p, plen))
                        return 0;
                len -= p - q;
        }
@@ -1105,7 +1104,8 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
        return 1;
 }
 
-static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
+static int
+collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
 {
        int len;
        if (buf) {
@@ -1122,10 +1122,13 @@ static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
 
 /* Check for ASN1 EOC and swallow it if found */
 
-static int asn1_check_eoc(const unsigned char **in, long len)
+static int
+asn1_check_eoc(const unsigned char **in, long len)
 {
        const unsigned char *p;
-       if (len < 2) return 0;
+
+       if (len < 2)
+               return 0;
        p = *in;
        if (!p[0] && !p[1]) {
                *in += 2;
@@ -1141,11 +1144,10 @@ static int asn1_check_eoc(const unsigned char **in, long len)
  * header length just read.
  */
 
-static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
-                               char *inf, char *cst,
-                               const unsigned char **in, long len,
-                               int exptag, int expclass, char opt,
-                               ASN1_TLC *ctx)
+static int
+asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf,
+    char *cst, const unsigned char **in, long len, int exptag, int expclass,
+    char opt, ASN1_TLC *ctx)
 {
        int i;
        int ptag, pclass;
@@ -1170,11 +1172,11 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
                        ctx->hdrlen = p - q;
                        ctx->valid = 1;
                        /* If definite length, and no error, length +
-                        * header can't exceed total amount of data available. 
+                        * header can't exceed total amount of data available.
                         */
                        if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
                                ASN1err(ASN1_F_ASN1_CHECK_TLEN,
-                                                       ASN1_R_TOO_LONG);
+                                   ASN1_R_TOO_LONG);
                                asn1_tlc_clear(ctx);
                                return 0;
                        }
@@ -1191,7 +1193,8 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
                        /* If type is OPTIONAL, not an error:
                         * indicate missing type.
                         */
-                       if (opt) return -1;
+                       if (opt)
+                               return -1;
                        asn1_tlc_clear(ctx);
                        ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG);
                        return 0;
@@ -1203,19 +1206,14 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
 
        if (i & 1)
                plen = len - (p - q);
-
        if (inf)
                *inf = i & 1;
-
        if (cst)
                *cst = i & V_ASN1_CONSTRUCTED;
-
        if (olen)
                *olen = plen;
-
        if (oclass)
                *oclass = pclass;
-
        if (otag)
                *otag = ptag;
 
index c9131cd..f5fc882 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -56,7 +56,6 @@
  *
  */
 
-
 #include <stddef.h>
 #include <string.h>
 #include "cryptlib.h"
 #include <openssl/objects.h>
 
 static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
-                                       const ASN1_ITEM *it,
-                                       int tag, int aclass);
+    const ASN1_ITEM *it, int tag, int aclass);
 static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
-                                       int skcontlen, const ASN1_ITEM *item,
-                                       int do_sort, int iclass);
+    int skcontlen, const ASN1_ITEM *item, int do_sort, int iclass);
 static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
-                                       const ASN1_TEMPLATE *tt,
-                                       int tag, int aclass);
+    const ASN1_TEMPLATE *tt, int tag, int aclass);
 static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
-                                       const ASN1_ITEM *it, int flags);
+    const ASN1_ITEM *it, int flags);
 
 /* Top level i2d equivalents: the 'ndef' variant instructs the encoder
  * to use indefinite length constructed encoding, where appropriate
  */
 
-int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out,
-                                               const ASN1_ITEM *it)
+int
+ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
 {
        return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF);
 }
 
-int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
+int
+ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
 {
        return asn1_item_flags_i2d(val, out, it, 0);
 }
 
 /* Encode an ASN1 item, this is use by the
- * standard 'i2d' function. 'out' points to 
+ * standard 'i2d' function. 'out' points to
  * a buffer to output the data to.
  *
  * The new i2d has one additional feature. If the output
@@ -100,8 +97,9 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
  * allocated and populated with the encoding.
  */
 
-static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
-                                       const ASN1_ITEM *it, int flags)
+static int
+asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it,
+    int flags)
 {
        if (out && !*out) {
                unsigned char *p, *buf;
@@ -126,8 +124,9 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
  * used in external types.
  */
 
-int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
-                       const ASN1_ITEM *it, int tag, int aclass)
+int
+ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it,
+    int tag, int aclass)
 {
        const ASN1_TEMPLATE *tt = NULL;
        unsigned char *p = NULL;
@@ -141,14 +140,14 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                return 0;
 
        if (aux && aux->asn1_cb)
-                asn1_cb = aux->asn1_cb;
+               asn1_cb = aux->asn1_cb;
 
-       switch(it->itype) {
+       switch (it->itype) {
 
        case ASN1_ITYPE_PRIMITIVE:
                if (it->templates)
                        return asn1_template_ex_i2d(pval, out, it->templates,
-                                                               tag, aclass);
+                           tag, aclass);
                return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
                break;
 
@@ -157,7 +156,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
 
        case ASN1_ITYPE_CHOICE:
                if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
-                               return 0;
+                       return 0;
                i = asn1_get_choice_selector(pval, it);
                if ((i >= 0) && (i < it->tcount)) {
                        ASN1_VALUE **pchval;
@@ -165,11 +164,11 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        chtt = it->templates + i;
                        pchval = asn1_get_field_ptr(pval, chtt);
                        return asn1_template_ex_i2d(pchval, out, chtt,
-                                                               -1, aclass);
+                           -1, aclass);
                }
                /* Fixme: error condition if selector out of range */
                if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
-                               return 0;
+                       return 0;
                break;
 
        case ASN1_ITYPE_EXTERN:
@@ -189,10 +188,11 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                if (out && (tag != -1))
                        *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
                return i;
-               
+
        case ASN1_ITYPE_NDEF_SEQUENCE:
                /* Use indefinite length constructed if requested */
-               if (aclass & ASN1_TFLG_NDEF) ndef = 2;
+               if (aclass & ASN1_TFLG_NDEF)
+                       ndef = 2;
                /* fall through */
 
        case ASN1_ITYPE_SEQUENCE:
@@ -209,11 +209,11 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                if (tag == -1) {
                        tag = V_ASN1_SEQUENCE;
                        /* Retain any other flags in aclass */
-                       aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)
-                                       | V_ASN1_UNIVERSAL;
+                       aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) |
+                           V_ASN1_UNIVERSAL;
                }
                if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
-                               return 0;
+                       return 0;
                /* First work out sequence content length */
                for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
                        const ASN1_TEMPLATE *seqtt;
@@ -224,7 +224,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        pseqval = asn1_get_field_ptr(pval, seqtt);
                        /* FIXME: check for errors in enhanced version */
                        seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt,
-                                                               -1, aclass);
+                           -1, aclass);
                }
 
                seqlen = ASN1_object_size(ndef, seqcontlen, tag);
@@ -245,24 +245,26 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                if (ndef == 2)
                        ASN1_put_eoc(out);
                if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
-                               return 0;
+                       return 0;
                return seqlen;
 
-               default:
+       default:
                return 0;
 
        }
        return 0;
 }
 
-int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out,
-                                                       const ASN1_TEMPLATE *tt)
+int
+ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out,
+    const ASN1_TEMPLATE *tt)
 {
        return asn1_template_ex_i2d(pval, out, tt, -1, 0);
 }
 
-static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
-                               const ASN1_TEMPLATE *tt, int tag, int iclass)
+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, ndef;
        flags = tt->flags;
@@ -288,7 +290,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                ttag = -1;
                tclass = 0;
        }
-       /* 
+       /*
         * Remove any class mask from iflag.
         */
        iclass &= ~ASN1_TFLG_TAG_CLASS;
@@ -301,7 +303,8 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
        /* if template and arguments require ndef, use it */
        if ((flags & ASN1_TFLG_NDEF) && (iclass & ASN1_TFLG_NDEF))
                ndef = 2;
-       else ndef = 1;
+       else
+               ndef = 1;
 
        if (flags & ASN1_TFLG_SK_MASK) {
                /* SET OF, SEQUENCE OF */
@@ -318,8 +321,8 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        /* 2 means we reorder */
                        if (flags & ASN1_TFLG_SEQUENCE_OF)
                                isset = 2;
-               }
-               else isset = 0;
+               } else
+                       isset = 0;
 
                /* Work out inner tag value: if EXPLICIT
                 * or no tagging use underlying type.
@@ -331,7 +334,8 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        skaclass = V_ASN1_UNIVERSAL;
                        if (isset)
                                sktag = V_ASN1_SET;
-                       else sktag = V_ASN1_SEQUENCE;
+                       else
+                               sktag = V_ASN1_SEQUENCE;
                }
 
                /* Determine total length of items */
@@ -339,14 +343,14 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
                        skitem = sk_ASN1_VALUE_value(sk, i);
                        skcontlen += ASN1_item_ex_i2d(&skitem, NULL,
-                                               ASN1_ITEM_ptr(tt->item),
-                                                       -1, iclass);
+                           ASN1_ITEM_ptr(tt->item), -1, iclass);
                }
                sklen = ASN1_object_size(ndef, skcontlen, sktag);
                /* If EXPLICIT need length of surrounding tag */
                if (flags & ASN1_TFLG_EXPTAG)
                        ret = ASN1_object_size(ndef, sklen, ttag);
-               else ret = sklen;
+               else
+                       ret = sklen;
 
                if (!out)
                        return ret;
@@ -359,7 +363,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                ASN1_put_object(out, ndef, skcontlen, sktag, skaclass);
                /* And the stuff itself */
                asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),
-                                                               isset, iclass);
+                   isset, iclass);
                if (ndef == 2) {
                        ASN1_put_eoc(out);
                        if (flags & ASN1_TFLG_EXPTAG)
@@ -373,7 +377,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                /* EXPLICIT tagging */
                /* Find length of tagged item */
                i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item),
-                                                               -1, iclass);
+                   -1, iclass);
                if (!i)
                        return 0;
                /* Find length of EXPLICIT tag */
@@ -382,7 +386,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
                        /* Output tag and item */
                        ASN1_put_object(out, ndef, i, ttag, tclass);
                        ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
-                                                               -1, iclass);
+                           -1, iclass);
                        if (ndef == 2)
                                ASN1_put_eoc(out);
                }
@@ -391,8 +395,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
 
        /* Either normal or IMPLICIT tagging: combine class and flags */
        return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
-                                               ttag, tclass | iclass);
-
+           ttag, tclass | iclass);
 }
 
 /* Temporary structure used to hold DER encoding of items for SET OF */
@@ -403,10 +406,12 @@ typedef   struct {
        ASN1_VALUE *field;
 } DER_ENC;
 
-static int der_cmp(const void *a, const void *b)
+static int
+der_cmp(const void *a, const void *b)
 {
        const DER_ENC *d1 = a, *d2 = b;
        int cmplen, i;
+
        cmplen = (d1->length < d2->length) ? d1->length : d2->length;
        i = memcmp(d1->data, d2->data, cmplen);
        if (i)
@@ -416,22 +421,22 @@ static int der_cmp(const void *a, const void *b)
 
 /* Output the content octets of SET OF or SEQUENCE OF */
 
-static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
-                                       int skcontlen, const ASN1_ITEM *item,
-                                       int do_sort, int iclass)
+static int
+asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen,
+    const ASN1_ITEM *item, int do_sort, int iclass)
 {
        int i;
        ASN1_VALUE *skitem;
        unsigned char *tmpdat = NULL, *p = NULL;
        DER_ENC *derlst = NULL, *tder;
-       if (do_sort)
-                {
+
+       if (do_sort) {
                /* Don't need to sort less than 2 items */
                if (sk_ASN1_VALUE_num(sk) < 2)
                        do_sort = 0;
                else {
-                       derlst = malloc(sk_ASN1_VALUE_num(sk)
-                                               * sizeof(*derlst));
+                       derlst = malloc(sk_ASN1_VALUE_num(sk) *
+                           sizeof(*derlst));
                        tmpdat = malloc(skcontlen);
                        if (!derlst || !tmpdat) {
                                free(derlst);
@@ -460,7 +465,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
 
        /* Now sort them */
        qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
-       /* Output sorted DER encoding */        
+       /* Output sorted DER encoding */
        p = *out;
        for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
                memcpy(p, tder->data, tder->length);
@@ -477,8 +482,9 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
        return 1;
 }
 
-static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
-                               const ASN1_ITEM *it, int tag, int aclass)
+static int
+asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
+    const ASN1_ITEM *it, int tag, int aclass)
 {
        int len;
        int utype;
@@ -500,12 +506,12 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
         * utype.
         */
        if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
-          (utype == V_ASN1_OTHER))
+           (utype == V_ASN1_OTHER))
                usetag = 0;
-       else usetag = 1;
+       else
+               usetag = 1;
 
        /* -1 means omit type */
-
        if (len == -1)
                return 0;
 
@@ -516,7 +522,8 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
        }
 
        /* If not implicitly tagged get tag from underlying type */
-       if (tag == -1) tag = utype;
+       if (tag == -1)
+               tag = utype;
 
        /* Output tag+length followed by content octets */
        if (out) {
@@ -536,8 +543,9 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
 
 /* Produce content octets from a structure */
 
-int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
-                               const ASN1_ITEM *it)
+int
+asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
+    const ASN1_ITEM *it)
 {
        ASN1_BOOLEAN *tbool = NULL;
        ASN1_STRING *strtmp;
@@ -547,13 +555,16 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
        unsigned char c;
        int len;
        const ASN1_PRIMITIVE_FUNCS *pf;
+
        pf = it->funcs;
        if (pf && pf->prim_i2c)
                return pf->prim_i2c(pval, cout, putype, it);
 
        /* Should type be omitted? */
-       if ((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
-               if (!*pval) return -1;
+       if ((it->itype != ASN1_ITYPE_PRIMITIVE) ||
+           (it->utype != V_ASN1_BOOLEAN)) {
+               if (!*pval)
+                       return -1;
        }
 
        if (it->itype == ASN1_ITYPE_MSTRING) {
@@ -568,10 +579,10 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
                utype = typ->type;
                *putype = utype;
                pval = &typ->value.asn1_value;
-       }
-       else utype = *putype;
+       } else
+               utype = *putype;
 
-       switch(utype) {
+       switch (utype) {
        case V_ASN1_OBJECT:
                otmp = (ASN1_OBJECT *)*pval;
                cont = otmp->data;
@@ -601,7 +612,7 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
 
        case V_ASN1_BIT_STRING:
                return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval,
-                                                       cout ? &cout : NULL);
+                   cout ? &cout : NULL);
                break;
 
        case V_ASN1_INTEGER:
@@ -612,7 +623,7 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
                 * as ASN1_INTEGER
                 */
                return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval,
-                                                       cout ? &cout : NULL);
+                   cout ? &cout : NULL);
                break;
 
        case V_ASN1_OCTET_STRING:
@@ -635,8 +646,8 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
                /* All based on ASN1_STRING and handled the same */
                strtmp = (ASN1_STRING *)*pval;
                /* Special handling for NDEF */
-               if ((it->size == ASN1_TFLG_NDEF)
-                       && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) {
+               if ((it->size == ASN1_TFLG_NDEF) &&
+                   (strtmp->flags & ASN1_STRING_FLAG_NDEF)) {
                        if (cout) {
                                strtmp->data = cout;
                                strtmp->length = 0;
index 5211276..9e6e757 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
 #include <openssl/asn1t.h>
 #include <openssl/objects.h>
 
-static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
+static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
+    int combine);
 
 /* Free up an ASN1 structure */
 
-void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
+void
+ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
 {
        asn1_item_combine_free(&val, it, 0);
 }
 
-void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
+void
+ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        asn1_item_combine_free(pval, it, 0);
 }
 
-static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
+static 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;
@@ -84,6 +88,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
        const ASN1_AUX *aux = it->funcs;
        ASN1_aux_cb *asn1_cb;
        int i;
+
        if (!pval)
                return;
        if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
@@ -93,8 +98,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
        else
                asn1_cb = 0;
 
-       switch(it->itype) {
-
+       switch (it->itype) {
        case ASN1_ITYPE_PRIMITIVE:
                if (it->templates)
                        ASN1_template_free(pval, it->templates);
@@ -147,10 +151,10 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
                        i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
                        if (i == 2)
                                return;
-               }               
+               }
                asn1_enc_free(pval, it);
                /* If we free up as normal we will invalidate any
-                * ANY DEFINED BY field and we wont be able to 
+                * ANY DEFINED BY field and we wont be able to
                 * determine the type of the field it defines. So
                 * free up in reverse order.
                 */
@@ -173,7 +177,8 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
        }
 }
 
-void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
+void
+ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
 {
        int i;
        if (tt->flags & ASN1_TFLG_SK_MASK) {
@@ -182,17 +187,17 @@ void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
                        ASN1_VALUE *vtmp;
                        vtmp = sk_ASN1_VALUE_value(sk, i);
                        asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item),
-                                                                       0);
+                           0);
                }
                sk_ASN1_VALUE_free(sk);
                *pval = NULL;
-       }
-       else
+       } else
                asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
-                                               tt->flags & ASN1_TFLG_COMBINE);
+                   tt->flags & ASN1_TFLG_COMBINE);
 }
 
-void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
+void
+ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        int utype;
        if (it) {
@@ -220,7 +225,7 @@ void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
                        return;
        }
 
-       switch(utype) {
+       switch (utype) {
        case V_ASN1_OBJECT:
                ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
                break;
index 00aa31d..dc9ddc4 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
 #include <string.h>
 
 static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
-                                                               int combine);
+    int combine);
 static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
 static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
 static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
 
-ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
+ASN1_VALUE *
+ASN1_item_new(const ASN1_ITEM *it)
 {
        ASN1_VALUE *ret = NULL;
        if (ASN1_item_ex_new(&ret, it) > 0)
@@ -80,13 +81,14 @@ ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
 
 /* Allocate an ASN1 structure */
 
-int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
+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)
+static int
+asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
 {
        const ASN1_TEMPLATE *tt = NULL;
        const ASN1_COMPAT_FUNCS *cf;
@@ -95,20 +97,21 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
        ASN1_aux_cb *asn1_cb;
        ASN1_VALUE **pseqval;
        int i;
+
        if (aux && aux->asn1_cb)
                asn1_cb = aux->asn1_cb;
        else
                asn1_cb = 0;
 
-       if (!combine) *pval = NULL;
+       if (!combine)
+               *pval = NULL;
 
 #ifdef CRYPTO_MDEBUG
        if (it->sname)
                CRYPTO_push_info(it->sname);
 #endif
 
-       switch(it->itype) {
-
+       switch (it->itype) {
        case ASN1_ITYPE_EXTERN:
                ef = it->funcs;
                if (ef && ef->asn1_ex_new) {
@@ -130,14 +133,13 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                if (it->templates) {
                        if (!ASN1_template_new(pval, it->templates))
                                goto memerr;
-               }
-               else if (!ASN1_primitive_new(pval, it))
-                               goto memerr;
+               } else if (!ASN1_primitive_new(pval, it))
+                       goto memerr;
                break;
 
        case ASN1_ITYPE_MSTRING:
                if (!ASN1_primitive_new(pval, it))
-                               goto memerr;
+                       goto memerr;
                break;
 
        case ASN1_ITYPE_CHOICE:
@@ -145,7 +147,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                        i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
                        if (!i)
                                goto auxerr;
-                       if (i==2) {
+                       if (i == 2) {
 #ifdef CRYPTO_MDEBUG
                                if (it->sname)
                                        CRYPTO_pop_info();
@@ -161,7 +163,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                }
                asn1_set_choice_selector(pval, -1, it);
                if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
                break;
 
        case ASN1_ITYPE_NDEF_SEQUENCE:
@@ -170,7 +172,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                        i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
                        if (!i)
                                goto auxerr;
-                       if (i==2) {
+                       if (i == 2) {
 #ifdef CRYPTO_MDEBUG
                                if (it->sname)
                                        CRYPTO_pop_info();
@@ -192,47 +194,50 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
                                goto memerr;
                }
                if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
-                               goto auxerr;
+                       goto auxerr;
                break;
-}
+       }
 #ifdef CRYPTO_MDEBUG
-       if (it->sname) CRYPTO_pop_info();
+       if (it->sname)
+               CRYPTO_pop_info();
 #endif
        return 1;
 
-       memerr:
+memerr:
        ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE);
 #ifdef CRYPTO_MDEBUG
-       if (it->sname) CRYPTO_pop_info();
+       if (it->sname)
+               CRYPTO_pop_info();
 #endif
        return 0;
 
-       auxerr:
+auxerr:
        ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ASN1_R_AUX_ERROR);
        ASN1_item_ex_free(pval, it);
 #ifdef CRYPTO_MDEBUG
-       if (it->sname) CRYPTO_pop_info();
+       if (it->sname)
+               CRYPTO_pop_info();
 #endif
        return 0;
 
 }
 
-static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
+static void
+asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        const ASN1_EXTERN_FUNCS *ef;
 
-       switch(it->itype) {
-
+       switch (it->itype) {
        case ASN1_ITYPE_EXTERN:
                ef = it->funcs;
-               if (ef && ef->asn1_ex_clear) 
+               if (ef && ef->asn1_ex_clear)
                        ef->asn1_ex_clear(pval, it);
-               else *pval = NULL;
+               else
+                       *pval = NULL;
                break;
 
-
        case ASN1_ITYPE_PRIMITIVE:
-               if (it->templates) 
+               if (it->templates)
                        asn1_template_clear(pval, it->templates);
                else
                        asn1_primitive_clear(pval, it);
@@ -251,11 +256,12 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
        }
 }
 
-
-int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
+int
+ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
 {
        const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
        int ret;
+
        if (tt->flags & ASN1_TFLG_OPTIONAL) {
                asn1_template_clear(pval, tt);
                return 1;
@@ -285,7 +291,7 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
        }
        /* Otherwise pass it back to the item routine */
        ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
-       done:
+done:
 #ifdef CRYPTO_MDEBUG
        if (it->sname)
                CRYPTO_pop_info();
@@ -293,10 +299,11 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
        return ret;
 }
 
-static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
+static void
+asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
 {
        /* If ADB or STACK just NULL the field */
-       if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) 
+       if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
                *pval = NULL;
        else
                asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
@@ -307,7 +314,8 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
  * all the old functions.
  */
 
-int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
+int
+ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        ASN1_TYPE *typ;
        ASN1_STRING *str;
@@ -323,7 +331,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
                utype = -1;
        else
                utype = it->utype;
-       switch(utype) {
+       switch (utype) {
        case V_ASN1_OBJECT:
                *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
                return 1;
@@ -357,14 +365,15 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
        return 0;
 }
 
-static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
+static void
+asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        int utype;
        if (it && it->funcs) {
                const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
                if (pf->prim_clear)
                        pf->prim_clear(pval, it);
-               else 
+               else
                        *pval = NULL;
                return;
        }
@@ -374,5 +383,6 @@ static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
                utype = it->utype;
        if (utype == V_ASN1_BOOLEAN)
                *(ASN1_BOOLEAN *)pval = it->size;
-       else *pval = NULL;
+       else
+               *pval = NULL;
 }
index 345daeb..1362499 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -56,7 +56,6 @@
  *
  */
 
-
 #include <stddef.h>
 #include "cryptlib.h"
 #include <openssl/asn1.h>
 
 /* ASN1_PCTX routines */
 
-ASN1_PCTX default_pctx = 
-{
+ASN1_PCTX default_pctx = {
        ASN1_PCTX_FLAGS_SHOW_ABSENT,    /* flags */
-       0,      /* nm_flags */
-       0,      /* cert_flags */
-       0,      /* oid_flags */
-       0       /* str_flags */
+       0,                              /* nm_flags */
+       0,                              /* cert_flags */
+       0,                              /* oid_flags */
+       0                               /* str_flags */
 };
-       
 
-ASN1_PCTX *ASN1_PCTX_new(void)
+
+ASN1_PCTX *
+ASN1_PCTX_new(void)
 {
        ASN1_PCTX *ret;
        ret = malloc(sizeof(ASN1_PCTX));
@@ -98,57 +97,68 @@ ASN1_PCTX *ASN1_PCTX_new(void)
        return ret;
 }
 
-void ASN1_PCTX_free(ASN1_PCTX *p)
+void
+ASN1_PCTX_free(ASN1_PCTX *p)
 {
        free(p);
 }
 
-unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p)
+unsigned long
+ASN1_PCTX_get_flags(ASN1_PCTX *p)
 {
        return p->flags;
 }
 
-void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags)
+void
+ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags)
 {
        p->flags = flags;
 }
 
-unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p)
+unsigned long
+ASN1_PCTX_get_nm_flags(ASN1_PCTX *p)
 {
        return p->nm_flags;
 }
 
-void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags)
+void
+ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags)
 {
        p->nm_flags = flags;
 }
 
-unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p)
+unsigned long
+ASN1_PCTX_get_cert_flags(ASN1_PCTX *p)
 {
        return p->cert_flags;
 }
 
-void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags)
+void
+ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags)
 {
        p->cert_flags = flags;
 }
 
-unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p)
+unsigned long
+ASN1_PCTX_get_oid_flags(ASN1_PCTX *p)
 {
        return p->oid_flags;
 }
 
-void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags)
+void
+ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags)
 {
        p->oid_flags = flags;
 }
 
-unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p)
+unsigned long
+ASN1_PCTX_get_str_flags(ASN1_PCTX *p)
 {
        return p->str_flags;
 }
 
-void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
+void
+ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
 {
        p->str_flags = flags;
 }
@@ -156,40 +166,38 @@ void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags)
 /* Main print routines */
 
 static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
-                               const ASN1_ITEM *it,
-                               const char *fname, const char *sname,
-                               int nohdr, const ASN1_PCTX *pctx);
+    const ASN1_ITEM *it, const char *fname, const char *sname, int nohdr,
+    const ASN1_PCTX *pctx);
 
 int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
-                               const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx);
+    const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx);
 
 static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
-                               const ASN1_ITEM *it, int indent,
-                               const char *fname, const char *sname,
-                               const ASN1_PCTX *pctx);
+    const ASN1_ITEM *it, int indent, const char *fname, const char *sname,
+    const ASN1_PCTX *pctx);
 
-static int asn1_print_fsname(BIO *out, int indent,
-                       const char *fname, const char *sname,
-                       const ASN1_PCTX *pctx);
+static int asn1_print_fsname(BIO *out, int indent, const char *fname,
+    const char *sname, const ASN1_PCTX *pctx);
 
-int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent,
-                               const ASN1_ITEM *it, const ASN1_PCTX *pctx)
+int
+ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, const ASN1_ITEM *it,
+    const ASN1_PCTX *pctx)
 {
        const char *sname;
+
        if (pctx == NULL)
                pctx = &default_pctx;
        if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME)
                sname = NULL;
        else
                sname = it->sname;
-       return asn1_item_print_ctx(out, &ifld, indent, it,
-                                                       NULL, sname, 0, pctx);
+       return asn1_item_print_ctx(out, &ifld, indent, it, NULL, sname,
+           0, pctx);
 }
 
-static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
-                               const ASN1_ITEM *it,
-                               const char *fname, const char *sname,
-                               int nohdr, const ASN1_PCTX *pctx)
+static int
+asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, const ASN1_ITEM *it,
+    const char *fname, const char *sname, int nohdr, const ASN1_PCTX *pctx)
 {
        const ASN1_TEMPLATE *tt;
        const ASN1_EXTERN_FUNCS *ef;
@@ -198,18 +206,19 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
        ASN1_aux_cb *asn1_cb;
        ASN1_PRINT_ARG parg;
        int i;
+
        if (aux && aux->asn1_cb) {
                parg.out = out;
                parg.indent = indent;
                parg.pctx = pctx;
                asn1_cb = aux->asn1_cb;
-       }
-       else asn1_cb = 0;
+       } else
+               asn1_cb = 0;
 
-       if(*fld == NULL) {
+       if (*fld == NULL) {
                if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) {
-                       if (!nohdr && !asn1_print_fsname(out, indent,
-                                                       fname, sname, pctx))
+                       if (!nohdr &&
+                           !asn1_print_fsname(out, indent, fname, sname, pctx))
                                return 0;
                        if (BIO_puts(out, "<ABSENT>\n") <= 0)
                                return 0;
@@ -217,22 +226,23 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                return 1;
        }
 
-       switch(it->itype) {
+       switch (it->itype) {
        case ASN1_ITYPE_PRIMITIVE:
-               if(it->templates) {
+               if (it->templates) {
                        if (!asn1_template_print_ctx(out, fld, indent,
-                                                       it->templates, pctx))
+                           it->templates, pctx))
                                return 0;
                }
                /* fall thru */
        case ASN1_ITYPE_MSTRING:
                if (!asn1_primitive_print(out, fld, it,
-                               indent, fname, sname,pctx))
+                   indent, fname, sname, pctx))
                        return 0;
                break;
 
        case ASN1_ITYPE_EXTERN:
-               if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
+               if (!nohdr &&
+                   !asn1_print_fsname(out, indent, fname, sname, pctx))
                        return 0;
                /* Use new style print routine if possible */
                ef = it->funcs;
@@ -243,23 +253,23 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                        if ((i == 2) && (BIO_puts(out, "\n") <= 0))
                                return 0;
                        return 1;
-               }
-               else if (sname && 
-                       BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0)
+               } else if (sname &&
+                   BIO_printf(out, ":EXTERNAL TYPE %s\n", sname) <= 0)
                        return 0;
                break;
 
        case ASN1_ITYPE_CHOICE:
 #if 0
-               if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
+               if (!nohdr &&
+                   !asn1_print_fsname(out, indent, fname, sname, pctx))
                        return 0;
 #endif
                /* CHOICE type, get selector */
                i = asn1_get_choice_selector(fld, it);
                /* This should never happen... */
-               if((i < 0) || (i >= it->tcount)) {
+               if ((i < 0) || (i >= it->tcount)) {
                        if (BIO_printf(out,
-                               "ERROR: selector [%d] invalid\n", i) <= 0)
+                           "ERROR: selector [%d] invalid\n", i) <= 0)
                                return 0;
                        return 1;
                }
@@ -271,7 +281,8 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
 
        case ASN1_ITYPE_SEQUENCE:
        case ASN1_ITYPE_NDEF_SEQUENCE:
-               if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
+               if (!nohdr &&
+                   !asn1_print_fsname(out, indent, fname, sname, pctx))
                        return 0;
                if (fname || sname) {
                        if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
@@ -292,12 +303,12 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                }
 
                /* Print each field entry */
-               for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
+               for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
                        const ASN1_TEMPLATE *seqtt;
                        seqtt = asn1_do_adb(fld, tt, 1);
                        tmpfld = asn1_get_field_ptr(fld, seqtt);
-                       if (!asn1_template_print_ctx(out, tmpfld,
-                                               indent + 2, seqtt, pctx))
+                       if (!asn1_template_print_ctx(out, tmpfld, indent + 2,
+                           seqtt, pctx))
                                return 0;
                }
                if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
@@ -312,7 +323,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                }
                break;
 
-               default:
+       default:
                BIO_printf(out, "Unprocessed type %d\n", it->itype);
                return 0;
        }
@@ -320,65 +331,65 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
        return 1;
 }
 
-int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
-                               const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx)
+int
+asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
+    const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx)
 {
        int i, flags;
        const char *sname, *fname;
+
        flags = tt->flags;
-       if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME)
+       if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME)
                sname = ASN1_ITEM_ptr(tt->item)->sname;
        else
                sname = NULL;
-       if(pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
+       if (pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
                fname = NULL;
        else
                fname = tt->field_name;
-       if(flags & ASN1_TFLG_SK_MASK) {
+       if (flags & ASN1_TFLG_SK_MASK) {
                char *tname;
                ASN1_VALUE *skitem;
                STACK_OF(ASN1_VALUE) *stack;
 
                /* SET OF, SEQUENCE OF */
                if (fname) {
-                       if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) {
-                               if(flags & ASN1_TFLG_SET_OF)
+                       if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) {
+                               if (flags & ASN1_TFLG_SET_OF)
                                        tname = "SET";
                                else
                                        tname = "SEQUENCE";
                                if (BIO_printf(out, "%*s%s OF %s {\n",
-                                       indent, "", tname, tt->field_name) <= 0)
+                                   indent, "", tname, tt->field_name) <= 0)
                                        return 0;
-                       }
-                       else if (BIO_printf(out, "%*s%s:\n", indent, "",
-                                       fname) <= 0)
+                       } else if (BIO_printf(out, "%*s%s:\n", indent, "",
+                           fname) <= 0)
                                return 0;
                }
                stack = (STACK_OF(ASN1_VALUE) *)*fld;
-               for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) {
+               for (i = 0; i < sk_ASN1_VALUE_num(stack); i++) {
                        if ((i > 0) && (BIO_puts(out, "\n") <= 0))
                                return 0;
-
                        skitem = sk_ASN1_VALUE_value(stack, i);
                        if (!asn1_item_print_ctx(out, &skitem, indent + 2,
-                               ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx))
+                           ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx))
                                return 0;
                }
                if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
-                               return 0;
-               if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
+                       return 0;
+               if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
                        if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
                                return 0;
                }
                return 1;
        }
        return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item),
-                                                       fname, sname, 0, pctx);
+           fname, sname, 0, pctx);
 }
 
-static int asn1_print_fsname(BIO *out, int indent,
-                       const char *fname, const char *sname,
-                       const ASN1_PCTX *pctx)
+static int
+asn1_print_fsname(BIO *out, int indent, const char *fname, const char *sname,
+    const ASN1_PCTX *pctx)
 {
        static char spaces[] = "                    ";
        const int nspaces = sizeof(spaces) - 1;
@@ -419,8 +430,8 @@ static int asn1_print_fsname(BIO *out, int indent,
        return 1;
 }
 
-static int asn1_print_boolean_ctx(BIO *out, int boolval,
-                                                       const ASN1_PCTX *pctx)
+static int
+asn1_print_boolean_ctx(BIO *out, int boolval, const ASN1_PCTX *pctx)
 {
        const char *str;
        switch (boolval) {
@@ -432,7 +443,7 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval,
                str = "FALSE";
                break;
 
-               default:
+       default:
                str = "TRUE";
                break;
 
@@ -444,8 +455,8 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval,
 
 }
 
-static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str,
-                                               const ASN1_PCTX *pctx)
+static int
+asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str, const ASN1_PCTX *pctx)
 {
        char *s;
        int ret = 1;
@@ -456,13 +467,13 @@ static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str,
        return ret;
 }
 
-static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid,
-                                               const ASN1_PCTX *pctx)
+static int
+asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, const ASN1_PCTX *pctx)
 {
        char objbuf[80];
        const char *ln;
        ln = OBJ_nid2ln(OBJ_obj2nid(oid));
-       if(!ln)
+       if (!ln)
                ln = "";
        OBJ_obj2txt(objbuf, sizeof objbuf, oid, 1);
        if (BIO_printf(out, "%s (%s)", ln, objbuf) <= 0)
@@ -470,36 +481,36 @@ static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid,
        return 1;
 }
 
-static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
-                                               const ASN1_PCTX *pctx)
+static int
+asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
+    const ASN1_PCTX *pctx)
 {
        if (str->type == V_ASN1_BIT_STRING) {
                if (BIO_printf(out, " (%ld unused bits)\n",
-                                       str->flags & 0x7) <= 0)
-                               return 0;
-       }
-       else if (BIO_puts(out, "\n") <= 0)
+                   str->flags & 0x7) <= 0)
+                       return 0;
+       } else if (BIO_puts(out, "\n") <= 0)
                return 0;
-       if ((str->length > 0)
-               && BIO_dump_indent(out, (char *)str->data, str->length,
-                               indent + 2) <= 0)
+       if ((str->length > 0) &&
+           BIO_dump_indent(out, (char *)str->data, str->length,
+           indent + 2) <= 0)
                return 0;
        return 1;
 }
 
-static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
-                               const ASN1_ITEM *it, int indent,
-                               const char *fname, const char *sname,
-                               const ASN1_PCTX *pctx)
+static int
+asn1_primitive_print(BIO *out, ASN1_VALUE **fld, const ASN1_ITEM *it,
+    int indent, const char *fname, const char *sname, const ASN1_PCTX *pctx)
 {
        long utype;
        ASN1_STRING *str;
        int ret = 1, needlf = 1;
        const char *pname;
        const ASN1_PRIMITIVE_FUNCS *pf;
+
        pf = it->funcs;
        if (!asn1_print_fsname(out, indent, fname, sname, pctx))
-                       return 0;
+               return 0;
        if (pf && pf->prim_print)
                return pf->prim_print(out, fld, it, indent, pctx);
        str = (ASN1_STRING *)*fld;
@@ -514,12 +525,12 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
                str = (ASN1_STRING *)*fld;
                if (pctx->flags & ASN1_PCTX_FLAGS_NO_ANY_TYPE)
                        pname = NULL;
-               else 
+               else
                        pname = ASN1_tag2str(utype);
        } else {
                if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE)
                        pname = ASN1_tag2str(utype);
-               else 
+               else
                        pname = NULL;
        }
 
@@ -575,14 +586,13 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
                if (BIO_puts(out, "\n") <= 0)
                        return 0;
                if (ASN1_parse_dump(out, str->data, str->length,
-                                               indent, 0) <= 0)
+                   indent, 0) <= 0)
                        ret = 0;
                needlf = 0;
                break;
 
        default:
                ret = ASN1_STRING_print_ex(out, str, pctx->str_flags);
-
        }
        if (!ret)
                return 0;
index 6fb1c37..3399e74 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -136,12 +136,12 @@ IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
 
 IMPLEMENT_ASN1_TYPE_ex(ASN1_OCTET_STRING_NDEF, ASN1_OCTET_STRING, ASN1_TFLG_NDEF)
 
-ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) = 
-       ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY)
+ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) =
+    ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY)
 ASN1_ITEM_TEMPLATE_END(ASN1_SEQUENCE_ANY)
 
-ASN1_ITEM_TEMPLATE(ASN1_SET_ANY) = 
-       ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, ASN1_SET_ANY, ASN1_ANY)
+ASN1_ITEM_TEMPLATE(ASN1_SET_ANY) =
+    ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, ASN1_SET_ANY, ASN1_ANY)
 ASN1_ITEM_TEMPLATE_END(ASN1_SET_ANY)
 
 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
index 9715dac..e1051c2 100644 (file)
@@ -10,7 +10,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -56,7 +56,6 @@
  *
  */
 
-
 #include <stddef.h>
 #include <string.h>
 #include <openssl/asn1.h>
@@ -73,7 +72,8 @@
  * the selector value
  */
 
-int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
+int
+asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        int *sel = offset2ptr(*pval, it->utype);
        return *sel;
@@ -83,8 +83,9 @@ int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
  * the selector value, return old value.
  */
 
-int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
-{      
+int
+asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
+{
        int *sel, ret;
        sel = offset2ptr(*pval, it->utype);
        ret = *sel;
@@ -92,18 +93,20 @@ int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
        return ret;
 }
 
-/* Do reference counting. The value 'op' decides what to do. 
+/* Do reference counting. The value 'op' decides what to do.
  * if it is +1 then the count is incremented. If op is 0 count is
  * set to 1. If op is -1 count is decremented and the return value
  * is the current refrence count or 0 if no reference count exists.
  */
 
-int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
+int
+asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
 {
        const ASN1_AUX *aux;
        int *lck, ret;
-       if ((it->itype != ASN1_ITYPE_SEQUENCE)
-          && (it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
+
+       if ((it->itype != ASN1_ITYPE_SEQUENCE) &&
+           (it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
                return 0;
        aux = it->funcs;
        if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
@@ -117,9 +120,11 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
        return ret;
 }
 
-static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
+static ASN1_ENCODING *
+asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        const ASN1_AUX *aux;
+
        if (!pval || !*pval)
                return NULL;
        aux = it->funcs;
@@ -128,9 +133,11 @@ static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
        return offset2ptr(*pval, aux->enc_offset);
 }
 
-void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
+void
+asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        ASN1_ENCODING *enc;
+
        enc = asn1_get_enc_ptr(pval, it);
        if (enc) {
                enc->enc = NULL;
@@ -139,9 +146,11 @@ void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
        }
 }
 
-void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
+void
+asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
 {
        ASN1_ENCODING *enc;
+
        enc = asn1_get_enc_ptr(pval, it);
        if (enc) {
                if (enc->enc)
@@ -152,10 +161,12 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
        }
 }
 
-int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
-                                                        const ASN1_ITEM *it)
+int
+asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
+    const ASN1_ITEM *it)
 {
        ASN1_ENCODING *enc;
+
        enc = asn1_get_enc_ptr(pval, it);
        if (!enc)
                return 1;
@@ -171,11 +182,13 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
 
        return 1;
 }
-               
-int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
-                                                       const ASN1_ITEM *it)
+
+int
+asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
+    const ASN1_ITEM *it)
 {
        ASN1_ENCODING *enc;
+
        enc = asn1_get_enc_ptr(pval, it);
        if (!enc || enc->modified)
                return 0;
@@ -189,9 +202,11 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
 }
 
 /* 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 **
+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);
@@ -206,14 +221,15 @@ ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
  * the relevant ASN1_TEMPLATE in the table and return it.
  */
 
-const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
-                                                               int nullerr)
+const ASN1_TEMPLATE *
+asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
 {
        const ASN1_ADB *adb;
        const ASN1_ADB_TABLE *atbl;
        long selector;
        ASN1_VALUE **sfld;
        int i;
+
        if (!(tt->flags & ASN1_TFLG_ADB_MASK))
                return tt;
 
@@ -234,9 +250,9 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
         * NB: don't check for NID_undef here because it
         * might be a legitimate value in the table
         */
-       if (tt->flags & ASN1_TFLG_ADB_OID) 
+       if (tt->flags & ASN1_TFLG_ADB_OID)
                selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
-       else 
+       else
                selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
 
        /* Try to find matching entry in table
@@ -255,13 +271,13 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
 
        /* No match, return default type */
        if (!adb->default_tt)
-               goto err;               
+               goto err;
        return adb->default_tt;
-       
-       err:
+
+err:
        /* FIXME: should log the value or OID of unsupported type */
        if (nullerr)
                ASN1err(ASN1_F_ASN1_DO_ADB,
-                       ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
+                   ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
        return NULL;
 }