summaryrefslogtreecommitdiffstats
path: root/apps/cms.c
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2020-09-28 08:29:59 +0200
committerDr. David von Oheimb <dev@ddvo.net>2021-05-19 09:23:30 +0200
commit1b96cc70eb466f12b5abd9d90900e875a2236509 (patch)
treeb17425875957738a1453dae5143acf429aaac0c4 /apps/cms.c
parent6b83d032a64848a66b60ca54729bcd79493f36ef (diff)
apps/cms.c: Simplify make_receipt_request() and load_content_info(()
Also improve adherence to code formatting rules. Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/12959)
Diffstat (limited to 'apps/cms.c')
-rw-r--r--apps/cms.c63
1 files changed, 27 insertions, 36 deletions
diff --git a/apps/cms.c b/apps/cms.c
index 64867e3702..d2225d51af 100644
--- a/apps/cms.c
+++ b/apps/cms.c
@@ -24,9 +24,9 @@
static int save_certs(char *signerfile, STACK_OF(X509) *signers);
static int cms_cb(int ok, X509_STORE_CTX *ctx);
static void receipt_request_print(CMS_ContentInfo *cms);
-static CMS_ReceiptRequest *make_receipt_request(
- STACK_OF(OPENSSL_STRING) *rr_to, int rr_allorfirst,
- STACK_OF(OPENSSL_STRING) *rr_from, OSSL_LIB_CTX *libctx);
+static CMS_ReceiptRequest
+*make_receipt_request(STACK_OF(OPENSSL_STRING) *rr_to, int rr_allorfirst,
+ STACK_OF(OPENSSL_STRING) *rr_from);
static int cms_set_pkey_param(EVP_PKEY_CTX *pctx,
STACK_OF(OPENSSL_STRING) *param);
@@ -227,14 +227,12 @@ const OPTIONS cms_options[] = {
{NULL}
};
-static CMS_ContentInfo *load_content_info(int informat, BIO *in, int flags, BIO **indata,
- const char *name,
- OSSL_LIB_CTX *libctx,
- const char *propq)
+static CMS_ContentInfo *load_content_info(int informat, BIO *in, int flags,
+ BIO **indata, const char *name)
{
CMS_ContentInfo *ret, *ci;
- ret = CMS_ContentInfo_new_ex(libctx, propq);
+ ret = CMS_ContentInfo_new_ex(app_get0_libctx(), app_get0_propq());
if (ret == NULL) {
BIO_printf(bio_err, "Error allocating CMS_contentinfo\n");
return NULL;
@@ -258,7 +256,7 @@ static CMS_ContentInfo *load_content_info(int informat, BIO *in, int flags, BIO
goto err;
}
return ret;
-err:
+ err:
CMS_ContentInfo_free(ret);
return NULL;
}
@@ -285,7 +283,6 @@ static void warn_binary(const char *file)
BIO_free(bio);
}
-
int cms_main(int argc, char **argv)
{
CONF *conf = NULL;
@@ -475,8 +472,7 @@ int cms_main(int argc, char **argv)
OPT_FMT_PEMDER | OPT_FMT_SMIME, &rctformat))
goto opthelp;
} else {
- rcms = load_content_info(rctformat, rctin, 0, NULL, "recipient",
- libctx, app_get0_propq());
+ rcms = load_content_info(rctformat, rctin, 0, NULL, "recipient");
}
break;
case OPT_CERTFILE:
@@ -605,8 +601,8 @@ int cms_main(int argc, char **argv)
signerfile = opt_arg();
break;
case OPT_ORIGINATOR:
- originatorfile = opt_arg();
- break;
+ originatorfile = opt_arg();
+ break;
case OPT_INKEY:
/* If previous -inkey argument add signer to list */
if (keyfile != NULL) {
@@ -860,8 +856,8 @@ int cms_main(int argc, char **argv)
if (originatorfile != NULL) {
if ((originator = load_cert(originatorfile, FORMAT_UNDEF,
"originator certificate file")) == NULL) {
- ERR_print_errors(bio_err);
- goto end;
+ ERR_print_errors(bio_err);
+ goto end;
}
}
@@ -897,8 +893,7 @@ int cms_main(int argc, char **argv)
goto end;
if (operation & SMIME_IP) {
- cms = load_content_info(informat, in, flags, &indata, "SMIME",
- libctx, app_get0_propq());
+ cms = load_content_info(informat, in, flags, &indata, "SMIME");
if (cms == NULL)
goto end;
if (contfile != NULL) {
@@ -931,8 +926,7 @@ int cms_main(int argc, char **argv)
goto end;
}
- rcms = load_content_info(rctformat, rctin, 0, NULL, "recipient", libctx,
- app_get0_propq);
+ rcms = load_content_info(rctformat, rctin, 0, NULL, "recipient");
if (rcms == NULL)
goto end;
}
@@ -967,7 +961,8 @@ int cms_main(int argc, char **argv)
for (i = 0; i < sk_X509_num(encerts); i++) {
CMS_RecipientInfo *ri;
cms_key_param *kparam;
- int tflags = flags | CMS_KEY_PARAM; /* This flag enforces allocating the EVP_PKEY_CTX for the recipient here */
+ int tflags = flags | CMS_KEY_PARAM;
+ /* This flag enforces allocating the EVP_PKEY_CTX for the recipient here */
EVP_PKEY_CTX *pctx;
X509 *x = sk_X509_value(encerts, i);
int res;
@@ -1061,13 +1056,11 @@ int cms_main(int argc, char **argv)
if (econtent_type != NULL)
CMS_set1_eContentType(cms, econtent_type);
- if (rr_to != NULL) {
- rr = make_receipt_request(rr_to, rr_allorfirst, rr_from, libctx);
- if (rr == NULL) {
- BIO_puts(bio_err,
- "Signed Receipt Request Creation Error\n");
- goto end;
- }
+ if (rr_to != NULL
+ && ((rr = make_receipt_request(rr_to, rr_allorfirst, rr_from))
+ == NULL)) {
+ BIO_puts(bio_err, "Signed Receipt Request Creation Error\n");
+ goto end;
}
} else {
flags |= CMS_REUSE_DIGEST;
@@ -1419,13 +1412,12 @@ static STACK_OF(GENERAL_NAMES) *make_names_stack(STACK_OF(OPENSSL_STRING) *ns)
return NULL;
}
-static CMS_ReceiptRequest *make_receipt_request(
- STACK_OF(OPENSSL_STRING) *rr_to, int rr_allorfirst,
- STACK_OF(OPENSSL_STRING) *rr_from,
- OSSL_LIB_CTX *libctx)
+static CMS_ReceiptRequest
+*make_receipt_request(STACK_OF(OPENSSL_STRING) *rr_to, int rr_allorfirst,
+ STACK_OF(OPENSSL_STRING) *rr_from)
{
STACK_OF(GENERAL_NAMES) *rct_to = NULL, *rct_from = NULL;
- CMS_ReceiptRequest *rr;
+
rct_to = make_names_stack(rr_to);
if (rct_to == NULL)
goto err;
@@ -1436,9 +1428,8 @@ static CMS_ReceiptRequest *make_receipt_request(
} else {
rct_from = NULL;
}
- rr = CMS_ReceiptRequest_create0_ex(NULL, -1, rr_allorfirst, rct_from,
- rct_to, libctx);
- return rr;
+ return CMS_ReceiptRequest_create0_ex(NULL, -1, rr_allorfirst, rct_from,
+ rct_to, app_get0_libctx());
err:
sk_GENERAL_NAMES_pop_free(rct_to, GENERAL_NAMES_free);
return NULL;