aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2023-06-21 12:20:52 +0000
committerIngo Klöcker <[email protected]>2023-06-21 12:38:50 +0000
commit1a9f192ab450288aea7a889527e78afd2c067b59 (patch)
tree7a26822f3ba236ffe96509c47da8308f3fab1296 /tests
parentqt: Support writing signed/encrypted archives directly to a file (diff)
downloadgpgme-1a9f192ab450288aea7a889527e78afd2c067b59.tar.gz
gpgme-1a9f192ab450288aea7a889527e78afd2c067b59.zip
core: Support reading the archive to decrypt/verify directly from a file
* src/engine-gpg.c (add_file_name_arg_or_data): New. (gpg_decrypt): Use add_file_name_arg_or_data instead of add_data for the ciphertext. (gpg_verify): Use add_file_name_arg_or_data instead of add_data for the signature and the signed text. * tests/run-decrypt.c (show_usage): New option --direct-file-io. (main): Parse new option. If option is given, then don't open input file, create simple data object instead of data object from stream and set input file name on input data. * tests/run-verify.c (show_usage): New option --direct-file-io. (main): Parse new option. If option is given, then don't open input files, create simple data objects instead of data objects from stream and set input file names on input data objects. -- This change makes it possible to tell gpg (and gpgtar) to read the input (i.e. the signed/encrypted data or the signature or the created archive) directly from the files with given file names instead of from streams piped through GpgME's Data IO. GnuPG-bug-id: 6530
Diffstat (limited to 'tests')
-rw-r--r--tests/run-decrypt.c37
-rw-r--r--tests/run-verify.c70
2 files changed, 83 insertions, 24 deletions
diff --git a/tests/run-decrypt.c b/tests/run-decrypt.c
index ee49ead6..de082d6f 100644
--- a/tests/run-decrypt.c
+++ b/tests/run-decrypt.c
@@ -94,6 +94,7 @@ show_usage (int ex)
" --archive extract files from an encrypted archive\n"
" --directory DIR extract the files into the directory DIR\n"
" --diagnostics print diagnostics\n"
+ " --direct-file-io pass FILE instead of stream with content of FILE to backend\n"
, stderr);
exit (ex);
}
@@ -122,6 +123,7 @@ main (int argc, char **argv)
int large_buffers = 0;
int sensitive = 0;
int diagnostics = 0;
+ int direct_file_io = 0;
if (argc)
{ argc--; argv++; }
@@ -221,6 +223,11 @@ main (int argc, char **argv)
directory = *argv;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--direct-file-io"))
+ {
+ direct_file_io = 1;
+ argc--; argv++;
+ }
else if (!strncmp (*argv, "--", 2))
show_usage (1);
@@ -229,13 +236,16 @@ main (int argc, char **argv)
if (argc < 1 || argc > 2)
show_usage (1);
- fp_in = fopen (argv[0], "rb");
- if (!fp_in)
+ if (!direct_file_io)
{
- err = gpgme_error_from_syserror ();
- fprintf (stderr, PGM ": can't open `%s': %s\n",
- argv[0], gpgme_strerror (err));
- exit (1);
+ fp_in = fopen (argv[0], "rb");
+ if (!fp_in)
+ {
+ err = gpgme_error_from_syserror ();
+ fprintf (stderr, PGM ": can't open `%s': %s\n",
+ argv[0], gpgme_strerror (err));
+ exit (1);
+ }
}
init_gpgme (protocol);
@@ -303,13 +313,26 @@ main (int argc, char **argv)
}
}
- err = gpgme_data_new_from_stream (&in, fp_in);
+ if (direct_file_io)
+ err = gpgme_data_new (&in);
+ else
+ err = gpgme_data_new_from_stream (&in, fp_in);
if (err)
{
fprintf (stderr, PGM ": error allocating data object: %s\n",
gpgme_strerror (err));
exit (1);
}
+ if (direct_file_io)
+ {
+ err = gpgme_data_set_file_name (in, argv[0]);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error setting file name (in): %s\n",
+ gpgme_strerror (err));
+ exit (1);
+ }
+ }
err = gpgme_data_new (&out);
if (err)
diff --git a/tests/run-verify.c b/tests/run-verify.c
index 8a400589..dba45557 100644
--- a/tests/run-verify.c
+++ b/tests/run-verify.c
@@ -239,6 +239,7 @@ show_usage (int ex)
" --archive extract files from a signed archive FILE\n"
" --directory DIR extract the files into the directory DIR\n"
" --diagnostics print diagnostics\n"
+ " --direct-file-io pass file names instead of streams with content of files to backend\n"
, stderr);
exit (ex);
}
@@ -258,6 +259,7 @@ main (int argc, char **argv)
int auto_key_import = 0;
gpgme_data_encoding_t encoding = GPGME_DATA_ENCODING_NONE;
int diagnostics = 0;
+ int direct_file_io = 0;
int repeats = 1;
int i;
@@ -343,6 +345,11 @@ main (int argc, char **argv)
diagnostics = 1;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--direct-file-io"))
+ {
+ direct_file_io = 1;
+ argc--; argv++;
+ }
else if (!strncmp (*argv, "--", 2))
show_usage (1);
@@ -369,24 +376,27 @@ main (int argc, char **argv)
printf ("Repeat: %i\n", i);
}
- fp_sig = fopen (argv[0], "rb");
- if (!fp_sig)
- {
- err = gpgme_error_from_syserror ();
- fprintf (stderr, PGM ": can't open `%s': %s\n",
- argv[0], gpgme_strerror (err));
- exit (1);
- }
- if (argc > 1)
+ if (!direct_file_io)
{
- fp_msg = fopen (argv[1], "rb");
- if (!fp_msg)
+ fp_sig = fopen (argv[0], "rb");
+ if (!fp_sig)
{
err = gpgme_error_from_syserror ();
fprintf (stderr, PGM ": can't open `%s': %s\n",
- argv[1], gpgme_strerror (err));
+ argv[0], gpgme_strerror (err));
exit (1);
}
+ if (argc > 1)
+ {
+ fp_msg = fopen (argv[1], "rb");
+ if (!fp_msg)
+ {
+ err = gpgme_error_from_syserror ();
+ fprintf (stderr, PGM ": can't open `%s': %s\n",
+ argv[1], gpgme_strerror (err));
+ exit (1);
+ }
+ }
}
err = gpgme_new (&ctx);
@@ -429,7 +439,10 @@ main (int argc, char **argv)
fail_if_err (err);
}
- err = gpgme_data_new_from_stream (&sig, fp_sig);
+ if (direct_file_io)
+ err = gpgme_data_new (&sig);
+ else
+ err = gpgme_data_new_from_stream (&sig, fp_sig);
if (err)
{
fprintf (stderr, PGM ": error allocating data object: %s\n",
@@ -437,15 +450,38 @@ main (int argc, char **argv)
exit (1);
}
gpgme_data_set_encoding (sig, encoding);
- if (fp_msg)
+ if (direct_file_io)
{
- err = gpgme_data_new_from_stream (&msg, fp_msg);
+ err = gpgme_data_set_file_name (sig, argv[0]);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error setting file name (sig): %s\n",
+ gpgme_strerror (err));
+ exit (1);
+ }
+ }
+ if (argc > 1)
+ {
+ if (direct_file_io)
+ err = gpgme_data_new (&msg);
+ else
+ err = gpgme_data_new_from_stream (&msg, fp_msg);
if (err)
{
fprintf (stderr, PGM ": error allocating data object: %s\n",
gpgme_strerror (err));
exit (1);
}
+ if (direct_file_io)
+ {
+ err = gpgme_data_set_file_name (msg, argv[1]);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error setting file name (msg): %s\n",
+ gpgme_strerror (err));
+ exit (1);
+ }
+ }
}
if (directory && (flags & GPGME_VERIFY_ARCHIVE))
@@ -454,14 +490,14 @@ main (int argc, char **argv)
if (err)
{
fprintf (stderr, PGM ": error allocating data object: %s\n",
- gpgme_strerror (err));
+ gpgme_strerror (err));
exit (1);
}
err = gpgme_data_set_file_name (out, directory);
if (err)
{
fprintf (stderr, PGM ": error setting file name (out): %s\n",
- gpgme_strerror (err));
+ gpgme_strerror (err));
exit (1);
}
}