diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2014-04-19 13:11:42 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2014-04-19 13:11:42 +0000 |
commit | 015b5c63bcf54cbd889ca25ea91971bed4fc8d79 (patch) | |
tree | 83eadfad3429210908268ddcce9bf728467ddd11 | |
parent | 909e9fded6a128ec1e663dd7ba9e5e516e37da60 (diff) |
More KNF.
-rw-r--r-- | lib/libssl/src/crypto/asn1/a_set.c | 19 | ||||
-rw-r--r-- | lib/libssl/src/crypto/asn1/a_sign.c | 96 | ||||
-rw-r--r-- | lib/libssl/src/crypto/asn1/a_strex.c | 350 | ||||
-rw-r--r-- | lib/libssl/src/crypto/asn1/a_strnid.c | 175 |
4 files changed, 379 insertions, 261 deletions
diff --git a/lib/libssl/src/crypto/asn1/a_set.c b/lib/libssl/src/crypto/asn1/a_set.c index 8a979848935..3aeb7e54fff 100644 --- a/lib/libssl/src/crypto/asn1/a_set.c +++ b/lib/libssl/src/crypto/asn1/a_set.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. - * + * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from + * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -104,7 +104,7 @@ i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp, i2d_of_void *i2d, if (pp == NULL) return r; - p= *pp; + p = *pp; ASN1_put_object(&p, 1, ret, ex_tag, ex_class); /* Modified by gp@nsj.co.jp */ @@ -179,7 +179,7 @@ d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length, } else ret = *a; - c.p= *pp; + c.p = *pp; c.max = (length == 0) ? 0 : (c.p + length); c.inf = ASN1_get_object(&c.p, &c.slen, &c.tag, &c.xclass, c.max - c.p); @@ -216,13 +216,14 @@ d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length, asn1_add_error(*pp, (int)(c.p - *pp)); goto err; } - if (!sk_OPENSSL_BLOCK_push(ret,s)) + if (!sk_OPENSSL_BLOCK_push(ret, s)) goto err; } if (a != NULL) *a = ret; *pp = c.p; return ret; + err: if (ret != NULL && (a == NULL || *a != ret)) { if (free_func != NULL) diff --git a/lib/libssl/src/crypto/asn1/a_sign.c b/lib/libssl/src/crypto/asn1/a_sign.c index 046f3b4a99a..40c68096696 100644 --- a/lib/libssl/src/crypto/asn1/a_sign.c +++ b/lib/libssl/src/crypto/asn1/a_sign.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. - * + * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from + * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -63,7 +63,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 @@ -125,9 +125,9 @@ #include <openssl/buffer.h> #include "asn1_locl.h" -int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, - ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, - const EVP_MD *type) +int +ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, + ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, const EVP_MD *type) { EVP_MD_CTX ctx; EVP_MD_CTX_init(&ctx); @@ -137,16 +137,16 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, } return ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, &ctx); } - -int ASN1_item_sign_ctx(const ASN1_ITEM *it, - X509_ALGOR *algor1, X509_ALGOR *algor2, - ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) + +int +ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, + ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) { const EVP_MD *type; EVP_PKEY *pkey; - unsigned char *buf_in=NULL,*buf_out=NULL; - size_t inl=0,outl=0,outll=0; + unsigned char *buf_in = NULL, *buf_out = NULL; + size_t inl = 0, outl = 0, outll = 0; int signid, paramtype; int rv; @@ -154,13 +154,14 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); if (!type || !pkey) { - ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED); + ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, + ASN1_R_CONTEXT_NOT_INITIALISED); return 0; } if (pkey->ameth->item_sign) { rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, - signature); + signature); if (rv == 1) outl = signature->length; /* Return value meanings: @@ -173,22 +174,19 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); if (rv <= 1) goto err; - } - else + } else rv = 2; if (rv == 2) { if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { if (!pkey->ameth || - !OBJ_find_sigid_by_algs(&signid, - EVP_MD_nid(type), - pkey->ameth->pkey_id)) { + !OBJ_find_sigid_by_algs(&signid, + EVP_MD_nid(type), pkey->ameth->pkey_id)) { ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, - ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); + ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); return 0; } - } - else + } else signid = type->pkey_type; if (pkey->ameth->pkey_flags & ASN1_PKEY_SIGPARAM_NULL) @@ -197,43 +195,49 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, paramtype = V_ASN1_UNDEF; if (algor1) - X509_ALGOR_set0(algor1, OBJ_nid2obj(signid), paramtype, NULL); + X509_ALGOR_set0(algor1, + OBJ_nid2obj(signid), paramtype, NULL); if (algor2) - X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, NULL); + X509_ALGOR_set0(algor2, + OBJ_nid2obj(signid), paramtype, NULL); } - inl=ASN1_item_i2d(asn,&buf_in, it); - outll=outl=EVP_PKEY_size(pkey); - buf_out=malloc((unsigned int)outl); + inl = ASN1_item_i2d(asn, &buf_in, it); + outll = outl = EVP_PKEY_size(pkey); + buf_out = malloc((unsigned int)outl); if ((buf_in == NULL) || (buf_out == NULL)) { - outl=0; - ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE); + outl = 0; + ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_MALLOC_FAILURE); goto err; } - if (!EVP_DigestSignUpdate(ctx, buf_in, inl) - || !EVP_DigestSignFinal(ctx, buf_out, &outl)) { - outl=0; - ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB); + if (!EVP_DigestSignUpdate(ctx, buf_in, inl) || + !EVP_DigestSignFinal(ctx, buf_out, &outl)) { + outl = 0; + ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); goto err; } - if (signature->data != NULL) free(signature->data); - signature->data=buf_out; - buf_out=NULL; - signature->length=outl; + if (signature->data != NULL) + free(signature->data); + signature->data = buf_out; + buf_out = NULL; + signature->length = outl; /* In the interests of compatibility, I'll make sure that * the bit string has a 'not-used bits' value of 0 */ - signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); - signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; + signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); + signature->flags |= ASN1_STRING_FLAG_BITS_LEFT; + err: EVP_MD_CTX_cleanup(ctx); if (buf_in != NULL) { - OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); + OPENSSL_cleanse((char *)buf_in, (unsigned int)inl); + free(buf_in); } if (buf_out != NULL) { - OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); + OPENSSL_cleanse((char *)buf_out, outll); + free(buf_out); } - return(outl); + return (outl); } diff --git a/lib/libssl/src/crypto/asn1/a_strex.c b/lib/libssl/src/crypto/asn1/a_strex.c index e92c1663038..248eac28f6a 100644 --- a/lib/libssl/src/crypto/asn1/a_strex.c +++ b/lib/libssl/src/crypto/asn1/a_strex.c @@ -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 @@ -71,7 +71,6 @@ * options. */ - #define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253) #define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \ @@ -84,27 +83,36 @@ * and a FILE pointer. */ #if 0 /* never used */ -static int send_mem_chars(void *arg, const void *buf, int len) +static int +send_mem_chars(void *arg, const void *buf, int len) { unsigned char **out = arg; - if(!out) return 1; + + if (!out) + return 1; memcpy(*out, buf, len); *out += len; return 1; } #endif -static int send_bio_chars(void *arg, const void *buf, int len) +static int +send_bio_chars(void *arg, const void *buf, int len) { - if(!arg) return 1; - if(BIO_write(arg, buf, len) != len) return 0; + if (!arg) + return 1; + if (BIO_write(arg, buf, len) != len) + return 0; return 1; } -static int send_fp_chars(void *arg, const void *buf, int len) +static int +send_fp_chars(void *arg, const void *buf, int len) { - if(!arg) return 1; - if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0; + if (!arg) + return 1; + if (fwrite(buf, 1, len, arg) != (unsigned int)len) + return 0; return 1; } @@ -117,50 +125,63 @@ typedef int char_io(void *arg, const void *buf, int len); * 4 byte forms. */ -static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg) +static int +do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, + char_io *io_ch, void *arg) { unsigned char chflgs, chtmp; - char tmphex[HEX_SIZE(long)+3]; + char tmphex[HEX_SIZE(long) + 3]; - if(c > 0xffffffffL) + if (c > 0xffffffffL) return -1; - if(c > 0xffff) { + if (c > 0xffff) { snprintf(tmphex, sizeof tmphex, "\\W%08lX", c); - if(!io_ch(arg, tmphex, 10)) return -1; + if (!io_ch(arg, tmphex, 10)) + return -1; return 10; } - if(c > 0xff) { + if (c > 0xff) { snprintf(tmphex, sizeof tmphex, "\\U%04lX", c); - if(!io_ch(arg, tmphex, 6)) return -1; + if (!io_ch(arg, tmphex, 6)) + return -1; return 6; } chtmp = (unsigned char)c; - if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB; - else chflgs = char_type[chtmp] & flags; - if(chflgs & CHARTYPE_BS_ESC) { + if (chtmp > 0x7f) + chflgs = flags & ASN1_STRFLGS_ESC_MSB; + else + chflgs = char_type[chtmp] & flags; + if (chflgs & CHARTYPE_BS_ESC) { /* If we don't escape with quotes, signal we need quotes */ - if(chflgs & ASN1_STRFLGS_ESC_QUOTE) { - if(do_quotes) *do_quotes = 1; - if(!io_ch(arg, &chtmp, 1)) return -1; + if (chflgs & ASN1_STRFLGS_ESC_QUOTE) { + if (do_quotes) + *do_quotes = 1; + if (!io_ch(arg, &chtmp, 1)) + return -1; return 1; } - if(!io_ch(arg, "\\", 1)) return -1; - if(!io_ch(arg, &chtmp, 1)) return -1; + if (!io_ch(arg, "\\", 1)) + return -1; + if (!io_ch(arg, &chtmp, 1)) + return -1; return 2; } - if(chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) { + if (chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) { snprintf(tmphex, sizeof tmphex, "\\%02X", chtmp); - if(!io_ch(arg, tmphex, 3)) return -1; + if (!io_ch(arg, tmphex, 3)) + return -1; return 3; } - /* If we get this far and do any escaping at all must escape + /* If we get this far and do any escaping at all must escape * the escape character itself: backslash. */ if (chtmp == '\\' && flags & ESC_FLAGS) { - if(!io_ch(arg, "\\\\", 2)) return -1; + if (!io_ch(arg, "\\\\", 2)) + return -1; return 2; } - if(!io_ch(arg, &chtmp, 1)) return -1; + if (!io_ch(arg, &chtmp, 1)) + return -1; return 1; } @@ -172,61 +193,72 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, ch * and converts to or from UTF8 as appropriate. */ -static int do_buf(unsigned char *buf, int buflen, - int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg) +static int +do_buf(unsigned char *buf, int buflen, int type, unsigned char flags, + char *quotes, char_io *io_ch, void *arg) { int i, outlen, len; unsigned char orflags, *p, *q; unsigned long c; + p = buf; q = buf + buflen; outlen = 0; - while(p != q) { - if(p == buf && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_FIRST_ESC_2253; - else orflags = 0; - switch(type & BUF_TYPE_WIDTH_MASK) { - case 4: + while (p != q) { + if (p == buf && flags & ASN1_STRFLGS_ESC_2253) + orflags = CHARTYPE_FIRST_ESC_2253; + else + orflags = 0; + switch (type & BUF_TYPE_WIDTH_MASK) { + case 4: c = ((unsigned long)*p++) << 24; c |= ((unsigned long)*p++) << 16; c |= ((unsigned long)*p++) << 8; c |= *p++; break; - case 2: + case 2: c = ((unsigned long)*p++) << 8; c |= *p++; break; - case 1: + case 1: c = *p++; break; - - case 0: + + case 0: i = UTF8_getc(p, buflen, &c); - if(i < 0) return -1; /* Invalid UTF8String */ + if (i < 0) + return -1; /* Invalid UTF8String */ p += i; break; - default: - return -1; /* invalid width */ + default: + return -1; /* invalid width */ } - if (p == q && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_LAST_ESC_2253; - if(type & BUF_TYPE_CONVUTF8) { + if (p == q && flags & ASN1_STRFLGS_ESC_2253) + orflags = CHARTYPE_LAST_ESC_2253; + if (type & BUF_TYPE_CONVUTF8) { unsigned char utfbuf[6]; int utflen; utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); - for(i = 0; i < utflen; i++) { + for (i = 0; i < utflen; i++) { /* We don't need to worry about setting orflags correctly - * because if utflen==1 its value will be correct anyway - * otherwise each character will be > 0x7f and so the + * because if utflen==1 its value will be correct anyway + * otherwise each character will be > 0x7f and so the * character will never be escaped on first and last. */ - len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg); - if(len < 0) return -1; + len = do_esc_char(utfbuf[i], + (unsigned char)(flags | orflags), quotes, + io_ch, arg); + if (len < 0) + return -1; outlen += len; } } else { - len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg); - if(len < 0) return -1; + len = do_esc_char(c, (unsigned char)(flags | orflags), + quotes, io_ch, arg); + if (len < 0) + return -1; outlen += len; } } @@ -235,18 +267,20 @@ static int do_buf(unsigned char *buf, int buflen, /* This function hex dumps a buffer of characters */ -static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) +static int +do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) { static const char hexdig[] = "0123456789ABCDEF"; unsigned char *p, *q; char hextmp[2]; - if(arg) { + if (arg) { p = buf; q = buf + buflen; - while(p != q) { + while (p != q) { hextmp[0] = hexdig[*p >> 4]; hextmp[1] = hexdig[*p & 0xf]; - if(!io_ch(arg, hextmp, 2)) return -1; + if (!io_ch(arg, hextmp, 2)) + return -1; p++; } } @@ -259,7 +293,8 @@ static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen * #01234 format. */ -static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) +static int +do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) { /* Placing the ASN1_STRING in a temp ASN1_TYPE allows * the DER encoding to readily obtained @@ -268,23 +303,27 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING unsigned char *der_buf, *p; int outlen, der_len; - if(!io_ch(arg, "#", 1)) return -1; + if (!io_ch(arg, "#", 1)) + return -1; /* If we don't dump DER encoding just dump content octets */ - if(!(lflags & ASN1_STRFLGS_DUMP_DER)) { + if (!(lflags & ASN1_STRFLGS_DUMP_DER)) { outlen = do_hex_dump(io_ch, arg, str->data, str->length); - if(outlen < 0) return -1; + if (outlen < 0) + return -1; return outlen + 1; } t.type = str->type; t.value.ptr = (char *)str; der_len = i2d_ASN1_TYPE(&t, NULL); der_buf = malloc(der_len); - if(!der_buf) return -1; + if (!der_buf) + return -1; p = der_buf; i2d_ASN1_TYPE(&t, &p); outlen = do_hex_dump(io_ch, arg, der_buf, der_len); free(der_buf); - if(outlen < 0) return -1; + if (outlen < 0) + return -1; return outlen + 1; } @@ -311,86 +350,102 @@ static const signed char tag2nbyte[] = { * occurred. */ -static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str) +static int +do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str) { int outlen, len; int type; char quotes; unsigned char flags; + quotes = 0; /* Keep a copy of escape flags */ flags = (unsigned char)(lflags & ESC_FLAGS); - type = str->type; - outlen = 0; - - if(lflags & ASN1_STRFLGS_SHOW_TYPE) { + if (lflags & ASN1_STRFLGS_SHOW_TYPE) { const char *tagname; tagname = ASN1_tag2str(type); outlen += strlen(tagname); - if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1; + if (!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) + return -1; outlen++; } /* Decide what to do with type, either dump content or display it */ /* Dump everything */ - if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1; + if (lflags & ASN1_STRFLGS_DUMP_ALL) + type = -1; /* Ignore the string type */ - else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1; + else if (lflags & ASN1_STRFLGS_IGNORE_TYPE) + type = 1; else { /* Else determine width based on type */ - if((type > 0) && (type < 31)) type = tag2nbyte[type]; - else type = -1; - if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1; + if ((type > 0) && (type < 31)) + type = tag2nbyte[type]; + else + type = -1; + if ((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) + type = 1; } - if(type == -1) { + if (type == -1) { len = do_dump(lflags, io_ch, arg, str); - if(len < 0) return -1; + if (len < 0) + return -1; outlen += len; return outlen; } - if(lflags & ASN1_STRFLGS_UTF8_CONVERT) { + if (lflags & ASN1_STRFLGS_UTF8_CONVERT) { /* Note: if string is UTF8 and we want * to convert to UTF8 then we just interpret * it as 1 byte per character to avoid converting * twice. */ - if(!type) type = 1; - else type |= BUF_TYPE_CONVUTF8; + if (!type) + type = 1; + else + type |= BUF_TYPE_CONVUTF8; } len = do_buf(str->data, str->length, type, flags, "es, io_ch, NULL); - if(len < 0) return -1; + if (len < 0) + return -1; outlen += len; - if(quotes) outlen += 2; - if(!arg) return outlen; - if(quotes && !io_ch(arg, "\"", 1)) return -1; - if(do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0) + if (quotes) + outlen += 2; + if (!arg) + return outlen; + if (quotes && !io_ch(arg, "\"", 1)) + return -1; + if (do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0) + return -1; + if (quotes && !io_ch(arg, "\"", 1)) return -1; - if(quotes && !io_ch(arg, "\"", 1)) return -1; return outlen; } /* Used for line indenting: print 'indent' spaces */ -static int do_indent(char_io *io_ch, void *arg, int indent) +static int +do_indent(char_io *io_ch, void *arg, int indent) { int i; - for(i = 0; i < indent; i++) - if(!io_ch(arg, " ", 1)) return 0; + for (i = 0; i < indent; i++) + if (!io_ch(arg, " ", 1)) + return 0; return 1; } #define FN_WIDTH_LN 25 #define FN_WIDTH_SN 10 -static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, - int indent, unsigned long flags) +static int +do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, int indent, + unsigned long flags) { int i, prev = -1, orflags, cnt; int fn_opt, fn_nid; @@ -402,18 +457,22 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, int outlen, len; char *sep_dn, *sep_mv, *sep_eq; int sep_dn_len, sep_mv_len, sep_eq_len; - if(indent < 0) indent = 0; + + if (indent < 0) + indent = 0; outlen = indent; - if(!do_indent(io_ch, arg, indent)) return -1; + if (!do_indent(io_ch, arg, indent)) + return -1; + switch (flags & XN_FLAG_SEP_MASK) { - case XN_FLAG_SEP_MULTILINE: + case XN_FLAG_SEP_MULTILINE: sep_dn = "\n"; sep_dn_len = 1; sep_mv = " + "; sep_mv_len = 3; break; - case XN_FLAG_SEP_COMMA_PLUS: + case XN_FLAG_SEP_COMMA_PLUS: sep_dn = ","; sep_dn_len = 1; sep_mv = "+"; @@ -421,7 +480,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, indent = 0; break; - case XN_FLAG_SEP_CPLUS_SPC: + case XN_FLAG_SEP_CPLUS_SPC: sep_dn = ", "; sep_dn_len = 2; sep_mv = " + "; @@ -429,7 +488,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, indent = 0; break; - case XN_FLAG_SEP_SPLUS_SPC: + case XN_FLAG_SEP_SPLUS_SPC: sep_dn = "; "; sep_dn_len = 2; sep_mv = " + "; @@ -437,11 +496,11 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, indent = 0; break; - default: + default: return -1; } - if(flags & XN_FLAG_SPC_EQ) { + if (flags & XN_FLAG_SPC_EQ) { sep_eq = " = "; sep_eq_len = 3; } else { @@ -451,19 +510,23 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, fn_opt = flags & XN_FLAG_FN_MASK; - cnt = X509_NAME_entry_count(n); - for(i = 0; i < cnt; i++) { - if(flags & XN_FLAG_DN_REV) - ent = X509_NAME_get_entry(n, cnt - i - 1); - else ent = X509_NAME_get_entry(n, i); - if(prev != -1) { - if(prev == ent->set) { - if(!io_ch(arg, sep_mv, sep_mv_len)) return -1; + cnt = X509_NAME_entry_count(n); + for (i = 0; i < cnt; i++) { + if (flags & XN_FLAG_DN_REV) + ent = X509_NAME_get_entry(n, cnt - i - 1); + else + ent = X509_NAME_get_entry(n, i); + if (prev != -1) { + if (prev == ent->set) { + if (!io_ch(arg, sep_mv, sep_mv_len)) + return -1; outlen += sep_mv_len; } else { - if(!io_ch(arg, sep_dn, sep_dn_len)) return -1; + if (!io_ch(arg, sep_dn, sep_dn_len)) + return -1; outlen += sep_dn_len; - if(!do_indent(io_ch, arg, indent)) return -1; + if (!do_indent(io_ch, arg, indent)) + return -1; outlen += indent; } } @@ -471,17 +534,18 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, fn = X509_NAME_ENTRY_get_object(ent); val = X509_NAME_ENTRY_get_data(ent); fn_nid = OBJ_obj2nid(fn); - if(fn_opt != XN_FLAG_FN_NONE) { + if (fn_opt != XN_FLAG_FN_NONE) { int objlen, fld_len; - if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) { + if ((fn_opt == XN_FLAG_FN_OID) || + (fn_nid == NID_undef)) { OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1); fld_len = 0; /* XXX: what should this be? */ objbuf = objtmp; } else { - if(fn_opt == XN_FLAG_FN_SN) { + if (fn_opt == XN_FLAG_FN_SN) { fld_len = FN_WIDTH_SN; objbuf = OBJ_nid2sn(fn_nid); - } else if(fn_opt == XN_FLAG_FN_LN) { + } else if (fn_opt == XN_FLAG_FN_LN) { fld_len = FN_WIDTH_LN; objbuf = OBJ_nid2ln(fn_nid); } else { @@ -490,24 +554,30 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, } } objlen = strlen(objbuf); - if(!io_ch(arg, objbuf, objlen)) return -1; + if (!io_ch(arg, objbuf, objlen)) + return -1; if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) { - if (!do_indent(io_ch, arg, fld_len - objlen)) return -1; + if (!do_indent(io_ch, arg, fld_len - objlen)) + return -1; outlen += fld_len - objlen; } - if(!io_ch(arg, sep_eq, sep_eq_len)) return -1; + if (!io_ch(arg, sep_eq, sep_eq_len)) + return -1; outlen += objlen + sep_eq_len; } /* If the field name is unknown then fix up the DER dump * flag. We might want to limit this further so it will * DER dump on anything other than a few 'standard' fields. */ - if((fn_nid == NID_undef) && (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS)) - orflags = ASN1_STRFLGS_DUMP_ALL; - else orflags = 0; - + if ((fn_nid == NID_undef) && + (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS)) + orflags = ASN1_STRFLGS_DUMP_ALL; + else + orflags = 0; + len = do_print_ex(io_ch, arg, flags | orflags, val); - if(len < 0) return -1; + if (len < 0) + return -1; outlen += len; } return outlen; @@ -515,36 +585,41 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, /* Wrappers round the main functions */ -int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) +int +X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) { - if(flags == XN_FLAG_COMPAT) + if (flags == XN_FLAG_COMPAT) return X509_NAME_print(out, nm, indent); return do_name_ex(send_bio_chars, out, nm, indent, flags); } #ifndef OPENSSL_NO_FP_API -int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) +int +X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) { - if(flags == XN_FLAG_COMPAT) { + if (flags == XN_FLAG_COMPAT) { BIO *btmp; int ret; btmp = BIO_new_fp(fp, BIO_NOCLOSE); - if(!btmp) return -1; + if (!btmp) + return -1; ret = X509_NAME_print(btmp, nm, indent); BIO_free(btmp); return ret; - } + } return do_name_ex(send_fp_chars, fp, nm, indent, flags); } #endif -int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) +int +ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) { return do_print_ex(send_bio_chars, out, flags, str); } #ifndef OPENSSL_NO_FP_API -int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) +int +ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) { return do_print_ex(send_fp_chars, fp, flags, str); } @@ -554,20 +629,27 @@ int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) * in output string or a negative error code */ -int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) +int +ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) { ASN1_STRING stmp, *str = &stmp; int mbflag, type, ret; - if(!in) return -1; + + if (!in) + return -1; type = in->type; - if((type < 0) || (type > 30)) return -1; + if ((type < 0) || (type > 30)) + return -1; mbflag = tag2nbyte[type]; - if(mbflag == -1) return -1; + if (mbflag == -1) + return -1; mbflag |= MBSTRING_FLAG; stmp.data = NULL; stmp.length = 0; - ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); - if(ret < 0) return ret; + ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, + B_ASN1_UTF8STRING); + if (ret < 0) + return ret; *out = stmp.data; return stmp.length; } diff --git a/lib/libssl/src/crypto/asn1/a_strnid.c b/lib/libssl/src/crypto/asn1/a_strnid.c index 6c59dcc8ec6..d1b804aec12 100644 --- a/lib/libssl/src/crypto/asn1/a_strnid.c +++ b/lib/libssl/src/crypto/asn1/a_strnid.c @@ -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 @@ -66,7 +66,7 @@ static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; static void st_free(ASN1_STRING_TABLE *tbl); static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, - const ASN1_STRING_TABLE * const *b); + const ASN1_STRING_TABLE * const *b); /* This is the global mask for the mbstring functions: this is use to @@ -76,12 +76,14 @@ static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, static unsigned long global_mask = 0xFFFFFFFFL; -void ASN1_STRING_set_default_mask(unsigned long mask) +void +ASN1_STRING_set_default_mask(unsigned long mask) { global_mask = mask; } -unsigned long ASN1_STRING_get_default_mask(void) +unsigned long +ASN1_STRING_get_default_mask(void) { return global_mask; } @@ -95,47 +97,59 @@ unsigned long ASN1_STRING_get_default_mask(void) * default: the default value, Printable, T61, BMP. */ -int ASN1_STRING_set_default_mask_asc(const char *p) +int +ASN1_STRING_set_default_mask_asc(const char *p) { unsigned long mask; char *end; - if(!strncmp(p, "MASK:", 5)) { - if(!p[5]) return 0; + + if (!strncmp(p, "MASK:", 5)) { + if (!p[5]) + return 0; mask = strtoul(p + 5, &end, 0); - if(*end) return 0; - } else if(!strcmp(p, "nombstr")) - mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)); - else if(!strcmp(p, "pkix")) - mask = ~((unsigned long)B_ASN1_T61STRING); - else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING; - else if(!strcmp(p, "default")) - mask = 0xFFFFFFFFL; - else return 0; + if (*end) + return 0; + } else if (!strcmp(p, "nombstr")) + mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)); + else if (!strcmp(p, "pkix")) + mask = ~((unsigned long)B_ASN1_T61STRING); + else if (!strcmp(p, "utf8only")) + mask = B_ASN1_UTF8STRING; + else if (!strcmp(p, "default")) + mask = 0xFFFFFFFFL; + else + return 0; ASN1_STRING_set_default_mask(mask); return 1; } /* The following function generates an ASN1_STRING based on limits in a table. - * Frequently the types and length of an ASN1_STRING are restricted by a + * Frequently the types and length of an ASN1_STRING are restricted by a * corresponding OID. For example certificates and certificate requests. */ -ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, - int inlen, int inform, int nid) +ASN1_STRING * +ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, int inlen, + int inform, int nid) { ASN1_STRING_TABLE *tbl; ASN1_STRING *str = NULL; unsigned long mask; int ret; - if(!out) out = &str; + if (!out) + out = &str; tbl = ASN1_STRING_TABLE_get(nid); - if(tbl) { + if (tbl) { mask = tbl->mask; - if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask; + if (!(tbl->flags & STABLE_NO_MASK)) + mask &= global_mask; ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask, - tbl->minsize, tbl->maxsize); - } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask); - if(ret <= 0) return NULL; + tbl->minsize, tbl->maxsize); + } else + ret = ASN1_mbstring_copy(out, in, inlen, inform, + DIRSTRING_TYPE & global_mask); + if (ret <= 0) + return NULL; return *out; } @@ -158,99 +172,116 @@ ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, /* This table must be kept in NID order */ static const ASN1_STRING_TABLE tbl_standard[] = { -{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0}, -{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, -{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0}, -{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0}, -{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0}, -{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0}, -{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK}, -{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0}, -{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0}, -{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0}, -{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0}, -{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0}, -{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0}, -{NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, -{NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, -{NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, -{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, -{NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, -{NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} + {NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0}, + {NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, + {NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0}, + {NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0}, + {NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0}, + {NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0}, + {NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK}, + {NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0}, + {NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0}, + {NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0}, + {NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0}, + {NID_surname, 1, ub_name, DIRSTRING_TYPE, 0}, + {NID_initials, 1, ub_name, DIRSTRING_TYPE, 0}, + {NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, + {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, + {NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, + {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, + {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, + {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} }; -static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, - const ASN1_STRING_TABLE * const *b) +static int +sk_table_cmp(const ASN1_STRING_TABLE * const *a, + const ASN1_STRING_TABLE * const *b) { return (*a)->nid - (*b)->nid; } DECLARE_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table); -static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) +static int +table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) { return a->nid - b->nid; } IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table); -ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid) +ASN1_STRING_TABLE * +ASN1_STRING_TABLE_get(int nid) { int idx; ASN1_STRING_TABLE *ttmp; ASN1_STRING_TABLE fnd; + fnd.nid = nid; - ttmp = OBJ_bsearch_table(&fnd, tbl_standard, - sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE)); - if(ttmp) return ttmp; - if(!stable) return NULL; + ttmp = OBJ_bsearch_table(&fnd, tbl_standard, + sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE)); + if (ttmp) + return ttmp; + if (!stable) + return NULL; idx = sk_ASN1_STRING_TABLE_find(stable, &fnd); - if(idx < 0) return NULL; + if (idx < 0) + return NULL; return sk_ASN1_STRING_TABLE_value(stable, idx); } - -int ASN1_STRING_TABLE_add(int nid, - long minsize, long maxsize, unsigned long mask, - unsigned long flags) + +int +ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize, unsigned long mask, + unsigned long flags) { ASN1_STRING_TABLE *tmp; char new_nid = 0; + flags &= ~STABLE_FLAGS_MALLOC; - if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); - if(!stable) { + if (!stable) + stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); + if (!stable) { ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); return 0; } - if(!(tmp = ASN1_STRING_TABLE_get(nid))) { + if (!(tmp = ASN1_STRING_TABLE_get(nid))) { tmp = malloc(sizeof(ASN1_STRING_TABLE)); - if(!tmp) { + if (!tmp) { ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, - ERR_R_MALLOC_FAILURE); + ERR_R_MALLOC_FAILURE); return 0; } tmp->flags = flags | STABLE_FLAGS_MALLOC; tmp->nid = nid; new_nid = 1; } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags; - if(minsize != -1) tmp->minsize = minsize; - if(maxsize != -1) tmp->maxsize = maxsize; + if (minsize != -1) + tmp->minsize = minsize; + if (maxsize != -1) + tmp->maxsize = maxsize; tmp->mask = mask; - if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp); + if (new_nid) + sk_ASN1_STRING_TABLE_push(stable, tmp); return 1; } -void ASN1_STRING_TABLE_cleanup(void) +void +ASN1_STRING_TABLE_cleanup(void) { STACK_OF(ASN1_STRING_TABLE) *tmp; + tmp = stable; - if(!tmp) return; + if (!tmp) + return; stable = NULL; sk_ASN1_STRING_TABLE_pop_free(tmp, st_free); } -static void st_free(ASN1_STRING_TABLE *tbl) +static void +st_free(ASN1_STRING_TABLE *tbl) { - if(tbl->flags & STABLE_FLAGS_MALLOC) free(tbl); + if (tbl->flags & STABLE_FLAGS_MALLOC) + free(tbl); } @@ -264,7 +295,7 @@ main() int i, last_nid = -1; for (tmp = tbl_standard, i = 0; - i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { + i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) { if (tmp->nid < last_nid) { last_nid = 0; break; @@ -278,9 +309,9 @@ main() } for (tmp = tbl_standard, i = 0; - i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { + i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) { printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, - OBJ_nid2ln(tmp->nid)); + OBJ_nid2ln(tmp->nid)); } } |