gpgsm: New option --input-size-hint.

* sm/gpgsm.c (oInputSizeHint): New.
(opts): Add "--input-size-hint".
(main): Set option.
* sm/server.c (option_handler): Add option "input-size-hint".
* sm/gpgsm.h (struct server_control_s): Add field input_size_hint.
* sm/encrypt.c (gpgsm_encrypt): Set the toatl file size.
* sm/decrypt.c (gpgsm_decrypt): Ditto.
* sm/sign.c (gpgsm_sign): Ditto.
* sm/verify.c (gpgsm_verify): Ditto.
--

This option allows to set a value for the progress output line.  Note
that as of now there is no other way to set the file size.

GnuPG-bug-id: 6534
This commit is contained in:
Werner Koch 2023-06-15 12:28:55 +02:00
parent a88aeee129
commit e9c337c0b9
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
8 changed files with 33 additions and 0 deletions

View File

@ -554,6 +554,13 @@ Assume the input data is plain base-64 encoded.
@opindex assume-binary @opindex assume-binary
Assume the input data is binary encoded. Assume the input data is binary encoded.
@item --input-size-hint @var{n}
@opindex input-size-hint
This option can be used to tell GPGSM the size of the input data in
bytes. @var{n} must be a positive base-10 number. It is used by the
@option{--status-fd} line ``PROGRESS'' to provide a value for
``total'' if that is not available by other means.
@anchor{option --p12-charset} @anchor{option --p12-charset}
@item --p12-charset @var{name} @item --p12-charset @var{name}
@opindex p12-charset @opindex p12-charset
@ -1721,6 +1728,9 @@ If @var{value} is true or @var{value} is not given all network access
is disabled for this session. This is the same as the command line is disabled for this session. This is the same as the command line
option @option{--disable-dirmngr}. option @option{--disable-dirmngr}.
@item input-size-hint
This is the same as the @option{--input-size-hint} command line option.
@end table @end table
@mansect see also @mansect see also

View File

@ -1108,6 +1108,8 @@ gpgsm_decrypt (ctrl_t ctrl, int in_fd, estream_t out_fp)
} }
gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl); gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl);
if (ctrl->input_size_hint)
gnupg_ksba_set_total (b64writer, ctrl->input_size_hint);
rc = ksba_cms_new (&cms); rc = ksba_cms_new (&cms);
if (rc) if (rc)

View File

@ -654,6 +654,8 @@ gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, estream_t out_fp)
} }
gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl); gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl);
if (ctrl->input_size_hint)
gnupg_ksba_set_total (b64writer, ctrl->input_size_hint);
err = ksba_cms_new (&cms); err = ksba_cms_new (&cms);
if (err) if (err)

View File

@ -139,6 +139,7 @@ enum cmd_and_opt_values {
oAssumeArmor, oAssumeArmor,
oAssumeBase64, oAssumeBase64,
oAssumeBinary, oAssumeBinary,
oInputSizeHint,
oBase64, oBase64,
oNoArmor, oNoArmor,
@ -326,6 +327,7 @@ static gpgrt_opt_t opts[] = {
N_("assume input is in base-64 format")), N_("assume input is in base-64 format")),
ARGPARSE_s_n (oAssumeBinary, "assume-binary", ARGPARSE_s_n (oAssumeBinary, "assume-binary",
N_("assume input is in binary format")), N_("assume input is in binary format")),
ARGPARSE_s_s (oInputSizeHint, "input-size-hint", "@"),
ARGPARSE_header ("Output", N_("Options controlling the output")), ARGPARSE_header ("Output", N_("Options controlling the output")),
@ -1188,6 +1190,10 @@ main ( int argc, char **argv)
ctrl.is_base64 = 0; ctrl.is_base64 = 0;
break; break;
case oInputSizeHint:
ctrl.input_size_hint = string_to_u64 (pargs.r.ret_str);
break;
case oDisableCRLChecks: case oDisableCRLChecks:
opt.no_crl_check = 1; opt.no_crl_check = 1;
break; break;

View File

@ -250,6 +250,11 @@ struct server_control_s
int is_pem; /* Is in PEM format */ int is_pem; /* Is in PEM format */
int is_base64; /* is in plain base-64 format */ int is_base64; /* is in plain base-64 format */
/* If > 0 a hint with the expected number of input data bytes. This
* is not necessary an exact number but intended to be used for
* progress info and to decide on how to allocate buffers. */
uint64_t input_size_hint;
int create_base64; /* Create base64 encoded output */ int create_base64; /* Create base64 encoded output */
int create_pem; /* create PEM output */ int create_pem; /* create PEM output */
const char *pem_name; /* PEM name to use */ const char *pem_name; /* PEM name to use */

View File

@ -298,6 +298,10 @@ option_handler (assuan_context_t ctx, const char *key, const char *value)
opt.request_origin = i; opt.request_origin = i;
} }
} }
else if (!strcmp (key, "input-size-hint"))
{
ctrl->input_size_hint = string_to_u64 (value);
}
else else
err = gpg_error (GPG_ERR_UNKNOWN_OPTION); err = gpg_error (GPG_ERR_UNKNOWN_OPTION);

View File

@ -688,6 +688,8 @@ gpgsm_sign (ctrl_t ctrl, certlist_t signerlist,
} }
gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl); gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl);
if (ctrl->input_size_hint)
gnupg_ksba_set_total (b64writer, ctrl->input_size_hint);
err = ksba_cms_new (&cms); err = ksba_cms_new (&cms);
if (err) if (err)

View File

@ -159,6 +159,8 @@ gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, estream_t out_fp)
} }
gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl); gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl);
if (ctrl->input_size_hint)
gnupg_ksba_set_total (b64writer, ctrl->input_size_hint);
rc = ksba_cms_new (&cms); rc = ksba_cms_new (&cms);
if (rc) if (rc)