summaryrefslogtreecommitdiffstats
path: root/apps/ts.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2015-09-04 12:49:06 +0200
committerRichard Levitte <levitte@openssl.org>2015-09-06 01:35:54 +0200
commitbdd58d98467e9f0f6635c1628e1eae304383afb1 (patch)
tree1927fc4a65f8fd8b5705c5c5e0278beabf2c2b28 /apps/ts.c
parentd303b9d85e1888494785f87ebd9bd233e63564a9 (diff)
Change the way apps open their input and output files
The different apps had the liberty to decide whether they would open their input and output files in binary mode or not, which could be confusing if two different apps were handling the same type of file in different ways. The solution is to centralise the decision of low level file organisation, and that the apps would use a selection of formats to state the intent of the file. Reviewed-by: Tim Hudson <tjh@openssl.org>
Diffstat (limited to 'apps/ts.c')
-rw-r--r--apps/ts.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/apps/ts.c b/apps/ts.c
index 6e6b834401..70729c5629 100644
--- 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) {
- 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
- && (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);
}
@@ -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. */
- if ((out_bio = bio_open_default(out, "wb")) == NULL)
- goto end;
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 ((out_bio = bio_open_default(out, 'w', FORMAT_ASN1)) == NULL)
+ 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. */
- if ((out_bio = bio_open_default(out, "wb")) == NULL)
- goto end;
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))
@@ -676,6 +678,8 @@ static int reply_command(CONF *conf, char *section, char *engine,
}
} 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))