1 /* t-export.c - Regression test.
2 * Copyright (C) 2000 Werner Koch (dd9jn)
3 * Copyright (C) 2001, 2003, 2004 g10 Code GmbH
4 *
5 * This file is part of GPGME.
6 *
7 * GPGME is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * GPGME is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, see <https://gnu.org/licenses/>.
19 * SPDX-License-Identifier: LGPL-2.1-or-later
20 */
21
22 /* We need to include config.h so that we know whether we are building
23 with large file system (LFS) support. */
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <assert.h>
32
33 #include <gpgme.h>
34
35 #include "t-support.h"
36
37
38 int
main(int argc,char ** argv)39 main (int argc, char **argv)
40 {
41 gpgme_ctx_t ctx;
42 gpgme_error_t err;
43 gpgme_data_t out;
44 const char *pattern[] = { "Alpha", "Bob", NULL };
45 gpgme_key_t keyarray[3];
46
47 (void)argc;
48 (void)argv;
49
50 init_gpgme (GPGME_PROTOCOL_OpenPGP);
51
52 err = gpgme_new (&ctx);
53 fail_if_err (err);
54
55 err = gpgme_data_new (&out);
56 fail_if_err (err);
57
58 gpgme_set_armor (ctx, 1);
59 err = gpgme_op_export_ext (ctx, pattern, 0, out);
60 fail_if_err (err);
61
62 fflush (NULL);
63 fputs ("Begin Result:\n", stdout);
64 print_data (out);
65 fputs ("End Result.\n", stdout);
66
67 gpgme_data_release (out);
68
69 /* Again. Now using a key array. */
70 err = gpgme_data_new (&out);
71 fail_if_err (err);
72
73 err = gpgme_get_key (ctx, "0x68697734" /* Alpha */, keyarray+0, 0);
74 fail_if_err (err);
75 err = gpgme_get_key (ctx, "0xA9E3B0B2" /* Bob */, keyarray+1, 0);
76 fail_if_err (err);
77 keyarray[2] = NULL;
78
79 gpgme_set_armor (ctx, 1);
80 err = gpgme_op_export_keys (ctx, keyarray, 0, out);
81 fail_if_err (err);
82
83 gpgme_key_unref (keyarray[0]);
84 gpgme_key_unref (keyarray[1]);
85
86 fflush (NULL);
87 fputs ("Begin Result:\n", stdout);
88 print_data (out);
89 fputs ("End Result.\n", stdout);
90
91 gpgme_data_release (out);
92
93
94 gpgme_release (ctx);
95
96 return 0;
97 }
98