More KNF.
authorjsing <jsing@openbsd.org>
Sat, 19 Apr 2014 07:20:59 +0000 (07:20 +0000)
committerjsing <jsing@openbsd.org>
Sat, 19 Apr 2014 07:20:59 +0000 (07:20 +0000)
12 files changed:
lib/libcrypto/asn1/asn_mime.c
lib/libcrypto/asn1/asn_moid.c
lib/libcrypto/asn1/asn_pack.c
lib/libcrypto/asn1/bio_asn1.c
lib/libcrypto/asn1/bio_ndef.c
lib/libcrypto/asn1/charmap.h
lib/libssl/src/crypto/asn1/asn_mime.c
lib/libssl/src/crypto/asn1/asn_moid.c
lib/libssl/src/crypto/asn1/asn_pack.c
lib/libssl/src/crypto/asn1/bio_asn1.c
lib/libssl/src/crypto/asn1/bio_ndef.c
lib/libssl/src/crypto/asn1/charmap.h

index 6cde8fd..8905575 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
  */
 
 typedef struct {
-char *param_name;                      /* Param name e.g. "micalg" */
-char *param_value;                     /* Param value e.g. "sha1" */
+       char *param_name;               /* Param name e.g. "micalg" */
+       char *param_value;              /* Param value e.g. "sha1" */
 } MIME_PARAM;
 
 DECLARE_STACK_OF(MIME_PARAM)
 IMPLEMENT_STACK_OF(MIME_PARAM)
 
 typedef struct {
-char *name;                            /* Name of line e.g. "content-type" */
-char *value;                           /* Value of line e.g. "text/plain" */
-STACK_OF(MIME_PARAM) *params;          /* Zero or more parameters */
+       char *name;                     /* Name of line e.g. "content-type" */
+       char *value;                    /* Value of line e.g. "text/plain" */
+       STACK_OF(MIME_PARAM) *params;   /* Zero or more parameters */
 } MIME_HEADER;
 
 DECLARE_STACK_OF(MIME_HEADER)
 IMPLEMENT_STACK_OF(MIME_HEADER)
 
 static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
-                                       const ASN1_ITEM *it);
+    const ASN1_ITEM *it);
 static char * strip_ends(char *name);
 static char * strip_start(char *name);
 static char * strip_end(char *name);
@@ -96,9 +96,9 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value);
 static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value);
 static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio);
 static int mime_hdr_cmp(const MIME_HEADER * const *a,
-                       const MIME_HEADER * const *b);
+    const MIME_HEADER * const *b);
 static int mime_param_cmp(const MIME_PARAM * const *a,
-                       const MIME_PARAM * const *b);
+    const MIME_PARAM * const *b);
 static void mime_param_free(MIME_PARAM *param);
 static int mime_bound_check(char *line, int linelen, char *bound, int blen);
 static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret);
@@ -112,15 +112,17 @@ static void mime_hdr_free(MIME_HEADER *hdr);
 
 /* Output an ASN1 structure in BER format streaming if necessary */
 
-int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
-                               const ASN1_ITEM *it)
+int
+i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
+    const ASN1_ITEM *it)
 {
        /* If streaming create stream BIO and copy all content through it */
        if (flags & SMIME_STREAM) {
                BIO *bio, *tbio;
                bio = BIO_new_NDEF(out, val, it);
                if (!bio) {
-                       ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE);
+                       ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,
+                           ERR_R_MALLOC_FAILURE);
                        return 0;
                }
                SMIME_crlf_copy(in, bio, flags);
@@ -142,14 +144,16 @@ int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
 
 /* Base 64 read and write of ASN1 structure */
 
-static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
-                               const ASN1_ITEM *it)
+static int
+B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
+    const ASN1_ITEM *it)
 {
        BIO *b64;
        int r;
+
        b64 = BIO_new(BIO_f_base64());
-       if(!b64) {
-               ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE);
+       if (!b64) {
+               ASN1err(ASN1_F_B64_WRITE_ASN1, ERR_R_MALLOC_FAILURE);
                return 0;
        }
        /* prepend the b64 BIO so all data is base64 encoded.
@@ -164,29 +168,31 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
 
 /* Streaming ASN1 PEM write */
 
-int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
-                               const char *hdr,
-                               const ASN1_ITEM *it)
+int
+PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
+    const char *hdr, const ASN1_ITEM *it)
 {
        int r;
+
        BIO_printf(out, "-----BEGIN %s-----\n", hdr);
        r = B64_write_ASN1(out, val, in, flags, it);
        BIO_printf(out, "-----END %s-----\n", hdr);
        return r;
 }
 
-static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
+static ASN1_VALUE *
+b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
 {
        BIO *b64;
        ASN1_VALUE *val;
-       if(!(b64 = BIO_new(BIO_f_base64()))) {
-               ASN1err(ASN1_F_B64_READ_ASN1,ERR_R_MALLOC_FAILURE);
+       if (!(b64 = BIO_new(BIO_f_base64()))) {
+               ASN1err(ASN1_F_B64_READ_ASN1, ERR_R_MALLOC_FAILURE);
                return 0;
-}
+       }
        bio = BIO_push(b64, bio);
        val = ASN1_item_d2i_bio(it, bio, NULL);
-       if(!val)
-               ASN1err(ASN1_F_B64_READ_ASN1,ASN1_R_DECODE_ERROR);
+       if (!val)
+               ASN1err(ASN1_F_B64_READ_ASN1, ASN1_R_DECODE_ERROR);
        (void)BIO_flush(bio);
        bio = BIO_pop(bio);
        BIO_free(b64);
@@ -195,10 +201,12 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
 
 /* Generate the MIME "micalg" parameter from RFC3851, RFC4490 */
 
-static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
+static int
+asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
 {
        const EVP_MD *md;
        int i, have_unknown = 0, write_comma, ret = 0, md_nid;
+
        have_unknown = 0;
        write_comma = 0;
        for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) {
@@ -219,33 +227,33 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
                        if (rv != -2)
                                goto err;
                }
-               switch(md_nid) {
-                       case NID_sha1:
+               switch (md_nid) {
+               case NID_sha1:
                        BIO_puts(out, "sha1");
                        break;
 
-                       case NID_md5:
+               case NID_md5:
                        BIO_puts(out, "md5");
                        break;
 
-                       case NID_sha256:
+               case NID_sha256:
                        BIO_puts(out, "sha-256");
                        break;
 
-                       case NID_sha384:
+               case NID_sha384:
                        BIO_puts(out, "sha-384");
                        break;
 
-                       case NID_sha512:
+               case NID_sha512:
                        BIO_puts(out, "sha-512");
                        break;
 
-                       case NID_id_GostR3411_94:
+               case NID_id_GostR3411_94:
                        BIO_puts(out, "gostr3411-94");
-                               goto err;
+                       goto err;
                        break;
 
-                       default:
+               default:
                        if (have_unknown)
                                write_comma = 0;
                        else {
@@ -258,23 +266,23 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
        }
 
        ret = 1;
-       err:
 
+err:
        return ret;
-
 }
 
 /* SMIME sender */
 
-int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
-                               int ctype_nid, int econt_nid,
-                               STACK_OF(X509_ALGOR) *mdalgs,
-                               const ASN1_ITEM *it)
+int
+SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
+    int ctype_nid, int econt_nid, STACK_OF(X509_ALGOR) *mdalgs,
+    const ASN1_ITEM *it)
 {
        char bound[33], c;
        int i;
        const char *mime_prefix, *mime_eol, *cname = "smime.p7m";
-       const char *msg_type=NULL;
+       const char *msg_type = NULL;
+
        if (flags & SMIME_OLDMIME)
                mime_prefix = "application/x-pkcs7-";
        else
@@ -284,16 +292,18 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
                mime_eol = "\r\n";
        else
                mime_eol = "\n";
-       if((flags & SMIME_DETACHED) && data) {
-       /* We want multipart/signed */
+       if ((flags & SMIME_DETACHED) && data) {
+               /* We want multipart/signed */
                /* Generate a random boundary */
                RAND_pseudo_bytes((unsigned char *)bound, 32);
-               for(i = 0; i < 32; i++) {
+               for (i = 0; i < 32; i++) {
                        c = bound[i] & 0xf;
-                       if(c < 10) c += '0';
-                       else c += 'A' - 10;
+                       if (c < 10)
+                               c += '0';
+                       else
+                               c += 'A' - 10;
                        bound[i] = c;
-       }
+               }
                bound[32] = 0;
                BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol);
                BIO_printf(bio, "Content-Type: multipart/signed;");
@@ -301,9 +311,9 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
                BIO_puts(bio, " micalg=\"");
                asn1_write_micalg(bio, mdalgs);
                BIO_printf(bio, "\"; boundary=\"----%s\"%s%s",
-                                               bound, mime_eol, mime_eol);
+                   bound, mime_eol, mime_eol);
                BIO_printf(bio, "This is an S/MIME signed message%s%s",
-                                               mime_eol, mime_eol);
+                   mime_eol, mime_eol);
                /* Now write out the first part */
                BIO_printf(bio, "------%s%s", bound, mime_eol);
                if (!asn1_output_data(bio, data, val, flags, it))
@@ -312,18 +322,18 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
 
                /* Headers for signature */
 
-               BIO_printf(bio, "Content-Type: %ssignature;", mime_prefix); 
+               BIO_printf(bio, "Content-Type: %ssignature;", mime_prefix);
                BIO_printf(bio, " name=\"smime.p7s\"%s", mime_eol);
                BIO_printf(bio, "Content-Transfer-Encoding: base64%s",
-                                                               mime_eol);
+                   mime_eol);
                BIO_printf(bio, "Content-Disposition: attachment;");
                BIO_printf(bio, " filename=\"smime.p7s\"%s%s",
-                                                       mime_eol, mime_eol);
+                   mime_eol, mime_eol);
                B64_write_ASN1(bio, val, NULL, 0, it);
-               BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound,
-                                                       mime_eol, mime_eol);
+               BIO_printf(bio, "%s------%s--%s%s", mime_eol, bound,
+                   mime_eol, mime_eol);
                return 1;
-}
+       }
 
        /* Determine smime-type header */
 
@@ -349,7 +359,7 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
                BIO_printf(bio, " smime-type=%s;", msg_type);
        BIO_printf(bio, " name=\"%s\"%s", cname, mime_eol);
        BIO_printf(bio, "Content-Transfer-Encoding: base64%s%s",
-                                               mime_eol, mime_eol);
+           mime_eol, mime_eol);
        if (!B64_write_ASN1(bio, val, data, flags, it))
                return 0;
        BIO_printf(bio, "%s", mime_eol);
@@ -359,8 +369,9 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
 /* Handle output of ASN1 data */
 
 
-static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
-                                       const ASN1_ITEM *it)
+static int
+asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
+    const ASN1_ITEM *it)
 {
        BIO *tmpbio;
        const ASN1_AUX *aux = it->funcs;
@@ -377,7 +388,7 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
 
        if (!aux || !aux->asn1_cb) {
                ASN1err(ASN1_F_ASN1_OUTPUT_DATA,
-                                       ASN1_R_STREAMING_NOT_SUPPORTED);
+                   ASN1_R_STREAMING_NOT_SUPPORTED);
                return 0;
        }
 
@@ -406,7 +417,6 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
        }
 
        return rv;
-
 }
 
 /* SMIME reader: handle multipart/signed and opaque signing.
@@ -414,7 +424,8 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
  * pointed to by "bcont". In opaque this is set to NULL
  */
 
-ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
+ASN1_VALUE *
+SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
 {
        BIO *asnin;
        STACK_OF(MIME_HEADER) *headers = NULL;
@@ -424,106 +435,114 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
        ASN1_VALUE *val;
        int ret;
 
-       if(bcont) *bcont = NULL;
+       if (bcont)
+               *bcont = NULL;
 
        if (!(headers = mime_parse_hdr(bio))) {
-               ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_PARSE_ERROR);
+               ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_PARSE_ERROR);
                return NULL;
-}
+       }
 
-       if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
+       if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE);
                return NULL;
-}
+       }
 
        /* Handle multipart/signed */
 
-       if(!strcmp(hdr->value, "multipart/signed")) {
+       if (!strcmp(hdr->value, "multipart/signed")) {
                /* Split into two parts */
                prm = mime_param_find(hdr, "boundary");
-               if(!prm || !prm->param_value) {
+               if (!prm || !prm->param_value) {
                        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-                       ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BOUNDARY);
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_NO_MULTIPART_BOUNDARY);
                        return NULL;
-       }
+               }
                ret = multi_split(bio, prm->param_value, &parts);
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-               if(!ret || (sk_BIO_num(parts) != 2) ) {
-                       ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BODY_FAILURE);
+               if (!ret || (sk_BIO_num(parts) != 2) ) {
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_NO_MULTIPART_BODY_FAILURE);
                        sk_BIO_pop_free(parts, BIO_vfree);
                        return NULL;
