X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fasn1%2Fa_strex.c;h=569b811998584a8612e8ea5040d4ec96407d5581;hp=02fe2bad1c90e40b515d0d1f1c0803ecd645f42e;hb=0baed24c1b2d9a1e53d9f81cf805ac65d68096b3;hpb=469938cb4012472d3d99ed7ead258aef3a5bc029 diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c index 02fe2bad1c..569b811998 100644 --- a/crypto/asn1/a_strex.c +++ b/crypto/asn1/a_strex.c @@ -57,6 +57,7 @@ */ #include +#include #include #include #include @@ -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; +}