New option to CA.pl to sign request using CA extensions.
[openssl.git] / crypto / asn1 / a_strex.c
index 02fe2bad1c90e40b515d0d1f1c0803ecd645f42e..af77b0919493f13d84689b3b9ec51dae475dae06 100644 (file)
@@ -509,3 +509,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;
+}