-       }
+               }
 
                /* Parse the signature piece */
                asnin = sk_BIO_value(parts, 1);
 
                if (!(headers = mime_parse_hdr(asnin))) {
-                       ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_SIG_PARSE_ERROR);
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_MIME_SIG_PARSE_ERROR);
                        sk_BIO_pop_free(parts, BIO_vfree);
                        return NULL;
-       }
+               }
 
                /* Get content type */
 
-               if(!(hdr = mime_hdr_find(headers, "content-type")) ||
-                                                                !hdr->value) {
+               if (!(hdr = mime_hdr_find(headers, "content-type")) ||
+                   !hdr->value) {
                        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-                       ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE);
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_NO_SIG_CONTENT_TYPE);
                        return NULL;
-       }
+               }
 
-               if(strcmp(hdr->value, "application/x-pkcs7-signature") &&
-                       strcmp(hdr->value, "application/pkcs7-signature")) {
-                       ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_SIG_INVALID_MIME_TYPE);
+               if (strcmp(hdr->value, "application/x-pkcs7-signature") &&
+                   strcmp(hdr->value, "application/pkcs7-signature")) {
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_SIG_INVALID_MIME_TYPE);
                        ERR_add_error_data(2, "type: ", hdr->value);
                        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                        sk_BIO_pop_free(parts, BIO_vfree);
                        return NULL;
-       }
+               }
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                /* Read in ASN1 */
-               if(!(val = b64_read_asn1(asnin, it))) {
-                       ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_ASN1_SIG_PARSE_ERROR);
+               if (!(val = b64_read_asn1(asnin, it))) {
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_ASN1_SIG_PARSE_ERROR);
                        sk_BIO_pop_free(parts, BIO_vfree);
                        return NULL;
-       }
+               }
 
-               if(bcont) {
+               if (bcont) {
                        *bcont = sk_BIO_value(parts, 0);
                        BIO_free(asnin);
                        sk_BIO_free(parts);
-       } else sk_BIO_pop_free(parts, BIO_vfree);
-               return val;
-}
-               
+               } else sk_BIO_pop_free(parts, BIO_vfree);
+                       return val;
+       }
+
        /* OK, if not multipart/signed try opaque signature */
 
        if (strcmp (hdr->value, "application/x-pkcs7-mime") &&
            strcmp (hdr->value, "application/pkcs7-mime")) {
-               ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_INVALID_MIME_TYPE);
+               ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_INVALID_MIME_TYPE);
                ERR_add_error_data(2, "type: ", hdr->value);
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                return NULL;
-}
+       }
 
        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-       
-       if(!(val = b64_read_asn1(bio, it))) {
+
+       if (!(val = b64_read_asn1(bio, it))) {
                ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR);
                return NULL;
-}
+       }
        return val;
-
 }
 
 /* Copy text from one BIO to another making the output CRLF at EOL */
-int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
+int
+SMIME_crlf_copy(BIO *in, BIO *out, int flags)
 {
        BIO *bf;
        char eol;
        int len;
        char linebuf[MAX_SMLEN];
+
        /* Buffer output so we don't write one line at a time. This is
         * useful when streaming as we don't end up with one OCTET STRING
         * per line.
@@ -532,17 +551,18 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
        if (!bf)
                return 0;
        out = BIO_push(bf, out);
-       if(flags & SMIME_BINARY) {
-               while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
-                                               BIO_write(out, linebuf, len);
+       if (flags & SMIME_BINARY) {
+               while ((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
+                       BIO_write(out, linebuf, len);
        } else {
-               if(flags & SMIME_TEXT)
+               if (flags & SMIME_TEXT)
                        BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
                while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
                        eol = strip_eol(linebuf, &len);
                        if (len)
                                BIO_write(out, linebuf, len);
-                       if(eol) BIO_write(out, "\r\n", 2);
+                       if (eol)
+                               BIO_write(out, "\r\n", 2);
                }
        }
        (void)BIO_flush(out);
@@ -552,7 +572,8 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
 }
 
 /* Strip off headers if they are text/plain */
-int SMIME_text(BIO *in, BIO *out)
+int
+SMIME_text(BIO *in, BIO *out)
 {
        char iobuf[4096];
        int len;
@@ -560,23 +581,23 @@ int SMIME_text(BIO *in, BIO *out)
        MIME_HEADER *hdr;
 
        if (!(headers = mime_parse_hdr(in))) {
-               ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_PARSE_ERROR);
+               ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_PARSE_ERROR);
                return 0;
-}
-       if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
-               ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_NO_CONTENT_TYPE);
+       }
+       if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
+               ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_NO_CONTENT_TYPE);
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                return 0;
-}
+       }
        if (strcmp (hdr->value, "text/plain")) {
-               ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_INVALID_MIME_TYPE);
+               ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_INVALID_MIME_TYPE);
                ERR_add_error_data(2, "type: ", hdr->value);
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                return 0;
-}
+       }
        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
        while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
-                                               BIO_write(out, iobuf, len);
+               BIO_write(out, iobuf, len);
        if (len < 0)
                return 0;
        return 1;
@@ -586,7 +607,8 @@ int SMIME_text(BIO *in, BIO *out)
  * canonical parts in a STACK of bios
  */
 
-static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
+static int
+multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
 {
        char linebuf[MAX_SMLEN];
        int len, blen;
@@ -603,27 +625,28 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
        *ret = parts;
        while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
                state = mime_bound_check(linebuf, len, bound, blen);
-               if(state == 1) {
+               if (state == 1) {
                        first = 1;
                        part++;
-       } else if(state == 2) {
+               } else if (state == 2) {
                        sk_BIO_push(parts, bpart);
                        return 1;
-       } else if(part) {
+               } else if (part) {
                        /* Strip CR+LF from linebuf */
                        next_eol = strip_eol(linebuf, &len);
-                       if(first) {
+                       if (first) {
                                first = 0;
-                               if(bpart) sk_BIO_push(parts, bpart);
+                               if (bpart)
+                                       sk_BIO_push(parts, bpart);
                                bpart = BIO_new(BIO_s_mem());
                                BIO_set_mem_eof_return(bpart, 0);
-               } else if (eol)
+                       } else if (eol)
                                BIO_write(bpart, "\r\n", 2);
                        eol = next_eol;
                        if (len)
                                BIO_write(bpart, linebuf, len);
+               }
        }
-}
        return 0;
 }
 
@@ -638,7 +661,8 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
 #define MIME_COMMENT   6
 
 
-static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
+static
+STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
 {
        char *p, *q, c;
        char *ntmp;
@@ -649,254 +673,294 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
 
        headers = sk_MIME_HEADER_new(mime_hdr_cmp);
        while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
-       /* If whitespace at line start then continuation line */
-       if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME;
-       else state = MIME_START;
-       ntmp = NULL;
-       /* Go through all characters */
-       for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
-
-       /* State machine to handle MIME headers
-        * if this looks horrible that's because it *is*
-         */
-
-               switch(state) {
+               /* If whitespace at line start then continuation line */
+               if (mhdr && isspace((unsigned char)linebuf[0]))
+                       state = MIME_NAME;
+               else
+                       state = MIME_START;
+               ntmp = NULL;
+
+               /* Go through all characters */
+               for (p = linebuf, q = linebuf;
+                   (c = *p) && (c != '\r') && (c != '\n'); p++) {
+
+                       /* State machine to handle MIME headers
+                        * if this looks horrible that's because it *is*
+                        */
+
+                       switch (state) {
                        case MIME_START:
-                       if(c == ':') {
-                               state = MIME_TYPE;
-                               *p = 0;
-                               ntmp = strip_ends(q);
-                               q = p + 1;
-               }
-                       break;
+                               if (c == ':') {
+                                       state = MIME_TYPE;
+                                       *p = 0;
+                                       ntmp = strip_ends(q);
+                                       q = p + 1;
+                               }
+                               break;
 
                        case MIME_TYPE:
-                       if(c == ';') {
-                               mime_debug("Found End Value\n");
-                               *p = 0;
-                               mhdr = mime_hdr_new(ntmp, strip_ends(q));
-                               sk_MIME_HEADER_push(headers, mhdr);
-                               ntmp = NULL;
-                               q = p + 1;
-                               state = MIME_NAME;
-               } else if(c == '(') {
-                               save_state = state;
-                               state = MIME_COMMENT;
-               }
-                       break;
+                               if (c == ';') {
+                                       mime_debug("Found End Value\n");
+                                       *p = 0;
+                                       mhdr = mime_hdr_new(ntmp,
+                                           strip_ends(q));
+                                       sk_MIME_HEADER_push(headers, mhdr);
+                                       ntmp = NULL;
+                                       q = p + 1;
+                                       state = MIME_NAME;
+                               } else if (c == '(') {
+                                       save_state = state;
+                                       state = MIME_COMMENT;
+                               }
+                               break;
 
                        case MIME_COMMENT:
-                       if(c == ')') {
-                               state = save_state;
-               }
-                       break;
+                               if (c == ')') {
+                                       state = save_state;
+                               }
+                               break;
 
                        case MIME_NAME:
-                       if(c == '=') {
-                               state = MIME_VALUE;
-                               *p = 0;
-                               ntmp = strip_ends(q);
-                               q = p + 1;
-               }
-                       break ;
+                               if (c == '=') {
+                                       state = MIME_VALUE;
+                                       *p = 0;
+                                       ntmp = strip_ends(q);
+                                       q = p + 1;
+                               }
+                               break;
 
                        case MIME_VALUE:
-                       if(c == ';') {
-                               state = MIME_NAME;
-                               *p = 0;
-                               mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
-                               ntmp = NULL;
-                               q = p + 1;
-               } else if (c == '"') {
-                               mime_debug("Found Quote\n");
-                               state = MIME_QUOTE;
-               } else if(c == '(') {
-                               save_state = state;
-                               state = MIME_COMMENT;
-               }
-                       break;
+                               if (c == ';') {
+                                       state = MIME_NAME;
+                                       *p = 0;
+                                       mime_hdr_addparam(mhdr, ntmp,
+                                           strip_ends(q));
+                                       ntmp = NULL;
+                                       q = p + 1;
+                               } else if (c == '"') {
+                                       mime_debug("Found Quote\n");
+                                       state = MIME_QUOTE;
+                               } else if (c == '(') {
+                                       save_state = state;
+                                       state = MIME_COMMENT;
+                               }
+                               break;
 
                        case MIME_QUOTE:
-                       if(c == '"') {
-                               mime_debug("Found Match Quote\n");
-                               state = MIME_VALUE;
+                               if (c == '"') {
+                                       mime_debug("Found Match Quote\n");
+                                       state = MIME_VALUE;
+                               }
+                               break;
+                       }
                }
-                       break;
-       }
-}
 
-       if(state == MIME_TYPE) {
-               mhdr = mime_hdr_new(ntmp, strip_ends(q));
-               sk_MIME_HEADER_push(headers, mhdr);
-} else if(state == MIME_VALUE)
-                        mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
-       if(p == linebuf) break; /* Blank line means end of headers */
-}
+               if (state == MIME_TYPE) {
+                       mhdr = mime_hdr_new(ntmp, strip_ends(q));
+                       sk_MIME_HEADER_push(headers, mhdr);
+               } else if (state == MIME_VALUE)
+                       mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
 
-return headers;
+               if (p == linebuf)
+                       break;  /* Blank line means end of headers */
+       }
 
+       return headers;
 }
 
-static char *strip_ends(char *name)
+static char *
+strip_ends(char *name)
 {
        return strip_end(strip_start(name));
 }
 
 /* Strip a parameter of whitespace from start of param */
