Commit d303b9d8 authored by Richard Levitte's avatar Richard Levitte
Browse files

Make the handling of output and input formats consistent



Most of all, we needed to sort out which ones are binary and which
ones are text, and make sure they are treated accordingly and
consistently so

Reviewed-by: default avatarTim Hudson <tjh@openssl.org>
parent e9daa815
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -163,8 +163,9 @@ int app_load_modules(const CONF *config);
void unbuffer(FILE *fp);

/* Often used in calls to bio_open_default. */
# define RB(xformat)  ((xformat) == FORMAT_ASN1 ? "rb" : "r")
# define WB(xformat)  ((xformat) == FORMAT_ASN1 ? "wb" : "w")
# define RB(xformat)  (((xformat) & B_FORMAT_TEXT) ? "rb" : "r")
# define WB(xformat)  (((xformat) & B_FORMAT_TEXT) ? "wb" : "w")
# define AB(xformat)  (((xformat) & B_FORMAT_TEXT) ? "ab" : "a")

/*
 * Common verification options.
@@ -535,14 +536,15 @@ void print_cert_checks(BIO *bio, X509 *x,
void store_setup_crl_download(X509_STORE *st);

/* See OPT_FMT_xxx, above. */
# define B_FORMAT_TEXT   0x8000
# define FORMAT_UNDEF    0
# define FORMAT_ASN1     1
# define FORMAT_TEXT     2
# define FORMAT_PEM      3
# define FORMAT_TEXT    (2 | B_FORMAT_TEXT)
# define FORMAT_PEM     (3 | B_FORMAT_TEXT)
# define FORMAT_PKCS12   5
# define FORMAT_SMIME    6
# define FORMAT_SMIME   (6 | B_FORMAT_TEXT)
# define FORMAT_ENGINE   7
# define FORMAT_PEMRSA   9      /* PEM RSAPubicKey format */
# define FORMAT_PEMRSA  (9 | B_FORMAT_TEXT)     /* PEM RSAPubicKey format */
# define FORMAT_ASN1RSA  10                     /* DER RSAPubicKey format */
# define FORMAT_MSBLOB   11                     /* MS Key blob format */
# define FORMAT_PVK      12                     /* MS PVK file format */
+1 −1
Original line number Diff line number Diff line
@@ -197,7 +197,7 @@ int asn1parse_main(int argc, char **argv)
        BIO_free(in);
    }

    if ((in = bio_open_default(infile, "r")) == NULL)
    if ((in = bio_open_default(infile, RB(informat))) == NULL)
        goto end;

    if (derfile && (derout = bio_open_default(derfile, "wb")) == NULL)
+2 −4
Original line number Diff line number Diff line
@@ -690,16 +690,14 @@ int cms_main(int argc, char **argv)
        flags &= ~CMS_DETACHED;

    if (operation & SMIME_OP) {
        if (outformat == FORMAT_ASN1)
            outmode = "wb";
        outmode = WB(outformat);
    } else {
        if (flags & CMS_BINARY)
            outmode = "wb";
    }

    if (operation & SMIME_IP) {
        if (informat == FORMAT_ASN1)
            inmode = "rb";
        inmode = RB(informat);
    } else {
        if (flags & CMS_BINARY)
            inmode = "rb";
+1 −1
Original line number Diff line number Diff line
@@ -346,7 +346,7 @@ int crl_main(int argc, char **argv)
            }
        }
    }
    out = bio_open_default(outfile, "w");
    out = bio_open_default(outfile, WB(outformat));
    if (out == NULL)
        goto end;

+1 −1
Original line number Diff line number Diff line
@@ -352,7 +352,7 @@ int dhparam_main(int argc, char **argv)
        /* dh != NULL */
    }

    out = bio_open_default(outfile, "w");
    out = bio_open_default(outfile, WB(outformat));
    if (out == NULL)
        goto end;

Loading