int opt_next(void);
void opt_begin(void);
int opt_format(const char *s, unsigned long flags, int *result);
+const char *format2str(int format);
int opt_int(const char *arg, int *result);
int opt_ulong(const char *arg, unsigned long *result);
int opt_long(const char *arg, long *result);
void opt_help(const OPTIONS * list);
void opt_print(const OPTIONS * opt, int doingparams, int width);
int opt_format_error(const char *s, unsigned long flags);
+void print_format_error(int format, unsigned long flags);
int opt_isdir(const char *name);
int opt_printf_stderr(const char *fmt, ...);
if (!load_pkcs12(cert, desc, NULL, NULL, NULL, &x, NULL))
goto end;
} else {
- BIO_printf(bio_err, "bad input format specified for %s\n", cert_descrip);
+ print_format_error(format,
+#if !defined(OPENSSL_NO_OCSP) && !defined(OPENSSL_NO_SOCK)
+ OPT_FMT_HTTP |
+#endif
+ OPT_FMT_PEMDER | OPT_FMT_PKCS12);
goto end;
}
+
end:
if (x == NULL && desc != NULL) {
BIO_printf(bio_err, "unable to load %s\n", desc);
} else if (format == FORMAT_PEM) {
x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);
} else {
- BIO_printf(bio_err, "bad input format specified for input crl\n");
+ print_format_error(format, OPT_FMT_PEMDER);
goto end;
}
req = d2i_X509_REQ_bio(in, NULL);
else if (format == FORMAT_PEM)
req = PEM_read_bio_X509_REQ(in, NULL, NULL, NULL);
- else if (desc)
- BIO_printf(bio_err, "unsupported format for loading %s\n", desc);
+ else {
+ print_format_error(format, OPT_FMT_PEMDER);
+ goto end;
+ }
end:
if (req == NULL && desc != NULL) {
pkey = b2i_PVK_bio(key, wrap_password_callback, &cb_data);
#endif
} else {
- BIO_printf(bio_err, "bad input format specified for key file\n");
+ print_format_error(format, OPT_FMT_PEMDER | OPT_FMT_PKCS12
+#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) && !defined (OPENSSL_NO_RC4)
+ | OPT_FMT_MSBLOB | FORMAT_PVK
+#endif
+#ifndef OPENSSL_NO_ENGINE
+ | OPT_FMT_ENGINE
+#endif
+ );
goto end;
}
end:
} else if (format == FORMAT_MSBLOB) {
pkey = b2i_PublicKey_bio(key);
#endif
+ } else {
+ print_format_error(format, OPT_FMT_PEMDER
+#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA)
+ | OPT_FMT_MSBLOB
+#endif
+ );
}
end:
BIO_free(key);
return 1;
}
+/* Return string representing the given format. */
+const char *format2str(int format)
+{
+ switch (format) {
+ default:
+ return "(undefined)";
+ case FORMAT_PEM:
+ return "PEM";
+ case FORMAT_ASN1:
+ return "DER";
+ case FORMAT_TEXT:
+ return "TEXT";
+ case FORMAT_NSS:
+ return "NSS";
+ case FORMAT_SMIME:
+ return "SMIME";
+ case FORMAT_MSBLOB:
+ return "MSBLOB";
+ case FORMAT_ENGINE:
+ return "ENGINE";
+ case FORMAT_HTTP:
+ return "HTTP";
+ case FORMAT_PKCS12:
+ return "P12";
+ case FORMAT_PVK:
+ return "PVK";
+ }
+}
+
+/* Print an error message about unsuitable/unsupported format requested. */
+void print_format_error(int format, unsigned long flags)
+{
+ (void)opt_format_error(format2str(format), flags);
+}
+
/* Parse a cipher name, put it in *EVP_CIPHER; return 0 on failure, else 1. */
int opt_cipher(const char *name, const EVP_CIPHER **cipherp)
{