-static char *strip_start(char *name)
+static char *
+strip_start(char *name)
 {
        char *p, c;
+
        /* Look for first non white space or quote */
-       for(p = name; (c = *p) ;p++) {
-               if(c == '"') {
+       for (p = name; (c = *p); p++) {
+               if (c == '"') {
                        /* Next char is start of string if non null */
-                       if(p[1]) return p + 1;
+                       if (p[1])
+                               return p + 1;
                        /* Else null string */
                        return NULL;
+               }
+               if (!isspace((unsigned char)c))
+                       return p;
        }
-               if(!isspace((unsigned char)c)) return p;
-}
        return NULL;
 }
 
 /* As above but strip from end of string : maybe should handle brackets? */
-static char *strip_end(char *name)
+static char *
+strip_end(char *name)
 {
        char *p, c;
-       if(!name) return NULL;
+
+       if (!name)
+               return NULL;
+
        /* Look for first non white space or quote */
-       for(p = name + strlen(name) - 1; p >= name ;p--) {
+       for (p = name + strlen(name) - 1; p >= name; p--) {
                c = *p;
-               if(c == '"') {
-                       if(p - 1 == name) return NULL;
+               if (c == '"') {
+                       if (p - 1 == name)
+                               return NULL;
                        *p = 0;
                        return name;
+               }
+               if (isspace((unsigned char)c))
+                       *p = 0;
+               else
+                       return name;
        }
-               if(isspace((unsigned char)c)) *p = 0;   
-               else return name;
-}
        return NULL;
 }
 
-static MIME_HEADER *mime_hdr_new(char *name, char *value)
+static MIME_HEADER *
+mime_hdr_new(char *name, char *value)
 {
        MIME_HEADER *mhdr;
        char *tmpname, *tmpval, *p;
        int c;
-       if(name) {
-               if(!(tmpname = BUF_strdup(name))) return NULL;
-               for(p = tmpname ; *p; p++) {
+       if (name) {
+               if (!(tmpname = BUF_strdup(name)))
+                       return NULL;
+               for (p = tmpname; *p; p++) {
                        c = (unsigned char)*p;
-                       if(isupper(c)) {
+                       if (isupper(c)) {
                                c = tolower(c);
                                *p = c;
+                       }
                }
-       }
-} else tmpname = NULL;
-       if(value) {
-               if(!(tmpval = BUF_strdup(value))) return NULL;
-               for(p = tmpval ; *p; p++) {
+       } else
+               tmpname = NULL;
+       if (value) {
+               if (!(tmpval = BUF_strdup(value)))
+                       return NULL;
+               for (p = tmpval; *p; p++) {
                        c = (unsigned char)*p;
-                       if(isupper(c)) {
+                       if (isupper(c)) {
                                c = tolower(c);
                                *p = c;
+                       }
                }
-       }
-} else tmpval = NULL;
-       mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER));
+       } else tmpval = NULL;
+               mhdr = (MIME_HEADER *)malloc(sizeof(MIME_HEADER));
        if (!mhdr) {
                OPENSSL_free(tmpname);
                return NULL;
-}
+       }
        mhdr->name = tmpname;
        mhdr->value = tmpval;
        if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) {
                free(mhdr);
                return NULL;
-}
+       }
        return mhdr;
 }
-               
-static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
+
+static int
+mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
 {
        char *tmpname, *tmpval, *p;
        int c;
        MIME_PARAM *mparam;
-       if(name) {
+
+       if (name) {
                tmpname = BUF_strdup(name);
-               if(!tmpname) return 0;
-               for(p = tmpname ; *p; p++) {
+               if (!tmpname)
+                       return 0;
+               for (p = tmpname; *p; p++) {
                        c = (unsigned char)*p;
-                       if(isupper(c)) {
+                       if (isupper(c)) {
                                c = tolower(c);
                                *p = c;
+                       }
                }
-       }
-} else tmpname = NULL;
-       if(value) {
+       } else
+               tmpname = NULL;
+       if (value) {
                tmpval = BUF_strdup(value);
-               if(!tmpval) return 0;
-} else tmpval = NULL;
+               if (!tmpval)
+                       return 0;
+       } else
+               tmpval = NULL;
        /* Parameter values are case sensitive so leave as is */
        mparam = (MIME_PARAM *) malloc(sizeof(MIME_PARAM));
-       if(!mparam) return 0;
+       if (!mparam)
+               return 0;
        mparam->param_name = tmpname;
        mparam->param_value = tmpval;
        sk_MIME_PARAM_push(mhdr->params, mparam);
        return 1;
 }
 
-static int mime_hdr_cmp(const MIME_HEADER * const *a,
-                       const MIME_HEADER * const *b)
+static int
+mime_hdr_cmp(const MIME_HEADER * const *a, const MIME_HEADER * const *b)
 {
        if (!(*a)->name || !(*b)->name)
                return !!(*a)->name - !!(*b)->name;
-
-       return(strcmp((*a)->name, (*b)->name));
+       return (strcmp((*a)->name, (*b)->name));
 }
 
-static int mime_param_cmp(const MIME_PARAM * const *a,
-                       const MIME_PARAM * const *b)
+static int
+mime_param_cmp(const MIME_PARAM * const *a, const MIME_PARAM * const *b)
 {
        if (!(*a)->param_name || !(*b)->param_name)
                return !!(*a)->param_name - !!(*b)->param_name;
-       return(strcmp((*a)->param_name, (*b)->param_name));
+       return (strcmp((*a)->param_name, (*b)->param_name));
 }
 
 /* Find a header with a given name (if possible) */
 
-static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name)
+static MIME_HEADER *
+mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name)
 {
        MIME_HEADER htmp;
        int idx;
        htmp.name = name;
        idx = sk_MIME_HEADER_find(hdrs, &htmp);
-       if(idx < 0) return NULL;
+       if (idx < 0)
+               return NULL;
        return sk_MIME_HEADER_value(hdrs, idx);
 }
 
-static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
+static MIME_PARAM *
+mime_param_find(MIME_HEADER *hdr, char *name)
 {
        MIME_PARAM param;
        int idx;
        param.param_name = name;
        idx = sk_MIME_PARAM_find(hdr->params, &param);
-       if(idx < 0) return NULL;
+       if (idx < 0)
+               return NULL;
        return sk_MIME_PARAM_value(hdr->params, idx);
 }
 
-static void mime_hdr_free(MIME_HEADER *hdr)
+static void
+mime_hdr_free(MIME_HEADER *hdr)
 {
-       if(hdr->name) free(hdr->name);
-       if(hdr->value) free(hdr->value);
-       if(hdr->params) sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
+       if (hdr->name)
+               free(hdr->name);
+       if (hdr->value)
+               free(hdr->value);
+       if (hdr->params)
+               sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
        free(hdr);
 }
 
-static void mime_param_free(MIME_PARAM *param)
+static void
+mime_param_free(MIME_PARAM *param)
 {
-       if(param->param_name) free(param->param_name);
-       if(param->param_value) free(param->param_value);
+       if (param->param_name)
+               free(param->param_name);
+       if (param->param_value)
+               free(param->param_value);
        free(param);
 }
 
@@ -905,21 +969,28 @@ static void mime_param_free(MIME_PARAM *param)
  * 1 : part boundary
  * 2 : final boundary
  */
-static int mime_bound_check(char *line, int linelen, char *bound, int blen)
+static int
+mime_bound_check(char *line, int linelen, char *bound, int blen)
 {
-       if(linelen == -1) linelen = strlen(line);
-       if(blen == -1) blen = strlen(bound);
+       if (linelen == -1)
+               linelen = strlen(line);
+       if (blen == -1)
+               blen = strlen(bound);
        /* Quickly eliminate if line length too short */
-       if(blen + 2 > linelen) return 0;
+       if (blen + 2 > linelen)
+               return 0;
        /* Check for part boundary */
-       if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) {
-               if(!strncmp(line + blen + 2, "--", 2)) return 2;
-               else return 1;
-}
+       if (!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) {
+               if (!strncmp(line + blen + 2, "--", 2))
+                       return 2;
+               else
+                       return 1;
+       }
        return 0;
 }
 
-static int strip_eol(char *linebuf, int *plen)
+static int
+strip_eol(char *linebuf, int *plen)
 {
        int len = *plen;
        char *p, c;
index 0c09a8e..7ddf212 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
 
 static int do_create(char *value, char *name);
 
-static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
+static int
+oid_module_init(CONF_IMODULE *md, const CONF *cnf)
 {
        int i;
        const char *oid_section;
        STACK_OF(CONF_VALUE) *sktmp;
        CONF_VALUE *oval;
+
        oid_section = CONF_imodule_get_value(md);
-       if(!(sktmp = NCONF_get_section(cnf, oid_section))) {
+       if (!(sktmp = NCONF_get_section(cnf, oid_section))) {
                ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
                return 0;
        }
-       for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
+       for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
                oval = sk_CONF_VALUE_value(sktmp, i);
-               if(!do_create(oval->value, oval->name)) {
+               if (!do_create(oval->value, oval->name)) {
                        ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT);
                        return 0;
                }
@@ -89,12 +91,14 @@ static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
        return 1;
 }
 
-static void oid_module_finish(CONF_IMODULE *md)
+static void
+oid_module_finish(CONF_IMODULE *md)
 {
        OBJ_cleanup();
 }
 
-void ASN1_add_oid_module(void)
+void
+ASN1_add_oid_module(void)
 {
        CONF_module_add("oid_section", oid_module_init, oid_module_finish);
 }
@@ -104,12 +108,13 @@ void ASN1_add_oid_module(void)
  * shortname = some long name, 1.2.3.4
  */
 
-
-static int do_create(char *value, char *name)
+static int
+do_create(char *value, char *name)
 {
        int nid;
        ASN1_OBJECT *oid;
        char *ln, *ostr, *p, *lntmp;
+
        p = strrchr(value, ',');
        if (!p) {
                ln = name;
@@ -119,7 +124,8 @@ static int do_create(char *value, char *name)
                ostr = p + 1;
                if (!*ostr)
                        return 0;
-               while(isspace((unsigned char)*ostr)) ostr++;
+               while (isspace((unsigned char)*ostr))
+                       ostr++;
        }
 
        nid = OBJ_create(ostr, name, ln);
@@ -129,9 +135,10 @@ static int do_create(char *value, char *name)
 
        if (p) {
                ln = value;
-               while(isspace((unsigned char)*ln)) ln++;
+               while (isspace((unsigned char)*ln))
+                       ln++;
                p--;
-               while(isspace((unsigned char)*p)) {
+               while (isspace((unsigned char)*p)) {
                        if (p == ln)
                                return 0;
                        p--;
@@ -148,5 +155,3 @@ static int do_create(char *value, char *name)
 
        return 1;
 }
-               
-               
index 13dc5d4..9752a68 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
 
 /* ASN1_ITEM versions of the above */
 
-ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
+ASN1_STRING *
+ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
 {
        ASN1_STRING *octmp;
 
        if (!oct || !*oct) {
                if (!(octmp = ASN1_STRING_new ())) {
-                       ASN1err(ASN1_F_ASN1_ITEM_PACK,ERR_R_MALLOC_FAILURE);
+                       ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
                        return NULL;
                }
-               if (oct) *oct = octmp;
-       } else octmp = *oct;
+               if (oct)
+                       *oct = octmp;
+       } else
+               octmp = *oct;
 
-       if(octmp->data) {
+       if (octmp->data) {
                free(octmp->data);
                octmp->data = NULL;
        }
-               
+
        if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
-               ASN1err(ASN1_F_ASN1_ITEM_PACK,ASN1_R_ENCODE_ERROR);
+               ASN1err(ASN1_F_ASN1_ITEM_PACK, ASN1_R_ENCODE_ERROR);
                return NULL;
        }
        if (!octmp->data) {
-               ASN1err(ASN1_F_ASN1_ITEM_PACK,ERR_R_MALLOC_FAILURE);
+               ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
                return NULL;
        }
        return octmp;
@@ -92,13 +95,14 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
 
 /* Extract an ASN1 object from an ASN1_STRING */
 
-void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
+void *
+ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
 {
        const unsigned char *p;
        void *ret;
 
        p = oct->data;
-       if(!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
-               ASN1err(ASN1_F_ASN1_ITEM_UNPACK,ASN1_R_DECODE_ERROR);
+       if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
+               ASN1err(ASN1_F_ASN1_ITEM_UNPACK, ASN1_R_DECODE_ERROR);
        return ret;
 }
index 8ebac02..36b8275 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
@@ -68,8 +68,7 @@
 /* Must be large enough for biggest tag+length */
 #define DEFAULT_ASN1_BUF_SIZE 20
 
-typedef enum 
-{
+typedef enum {
        ASN1_STATE_START,
        ASN1_STATE_PRE_COPY,
        ASN1_STATE_HEADER,
@@ -79,14 +78,12 @@ typedef enum
        ASN1_STATE_DONE
 } asn1_bio_state_t;
 
-typedef struct BIO_ASN1_EX_FUNCS_st
-{
+typedef struct BIO_ASN1_EX_FUNCS_st {
        asn1_ps_func    *ex_func;
        asn1_ps_func    *ex_free_func;
 } BIO_ASN1_EX_FUNCS;
 
-typedef struct BIO_ASN1_BUF_CTX_t
-{
+typedef struct BIO_ASN1_BUF_CTX_t {
        /* Internal state */
        asn1_bio_state_t state;
        /* Internal buffer */
@@ -110,7 +107,7 @@ typedef struct BIO_ASN1_BUF_CTX_t
 } BIO_ASN1_BUF_CTX;
 
 
-static int asn1_bio_write(BIO *h, const char *buf,int num);
+static int asn1_bio_write(BIO *h, const char *buf, int num);
 static int asn1_bio_read(BIO *h, char *buf, int size);
 static int asn1_bio_puts(BIO *h, const char *str);
 static int asn1_bio_gets(BIO *h, char *str, int size);
@@ -121,14 +118,12 @@ static long asn1_bio_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
 
 static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size);
 static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
-                               asn1_ps_func *cleanup, asn1_bio_state_t next);
+    asn1_ps_func *cleanup, asn1_bio_state_t next);
 static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
-                               asn1_ps_func *setup, 
-                               asn1_bio_state_t ex_state,
-                               asn1_bio_state_t other_state);
+    asn1_ps_func *setup, asn1_bio_state_t ex_state,
+    asn1_bio_state_t other_state);
 
-static BIO_METHOD methods_asn1=
-{
+static BIO_METHOD methods_asn1 = {
        BIO_TYPE_ASN1,
        "asn1",
        asn1_bio_write,
@@ -141,13 +136,14 @@ static BIO_METHOD methods_asn1=
        asn1_bio_callback_ctrl,
 };
 
-BIO_METHOD *BIO_f_asn1(void)
+BIO_METHOD *
+BIO_f_asn1(void)
 {
-       return(&methods_asn1);
+       return (&methods_asn1);
 }
 
-
-static int asn1_bio_new(BIO *b)
+static int
+asn1_bio_new(BIO *b)
 {
        BIO_ASN1_BUF_CTX *ctx;
        ctx = malloc(sizeof(BIO_ASN1_BUF_CTX));
@@ -156,14 +152,15 @@ static int asn1_bio_new(BIO *b)
        if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) {
                free(ctx);
                return 0;
-}
+       }
        b->init = 1;
        b->ptr = (char *)ctx;
        b->flags = 0;
        return 1;
 }
 
-static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
+static int
+asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
 {
        ctx->buf = malloc(size);
        if (!ctx->buf)
@@ -181,9 +178,11 @@ static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
        return 1;
 }
 
-static int asn1_bio_free(BIO *b)
+static int
+asn1_bio_free(BIO *b)
 {
        BIO_ASN1_BUF_CTX *ctx;
+
        ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
        if (ctx == NULL)
                return 0;
@@ -196,11 +195,13 @@ static int asn1_bio_free(BIO *b)
        return 1;
 }
 
-static int asn1_bio_write(BIO *b, const char *in , int inl)
+static int
+asn1_bio_write(BIO *b, const char *in , int inl)
 {
        BIO_ASN1_BUF_CTX *ctx;
        int wrmax, wrlen, ret;
        unsigned char *p;
+
        if (!in || (inl < 0) || (b->next_bio == NULL))
                return 0;
        ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
@@ -210,42 +211,38 @@ static int asn1_bio_write(BIO *b, const char *in , int inl)
        wrlen = 0;
        ret = -1;
 
-       for(;;) {
+       for (;;) {
                switch (ctx->state) {
 
                        /* Setup prefix data, call it */
                case ASN1_STATE_START:
                        if (!asn1_bio_setup_ex(b, ctx, ctx->prefix,
-                               ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER))
+                                   ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER))
                                return 0;
                        break;
 
                        /* Copy any pre data first */
                case ASN1_STATE_PRE_COPY:
-
                        ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free,
-                                                       ASN1_STATE_HEADER);
-
+                           ASN1_STATE_HEADER);
                        if (ret <= 0)
                                goto done;
-
                        break;
 
                case ASN1_STATE_HEADER:
                        ctx->buflen =
-                               ASN1_object_size(0, inl, ctx->asn1_tag) - inl;
+                           ASN1_object_size(0, inl, ctx->asn1_tag) - inl;
                        OPENSSL_assert(ctx->buflen <= ctx->bufsize);
                        p = ctx->buf;
                        ASN1_put_object(&p, 0, inl,
-                                       ctx->asn1_tag, ctx->asn1_class);
+                           ctx->asn1_tag, ctx->asn1_class);
                        ctx->copylen = inl;
                        ctx->state = ASN1_STATE_HEADER_COPY;
-
                        break;
 
-               case ASN1_STATE_HEADER_COPY:    
+               case ASN1_STATE_HEADER_COPY:
                        ret = BIO_write(b->next_bio,
-                                       ctx->buf + ctx->bufpos, ctx->buflen);
+                           ctx->buf + ctx->bufpos, ctx->buflen);
                        if (ret <= 0)
                                goto done;
 
@@ -256,7 +253,6 @@ static int asn1_bio_write(BIO *b, const char *in , int inl)
                                ctx->bufpos = 0;
                                ctx->state = ASN1_STATE_DATA_COPY;
                        }
