Fix libzypp build error
[platform/upstream/gpgme.git] / tests / gpgsm / cms-decrypt.c
1 /* cms-decrypt.c  - Helper to debug the decrupt operation.
2  * Copyright (C) 2008 g10 Code GmbH
3  *
4  * This file is part of GPGME.
5  *
6  * GPGME is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as
8  * published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * GPGME is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, see <https://gnu.org/licenses/>.
18  * SPDX-License-Identifier: LGPL-2.1-or-later
19  */
20
21 /* We need to include config.h so that we know whether we are building
22    with large file system (LFS) support. */
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30
31 #include <gpgme.h>
32
33 #define PGM "cms-decrypt"
34
35 #include "t-support.h"
36
37 static const char *
38 nonnull (const char *s)
39 {
40   return s? s :"[none]";
41 }
42
43
44 int
45 main (int argc, char **argv)
46 {
47   gpgme_error_t err;
48   gpgme_ctx_t ctx;
49   gpgme_data_t in, out;
50   gpgme_decrypt_result_t result;
51   gpgme_recipient_t recp;
52
53   if (argc)
54     { argc--; argv++; }
55
56   if (argc != 1)
57     {
58       fputs ("usage: " PGM " FILE\n", stderr);
59       exit (1);
60     }
61
62   init_gpgme (GPGME_PROTOCOL_CMS);
63
64   err = gpgme_new (&ctx);
65   fail_if_err (err);
66   gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
67
68
69   err = gpgme_data_new_from_file (&in, *argv, 1);
70   fail_if_err (err);
71
72   err = gpgme_data_new (&out);
73   fail_if_err (err);
74
75   err = gpgme_op_decrypt (ctx, in, out);
76   printf ("gpgme_op_decrypt: %s <%s> (%u)\n",
77           gpgme_strerror (err), gpgme_strsource (err), err);
78   result = gpgme_op_decrypt_result (ctx);
79   if (!result)
80     {
81       fputs (PGM ": error: decryption result missing\n", stderr);
82       exit (1);
83     }
84
85   printf ("unsupported_algorithm: %s\n",
86           nonnull (result->unsupported_algorithm));
87   printf ("wrong_key_usage: %u\n",  result->wrong_key_usage);
88   printf ("file_name: %s\n", nonnull (result->file_name));
89   for (recp = result->recipients; recp; recp = recp->next)
90     {
91       printf ("recipient.status: %s <%s> (%u)\n",
92               gpgme_strerror (recp->status), gpgme_strsource (recp->status),
93               recp->status);
94       printf ("recipient.pkalgo: %d\n", recp->pubkey_algo);
95       printf ("recipient.keyid : %s\n", nonnull (recp->keyid));
96     }
97
98   if (!err)
99     {
100       puts ("plaintext:");
101       print_data (out);
102       gpgme_data_release (out);
103     }
104
105   gpgme_data_release (in);
106
107   gpgme_release (ctx);
108   return 0;
109 }