X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fasn1%2Fa_strex.c;h=569b811998584a8612e8ea5040d4ec96407d5581;hp=ef225be06a8c517e09f73373397a5c6d31cd4beb;hb=0baed24c1b2d9a1e53d9f81cf805ac65d68096b3;hpb=a657546f9c376f4b7ba4dce14649598fb1a38de5;ds=sidebyside diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c index ef225be06a..569b811998 100644 --- a/crypto/asn1/a_strex.c +++ b/crypto/asn1/a_strex.c @@ -57,6 +57,7 @@ */ #include +#include #include #include #include @@ -96,7 +97,7 @@ int send_bio_chars(void *arg, const void *buf, int len) int send_fp_chars(void *arg, const void *buf, int len) { if(!arg) return 1; - if(fwrite(buf, 1, len, arg) != len) return 0; + if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0; return 1; } @@ -123,7 +124,7 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, ch if(!io_ch(arg, tmphex, 6)) return -1; return 6; } - chtmp = c; + chtmp = (unsigned char)c; if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB; else chflgs = char_type[chtmp] & flags; if(chflgs & CHARTYPE_BS_ESC) { @@ -200,12 +201,12 @@ static int do_buf(unsigned char *buf, int buflen, * otherwise each character will be > 0x7f and so the * character will never be escaped on first and last. */ - len = do_esc_char(utfbuf[i], flags | orflags, quotes, io_ch, arg); + 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, flags | orflags, quotes, io_ch, arg); + len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg); if(len < 0) return -1; outlen += len; } @@ -304,14 +305,14 @@ static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STR unsigned char flags; quotes = 0; /* Keep a copy of escape flags */ - flags = lflags & ESC_FLAGS; + flags = (unsigned char)(lflags & ESC_FLAGS); type = str->type; outlen = 0; - if(lflags & ASN1_STRFLGS_SHOW_NAME) { + if(lflags & ASN1_STRFLGS_SHOW_TYPE) { const char *tagname; tagname = ASN1_tag2str(type); outlen += strlen(tagname); @@ -392,8 +393,8 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, case XN_FLAG_SEP_MULTILINE: sep_dn = "\n"; sep_dn_len = 1; - sep_mv = "+"; - sep_mv_len = 1; + sep_mv = " + "; + sep_mv_len = 3; break; case XN_FLAG_SEP_COMMA_PLUS: @@ -446,9 +447,9 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, } else { if(!io_ch(arg, sep_dn, sep_dn_len)) return -1; outlen += sep_dn_len; + if(!do_indent(io_ch, arg, indent)) return -1; + outlen += indent; } - if(!do_indent(io_ch, arg, indent)) return -1; - outlen += indent; } prev = ent->set; fn = X509_NAME_ENTRY_get_object(ent); @@ -509,3 +510,24 @@ int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) { return do_print_ex(send_fp_chars, fp, flags, str); } + +/* Utility function: convert any string type to UTF8, returns number of bytes + * in output string or a negative error code + */ + +int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) +{ + ASN1_STRING stmp, *str = &stmp; + int mbflag, type, ret; + if(!*out || !in) return -1; + type = in->type; + if((type < 0) || (type > 30)) return -1; + mbflag = tag2nbyte[type]; + if(mbflag == -1) return -1; + mbflag |= MBSTRING_FLAG; + stmp.data = NULL; + ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); + if(ret < 0) return ret; + if(out) *out = stmp.data; + return stmp.length; +}