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.
This commit is contained in:
Werner Koch 2025-03-18 16:22:58 +01:00
parent 926b1f1f1e
commit 91a59d2a35
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
8 changed files with 36 additions and 7 deletions

4
NEWS
View File

@ -7,6 +7,9 @@ Noteworthy changes in version 2.0.0 (unreleased)
* New function gpgme_op_random_value to get a cryptographically
strong unsigned integer random value. [T6694]
* New decrypt flag to skip the actual decryption so that information
about the recipients can be retrieved.
* Removed the gpgme_attr_t enums and their functions which were
deprecated since 2003. [rMd54d6eaa64]
@ -22,6 +25,7 @@ Noteworthy changes in version 2.0.0 (unreleased)
gpgme_op_random_value NEW.
GPGME_RANDOM_MODE_NORMAL NEW.
GPGME_RANDOM_MODE_ZBASE32 NEW.
GPGME_DECRYPT_LISTONLY NEW.
gpgme_attr_t REMOVED.
gpgme_get_sig_ulong_attr REMOVED.
gpgme_get_sig_string_attr REMOVED.

View File

@ -5830,6 +5830,15 @@ be an OpenPGP message with only the encryption layer removed. This
requires GnuPG 2.1.12 and works only for OpenPGP. This is the
counterpart to @code{GPGME_ENCRYPT_WRAP}.
@item GPGME_DECRYPT_LIST
@since{2.0.0}
The @code{GPGME_DECRYPT_LIST} symbol specifies that the actual
decryption step of an OpenPGP message shall be skipped. This can be
used to information on the keyids of the recipients of some encrypted
data. Note that most other result items have no or no useful
information in this case.
@end table
The function returns the error codes as described for

View File

@ -62,7 +62,7 @@ decrypt_verify_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;

View File

@ -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;

View File

@ -1952,6 +1952,9 @@ gpg_decrypt (void *engine,
err = add_arg (gpg, "--unwrap");
}
if (!err && (flags & GPGME_DECRYPT_LISTONLY))
err = add_arg (gpg, "--list-only");
if (!err && export_session_key)
err = add_gpg_arg (gpg, "--show-session-key");

View File

@ -1491,6 +1491,7 @@ typedef enum
{
GPGME_DECRYPT_VERIFY = 1,
GPGME_DECRYPT_ARCHIVE = 2,
GPGME_DECRYPT_LISTONLY = 16,
GPGME_DECRYPT_UNWRAP = 128
}
gpgme_decrypt_flags_t;

View File

@ -86,7 +86,8 @@ gpgme_error_t _gpgme_verify_status_handler (void *priv,
/* From decrypt.c. */
gpgme_error_t _gpgme_op_decrypt_init_result (gpgme_ctx_t ctx,
gpgme_data_t plaintext);
gpgme_data_t plaintext,
gpgme_decrypt_flags_t flags);
gpgme_error_t _gpgme_decrypt_status_handler (void *priv,
gpgme_status_code_t code,
char *args);

View File

@ -90,6 +90,7 @@ show_usage (int ex)
" --no-symkey-cache disable the use of that cache\n"
" --ignore-mdc-error allow decryption of legacy data\n"
" --unwrap remove only the encryption layer\n"
" --list-only no actual decryption\n"
" --large-buffers use large I/O buffer\n"
" --sensitive mark data objects as sensitive\n"
" --output FILE write output to FILE instead of stdout\n"
@ -215,6 +216,11 @@ main (int argc, char **argv)
raw_output = 1;
argc--; argv++;
}
else if (!strcmp (*argv, "--list-only"))
{
flags |= GPGME_DECRYPT_LISTONLY;
argc--; argv++;
}
else if (!strcmp (*argv, "--output"))
{
argc--; argv++;
@ -445,7 +451,7 @@ main (int argc, char **argv)
{
if (!raw_output)
print_result (result);
if (!output)
if (!output && !(flags & GPGME_DECRYPT_LISTONLY))
{
if (!raw_output)
fputs ("Begin Output:\n", stdout);