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.
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_ASN1RSA 10 /* DER RSAPubicKey format */
-# define FORMAT_MSBLOB 11 /* MS Key blob format */
-# define FORMAT_PVK 12 /* MS PVK file format */
-# define FORMAT_HTTP 13 /* Download using HTTP */
-# define FORMAT_NSS 14 /* NSS keylog 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 */
+# define FORMAT_HTTP 13 /* Download using HTTP */
+# define FORMAT_NSS 14 /* NSS keylog format */
# define EXT_COPY_NONE 0
# define EXT_COPY_ADD 1
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)
extensions = "default";
}
- /*****************************************************************/
+ /*****************************************************************/
if (req || gencrl) {
Sout = bio_open_default(outfile, "w");
if (Sout == NULL)
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";
}
}
}
- out = bio_open_default(outfile, "w");
+ out = bio_open_default(outfile, WB(outformat));
if (out == NULL)
goto end;
/* dh != NULL */
}
- out = bio_open_default(outfile, "w");
+ out = bio_open_default(outfile, WB(outformat));
if (out == NULL)
goto end;
goto end;
}
- out = bio_open_owner(outfile, "w", private);
+ out = bio_open_owner(outfile, WB(outformat), private);
if (out == NULL)
goto end;
}
private = genkey ? 1 : 0;
- in = bio_open_default(infile, "r");
+ in = bio_open_default(infile, RB(informat));
if (in == NULL)
goto end;
- out = bio_open_owner(outfile, "w", private);
+ out = bio_open_owner(outfile, WB(outformat), private);
if (out == NULL)
goto end;
unbuffer(stdin);
in = dup_bio_in();
} else
- in = bio_open_default(infile, "r");
+ in = bio_open_default(infile, base64 ? "r" : "rb");
if (in == NULL)
goto end;
}
}
- out = bio_open_default(outfile, "w");
+ out = bio_open_default(outfile, base64 ? "w" : "wb");
if (out == NULL)
goto end;
if (!app_load_modules(NULL))
goto end;
- out = bio_open_owner(outfile, "wb", private);
+ out = bio_open_owner(outfile, WB(outformat), private);
if (out == NULL)
goto end;
if ((pbe_nid == -1) && !cipher)
pbe_nid = NID_pbeWithMD5AndDES_CBC;
- in = bio_open_default(infile, "rb");
+ in = bio_open_default(infile, RB(informat));
if (in == NULL)
goto end;
- out = bio_open_owner(outfile, "wb", private);
+ out = bio_open_owner(outfile, WB(outformat), private);
if (out == NULL)
goto end;
if (!app_load_modules(NULL))
goto end;
- out = bio_open_owner(outfile, "wb", private);
+ out = bio_open_owner(outfile, WB(outformat), private);
if (out == NULL)
goto end;
BIO_printf(bio_err, "%ld semi-random bytes loaded\n",
app_RAND_load_files(inrand));
- out = bio_open_default(outfile, "w");
+ out = bio_open_default(outfile, base64 ? "w" : "wb");
if (out == NULL)
goto end;
out = bio_open_default(outfile,
keyout != NULL && outfile != NULL &&
- strcmp(keyout, outfile) == 0 ? "a" : "w");
+ strcmp(keyout, outfile) == 0
+ ? AB(outformat) : WB(outformat));
if (out == NULL)
goto end;
goto end;
}
- out = bio_open_owner(outfile, "w", private);
+ out = bio_open_owner(outfile, WB(outformat), private);
if (out == NULL)
goto end;
}
if (!noout || text) {
- const char* modeflag = "w";
- if (outformat == FORMAT_ASN1 || outformat == FORMAT_NSS)
- modeflag = "wb";
- out = bio_open_default(outfile, modeflag);
+ out = bio_open_default(outfile, WB(outformat));
if (out == NULL)
goto end;
}
flags &= ~PKCS7_DETACHED;
if (operation & SMIME_OP) {
- if (outformat == FORMAT_ASN1)
- outmode = "wb";
+ outmode = WB(outformat);
} else {
if (flags & PKCS7_BINARY)
outmode = "wb";
}
if (operation & SMIME_IP) {
- if (informat == FORMAT_ASN1)
- inmode = "rb";
+ inmode = RB(informat);
} else {
if (flags & PKCS7_BINARY)
inmode = "rb";
if (!app_load_modules(NULL))
goto end;
- out = bio_open_default(outfile, "w");
+ out = bio_open_default(outfile, WB(outformat));
if (out == NULL)
goto end;
BIO_printf(bio_err, "We need a private key to sign with\n");
goto end;
}
- in = bio_open_default(infile, "r");
+ in = bio_open_default(infile, RB(informat));
if (in == NULL)
goto end;
req = PEM_read_bio_X509_REQ(in, NULL, NULL, NULL);