~ubuntu-branches/ubuntu/lucid/gpgme1.0/lucid

« back to all changes in this revision

Viewing changes to tests/gpg/t-encrypt.c

  • Committer: Bazaar Package Importer
  • Author(s): Jose Carlos Garcia Sogo
  • Date: 2004-11-16 21:36:40 UTC
  • Revision ID: james.westby@ubuntu.com-20041116213640-6ffmegu7bqe05u7l
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* t-encrypt.c - Regression test.
 
2
   Copyright (C) 2000 Werner Koch (dd9jn)
 
3
   Copyright (C) 2001, 2002, 2003 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 General Public License as published by
 
9
   the Free Software Foundation; either version 2 of the License, or
 
10
   (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
   General Public License for more details.
 
16
 
 
17
   You should have received a copy of the GNU General Public License
 
18
   along with GPGME; if not, write to the Free Software Foundation,
 
19
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
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
#include "t-support.h"
 
34
 
 
35
 
 
36
int 
 
37
main (int argc, char *argv[])
 
38
{
 
39
  gpgme_ctx_t ctx;
 
40
  gpgme_error_t err;
 
41
  gpgme_data_t in, out;
 
42
  gpgme_key_t key[3] = { NULL, NULL, NULL };
 
43
  gpgme_encrypt_result_t result;
 
44
 
 
45
  init_gpgme (GPGME_PROTOCOL_OpenPGP);
 
46
    
 
47
  err = gpgme_new (&ctx);
 
48
  fail_if_err (err);
 
49
  gpgme_set_armor (ctx, 1);
 
50
 
 
51
  err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
 
52
  fail_if_err (err);
 
53
 
 
54
  err = gpgme_data_new (&out);
 
55
  fail_if_err (err);
 
56
 
 
57
  err = gpgme_get_key (ctx, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
 
58
                       &key[0], 0);
 
59
  fail_if_err (err);
 
60
  err = gpgme_get_key (ctx, "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2",
 
61
                       &key[1], 0);
 
62
  fail_if_err (err);
 
63
 
 
64
  err = gpgme_op_encrypt (ctx, key, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
 
65
  fail_if_err (err);
 
66
  result = gpgme_op_encrypt_result (ctx);
 
67
  if (result->invalid_recipients)
 
68
    {
 
69
      fprintf (stderr, "Invalid recipient encountered: %s\n",
 
70
               result->invalid_recipients->fpr);
 
71
      exit (1);
 
72
    }
 
73
  print_data (out);
 
74
 
 
75
  gpgme_key_unref (key[0]);
 
76
  gpgme_key_unref (key[1]);
 
77
  gpgme_data_release (in);
 
78
  gpgme_data_release (out);
 
79
  gpgme_release (ctx);
 
80
  return 0;
 
81
}