1 /* t-encrypt.c - Regression test.
2 * Copyright (C) 2000 Werner Koch (dd9jn)
3 * Copyright (C) 2001, 2002, 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 <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #include <gpgme.h>
33
34 #include "t-support.h"
35
36
37 int
main(int argc,char * argv[])38 main (int argc, char *argv[])
39 {
40 gpgme_ctx_t ctx;
41 gpgme_error_t err;
42 gpgme_data_t in, out;
43 gpgme_key_t key[3] = { NULL, NULL, NULL };
44 gpgme_encrypt_result_t result;
45
46 (void)argc;
47 (void)argv;
48
49 init_gpgme (GPGME_PROTOCOL_OpenPGP);
50
51 err = gpgme_new (&ctx);
52 fail_if_err (err);
53 gpgme_set_armor (ctx, 1);
54
55 err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
56 fail_if_err (err);
57
58 err = gpgme_data_new (&out);
59 fail_if_err (err);
60
61 err = gpgme_get_key (ctx, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
62 &key[0], 0);
63 fail_if_err (err);
64 err = gpgme_get_key (ctx, "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2",
65 &key[1], 0);
66 fail_if_err (err);
67
68 err = gpgme_op_encrypt (ctx, key, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
69 fail_if_err (err);
70 result = gpgme_op_encrypt_result (ctx);
71 if (result->invalid_recipients)
72 {
73 fprintf (stderr, "Invalid recipient encountered: %s\n",
74 result->invalid_recipients->fpr);
75 exit (1);
76 }
77 print_data (out);
78
79 gpgme_key_unref (key[0]);
80 gpgme_key_unref (key[1]);
81 gpgme_data_release (in);
82 gpgme_data_release (out);
83 gpgme_release (ctx);
84 return 0;
85 }
86