Imported Upstream version 1.14.0
[platform/upstream/gpgme.git] / tests / run-sign.c
index 70853ed..55b2e48 100644 (file)
@@ -1,21 +1,22 @@
 /* run-sign.c  - Helper to perform a sign operation
-   Copyright (C) 2009 g10 Code GmbH
-
-   This file is part of GPGME.
-
-   GPGME is free software; you can redistribute it and/or modify it
-   under the terms of the GNU Lesser General Public License as
-   published by the Free Software Foundation; either version 2.1 of
-   the License, or (at your option) any later version.
-
-   GPGME is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this program; if not, see <http://www.gnu.org/licenses/>.
-*/
+ * Copyright (C) 2009 g10 Code GmbH
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * GPGME is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <https://gnu.org/licenses/>.
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
 
 /* We need to include config.h so that we know whether we are building
    with large file system (LFS) support. */
@@ -83,6 +84,8 @@ show_usage (int ex)
          "  --uiserver       use the UI server\n"
          "  --loopback       use a loopback pinentry\n"
          "  --key NAME       use key NAME for signing\n"
+         "  --sender MBOX    use MBOX as sender address\n"
+         "  --include-key-block  use this option with gpg\n"
          , stderr);
   exit (ex);
 }
@@ -101,6 +104,9 @@ main (int argc, char **argv)
   gpgme_sign_result_t result;
   int print_status = 0;
   int use_loopback = 0;
+  int include_key_block = 0;
+  const char *sender = NULL;
+  const char *s;
 
   if (argc)
     { argc--; argv++; }
@@ -148,11 +154,24 @@ main (int argc, char **argv)
           key_string = *argv;
           argc--; argv++;
         }
+      else if (!strcmp (*argv, "--sender"))
+        {
+          argc--; argv++;
+          if (!argc)
+            show_usage (1);
+          sender = *argv;
+          argc--; argv++;
+        }
       else if (!strcmp (*argv, "--loopback"))
         {
           use_loopback = 1;
           argc--; argv++;
         }
+      else if (!strcmp (*argv, "--include-key-block"))
+        {
+          include_key_block = 1;
+          argc--; argv++;
+        }
       else if (!strncmp (*argv, "--", 2))
         show_usage (1);
 
@@ -185,6 +204,8 @@ main (int argc, char **argv)
       err = gpgme_get_key (ctx, key_string, &akey, 1);
       if (err)
         {
+          fprintf (stderr, PGM ": get key '%s' failed: %s\n",
+                   key_string, gpg_strerror (err));
           exit (1);
         }
       err = gpgme_signers_add (ctx, akey);
@@ -192,6 +213,23 @@ main (int argc, char **argv)
       gpgme_key_unref (akey);
     }
 
+  if (sender)
+    {
+      err = gpgme_set_sender (ctx, sender);
+      fail_if_err (err);
+    }
+
+  if (include_key_block)
+    {
+      err = gpgme_set_ctx_flag (ctx, "include-key-block", "1");
+      if (err)
+        {
+          fprintf (stderr, PGM ": error setting include-key-block:  %s\n",
+                   gpgme_strerror (err));
+          exit (1);
+        }
+    }
+
   err = gpgme_data_new_from_file (&in, *argv, 1);
   if (err)
     {
@@ -213,6 +251,9 @@ main (int argc, char **argv)
       exit (1);
     }
 
+  if ((s = gpgme_get_ctx_flag (ctx, "redraw")) && *s)
+    fputs ("Screen redraw suggested\n", stdout);
+
   fputs ("Begin Output:\n", stdout);
   print_data (out);
   fputs ("End Output.\n", stdout);