From 91a59d2a35540769c055da2341b5face0be6c286 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 18 Mar 2025 16:22:58 +0100 Subject: New decrypt flags GPGME_DECRYPT_LISTONLY. * src/gpgme.h.in (GPGME_DECRYPT_LISTONLY): New. * src/decrypt.c (op_data_t): Add member list_only. (_gpgme_decrypt_status_handler): Do not return NO_DATA in list_only mode. (_gpgme_op_decrypt_init_result): Add arg flags and set the list_only flag. (_gpgme_decrypt_start): Pss flags to the init function. * src/decrypt-verify.c (decrypt_verify_start): Ditto. * src/engine-gpg.c (gpg_decrypt): Add --list-only if flag is set. * tests/run-decrypt.c (main): Add option --list-only. --- src/decrypt.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/decrypt.c') diff --git a/src/decrypt.c b/src/decrypt.c index e5d2f7c7..c6030eef 100644 --- a/src/decrypt.c +++ b/src/decrypt.c @@ -44,7 +44,10 @@ typedef struct int okay; - /* A flag telling that the a decryption failed and two optional error + /* Indicates that list only mode is active. */ + int list_only; + + /* A flag telling that the decryption failed and two optional error * codes to further specify the failure for public key decryption and * symmetric decryption. */ int failed; @@ -419,7 +422,7 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code, /* Generic decryption failed error code. */ return gpg_error (GPG_ERR_DECRYPT_FAILED); } - else if (!opd->okay) + else if (!opd->okay && !opd->list_only) { /* No data was found. */ return gpg_error (GPG_ERR_NO_DATA); @@ -540,7 +543,8 @@ decrypt_status_handler (void *priv, gpgme_status_code_t code, char *args) gpgme_error_t -_gpgme_op_decrypt_init_result (gpgme_ctx_t ctx, gpgme_data_t plaintext) +_gpgme_op_decrypt_init_result (gpgme_ctx_t ctx, gpgme_data_t plaintext, + gpgme_decrypt_flags_t flags) { gpgme_error_t err; void *hook; @@ -552,6 +556,7 @@ _gpgme_op_decrypt_init_result (gpgme_ctx_t ctx, gpgme_data_t plaintext) if (err) return err; + opd->list_only = !!(flags & GPGME_DECRYPT_LISTONLY); opd->last_recipient_p = &opd->result.recipients; opd->plaintext_dserial = _gpgme_data_get_dserial (plaintext); return 0; @@ -571,7 +576,7 @@ _gpgme_decrypt_start (gpgme_ctx_t ctx, int synchronous, if (err) return err; - err = _gpgme_op_decrypt_init_result (ctx, plain); + err = _gpgme_op_decrypt_init_result (ctx, plain, flags); if (err) return err; -- cgit v1.2.3