-
                        break;
 
                case ASN1_STATE_DATA_COPY:
@@ -275,46 +271,44 @@ static int asn1_bio_write(BIO *b, const char *in , int inl)
 
                        if (ctx->copylen == 0)
                                ctx->state = ASN1_STATE_HEADER;
-
                        if (inl == 0)
                                goto done;
-
                        break;
 
-                       default:
+               default:
                        BIO_clear_retry_flags(b);
                        return 0;
-
                }
 
        }
 
-       done:
+done:
        BIO_clear_retry_flags(b);
        BIO_copy_next_retry(b);
 
        return (wrlen > 0) ? wrlen : ret;
-
 }
 
-static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
-                               asn1_ps_func *cleanup, asn1_bio_state_t next)
+static int
+asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, asn1_ps_func *cleanup,
+    asn1_bio_state_t next)
 {
        int ret;
+
        if (ctx->ex_len <= 0)
                return 1;
-       for(;;) {
+       for (;;) {
                ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos,
-                                                               ctx->ex_len);
+                   ctx->ex_len);
                if (ret <= 0)
                        break;
                ctx->ex_len -= ret;
                if (ctx->ex_len > 0)
                        ctx->ex_pos += ret;
                else {
-                       if(cleanup)
+                       if (cleanup)
                                cleanup(b, &ctx->ex_buf, &ctx->ex_len,
-                                                               &ctx->ex_arg);
+                                   &ctx->ex_arg);
                        ctx->state = next;
                        ctx->ex_pos = 0;
                        break;
@@ -323,10 +317,9 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
        return ret;
 }
 
-static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
-                               asn1_ps_func *setup, 
-                               asn1_bio_state_t ex_state,
-                               asn1_bio_state_t other_state)
+static int
+asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, asn1_ps_func *setup,
+    asn1_bio_state_t ex_state, asn1_bio_state_t other_state)
 {
        if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) {
                BIO_clear_retry_flags(b);
@@ -339,45 +332,52 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
        return 1;
 }
 
-static int asn1_bio_read(BIO *b, char *in , int inl)
+static int
+asn1_bio_read(BIO *b, char *in , int inl)
 {
        if (!b->next_bio)
                return 0;
        return BIO_read(b->next_bio, in , inl);
 }
 
-static int asn1_bio_puts(BIO *b, const char *str)
+static int
+asn1_bio_puts(BIO *b, const char *str)
 {
        return asn1_bio_write(b, str, strlen(str));
 }
 
-static int asn1_bio_gets(BIO *b, char *str, int size)
+static int
+asn1_bio_gets(BIO *b, char *str, int size)
 {
        if (!b->next_bio)
                return 0;
        return BIO_gets(b->next_bio, str , size);
 }
 
-static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+static long
+asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
 {
-       if (b->next_bio == NULL) return(0);
-       return BIO_callback_ctrl(b->next_bio,cmd,fp);
+       if (b->next_bio == NULL)
+               return (0);
+       return BIO_callback_ctrl(b->next_bio, cmd, fp);
 }
 
-static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
+static long
+asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
 {
        BIO_ASN1_BUF_CTX *ctx;
        BIO_ASN1_EX_FUNCS *ex_func;
        long ret = 1;
+
        ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
        if (ctx == NULL)
                return 0;
-       switch(cmd) {
+       switch (cmd) {
 
        case BIO_C_SET_PREFIX:
                ex_func = arg2;
-               ctx->prefix  = ex_func->ex_func;
-               ctx->prefix_free  = ex_func->ex_free_func;
+               ctx->prefix = ex_func->ex_func;
+               ctx->prefix_free = ex_func->ex_free_func;
                break;
 
        case BIO_C_GET_PREFIX:
@@ -388,8 +388,8 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
 
        case BIO_C_SET_SUFFIX:
                ex_func = arg2;
-               ctx->suffix  = ex_func->ex_func;
-               ctx->suffix_free  = ex_func->ex_free_func;
+               ctx->suffix = ex_func->ex_func;
+               ctx->suffix_free = ex_func->ex_free_func;
                break;
 
        case BIO_C_GET_SUFFIX:
@@ -413,13 +413,13 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
                /* Call post function if possible */
                if (ctx->state == ASN1_STATE_HEADER) {
                        if (!asn1_bio_setup_ex(b, ctx, ctx->suffix,
-                               ASN1_STATE_POST_COPY, ASN1_STATE_DONE))
+                           ASN1_STATE_POST_COPY, ASN1_STATE_DONE))
                                return 0;
                }
 
                if (ctx->state == ASN1_STATE_POST_COPY) {
                        ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free,
-                                                       ASN1_STATE_DONE);
+                           ASN1_STATE_DONE);
                        if (ret <= 0)
                                return ret;
                }
@@ -443,20 +443,24 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
        return ret;
 }
 
-static int asn1_bio_set_ex(BIO *b, int cmd,
-               asn1_ps_func *ex_func, asn1_ps_func *ex_free_func)
+static int
+asn1_bio_set_ex(BIO *b, int cmd, asn1_ps_func *ex_func, asn1_ps_func
+    *ex_free_func)
 {
        BIO_ASN1_EX_FUNCS extmp;
+
        extmp.ex_func = ex_func;
        extmp.ex_free_func = ex_free_func;
        return BIO_ctrl(b, cmd, 0, &extmp);
 }
 
-static int asn1_bio_get_ex(BIO *b, int cmd,
-               asn1_ps_func **ex_func, asn1_ps_func **ex_free_func)
+static int
+asn1_bio_get_ex(BIO *b, int cmd, asn1_ps_func **ex_func,
+    asn1_ps_func **ex_free_func)
 {
        BIO_ASN1_EX_FUNCS extmp;
        int ret;
+
        ret = BIO_ctrl(b, cmd, 0, &extmp);
        if (ret > 0) {
                *ex_func = extmp.ex_func;
@@ -465,22 +469,26 @@ static int asn1_bio_get_ex(BIO *b, int cmd,
        return ret;
 }
 
-int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free)
+int
+BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free)
 {
        return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free);
 }
 
-int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free)
+int
+BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free)
 {
        return asn1_bio_get_ex(b, BIO_C_GET_PREFIX, pprefix, pprefix_free);
 }
 
-int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free)
+int
+BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free)
 {
        return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free);
 }
 
-int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free)
+int
+BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free)
 {
        return asn1_bio_get_ex(b, BIO_C_GET_SUFFIX, psuffix, psuffix_free);
 }
index 595e647..f00d38e 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
@@ -78,8 +78,7 @@
 
 /* BIO support data stored in the ASN1 BIO ex_arg */
 
-typedef struct ndef_aux_st
-{
+typedef struct ndef_aux_st {
        /* ASN1 structure this BIO refers to */
        ASN1_VALUE *val;
        const ASN1_ITEM *it;
@@ -98,7 +97,8 @@ static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
 static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg);
 static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg);
 
-BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
+BIO *
+BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
 {
        NDEF_SUPPORT *ndef_aux = NULL;
        BIO *asn_bio = NULL;
@@ -143,7 +143,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
 
        return sarg.ndef_bio;
 
-       err:
+err:
        if (asn_bio)
                BIO_free(asn_bio);
        if (ndef_aux)
@@ -151,7 +151,8 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
        return NULL;
 }
 
-static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+static int
+ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
 {
        NDEF_SUPPORT *ndef_aux;
        unsigned char *p;
@@ -176,7 +177,8 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
        return 1;
 }
 
-static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+static int
+ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
 {
        NDEF_SUPPORT *ndef_aux;
 
@@ -194,7 +196,8 @@ static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
        return 1;
 }
 
-static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+static int
+ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
 {
        NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg;
        if (!ndef_prefix_free(b, pbuf, plen, parg))
@@ -204,7 +207,8 @@ static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
        return 1;
 }
 
-static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+static int
+ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
 {
        NDEF_SUPPORT *ndef_aux;
        unsigned char *p;
@@ -224,7 +228,7 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
        sarg.out = ndef_aux->out;
        sarg.boundary = ndef_aux->boundary;
        if (aux->asn1_cb(ASN1_OP_STREAM_POST,
-                               &ndef_aux->val, ndef_aux->it, &sarg) <= 0)
+           &ndef_aux->val, ndef_aux->it, &sarg) <= 0)
                return 0;
 
        derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
