Apply suggestions from code review

Added more detailed error messages.
Fixed formatting and indentation.

Co-authored-by: Małgorzata Olszówka <Malgorzata.Olszowka@stunnel.org>
This commit is contained in:
Michał Trojnara 2023-07-21 11:27:44 +02:00
parent f2f3a8891c
commit adcfd9a33f

View File

@ -2002,12 +2002,10 @@ static int verify_member(FILE_FORMAT_CTX *ctx, CatalogAuthAttr *attribute)
printf("Failed to extract current message digest\n\n"); printf("Failed to extract current message digest\n\n");
return 1; /* FAILED */ return 1; /* FAILED */
} }
if (!ctx->format->digest_calc) { if (!ctx->format->digest_calc) {
printf("Unsupported command\n"); printf("Unsupported method: digest_calc\n");
return 1; /* Failed */ return 1; /* FAILED */
} }
md = EVP_get_digestbynid(mdtype); md = EVP_get_digestbynid(mdtype);
cmdbuf = ctx->format->digest_calc(ctx, md); cmdbuf = ctx->format->digest_calc(ctx, md);
if (!cmdbuf) { if (!cmdbuf) {
@ -2225,13 +2223,14 @@ static int verify_signed_file(FILE_FORMAT_CTX *ctx, GLOBAL_OPTIONS *options)
PKCS7 *p7; PKCS7 *p7;
STACK_OF(PKCS7) *signatures; STACK_OF(PKCS7) *signatures;
int detached = options->catalog ? 1 : 0; int detached = options->catalog ? 1 : 0;
if (!ctx->format->check_file) { if (!ctx->format->check_file) {
printf("Unsupported command\n"); printf("Unsupported method: check_file\n");
return 1; /* Failed */ return 1; /* FAILED */
} }
if (!ctx->format->check_file(ctx, detached)) if (!ctx->format->check_file(ctx, detached))
return 1; /* Failed */ return 1; /* FAILED */
if (detached) { if (detached) {
GLOBAL_OPTIONS *cat_options; GLOBAL_OPTIONS *cat_options;
@ -2248,21 +2247,18 @@ static int verify_signed_file(FILE_FORMAT_CTX *ctx, GLOBAL_OPTIONS *options)
printf("CAT file initialization error\n"); printf("CAT file initialization error\n");
return 1; /* Failed */ return 1; /* Failed */
} }
if (!cat_ctx->format->pkcs7_extract) { if (!cat_ctx->format->pkcs7_extract) {
printf("Unsupported command\n"); printf("Unsupported command: extract-signature\n");
return 1; /* Failed */ return 1; /* FAILED */
} }
p7 = cat_ctx->format->pkcs7_extract(cat_ctx); p7 = cat_ctx->format->pkcs7_extract(cat_ctx);
cat_ctx->format->ctx_cleanup(cat_ctx, NULL, NULL); cat_ctx->format->ctx_cleanup(cat_ctx, NULL, NULL);
OPENSSL_free(cat_options); OPENSSL_free(cat_options);
} else { } else {
if (!ctx->format->pkcs7_extract) { if (!ctx->format->pkcs7_extract) {
printf("Unsupported command\n"); printf("Unsupported command: extract-signature\n");
return 1; /* Failed */ return 1; /* FAILED */
} }
p7 = ctx->format->pkcs7_extract(ctx); p7 = ctx->format->pkcs7_extract(ctx);
} }
if (!p7) { if (!p7) {
@ -2289,8 +2285,8 @@ static int verify_signed_file(FILE_FORMAT_CTX *ctx, GLOBAL_OPTIONS *options)
ret &= verify_signature(ctx, sig); ret &= verify_signature(ctx, sig);
} }
} else { } else {
printf("Unsupported command\n"); printf("Unsupported method: verify_digests\n");
return 1; /* Failed */ return 1; /* FAILED */
} }
} }
printf("Number of verified signatures: %d\n", i); printf("Number of verified signatures: %d\n", i);
@ -3772,7 +3768,7 @@ int main(int argc, char **argv)
goto skip_signing; goto skip_signing;
} else if (options.cmd == CMD_EXTRACT) { } else if (options.cmd == CMD_EXTRACT) {
if (!ctx->format->pkcs7_extract) { if (!ctx->format->pkcs7_extract) {
DO_EXIT_0("Unsupported command\n"); DO_EXIT_0("Unsupported command: extract-signature\n");
} }
p7 = ctx->format->pkcs7_extract(ctx); p7 = ctx->format->pkcs7_extract(ctx);
if (!p7) { if (!p7) {
@ -3783,7 +3779,7 @@ int main(int argc, char **argv)
goto skip_signing; goto skip_signing;
} else if (options.cmd == CMD_REMOVE) { } else if (options.cmd == CMD_REMOVE) {
if (!ctx->format->remove_pkcs7) { if (!ctx->format->remove_pkcs7) {
DO_EXIT_0("Unsupported command\n"); DO_EXIT_0("Unsupported command: remove-signature\n");
} }
ret = ctx->format->remove_pkcs7(ctx, hash, outdata); ret = ctx->format->remove_pkcs7(ctx, hash, outdata);
if (ctx->format->update_data_size) { if (ctx->format->update_data_size) {