Addapt seldom compiled code to new semantics of the key schedule (not
[openssl.git] / crypto / asn1 / a_strex.c
index af77b0919493f13d84689b3b9ec51dae475dae06..128aa7e772c0091eebd35d296d13e3a84cfe0693 100644 (file)
@@ -57,6 +57,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <openssl/crypto.h>
 #include <openssl/x509.h>
 #include <openssl/asn1.h>
@@ -370,6 +371,8 @@ static int do_indent(char_io *io_ch, void *arg, int indent)
        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)
@@ -455,19 +458,29 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
                val = X509_NAME_ENTRY_get_data(ent);
                fn_nid = OBJ_obj2nid(fn);
                if(fn_opt != XN_FLAG_FN_NONE) {
-                       int objlen;
+                       int objlen, fld_len;
                        if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) {
                                OBJ_obj2txt(objtmp, 80, 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 objbuf = "";
+                               } else {
+                                       fld_len = 0; /* XXX: what should this be? */
+                                       objbuf = "";
+                               }
                        }
                        objlen = strlen(objbuf);
                        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;
+                               outlen += fld_len - objlen;
+                       }
                        if(!io_ch(arg, sep_eq, sep_eq_len)) return -1;
                        outlen += objlen + sep_eq_len;
                }
@@ -490,12 +503,24 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
 
 int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
 {
+       if(flags == XN_FLAG_COMPAT)
+               return X509_NAME_print(out, nm, indent);
        return do_name_ex(send_bio_chars, out, nm, indent, flags);
 }
 
 
 int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
 {
+       if(flags == XN_FLAG_COMPAT)
+               {
+               BIO *btmp;
+               int ret;
+               btmp = BIO_new_fp(fp, BIO_NOCLOSE);
+               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);
 }