index b55e638..acab65b 100644 (file)
@@ -3,13 +3,12 @@
  */
 
 static const unsigned char char_type[] = {
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-120, 0, 1,40, 0, 0, 0,16,16,16, 0,25,25,16,16,16,
-16,16,16,16,16,16,16,16,16,16,16, 9, 9,16, 9,16,
0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
-16,16,16,16,16,16,16,16,16,16,16, 0, 1, 0, 0, 0,
0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
-16,16,16,16,16,16,16,16,16,16,16, 0, 0, 0, 0, 2
      2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+       120, 0, 1, 40, 0, 0, 0, 16, 16, 16, 0, 25, 25, 16, 16, 16,
+       16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 9, 9, 16, 9, 16,
      0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+       16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 1, 0, 0, 0,
      0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+       16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 2
 };
-
index 6cde8fd..8905575 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
  */
 
 typedef struct {
-char *param_name;                      /* Param name e.g. "micalg" */
-char *param_value;                     /* Param value e.g. "sha1" */
+       char *param_name;               /* Param name e.g. "micalg" */
+       char *param_value;              /* Param value e.g. "sha1" */
 } MIME_PARAM;
 
 DECLARE_STACK_OF(MIME_PARAM)
 IMPLEMENT_STACK_OF(MIME_PARAM)
 
 typedef struct {
-char *name;                            /* Name of line e.g. "content-type" */
-char *value;                           /* Value of line e.g. "text/plain" */
-STACK_OF(MIME_PARAM) *params;          /* Zero or more parameters */
+       char *name;                     /* Name of line e.g. "content-type" */
+       char *value;                    /* Value of line e.g. "text/plain" */
+       STACK_OF(MIME_PARAM) *params;   /* Zero or more parameters */
 } MIME_HEADER;
 
 DECLARE_STACK_OF(MIME_HEADER)
 IMPLEMENT_STACK_OF(MIME_HEADER)
 
 static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
-                                       const ASN1_ITEM *it);
+    const ASN1_ITEM *it);
 static char * strip_ends(char *name);
 static char * strip_start(char *name);
 static char * strip_end(char *name);
@@ -96,9 +96,9 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value);
 static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value);
 static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio);
 static int mime_hdr_cmp(const MIME_HEADER * const *a,
-                       const MIME_HEADER * const *b);
+    const MIME_HEADER * const *b);
 static int mime_param_cmp(const MIME_PARAM * const *a,
-                       const MIME_PARAM * const *b);
+    const MIME_PARAM * const *b);
 static void mime_param_free(MIME_PARAM *param);
 static int mime_bound_check(char *line, int linelen, char *bound, int blen);
 static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret);
@@ -112,15 +112,17 @@ static void mime_hdr_free(MIME_HEADER *hdr);
 
 /* Output an ASN1 structure in BER format streaming if necessary */
 
-int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
-                               const ASN1_ITEM *it)
+int
+i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
+    const ASN1_ITEM *it)
 {
        /* If streaming create stream BIO and copy all content through it */
        if (flags & SMIME_STREAM) {
                BIO *bio, *tbio;
                bio = BIO_new_NDEF(out, val, it);
                if (!bio) {
-                       ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE);
+                       ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,
+                           ERR_R_MALLOC_FAILURE);
                        return 0;
                }
                SMIME_crlf_copy(in, bio, flags);
@@ -142,14 +144,16 @@ int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
 
 /* Base 64 read and write of ASN1 structure */
 
-static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
-                               const ASN1_ITEM *it)
+static int
+B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
+    const ASN1_ITEM *it)
 {
        BIO *b64;
        int r;
+
        b64 = BIO_new(BIO_f_base64());
-       if(!b64) {
-               ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE);
+       if (!b64) {
+               ASN1err(ASN1_F_B64_WRITE_ASN1, ERR_R_MALLOC_FAILURE);
                return 0;
        }
        /* prepend the b64 BIO so all data is base64 encoded.
@@ -164,29 +168,31 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
 
 /* Streaming ASN1 PEM write */
 
-int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
-                               const char *hdr,
-                               const ASN1_ITEM *it)
+int
+PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
+    const char *hdr, const ASN1_ITEM *it)
 {
        int r;
+
        BIO_printf(out, "-----BEGIN %s-----\n", hdr);
        r = B64_write_ASN1(out, val, in, flags, it);
        BIO_printf(out, "-----END %s-----\n", hdr);
        return r;
 }
 
-static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
+static ASN1_VALUE *
+b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
 {
        BIO *b64;
        ASN1_VALUE *val;
-       if(!(b64 = BIO_new(BIO_f_base64()))) {
-               ASN1err(ASN1_F_B64_READ_ASN1,ERR_R_MALLOC_FAILURE);
+       if (!(b64 = BIO_new(BIO_f_base64()))) {
+               ASN1err(ASN1_F_B64_READ_ASN1, ERR_R_MALLOC_FAILURE);
                return 0;
-}
+       }
        bio = BIO_push(b64, bio);
        val = ASN1_item_d2i_bio(it, bio, NULL);
-       if(!val)
-               ASN1err(ASN1_F_B64_READ_ASN1,ASN1_R_DECODE_ERROR);
+       if (!val)
+               ASN1err(ASN1_F_B64_READ_ASN1, ASN1_R_DECODE_ERROR);
        (void)BIO_flush(bio);
        bio = BIO_pop(bio);
        BIO_free(b64);
@@ -195,10 +201,12 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
 
 /* Generate the MIME "micalg" parameter from RFC3851, RFC4490 */
 
-static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
+static int
+asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
 {
        const EVP_MD *md;
        int i, have_unknown = 0, write_comma, ret = 0, md_nid;
+
        have_unknown = 0;
        write_comma = 0;
        for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) {
@@ -219,33 +227,33 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
                        if (rv != -2)
                                goto err;
                }
-               switch(md_nid) {
-                       case NID_sha1:
+               switch (md_nid) {
+               case NID_sha1:
                        BIO_puts(out, "sha1");
                        break;
 
-                       case NID_md5:
+               case NID_md5:
                        BIO_puts(out, "md5");
                        break;
 
-                       case NID_sha256:
+               case NID_sha256:
                        BIO_puts(out, "sha-256");
                        break;
 
-                       case NID_sha384:
+               case NID_sha384:
                        BIO_puts(out, "sha-384");
                        break;
 
-                       case NID_sha512:
+               case NID_sha512:
                        BIO_puts(out, "sha-512");
                        break;
 
-                       case NID_id_GostR3411_94:
+               case NID_id_GostR3411_94:
                        BIO_puts(out, "gostr3411-94");
-                               goto err;
+                       goto err;
                        break;
 
-                       default:
+               default:
                        if (have_unknown)
                                write_comma = 0;
                        else {
@@ -258,23 +266,23 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
        }
 
        ret = 1;
-       err:
 
+err:
        return ret;
-
 }
 
 /* SMIME sender */
 
-int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
-                               int ctype_nid, int econt_nid,
-                               STACK_OF(X509_ALGOR) *mdalgs,
-                               const ASN1_ITEM *it)
+int
+SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
+    int ctype_nid, int econt_nid, STACK_OF(X509_ALGOR) *mdalgs,
+    const ASN1_ITEM *it)
 {
        char bound[33], c;
        int i;
        const char *mime_prefix, *mime_eol, *cname = "smime.p7m";
-       const char *msg_type=NULL;
+       const char *msg_type = NULL;
+
        if (flags & SMIME_OLDMIME)
                mime_prefix = "application/x-pkcs7-";
        else
@@ -284,16 +292,18 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
                mime_eol = "\r\n";
        else
                mime_eol = "\n";
-       if((flags & SMIME_DETACHED) && data) {
-       /* We want multipart/signed */
+       if ((flags & SMIME_DETACHED) && data) {
+               /* We want multipart/signed */
                /* Generate a random boundary */
                RAND_pseudo_bytes((unsigned char *)bound, 32);
-               for(i = 0; i < 32; i++) {
+               for (i = 0; i < 32; i++) {
                        c = bound[i] & 0xf;
-                       if(c < 10) c += '0';
-                       else c += 'A' - 10;
+                       if (c < 10)
+                               c += '0';
+                       else
+                               c += 'A' - 10;
                        bound[i] = c;
-       }
+               }
                bound[32] = 0;
                BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol);
                BIO_printf(bio, "Content-Type: multipart/signed;");
@@ -301,9 +311,9 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
                BIO_puts(bio, " micalg=\"");
                asn1_write_micalg(bio, mdalgs);
                BIO_printf(bio, "\"; boundary=\"----%s\"%s%s",
-                                               bound, mime_eol, mime_eol);
+                   bound, mime_eol, mime_eol);
                BIO_printf(bio, "This is an S/MIME signed message%s%s",
-                                               mime_eol, mime_eol);
+                   mime_eol, mime_eol);
                /* Now write out the first part */
                BIO_printf(bio, "------%s%s", bound, mime_eol);
                if (!asn1_output_data(bio, data, val, flags, it))
@@ -312,18 +322,18 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
 
                /* Headers for signature */
 
-               BIO_printf(bio, "Content-Type: %ssignature;", mime_prefix); 
+               BIO_printf(bio, "Content-Type: %ssignature;", mime_prefix);
                BIO_printf(bio, " name=\"smime.p7s\"%s", mime_eol);
                BIO_printf(bio, "Content-Transfer-Encoding: base64%s",
-                                                               mime_eol);
+                   mime_eol);
                BIO_printf(bio, "Content-Disposition: attachment;");
                BIO_printf(bio, " filename=\"smime.p7s\"%s%s",
-                                                       mime_eol, mime_eol);
+                   mime_eol, mime_eol);
                B64_write_ASN1(bio, val, NULL, 0, it);
-               BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound,
-                                                       mime_eol, mime_eol);
+               BIO_printf(bio, "%s------%s--%s%s", mime_eol, bound,
+                   mime_eol, mime_eol);
                return 1;
-}
+       }
 
        /* Determine smime-type header */
 
@@ -349,7 +359,7 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
                BIO_printf(bio, " smime-type=%s;", msg_type);
        BIO_printf(bio, " name=\"%s\"%s", cname, mime_eol);
        BIO_printf(bio, "Content-Transfer-Encoding: base64%s%s",
-                                               mime_eol, mime_eol);
+           mime_eol, mime_eol);
        if (!B64_write_ASN1(bio, val, data, flags, it))
                return 0;
        BIO_printf(bio, "%s", mime_eol);
@@ -359,8 +369,9 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
 /* Handle output of ASN1 data */
 
 
-static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
-                                       const ASN1_ITEM *it)
+static int
+asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
+    const ASN1_ITEM *it)
 {
        BIO *tmpbio;
        const ASN1_AUX *aux = it->funcs;
@@ -377,7 +388,7 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
 
        if (!aux || !aux->asn1_cb) {
                ASN1err(ASN1_F_ASN1_OUTPUT_DATA,
-                                       ASN1_R_STREAMING_NOT_SUPPORTED);
+                   ASN1_R_STREAMING_NOT_SUPPORTED);
                return 0;
        }
 
@@ -406,7 +417,6 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
        }
 
        return rv;
-
 }
 
 /* SMIME reader: handle multipart/signed and opaque signing.
@@ -414,7 +424,8 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
  * pointed to by "bcont". In opaque this is set to NULL
  */
 
-ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
+ASN1_VALUE *
+SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
 {
        BIO *asnin;
        STACK_OF(MIME_HEADER) *headers = NULL;
@@ -424,106 +435,114 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
        ASN1_VALUE *val;
        int ret;
 
-       if(bcont) *bcont = NULL;
+       if (bcont)
+               *bcont = NULL;
 
        if (!(headers = mime_parse_hdr(bio))) {
-               ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_PARSE_ERROR);
+               ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_PARSE_ERROR);
                return NULL;
-}
+       }
 
-       if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
+       if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE);
                return NULL;
-}
+       }
 
        /* Handle multipart/signed */
 
-       if(!strcmp(hdr->value, "multipart/signed")) {
+       if (!strcmp(hdr->value, "multipart/signed")) {
                /* Split into two parts */
                prm = mime_param_find(hdr, "boundary");
-               if(!prm || !prm->param_value) {
+               if (!prm || !prm->param_value) {
                        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-                       ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BOUNDARY);
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_NO_MULTIPART_BOUNDARY);
                        return NULL;
-       }
+               }
                ret = multi_split(bio, prm->param_value, &parts);
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-               if(!ret || (sk_BIO_num(parts) != 2) ) {
-                       ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BODY_FAILURE);
+               if (!ret || (sk_BIO_num(parts) != 2) ) {
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_NO_MULTIPART_BODY_FAILURE);
                        sk_BIO_pop_free(parts, BIO_vfree);
                        return NULL;
-       }
+               }
 
                /* Parse the signature piece */
                asnin = sk_BIO_value(parts, 1);
 
                if (!(headers = mime_parse_hdr(asnin))) {
-                       ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_SIG_PARSE_ERROR);
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_MIME_SIG_PARSE_ERROR);
                        sk_BIO_pop_free(parts, BIO_vfree);
                        return NULL;
-       }
+               }
 
                /* Get content type */
 
