Change the way apps open their input and output files
[openssl.git] / apps / ts.c
index 6e6b834401324d34b3134eccf3bb88d720f14fc8..70729c5629660f5a638cdfa22e046049e4ba2942 100644 (file)
--- a/apps/ts.c
+++ b/apps/ts.c
@@ -429,13 +429,13 @@ static int query_command(const char *data, char *digest, const EVP_MD *md,
 
     /* Build query object either from file or from scratch. */
     if (in != NULL) {
 
     /* Build query object either from file or from scratch. */
     if (in != NULL) {
-        if ((in_bio = BIO_new_file(in, "rb")) == NULL)
+        if ((in_bio = bio_open_default(in, 'r', FORMAT_ASN1)) == NULL)
             goto end;
         query = d2i_TS_REQ_bio(in_bio, NULL);
     } else {
         /* Open the file if no explicit digest bytes were specified. */
         if (digest == NULL
             goto end;
         query = d2i_TS_REQ_bio(in_bio, NULL);
     } else {
         /* Open the file if no explicit digest bytes were specified. */
         if (digest == NULL
-            && (data_bio = bio_open_default(data, "rb")) == NULL)
+            && (data_bio = bio_open_default(data, 'r', FORMAT_ASN1)) == NULL)
             goto end;
         query = create_query(data_bio, digest, md, policy, no_nonce, cert);
     }
             goto end;
         query = create_query(data_bio, digest, md, policy, no_nonce, cert);
     }
@@ -443,14 +443,16 @@ static int query_command(const char *data, char *digest, const EVP_MD *md,
         goto end;
 
     /* Write query either in ASN.1 or in text format. */
         goto end;
 
     /* Write query either in ASN.1 or in text format. */
-    if ((out_bio = bio_open_default(out, "wb")) == NULL)
-        goto end;
     if (text) {
         /* Text output. */
     if (text) {
         /* Text output. */
+        if ((out_bio = bio_open_default(out, 'w', FORMAT_TEXT)) == NULL)
+            goto end;
         if (!TS_REQ_print_bio(out_bio, query))
             goto end;
     } else {
         /* ASN.1 output. */
         if (!TS_REQ_print_bio(out_bio, query))
             goto end;
     } else {
         /* ASN.1 output. */
+        if ((out_bio = bio_open_default(out, 'w', FORMAT_ASN1)) == NULL)
+            goto end;
         if (!i2d_TS_REQ_bio(out_bio, query))
             goto end;
     }
         if (!i2d_TS_REQ_bio(out_bio, query))
             goto end;
     }
@@ -662,10 +664,10 @@ static int reply_command(CONF *conf, char *section, char *engine,
         goto end;
 
     /* Write response either in ASN.1 or text format. */
         goto end;
 
     /* Write response either in ASN.1 or text format. */
-    if ((out_bio = bio_open_default(out, "wb")) == NULL)
-        goto end;
     if (text) {
         /* Text output. */
     if (text) {
         /* Text output. */
+        if ((out_bio = bio_open_default(out, 'w', FORMAT_TEXT)) == NULL)
+        goto end;
         if (token_out) {
             TS_TST_INFO *tst_info = TS_RESP_get_tst_info(response);
             if (!TS_TST_INFO_print_bio(out_bio, tst_info))
         if (token_out) {
             TS_TST_INFO *tst_info = TS_RESP_get_tst_info(response);
             if (!TS_TST_INFO_print_bio(out_bio, tst_info))
@@ -676,6 +678,8 @@ static int reply_command(CONF *conf, char *section, char *engine,
         }
     } else {
         /* ASN.1 DER output. */
         }
     } else {
         /* ASN.1 DER output. */
+        if ((out_bio = bio_open_default(out, 'w', FORMAT_ASN1)) == NULL)
+            goto end;
         if (token_out) {
             PKCS7 *token = TS_RESP_get_token(response);
             if (!i2d_PKCS7_bio(out_bio, token))
         if (token_out) {
             PKCS7 *token = TS_RESP_get_token(response);
             if (!i2d_PKCS7_bio(out_bio, token))