-               if(!(hdr = mime_hdr_find(headers, "content-type")) ||
-                                                                !hdr->value) {
+               if (!(hdr = mime_hdr_find(headers, "content-type")) ||
+                   !hdr->value) {
                        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-                       ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE);
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_NO_SIG_CONTENT_TYPE);
                        return NULL;
-       }
+               }
 
-               if(strcmp(hdr->value, "application/x-pkcs7-signature") &&
-                       strcmp(hdr->value, "application/pkcs7-signature")) {
-                       ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_SIG_INVALID_MIME_TYPE);
+               if (strcmp(hdr->value, "application/x-pkcs7-signature") &&
+                   strcmp(hdr->value, "application/pkcs7-signature")) {
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_SIG_INVALID_MIME_TYPE);
                        ERR_add_error_data(2, "type: ", hdr->value);
                        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                        sk_BIO_pop_free(parts, BIO_vfree);
                        return NULL;
-       }
+               }
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                /* Read in ASN1 */
-               if(!(val = b64_read_asn1(asnin, it))) {
-                       ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_ASN1_SIG_PARSE_ERROR);
+               if (!(val = b64_read_asn1(asnin, it))) {
+                       ASN1err(ASN1_F_SMIME_READ_ASN1,
+                           ASN1_R_ASN1_SIG_PARSE_ERROR);
                        sk_BIO_pop_free(parts, BIO_vfree);
                        return NULL;
-       }
+               }
 
-               if(bcont) {
+               if (bcont) {
                        *bcont = sk_BIO_value(parts, 0);
                        BIO_free(asnin);
                        sk_BIO_free(parts);
-       } else sk_BIO_pop_free(parts, BIO_vfree);
-               return val;
-}
-               
+               } else sk_BIO_pop_free(parts, BIO_vfree);
+                       return val;
+       }
+
        /* OK, if not multipart/signed try opaque signature */
 
        if (strcmp (hdr->value, "application/x-pkcs7-mime") &&
            strcmp (hdr->value, "application/pkcs7-mime")) {
-               ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_INVALID_MIME_TYPE);
+               ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_INVALID_MIME_TYPE);
                ERR_add_error_data(2, "type: ", hdr->value);
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                return NULL;
-}
+       }
 
        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-       
-       if(!(val = b64_read_asn1(bio, it))) {
+
+       if (!(val = b64_read_asn1(bio, it))) {
                ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR);
                return NULL;
-}
+       }
        return val;
-
 }
 
 /* Copy text from one BIO to another making the output CRLF at EOL */
-int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
+int
+SMIME_crlf_copy(BIO *in, BIO *out, int flags)
 {
        BIO *bf;
        char eol;
        int len;
        char linebuf[MAX_SMLEN];
+
        /* Buffer output so we don't write one line at a time. This is
         * useful when streaming as we don't end up with one OCTET STRING
         * per line.
@@ -532,17 +551,18 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
        if (!bf)
                return 0;
        out = BIO_push(bf, out);
-       if(flags & SMIME_BINARY) {
-               while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
-                                               BIO_write(out, linebuf, len);
+       if (flags & SMIME_BINARY) {
+               while ((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
+                       BIO_write(out, linebuf, len);
        } else {
-               if(flags & SMIME_TEXT)
+               if (flags & SMIME_TEXT)
                        BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
                while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
                        eol = strip_eol(linebuf, &len);
                        if (len)
                                BIO_write(out, linebuf, len);
-                       if(eol) BIO_write(out, "\r\n", 2);
+                       if (eol)
+                               BIO_write(out, "\r\n", 2);
                }
        }
        (void)BIO_flush(out);
@@ -552,7 +572,8 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
 }
 
 /* Strip off headers if they are text/plain */
-int SMIME_text(BIO *in, BIO *out)
+int
+SMIME_text(BIO *in, BIO *out)
 {
        char iobuf[4096];
        int len;
@@ -560,23 +581,23 @@ int SMIME_text(BIO *in, BIO *out)
        MIME_HEADER *hdr;
 
        if (!(headers = mime_parse_hdr(in))) {
-               ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_PARSE_ERROR);
+               ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_PARSE_ERROR);
                return 0;
-}
-       if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
-               ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_NO_CONTENT_TYPE);
+       }
+       if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
+               ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_NO_CONTENT_TYPE);
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                return 0;
-}
+       }
        if (strcmp (hdr->value, "text/plain")) {
-               ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_INVALID_MIME_TYPE);
+               ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_INVALID_MIME_TYPE);
                ERR_add_error_data(2, "type: ", hdr->value);
                sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
                return 0;
-}
+       }
        sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
        while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
-                                               BIO_write(out, iobuf, len);
+               BIO_write(out, iobuf, len);
        if (len < 0)
                return 0;
        return 1;
@@ -586,7 +607,8 @@ int SMIME_text(BIO *in, BIO *out)
  * canonical parts in a STACK of bios
  */
 
-static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
+static int
+multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
 {
        char linebuf[MAX_SMLEN];
        int len, blen;
@@ -603,27 +625,28 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
        *ret = parts;
        while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
                state = mime_bound_check(linebuf, len, bound, blen);
-               if(state == 1) {
+               if (state == 1) {
                        first = 1;
                        part++;
-       } else if(state == 2) {
+               } else if (state == 2) {
                        sk_BIO_push(parts, bpart);
                        return 1;
-       } else if(part) {
+               } else if (part) {
                        /* Strip CR+LF from linebuf */
                        next_eol = strip_eol(linebuf, &len);
-                       if(first) {
+                       if (first) {
                                first = 0;
-                               if(bpart) sk_BIO_push(parts, bpart);
+                               if (bpart)
+                                       sk_BIO_push(parts, bpart);
                                bpart = BIO_new(BIO_s_mem());
                                BIO_set_mem_eof_return(bpart, 0);
-               } else if (eol)
+                       } else if (eol)
                                BIO_write(bpart, "\r\n", 2);
                        eol = next_eol;
                        if (len)
                                BIO_write(bpart, linebuf, len);
+               }
        }
-}
        return 0;
 }
 
@@ -638,7 +661,8 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
 #define MIME_COMMENT   6
 
 
-static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
+static
+STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
 {
        char *p, *q, c;
        char *ntmp;
@@ -649,254 +673,294 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
 
        headers = sk_MIME_HEADER_new(mime_hdr_cmp);
        while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
-       /* If whitespace at line start then continuation line */
-       if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME;
-       else state = MIME_START;
-       ntmp = NULL;
-       /* Go through all characters */
-       for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
-
-       /* State machine to handle MIME headers
-        * if this looks horrible that's because it *is*
-         */
-
-               switch(state) {
+               /* If whitespace at line start then continuation line */
+               if (mhdr && isspace((unsigned char)linebuf[0]))
+                       state = MIME_NAME;
+               else
+                       state = MIME_START;
+               ntmp = NULL;
+
+               /* Go through all characters */
+               for (p = linebuf, q = linebuf;
+                   (c = *p) && (c != '\r') && (c != '\n'); p++) {
+
+                       /* State machine to handle MIME headers
+                        * if this looks horrible that's because it *is*
+                        */
+
+                       switch (state) {
                        case MIME_START:
-                       if(c == ':') {
-                               state = MIME_TYPE;
-                               *p = 0;
-                               ntmp = strip_ends(q);
-                               q = p + 1;
-               }
-                       break;
+                               if (c == ':') {
+                                       state = MIME_TYPE;
+                                       *p = 0;
+                                       ntmp = strip_ends(q);
+                                       q = p + 1;
+                               }
+                               break;
 
                        case MIME_TYPE:
-                       if(c == ';') {
-                               mime_debug("Found End Value\n");
-                               *p = 0;
-                               mhdr = mime_hdr_new(ntmp, strip_ends(q));
-                               sk_MIME_HEADER_push(headers, mhdr);
-                               ntmp = NULL;
-                               q = p + 1;
-                               state = MIME_NAME;
-               } else if(c == '(') {
-                               save_state = state;
-                               state = MIME_COMMENT;
-               }
-                       break;
+                               if (c == ';') {
+                                       mime_debug("Found End Value\n");
+                                       *p = 0;
+                                       mhdr = mime_hdr_new(ntmp,
+                                           strip_ends(q));
+                                       sk_MIME_HEADER_push(headers, mhdr);
+                                       ntmp = NULL;
+                                       q = p + 1;
+                                       state = MIME_NAME;
+                               } else if (c == '(') {
+                                       save_state = state;
+                                       state = MIME_COMMENT;
+                               }
+                               break;
 
                        case MIME_COMMENT:
-                       if(c == ')') {
-                               state = save_state;
-               }
-                       break;
+                               if (c == ')') {
+                                       state = save_state;
+                               }
+                               break;
 
                        case MIME_NAME:
-                       if(c == '=') {
-                               state = MIME_VALUE;
-                               *p = 0;
-                               ntmp = strip_ends(q);
-                               q = p + 1;
-               }
-                       break ;
+                               if (c == '=') {
+                                       state = MIME_VALUE;
+                                       *p = 0;
+                                       ntmp = strip_ends(q);
+                                       q = p + 1;
+                               }
+                               break;
 
                        case MIME_VALUE:
-                       if(c == ';') {
-                               state = MIME_NAME;
-                               *p = 0;
-                               mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
-                               ntmp = NULL;
-                               q = p + 1;
-               } else if (c == '"') {
-                               mime_debug("Found Quote\n");
-                               state = MIME_QUOTE;
-               } else if(c == '(') {
-                               save_state = state;
-                               state = MIME_COMMENT;
-               }
-                       break;
+                               if (c == ';') {
+                                       state = MIME_NAME;
+                                       *p = 0;
+                                       mime_hdr_addparam(mhdr, ntmp,
+                                           strip_ends(q));
+                                       ntmp = NULL;
+                                       q = p + 1;
+                               } else if (c == '"') {
+                                       mime_debug("Found Quote\n");
+                                       state = MIME_QUOTE;
+                               } else if (c == '(') {
+                                       save_state = state;
+                                       state = MIME_COMMENT;
+                               }
+                               break;
 
                        case MIME_QUOTE:
-                       if(c == '"') {
-                               mime_debug("Found Match Quote\n");
-                               state = MIME_VALUE;
+                               if (c == '"') {
+                                       mime_debug("Found Match Quote\n");
+                                       state = MIME_VALUE;
+                               }
+                               break;
+                       }
                }
-                       break;
-       }
-}
 
-       if(state == MIME_TYPE) {
-               mhdr = mime_hdr_new(ntmp, strip_ends(q));
-               sk_MIME_HEADER_push(headers, mhdr);
-} else if(state == MIME_VALUE)
-                        mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
-       if(p == linebuf) break; /* Blank line means end of headers */
-}
+               if (state == MIME_TYPE) {
+                       mhdr = mime_hdr_new(ntmp, strip_ends(q));
+                       sk_MIME_HEADER_push(headers, mhdr);
+               } else if (state == MIME_VALUE)
+                       mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
 
-return headers;
+               if (p == linebuf)
+                       break;  /* Blank line means end of headers */
+       }
 
+       return headers;
 }
 
-static char *strip_ends(char *name)
+static char *
+strip_ends(char *name)
 {
        return strip_end(strip_start(name));
 }
 
 /* Strip a parameter of whitespace from start of param */
-static char *strip_start(char *name)
+static char *
+strip_start(char *name)
 {
        char *p, c;
+
        /* Look for first non white space or quote */
-       for(p = name; (c = *p) ;p++) {
-               if(c == '"') {
+       for (p = name; (c = *p); p++) {
+               if (c == '"') {
                        /* Next char is start of string if non null */
-                       if(p[1]) return p + 1;
+                       if (p[1])
+                               return p + 1;
                        /* Else null string */
                        return NULL;
+               }
+               if (!isspace((unsigned char)c))
+                       return p;
        }
-               if(!isspace((unsigned char)c)) return p;
-}
        return NULL;
 }
 
 /* As above but strip from end of string : maybe should handle brackets? */
-static char *strip_end(char *name)
+static char *
+strip_end(char *name)
 {
        char *p, c;
-       if(!name) return NULL;
+
+       if (!name)
+               return NULL;
+
        /* Look for first non white space or quote */
-       for(p = name + strlen(name) - 1; p >= name ;p--) {
+       for (p = name + strlen(name) - 1; p >= name; p--) {
                c = *p;
-               if(c == '"') {
-                       if(p - 1 == name) return NULL;
+               if (c == '"') {
+                       if (p - 1 == name)
+                               return NULL;
                        *p = 0;
                        return name;
+               }
+               if (isspace((unsigned char)c))
+                       *p = 0;
+               else
+                       return name;
        }
-               if(isspace((unsigned char)c)) *p = 0;   
-               else return name;
-}
        return NULL;
 }
 
-static MIME_HEADER *mime_hdr_new(char *name, char *value)
+static MIME_HEADER *
+mime_hdr_new(char *name, char *value)
 {
        MIME_HEADER *mhdr;
        char *tmpname, *tmpval, *p;
        int c;
-       if(name) {
-               if(!(tmpname = BUF_strdup(name))) return NULL;
-               for(p = tmpname ; *p; p++) {
+       if (name) {
+               if (!(tmpname = BUF_strdup(name)))
+                       return NULL;
+               for (p = tmpname; *p; p++) {
                        c = (unsigned char)*p;
-                       if(isupper(c)) {
+                       if (isupper(c)) {
                                c = tolower(c);
                                *p = c;
+                       }
                }
-       }
-} else tmpname = NULL;
-       if(value) {
-               if(!(tmpval = BUF_strdup(value))) return NULL;
-               for(p = tmpval ; *p; p++) {
+       } else
+               tmpname = NULL;
+       if (value) {
+               if (!(tmpval = BUF_strdup(value)))
+                       return NULL;
+               for (p = tmpval; *p; p++) {
                        c = (unsigned char)*p;
-                       if(isupper(c)) {
+                       if (isupper(c)) {
                                c = tolower(c);
                                *p = c;
+                       }
                }
-       }
-} else tmpval = NULL;
-       mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER));
+       } else tmpval = NULL;
+               mhdr = (MIME_HEADER *)malloc(sizeof(MIME_HEADER));
        if (!mhdr) {
                OPENSSL_free(tmpname);
                return NULL;
-}
+       }
        mhdr->name = tmpname;
        mhdr->value = tmpval;
        if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) {
                free(mhdr);
                return NULL;
-}
+       }
        return mhdr;
 }
-               
-static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
+
+static int
+mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
 {
        char *tmpname, *tmpval, *p;
        int c;
        MIME_PARAM *mparam;
-       if(name) {
+
+       if (name) {
                tmpname = BUF_strdup(name);
-               if(!tmpname) return 0;
-               for(p = tmpname ; *p; p++) {
+               if (!tmpname)
+                       return 0;
+               for (p = tmpname; *p; p++) {
                        c = (unsigned char)*p;
-                       if(isupper(c)) {
+                       if (isupper(c)) {
                                c = tolower(c);
                                *p = c;
+                       }
                }
-       }
-} else tmpname = NULL;
-       if(value) {
+       } else
+               tmpname = NULL;
+       if (value) {
                tmpval = BUF_strdup(value);
-               if(!tmpval) return 0;
-} else tmpval = NULL;
+               if (!tmpval)
+                       return 0;
+       } else
+               tmpval = NULL;
        /* Parameter values are case sensitive so leave as is */
        mparam = (MIME_PARAM *) malloc(sizeof(MIME_PARAM));
-       if(!mparam) return 0;
+       if (!mparam)
+               return 0;
        mparam->param_name = tmpname;
        mparam->param_value = tmpval;
        sk_MIME_PARAM_push(mhdr->params, mparam);
        return 1;
 }
 
-static int mime_hdr_cmp(const MIME_HEADER * const *a,
-                       const MIME_HEADER * const *b)
+static int
+mime_hdr_cmp(const MIME_HEADER * const *a, const MIME_HEADER * const *b)
 {
        if (!(*a)->name || !(*b)->name)
                return !!(*a)->name - !!(*b)->name;
-
-       return(strcmp((*a)->name, (*b)->name));
+       return (strcmp((*a)->name, (*b)->name));
 }
 
-static int mime_param_cmp(const MIME_PARAM * const *a,
-                       const MIME_PARAM * const *b)
+static int
+mime_param_cmp(const MIME_PARAM * const *a, const MIME_PARAM * const *b)
 {
        if (!(*a)->param_name || !(*b)->param_name)
                return !!(*a)->param_name - !!(*b)->param_name;
-       return(strcmp((*a)->param_name, (*b)->param_name));
+       return (strcmp((*a)->param_name, (*b)->param_name));
 }
 
 /* Find a header with a given name (if possible) */
 
-static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name)
+static MIME_HEADER *
+mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name)
 {
        MIME_HEADER htmp;
        int idx;
        htmp.name = name;
        idx = sk_MIME_HEADER_find(hdrs, &htmp);
-       if(idx < 0) return NULL;
+       if (idx < 0)
+               return NULL;
        return sk_MIME_HEADER_value(hdrs, idx);
 }
 
-static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
+static MIME_PARAM *
+mime_param_find(MIME_HEADER *hdr, char *name)
 {
        MIME_PARAM param;
        int idx;
        param.param_name = name;
        idx = sk_MIME_PARAM_find(hdr->params, &param);
-       if(idx < 0) return NULL;
+       if (idx < 0)
+               return NULL;
        return sk_MIME_PARAM_value(hdr->params, idx);
 }
 
-static void mime_hdr_free(MIME_HEADER *hdr)
+static void
+mime_hdr_free(MIME_HEADER *hdr)
 {
-       if(hdr->name) free(hdr->name);
-       if(hdr->value) free(hdr->value);
-       if(hdr->params) sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
+       if (hdr->name)
+               free(hdr->name);
+       if (hdr->value)
+               free(hdr->value);
+       if (hdr->params)
+               sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
        free(hdr);
 }
 
-static void mime_param_free(MIME_PARAM *param)
+static void
+mime_param_free(MIME_PARAM *param)
 {
-       if(param->param_name) free(param->param_name);
-       if(param->param_value) free(param->param_value);
+       if (param->param_name)
+               free(param->param_name);
+       if (param->param_value)
+               free(param->param_value);
        free(param);
 }
 
@@ -905,21 +969,28 @@ static void mime_param_free(MIME_PARAM *param)
  * 1 : part boundary
  * 2 : final boundary
  */
-static int mime_bound_check(char *line, int linelen, char *bound, int blen)
+static int
+mime_bound_check(char *line, int linelen, char *bound, int blen)
 {
-       if(linelen == -1) linelen = strlen(line);
-       if(blen == -1) blen = strlen(bound);
+       if (linelen == -1)
+               linelen = strlen(line);
+       if (blen == -1)
+               blen = strlen(bound);
        /* Quickly eliminate if line length too short */
-       if(blen + 2 > linelen) return 0;
+       if (blen + 2 > linelen)
+               return 0;
        /* Check for part boundary */
-       if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) {
-               if(!strncmp(line + blen + 2, "--", 2)) return 2;
-               else return 1;
-}
+       if (!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) {
+               if (!strncmp(line + blen + 2, "--", 2))
+                       return 2;
+               else
+                       return 1;
+       }
        return 0;
 }
 
-static int strip_eol(char *linebuf, int *plen)
+static int
+strip_eol(char *linebuf, int *plen)
 {
        int len = *plen;
        char *p, c;
index 0c09a8e..7ddf212 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
 
 static int do_create(char *value, char *name);
 
-static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
+static int
+oid_module_init(CONF_IMODULE *md, const CONF *cnf)
 {
        int i;
        const char *oid_section;
        STACK_OF(CONF_VALUE) *sktmp;
        CONF_VALUE *oval;
+
        oid_section = CONF_imodule_get_value(md);
-       if(!(sktmp = NCONF_get_section(cnf, oid_section))) {
+       if (!(sktmp = NCONF_get_section(cnf, oid_section))) {
                ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
                return 0;
        }
-       for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
+       for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
                oval = sk_CONF_VALUE_value(sktmp, i);
-               if(!do_create(oval->value, oval->name)) {
+               if (!do_create(oval->value, oval->name)) {
                        ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT);
                        return 0;
                }
@@ -89,12 +91,14 @@ static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
        return 1;
 }
 
-static void oid_module_finish(CONF_IMODULE *md)
+static void
+oid_module_finish(CONF_IMODULE *md)
 {
        OBJ_cleanup();
 }
 
-void ASN1_add_oid_module(void)
+void
+ASN1_add_oid_module(void)
 {
        CONF_module_add("oid_section", oid_module_init, oid_module_finish);
 }
@@ -104,12 +108,13 @@ void ASN1_add_oid_module(void)
  * shortname = some long name, 1.2.3.4
  */
 
-
-static int do_create(char *value, char *name)
+static int
+do_create(char *value, char *name)
 {
        int nid;
        ASN1_OBJECT *oid;
        char *ln, *ostr, *p, *lntmp;
+
        p = strrchr(value, ',');
        if (!p) {
                ln = name;
@@ -119,7 +124,8 @@ static int do_create(char *value, char *name)
                ostr = p + 1;
                if (!*ostr)
                        return 0;
-               while(isspace((unsigned char)*ostr)) ostr++;
+               while (isspace((unsigned char)*ostr))
+                       ostr++;
        }
 
        nid = OBJ_create(ostr, name, ln);
@@ -129,9 +135,10 @@ static int do_create(char *value, char *name)
 
        if (p) {
                ln = value;
-               while(isspace((unsigned char)*ln)) ln++;
+               while (isspace((unsigned char)*ln))
+                       ln++;
                p--;
-               while(isspace((unsigned char)*p)) {
+               while (isspace((unsigned char)*p)) {
                        if (p == ln)
                                return 0;
                        p--;
@@ -148,5 +155,3 @@ static int do_create(char *value, char *name)
 
        return 1;
 }
-               
-               
index 13dc5d4..9752a68 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
 
 /* ASN1_ITEM versions of the above */
 
-ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
+ASN1_STRING *
+ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
 {
        ASN1_STRING *octmp;
 
        if (!oct || !*oct) {
                if (!(octmp = ASN1_STRING_new ())) {
-                       ASN1err(ASN1_F_ASN1_ITEM_PACK,ERR_R_MALLOC_FAILURE);
+                       ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
                        return NULL;
                }
-               if (oct) *oct = octmp;
-       } else octmp = *oct;
+               if (oct)
+                       *oct = octmp;
+       } else
+               octmp = *oct;
 
-       if(octmp->data) {
+       if (octmp->data) {
                free(octmp->data);
                octmp->data = NULL;
        }
-               
+
        if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
-               ASN1err(ASN1_F_ASN1_ITEM_PACK,ASN1_R_ENCODE_ERROR);
+               ASN1err(ASN1_F_ASN1_ITEM_PACK, ASN1_R_ENCODE_ERROR);
                return NULL;
        }
        if (!octmp->data) {
-               ASN1err(ASN1_F_ASN1_ITEM_PACK,ERR_R_MALLOC_FAILURE);
+               ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
                return NULL;
        }
        return octmp;
@@ -92,13 +95,14 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
 
 /* Extract an ASN1 object from an ASN1_STRING */
 
-void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
+void *
+ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
 {
        const unsigned char *p;
        void *ret;
 
        p = oct->data;
-       if(!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
-               ASN1err(ASN1_F_ASN1_ITEM_UNPACK,ASN1_R_DECODE_ERROR);
+       if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
+               ASN1err(ASN1_F_ASN1_ITEM_UNPACK, ASN1_R_DECODE_ERROR);
        return ret;
 }
index 8ebac02..36b8275 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
@@ -68,8 +68,7 @@
 /* Must be large enough for biggest tag+length */
 #define DEFAULT_ASN1_BUF_SIZE 20
 
-typedef enum 
-{
+typedef enum {
        ASN1_STATE_START,
        ASN1_STATE_PRE_COPY,
        ASN1_STATE_HEADER,
@@ -79,14 +78,12 @@ typedef enum
        ASN1_STATE_DONE
 } asn1_bio_state_t;
 
-typedef struct BIO_ASN1_EX_FUNCS_st
-{
+typedef struct BIO_ASN1_EX_FUNCS_st {
        asn1_ps_func    *ex_func;
        asn1_ps_func    *ex_free_func;
 } BIO_ASN1_EX_FUNCS;
 
-typedef struct BIO_ASN1_BUF_CTX_t
-{
+typedef struct BIO_ASN1_BUF_CTX_t {
        /* Internal state */
        asn1_bio_state_t state;
        /* Internal buffer */
@@ -110,7 +107,7 @@ typedef struct BIO_ASN1_BUF_CTX_t
 } BIO_ASN1_BUF_CTX;
 
 
-static int asn1_bio_write(BIO *h, const char *buf,int num);
+static int asn1_bio_write(BIO *h, const char *buf, int num);
 static int asn1_bio_read(BIO *h, char *buf, int size);
 static int asn1_bio_puts(BIO *h, const char *str);
 static int asn1_bio_gets(BIO *h, char *str, int size);
@@ -121,14 +118,12 @@ static long asn1_bio_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
 
 static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size);
 static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
-                               asn1_ps_func *cleanup, asn1_bio_state_t next);
+    asn1_ps_func *cleanup, asn1_bio_state_t next);
 static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
-                               asn1_ps_func *setup, 
-                               asn1_bio_state_t ex_state,
-                               asn1_bio_state_t other_state);
+    asn1_ps_func *setup, asn1_bio_state_t ex_state,
+    asn1_bio_state_t other_state);
 
-static BIO_METHOD methods_asn1=
-{
+static BIO_METHOD methods_asn1 = {
        BIO_TYPE_ASN1,
        "asn1",
        asn1_bio_write,
@@ -141,13 +136,14 @@ static BIO_METHOD methods_asn1=
        asn1_bio_callback_ctrl,
 };
 
-BIO_METHOD *BIO_f_asn1(void)
+BIO_METHOD *
+BIO_f_asn1(void)
 {
-       return(&methods_asn1);
+       return (&methods_asn1);
 }
 
-
-static int asn1_bio_new(BIO *b)
+static int
+asn1_bio_new(BIO *b)
 {
        BIO_ASN1_BUF_CTX *ctx;
        ctx = malloc(sizeof(BIO_ASN1_BUF_CTX));
@@ -156,14 +152,15 @@ static int asn1_bio_new(BIO *b)
        if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) {
                free(ctx);
                return 0;
-}
+       }
        b->init = 1;
        b->ptr = (char *)ctx;
        b->flags = 0;
        return 1;
 }
 
-static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
+static int
+asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
 {
        ctx->buf = malloc(size);
        if (!ctx->buf)
@@ -181,9 +178,11 @@ static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
        return 1;
 }
 
-static int asn1_bio_free(BIO *b)
+static int
+asn1_bio_free(BIO *b)
 {
        BIO_ASN1_BUF_CTX *ctx;
+
        ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
        if (ctx == NULL)
                return 0;
@@ -196,11 +195,13 @@ static int asn1_bio_free(BIO *b)
        return 1;
 }
 
-static int asn1_bio_write(BIO *b, const char *in , int inl)
+static int
+asn1_bio_write(BIO *b, const char *in , int inl)
 {
        BIO_ASN1_BUF_CTX *ctx;
        int wrmax, wrlen, ret;
        unsigned char *p;
+
        if (!in || (inl < 0) || (b->next_bio == NULL))
                return 0;
        ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
@@ -210,42 +211,38 @@ static int asn1_bio_write(BIO *b, const char *in , int inl)
        wrlen = 0;
        ret = -1;
 
-       for(;;) {
+       for (;;) {
                switch (ctx->state) {
 
                        /* Setup prefix data, call it */
                case ASN1_STATE_START:
                        if (!asn1_bio_setup_ex(b, ctx, ctx->prefix,
-                               ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER))
+                                   ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER))
                                return 0;
                        break;
 
                        /* Copy any pre data first */
                case ASN1_STATE_PRE_COPY:
-
                        ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free,
-                                                       ASN1_STATE_HEADER);
-
+                           ASN1_STATE_HEADER);
                        if (ret <= 0)
                                goto done;
-
                        break;
 
                case ASN1_STATE_HEADER:
                        ctx->buflen =
-                               ASN1_object_size(0, inl, ctx->asn1_tag) - inl;
+                           ASN1_object_size(0, inl, ctx->asn1_tag) - inl;
                        OPENSSL_assert(ctx->buflen <= ctx->bufsize);
                        p = ctx->buf;
                        ASN1_put_object(&p, 0, inl,
-                                       ctx->asn1_tag, ctx->asn1_class);
+                           ctx->asn1_tag, ctx->asn1_class);
                        ctx->copylen = inl;
                        ctx->state = ASN1_STATE_HEADER_COPY;
-
                        break;
 
-               case ASN1_STATE_HEADER_COPY:    
+               case ASN1_STATE_HEADER_COPY:
                        ret = BIO_write(b->next_bio,
-                                       ctx->buf + ctx->bufpos, ctx->buflen);
+                           ctx->buf + ctx->bufpos, ctx->buflen);
                        if (ret <= 0)
                                goto done;
 
@@ -256,7 +253,6 @@ static int asn1_bio_write(BIO *b, const char *in , int inl)
                                ctx->bufpos = 0;
                                ctx->state = ASN1_STATE_DATA_COPY;
                        }
-
                        break;
 
                case ASN1_STATE_DATA_COPY:
@@ -275,46 +271,44 @@ static int asn1_bio_write(BIO *b, const char *in , int inl)
 
                        if (ctx->copylen == 0)
                                ctx->state = ASN1_STATE_HEADER;
-
                        if (inl == 0)
                                goto done;
-
                        break;
 
-                       default:
+               default:
                        BIO_clear_retry_flags(b);
                        return 0;
-
                }
 
        }
 
-       done:
+done:
        BIO_clear_retry_flags(b);
        BIO_copy_next_retry(b);
 
        return (wrlen > 0) ? wrlen : ret;
-
 }
 
-static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
-                               asn1_ps_func *cleanup, asn1_bio_state_t next)
+static int
+asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, asn1_ps_func *cleanup,
+    asn1_bio_state_t next)
 {
        int ret;
+
        if (ctx->ex_len <= 0)
                return 1;
-       for(;;) {
+       for (;;) {
                ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos,
-                                                               ctx->ex_len);
+                   ctx->ex_len);
                if (ret <= 0)
                        break;
                ctx->ex_len -= ret;
                if (ctx->ex_len > 0)
                        ctx->ex_pos += ret;
                else {
-                       if(cleanup)
+                       if (cleanup)
                                cleanup(b, &ctx->ex_buf, &ctx->ex_len,
-                                                               &ctx->ex_arg);
+                                   &ctx->ex_arg);
                        ctx->state = next;
                        ctx->ex_pos = 0;
                        break;
@@ -323,10 +317,9 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
        return ret;
 }
 
-static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
-                               asn1_ps_func *setup, 
-                               asn1_bio_state_t ex_state,
-                               asn1_bio_state_t other_state)
+static int
+asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, asn1_ps_func *setup,
+    asn1_bio_state_t ex_state, asn1_bio_state_t other_state)
 {
        if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) {
                BIO_clear_retry_flags(b);
@@ -339,45 +332,52 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
        return 1;
 }
 
-static int asn1_bio_read(BIO *b, char *in , int inl)
+static int
+asn1_bio_read(BIO *b, char *in , int inl)
 {
        if (!b->next_bio)
                return 0;
        return BIO_read(b->next_bio, in , inl);
 }
 
-static int asn1_bio_puts(BIO *b, const char *str)
+static int
+asn1_bio_puts(BIO *b, const char *str)
 {
        return asn1_bio_write(b, str, strlen(str));
 }
 
-static int asn1_bio_gets(BIO *b, char *str, int size)
+static int
+asn1_bio_gets(BIO *b, char *str, int size)
 {
        if (!b->next_bio)
                return 0;
        return BIO_gets(b->next_bio, str , size);
 }
 
-static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+static long
+asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
 {
-       if (b->next_bio == NULL) return(0);
-       return BIO_callback_ctrl(b->next_bio,cmd,fp);
+       if (b->next_bio == NULL)
+               return (0);
+       return BIO_callback_ctrl(b->next_bio, cmd, fp);
 }
 
-static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
+static long
+asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
 {
        BIO_ASN1_BUF_CTX *ctx;
        BIO_ASN1_EX_FUNCS *ex_func;
        long ret = 1;
+
        ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
        if (ctx == NULL)
                return 0;
-       switch(cmd) {
+       switch (cmd) {
 
        case BIO_C_SET_PREFIX:
                ex_func = arg2;
-               ctx->prefix  = ex_func->ex_func;
-               ctx->prefix_free  = ex_func->ex_free_func;
+               ctx->prefix = ex_func->ex_func;
+               ctx->prefix_free = ex_func->ex_free_func;
                break;
 
        case BIO_C_GET_PREFIX:
@@ -388,8 +388,8 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
 
        case BIO_C_SET_SUFFIX:
                ex_func = arg2;
-               ctx->suffix  = ex_func->ex_func;
-               ctx->suffix_free  = ex_func->ex_free_func;
+               ctx->suffix = ex_func->ex_func;
+               ctx->suffix_free = ex_func->ex_free_func;
                break;
 
        case BIO_C_GET_SUFFIX:
@@ -413,13 +413,13 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
                /* Call post function if possible */
                if (ctx->state == ASN1_STATE_HEADER) {
                        if (!asn1_bio_setup_ex(b, ctx, ctx->suffix,
-                               ASN1_STATE_POST_COPY, ASN1_STATE_DONE))
+                           ASN1_STATE_POST_COPY, ASN1_STATE_DONE))
                                return 0;
                }
 
                if (ctx->state == ASN1_STATE_POST_COPY) {
                        ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free,
-                                                       ASN1_STATE_DONE);
+                           ASN1_STATE_DONE);
                        if (ret <= 0)
                                return ret;
                }
@@ -443,20 +443,24 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
        return ret;
 }
 
-static int asn1_bio_set_ex(BIO *b, int cmd,
-               asn1_ps_func *ex_func, asn1_ps_func *ex_free_func)
+static int
+asn1_bio_set_ex(BIO *b, int cmd, asn1_ps_func *ex_func, asn1_ps_func
+    *ex_free_func)
 {
        BIO_ASN1_EX_FUNCS extmp;
+
        extmp.ex_func = ex_func;
        extmp.ex_free_func = ex_free_func;
        return BIO_ctrl(b, cmd, 0, &extmp);
 }
 
-static int asn1_bio_get_ex(BIO *b, int cmd,
-               asn1_ps_func **ex_func, asn1_ps_func **ex_free_func)
+static int
+asn1_bio_get_ex(BIO *b, int cmd, asn1_ps_func **ex_func,
+    asn1_ps_func **ex_free_func)
 {
        BIO_ASN1_EX_FUNCS extmp;
        int ret;
+
        ret = BIO_ctrl(b, cmd, 0, &extmp);
        if (ret > 0) {
                *ex_func = extmp.ex_func;
@@ -465,22 +469,26 @@ static int asn1_bio_get_ex(BIO *b, int cmd,
        return ret;
 }
 
-int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free)
+int
+BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free)
 {
        return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free);
 }
 
-int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free)
+int
+BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free)
 {
        return asn1_bio_get_ex(b, BIO_C_GET_PREFIX, pprefix, pprefix_free);
 }
 
-int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free)
+int
+BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free)
 {
        return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free);
 }
 
-int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free)
+int
+BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free)
 {
        return asn1_bio_get_ex(b, BIO_C_GET_SUFFIX, psuffix, psuffix_free);
 }
index 595e647..f00d38e 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
@@ -78,8 +78,7 @@
 
 /* BIO support data stored in the ASN1 BIO ex_arg */
 
-typedef struct ndef_aux_st
-{
+typedef struct ndef_aux_st {
        /* ASN1 structure this BIO refers to */
        ASN1_VALUE *val;
        const ASN1_ITEM *it;
@@ -98,7 +97,8 @@ static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
 static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg);
 static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg);
 
-BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
+BIO *
+BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
 {
        NDEF_SUPPORT *ndef_aux = NULL;
        BIO *asn_bio = NULL;
@@ -143,7 +143,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
 
        return sarg.ndef_bio;
 
-       err:
+err:
        if (asn_bio)
                BIO_free(asn_bio);
        if (ndef_aux)
@@ -151,7 +151,8 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
        return NULL;
 }
 
-static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+static int
+ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
 {
        NDEF_SUPPORT *ndef_aux;
        unsigned char *p;
@@ -176,7 +177,8 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
        return 1;
 }
 
-static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+static int
+ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
 {
        NDEF_SUPPORT *ndef_aux;
 
@@ -194,7 +196,8 @@ static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
        return 1;
 }
 
-static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+static int
+ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
 {
        NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg;
        if (!ndef_prefix_free(b, pbuf, plen, parg))
@@ -204,7 +207,8 @@ static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
        return 1;
 }
 
-static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
+static int
+ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
 {
        NDEF_SUPPORT *ndef_aux;
        unsigned char *p;
@@ -224,7 +228,7 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
        sarg.out = ndef_aux->out;
        sarg.boundary = ndef_aux->boundary;
        if (aux->asn1_cb(ASN1_OP_STREAM_POST,
-                               &ndef_aux->val, ndef_aux->it, &sarg) <= 0)
+           &ndef_aux->val, ndef_aux->it, &sarg) <= 0)
                return 0;
 
        derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
index b55e638..acab65b 100644 (file)
@@ -3,13 +3,12 @@
  */
 
 static const unsigned char char_type[] = {
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-120, 0, 1,40, 0, 0, 0,16,16,16, 0,25,25,16,16,16,
-16,16,16,16,16,16,16,16,16,16,16, 9, 9,16, 9,16,
0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
-16,16,16,16,16,16,16,16,16,16,16, 0, 1, 0, 0, 0,
0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
-16,16,16,16,16,16,16,16,16,16,16, 0, 0, 0, 0, 2
      2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+       120, 0, 1, 40, 0, 0, 0, 16, 16, 16, 0, 25, 25, 16, 16, 16,
+       16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 9, 9, 16, 9, 16,
      0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+       16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 1, 0, 0, 0,
      0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+       16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 2
 };
-