New API gpgme_op_getauditlog.
[gpgme.git] / gpgme / gpgme.h
1 /* gpgme.h - Public interface to GnuPG Made Easy.
2    Copyright (C) 2000 Werner Koch (dd9jn)
3    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 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 <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef GPGME_H
22 #define GPGME_H
23
24 #ifdef __GNUC__
25 #define _GPGME_INLINE __inline__
26 #elif __STDC_VERSION__ >= 199901L
27 #define _GPGME_INLINE inline
28 #else
29 #define _GPGME_INLINE
30 #endif
31
32 /* Include stdio.h for the FILE type definition.  */
33 #include <stdio.h>
34
35 #ifdef _MSC_VER
36   typedef long off_t;
37   typedef long ssize_t;
38 #else
39 # include <sys/types.h>
40 #endif
41
42 #include <gpg-error.h>
43
44 #ifdef __cplusplus
45 extern "C" {
46 #if 0 /* just to make Emacs auto-indent happy */
47 }
48 #endif
49 #endif /* __cplusplus */
50
51
52 \f
53 /* Check for compiler features.  */
54 #if __GNUC__
55 #define _GPGME_GCC_VERSION (__GNUC__ * 10000 \
56                             + __GNUC_MINOR__ * 100 \
57                             + __GNUC_PATCHLEVEL__)
58
59 #if _GPGME_GCC_VERSION > 30100
60 #define _GPGME_DEPRECATED       __attribute__ ((__deprecated__))
61 #endif
62 #endif
63
64 #ifndef _GPGME_DEPRECATED
65 #define _GPGME_DEPRECATED
66 #endif
67
68 \f
69 /* The version of this header should match the one of the library.  Do
70    not use this symbol in your application, use gpgme_check_version
71    instead.  The purpose of this macro is to let autoconf (using the
72    AM_PATH_GPGME macro) check that this header matches the installed
73    library.  Warning: Do not edit the next line.  configure will do
74    that for you!  */
75 #define GPGME_VERSION "1.1.6-svn1258"
76
77
78 \f
79 /* Some opaque data types used by GPGME.  */
80
81 /* The context holds some global state and configration options, as
82    well as the results of a crypto operation.  */
83 struct gpgme_context;
84 typedef struct gpgme_context *gpgme_ctx_t;
85
86 /* The data object is used by GPGME to exchange arbitrary data.  */
87 struct gpgme_data;
88 typedef struct gpgme_data *gpgme_data_t;
89
90 \f
91 /* Wrappers for the libgpg-error library.  */
92
93 typedef gpg_error_t gpgme_error_t;
94 typedef gpg_err_code_t gpgme_err_code_t;
95 typedef gpg_err_source_t gpgme_err_source_t;
96
97
98 static _GPGME_INLINE gpgme_error_t
99 gpgme_err_make (gpgme_err_source_t source, gpgme_err_code_t code)
100 {
101   return gpg_err_make (source, code);
102 }
103
104
105 /* The user can define GPGME_ERR_SOURCE_DEFAULT before including this
106    file to specify a default source for gpgme_error.  */
107 #ifndef GPGME_ERR_SOURCE_DEFAULT
108 #define GPGME_ERR_SOURCE_DEFAULT  GPG_ERR_SOURCE_USER_1
109 #endif
110
111 static _GPGME_INLINE gpgme_error_t
112 gpgme_error (gpgme_err_code_t code)
113 {
114   return gpgme_err_make (GPGME_ERR_SOURCE_DEFAULT, code);
115 }
116
117
118 static _GPGME_INLINE gpgme_err_code_t
119 gpgme_err_code (gpgme_error_t err)
120 {
121   return gpg_err_code (err);
122 }
123
124
125 static _GPGME_INLINE gpgme_err_source_t
126 gpgme_err_source (gpgme_error_t err)
127 {
128   return gpg_err_source (err);
129 }
130
131
132 /* Return a pointer to a string containing a description of the error
133    code in the error value ERR.  This function is not thread safe.  */
134 const char *gpgme_strerror (gpgme_error_t err);
135
136 /* Return the error string for ERR in the user-supplied buffer BUF of
137    size BUFLEN.  This function is, in contrast to gpg_strerror,
138    thread-safe if a thread-safe strerror_r() function is provided by
139    the system.  If the function succeeds, 0 is returned and BUF
140    contains the string describing the error.  If the buffer was not
141    large enough, ERANGE is returned and BUF contains as much of the
142    beginning of the error string as fits into the buffer.  */
143 int gpgme_strerror_r (gpg_error_t err, char *buf, size_t buflen);
144
145
146 /* Return a pointer to a string containing a description of the error
147    source in the error value ERR.  */
148 const char *gpgme_strsource (gpgme_error_t err);
149
150
151 /* Retrieve the error code for the system error ERR.  This returns
152    GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
153    this).  */
154 gpgme_err_code_t gpgme_err_code_from_errno (int err);
155
156
157 /* Retrieve the system error for the error code CODE.  This returns 0
158    if CODE is not a system error code.  */
159 int gpgme_err_code_to_errno (gpgme_err_code_t code);
160
161   
162 /* Return an error value with the error source SOURCE and the system
163    error ERR.  */
164 gpgme_error_t gpgme_err_make_from_errno (gpgme_err_source_t source, int err);
165
166
167 /* Return an error value with the system error ERR.  */
168 gpgme_err_code_t gpgme_error_from_errno (int err);
169
170 \f
171 /* The possible encoding mode of gpgme_data_t objects.  */
172 typedef enum
173   {
174     GPGME_DATA_ENCODING_NONE   = 0,     /* Not specified.  */
175     GPGME_DATA_ENCODING_BINARY = 1,
176     GPGME_DATA_ENCODING_BASE64 = 2,
177     GPGME_DATA_ENCODING_ARMOR  = 3      /* Either PEM or OpenPGP Armor.  */
178   }
179 gpgme_data_encoding_t;
180
181 \f
182 /* Public key algorithms from libgcrypt.  */
183 typedef enum
184   {
185     GPGME_PK_RSA   = 1,
186     GPGME_PK_RSA_E = 2,
187     GPGME_PK_RSA_S = 3,
188     GPGME_PK_ELG_E = 16,
189     GPGME_PK_DSA   = 17,
190     GPGME_PK_ELG   = 20
191   }
192 gpgme_pubkey_algo_t;
193
194
195 /* Hash algorithms from libgcrypt.  */
196 typedef enum
197   {
198     GPGME_MD_NONE          = 0,  
199     GPGME_MD_MD5           = 1,
200     GPGME_MD_SHA1          = 2,
201     GPGME_MD_RMD160        = 3,
202     GPGME_MD_MD2           = 5,
203     GPGME_MD_TIGER         = 6,   /* TIGER/192. */
204     GPGME_MD_HAVAL         = 7,   /* HAVAL, 5 pass, 160 bit. */
205     GPGME_MD_SHA256        = 8,
206     GPGME_MD_SHA384        = 9,
207     GPGME_MD_SHA512        = 10,
208     GPGME_MD_MD4           = 301,
209     GPGME_MD_CRC32         = 302,
210     GPGME_MD_CRC32_RFC1510 = 303,
211     GPGME_MD_CRC24_RFC2440 = 304
212   }
213 gpgme_hash_algo_t;
214
215 \f
216 /* The possible signature stati.  Deprecated, use error value in sig
217    status.  */
218 typedef enum
219   {
220     GPGME_SIG_STAT_NONE  = 0,
221     GPGME_SIG_STAT_GOOD  = 1,
222     GPGME_SIG_STAT_BAD   = 2,
223     GPGME_SIG_STAT_NOKEY = 3,
224     GPGME_SIG_STAT_NOSIG = 4,
225     GPGME_SIG_STAT_ERROR = 5,
226     GPGME_SIG_STAT_DIFF  = 6,
227     GPGME_SIG_STAT_GOOD_EXP = 7,
228     GPGME_SIG_STAT_GOOD_EXPKEY = 8
229   }
230 _gpgme_sig_stat_t;
231 typedef _gpgme_sig_stat_t gpgme_sig_stat_t _GPGME_DEPRECATED;
232
233
234 /* The available signature modes.  */
235 typedef enum
236   {
237     GPGME_SIG_MODE_NORMAL = 0,
238     GPGME_SIG_MODE_DETACH = 1,
239     GPGME_SIG_MODE_CLEAR  = 2
240   }
241 gpgme_sig_mode_t;
242
243 \f
244 /* The available key and signature attributes.  Deprecated, use the
245    individual result structures instead.  */
246 typedef enum
247   {
248     GPGME_ATTR_KEYID        = 1,
249     GPGME_ATTR_FPR          = 2,
250     GPGME_ATTR_ALGO         = 3,
251     GPGME_ATTR_LEN          = 4,
252     GPGME_ATTR_CREATED      = 5,
253     GPGME_ATTR_EXPIRE       = 6,
254     GPGME_ATTR_OTRUST       = 7,
255     GPGME_ATTR_USERID       = 8,
256     GPGME_ATTR_NAME         = 9,
257     GPGME_ATTR_EMAIL        = 10,
258     GPGME_ATTR_COMMENT      = 11,
259     GPGME_ATTR_VALIDITY     = 12,
260     GPGME_ATTR_LEVEL        = 13,
261     GPGME_ATTR_TYPE         = 14,
262     GPGME_ATTR_IS_SECRET    = 15,
263     GPGME_ATTR_KEY_REVOKED  = 16,
264     GPGME_ATTR_KEY_INVALID  = 17,
265     GPGME_ATTR_UID_REVOKED  = 18,
266     GPGME_ATTR_UID_INVALID  = 19,
267     GPGME_ATTR_KEY_CAPS     = 20,
268     GPGME_ATTR_CAN_ENCRYPT  = 21,
269     GPGME_ATTR_CAN_SIGN     = 22,
270     GPGME_ATTR_CAN_CERTIFY  = 23,
271     GPGME_ATTR_KEY_EXPIRED  = 24,
272     GPGME_ATTR_KEY_DISABLED = 25,
273     GPGME_ATTR_SERIAL       = 26,
274     GPGME_ATTR_ISSUER       = 27,
275     GPGME_ATTR_CHAINID      = 28,
276     GPGME_ATTR_SIG_STATUS   = 29,
277     GPGME_ATTR_ERRTOK       = 30,
278     GPGME_ATTR_SIG_SUMMARY  = 31,
279     GPGME_ATTR_SIG_CLASS    = 32
280   }
281 _gpgme_attr_t;
282 typedef _gpgme_attr_t gpgme_attr_t _GPGME_DEPRECATED;
283
284 \f
285 /* The available validities for a trust item or key.  */
286 typedef enum
287   {
288     GPGME_VALIDITY_UNKNOWN   = 0,
289     GPGME_VALIDITY_UNDEFINED = 1,
290     GPGME_VALIDITY_NEVER     = 2,
291     GPGME_VALIDITY_MARGINAL  = 3,
292     GPGME_VALIDITY_FULL      = 4,
293     GPGME_VALIDITY_ULTIMATE  = 5
294   }
295 gpgme_validity_t;
296
297 \f
298 /* The available protocols.  */
299 typedef enum
300   {
301     GPGME_PROTOCOL_OpenPGP = 0,  /* The default mode.  */
302     GPGME_PROTOCOL_CMS     = 1,
303     GPGME_PROTOCOL_UNKNOWN = 255
304   }
305 gpgme_protocol_t;
306
307 \f
308 /* The available keylist mode flags.  */
309 #define GPGME_KEYLIST_MODE_LOCAL                1
310 #define GPGME_KEYLIST_MODE_EXTERN               2
311 #define GPGME_KEYLIST_MODE_SIGS                 4
312 #define GPGME_KEYLIST_MODE_SIG_NOTATIONS        8
313 #define GPGME_KEYLIST_MODE_VALIDATE             256
314
315 typedef unsigned int gpgme_keylist_mode_t;
316
317 \f
318 /* Flags for the audit log functions.  */
319 #define GPGME_AUDITLOG_HTML      1 
320 #define GPGME_AUDITLOG_WITH_HELP 128
321
322 \f
323 /* Signature notations.  */
324
325 /* The available signature notation flags.  */
326 #define GPGME_SIG_NOTATION_HUMAN_READABLE       1
327 #define GPGME_SIG_NOTATION_CRITICAL             2
328
329 typedef unsigned int gpgme_sig_notation_flags_t;
330
331 struct _gpgme_sig_notation
332 {
333   struct _gpgme_sig_notation *next;
334
335   /* If NAME is a null pointer, then VALUE contains a policy URL
336      rather than a notation.  */
337   char *name;
338
339   /* The value of the notation data.  */
340   char *value;
341
342   /* The length of the name of the notation data.  */
343   int name_len;
344
345   /* The length of the value of the notation data.  */
346   int value_len;
347
348   /* The accumulated flags.  */
349   gpgme_sig_notation_flags_t flags;
350
351   /* Notation data is human-readable.  */
352   unsigned int human_readable : 1;
353
354   /* Notation data is critical.  */
355   unsigned int critical : 1;
356
357   /* Internal to GPGME, do not use.  */
358   int _unused : 30;
359 };
360 typedef struct _gpgme_sig_notation *gpgme_sig_notation_t;
361
362 \f
363 /* The possible stati for the edit operation.  */
364 typedef enum
365   {
366     GPGME_STATUS_EOF,
367     /* mkstatus processing starts here */
368     GPGME_STATUS_ENTER,
369     GPGME_STATUS_LEAVE,
370     GPGME_STATUS_ABORT,
371
372     GPGME_STATUS_GOODSIG,
373     GPGME_STATUS_BADSIG,
374     GPGME_STATUS_ERRSIG,
375
376     GPGME_STATUS_BADARMOR,
377
378     GPGME_STATUS_RSA_OR_IDEA,
379     GPGME_STATUS_KEYEXPIRED,
380     GPGME_STATUS_KEYREVOKED,
381
382     GPGME_STATUS_TRUST_UNDEFINED,
383     GPGME_STATUS_TRUST_NEVER,
384     GPGME_STATUS_TRUST_MARGINAL,
385     GPGME_STATUS_TRUST_FULLY,
386     GPGME_STATUS_TRUST_ULTIMATE,
387
388     GPGME_STATUS_SHM_INFO,
389     GPGME_STATUS_SHM_GET,
390     GPGME_STATUS_SHM_GET_BOOL,
391     GPGME_STATUS_SHM_GET_HIDDEN,
392
393     GPGME_STATUS_NEED_PASSPHRASE,
394     GPGME_STATUS_VALIDSIG,
395     GPGME_STATUS_SIG_ID,
396     GPGME_STATUS_ENC_TO,
397     GPGME_STATUS_NODATA,
398     GPGME_STATUS_BAD_PASSPHRASE,
399     GPGME_STATUS_NO_PUBKEY,
400     GPGME_STATUS_NO_SECKEY,
401     GPGME_STATUS_NEED_PASSPHRASE_SYM,
402     GPGME_STATUS_DECRYPTION_FAILED,
403     GPGME_STATUS_DECRYPTION_OKAY,
404     GPGME_STATUS_MISSING_PASSPHRASE,
405     GPGME_STATUS_GOOD_PASSPHRASE,
406     GPGME_STATUS_GOODMDC,
407     GPGME_STATUS_BADMDC,
408     GPGME_STATUS_ERRMDC,
409     GPGME_STATUS_IMPORTED,
410     GPGME_STATUS_IMPORT_OK,
411     GPGME_STATUS_IMPORT_PROBLEM,
412     GPGME_STATUS_IMPORT_RES,
413     GPGME_STATUS_FILE_START,
414     GPGME_STATUS_FILE_DONE,
415     GPGME_STATUS_FILE_ERROR,
416
417     GPGME_STATUS_BEGIN_DECRYPTION,
418     GPGME_STATUS_END_DECRYPTION,
419     GPGME_STATUS_BEGIN_ENCRYPTION,
420     GPGME_STATUS_END_ENCRYPTION,
421
422     GPGME_STATUS_DELETE_PROBLEM,
423     GPGME_STATUS_GET_BOOL,
424     GPGME_STATUS_GET_LINE,
425     GPGME_STATUS_GET_HIDDEN,
426     GPGME_STATUS_GOT_IT,
427     GPGME_STATUS_PROGRESS,
428     GPGME_STATUS_SIG_CREATED,
429     GPGME_STATUS_SESSION_KEY,
430     GPGME_STATUS_NOTATION_NAME,
431     GPGME_STATUS_NOTATION_DATA,
432     GPGME_STATUS_POLICY_URL,
433     GPGME_STATUS_BEGIN_STREAM,
434     GPGME_STATUS_END_STREAM,
435     GPGME_STATUS_KEY_CREATED,
436     GPGME_STATUS_USERID_HINT,
437     GPGME_STATUS_UNEXPECTED,
438     GPGME_STATUS_INV_RECP,
439     GPGME_STATUS_NO_RECP,
440     GPGME_STATUS_ALREADY_SIGNED,
441     GPGME_STATUS_SIGEXPIRED,
442     GPGME_STATUS_EXPSIG,
443     GPGME_STATUS_EXPKEYSIG,
444     GPGME_STATUS_TRUNCATED,
445     GPGME_STATUS_ERROR,
446     GPGME_STATUS_NEWSIG,
447     GPGME_STATUS_REVKEYSIG,
448     GPGME_STATUS_SIG_SUBPACKET,
449     GPGME_STATUS_NEED_PASSPHRASE_PIN,
450     GPGME_STATUS_SC_OP_FAILURE,
451     GPGME_STATUS_SC_OP_SUCCESS,
452     GPGME_STATUS_CARDCTRL,
453     GPGME_STATUS_BACKUP_KEY_CREATED,
454     GPGME_STATUS_PKA_TRUST_BAD,
455     GPGME_STATUS_PKA_TRUST_GOOD,
456
457     GPGME_STATUS_PLAINTEXT
458   }
459 gpgme_status_code_t;
460
461 \f
462 /* The engine information structure.  */
463 struct _gpgme_engine_info
464 {
465   struct _gpgme_engine_info *next;
466
467   /* The protocol ID.  */
468   gpgme_protocol_t protocol;
469
470   /* The file name of the engine binary.  */
471   char *file_name;
472   
473   /* The version string of the installed engine.  */
474   char *version;
475
476   /* The minimum version required for GPGME.  */
477   const char *req_version;
478
479   /* The home directory used, or NULL if default.  */
480   char *home_dir;
481 };
482 typedef struct _gpgme_engine_info *gpgme_engine_info_t;
483
484 \f
485 /* A subkey from a key.  */
486 struct _gpgme_subkey
487 {
488   struct _gpgme_subkey *next;
489
490   /* True if subkey is revoked.  */
491   unsigned int revoked : 1;
492
493   /* True if subkey is expired.  */
494   unsigned int expired : 1;
495
496   /* True if subkey is disabled.  */
497   unsigned int disabled : 1;
498
499   /* True if subkey is invalid.  */
500   unsigned int invalid : 1;
501
502   /* True if subkey can be used for encryption.  */
503   unsigned int can_encrypt : 1;
504
505   /* True if subkey can be used for signing.  */
506   unsigned int can_sign : 1;
507
508   /* True if subkey can be used for certification.  */
509   unsigned int can_certify : 1;
510
511   /* True if subkey is secret.  */
512   unsigned int secret : 1;
513
514   /* True if subkey can be used for authentication.  */
515   unsigned int can_authenticate : 1;
516
517   /* True if subkey is qualified for signatures according to German law.  */
518   unsigned int is_qualified : 1;
519
520   /* Internal to GPGME, do not use.  */
521   unsigned int _unused : 22;
522   
523   /* Public key algorithm supported by this subkey.  */
524   gpgme_pubkey_algo_t pubkey_algo;
525
526   /* Length of the subkey.  */
527   unsigned int length;
528
529   /* The key ID of the subkey.  */
530   char *keyid;
531
532   /* Internal to GPGME, do not use.  */
533   char _keyid[16 + 1];
534
535   /* The fingerprint of the subkey in hex digit form.  */
536   char *fpr;
537
538   /* The creation timestamp, -1 if invalid, 0 if not available.  */
539   long int timestamp;
540
541   /* The expiration timestamp, 0 if the subkey does not expire.  */
542   long int expires;
543 };
544 typedef struct _gpgme_subkey *gpgme_subkey_t;
545
546
547 /* A signature on a user ID.  */
548 struct _gpgme_key_sig
549 {
550   struct _gpgme_key_sig *next;
551
552   /* True if the signature is a revocation signature.  */
553   unsigned int revoked : 1;
554
555   /* True if the signature is expired.  */
556   unsigned int expired : 1;
557
558   /* True if the signature is invalid.  */
559   unsigned int invalid : 1;
560
561   /* True if the signature should be exported.  */
562   unsigned int exportable : 1;
563
564   /* Internal to GPGME, do not use.  */
565   unsigned int _unused : 28;
566
567   /* The public key algorithm used to create the signature.  */
568   gpgme_pubkey_algo_t pubkey_algo;
569
570   /* The key ID of key used to create the signature.  */
571   char *keyid;
572
573   /* Internal to GPGME, do not use.  */
574   char _keyid[16 + 1];
575
576   /* The creation timestamp, -1 if invalid, 0 if not available.  */
577   long int timestamp;
578
579   /* The expiration timestamp, 0 if the subkey does not expire.  */
580   long int expires;
581
582   /* Same as in gpgme_signature_t.  */
583   gpgme_error_t status;
584
585 #ifdef __cplusplus
586   unsigned int _obsolete_class _GPGME_DEPRECATED;
587 #else
588   /* Must be set to SIG_CLASS below.  */
589   unsigned int class _GPGME_DEPRECATED;
590 #endif
591
592   /* The user ID string.  */
593   char *uid;
594
595   /* The name part of the user ID.  */
596   char *name;
597
598   /* The email part of the user ID.  */
599   char *email;
600
601   /* The comment part of the user ID.  */
602   char *comment;
603
604   /* Crypto backend specific signature class.  */
605   unsigned int sig_class;
606
607   /* Notation data and policy URLs.  */
608   gpgme_sig_notation_t notations;
609
610   /* Internal to GPGME, do not use.  */
611   gpgme_sig_notation_t _last_notation;
612 };
613 typedef struct _gpgme_key_sig *gpgme_key_sig_t;
614
615
616 /* An user ID from a key.  */
617 struct _gpgme_user_id
618 {
619   struct _gpgme_user_id *next;
620
621   /* True if the user ID is revoked.  */
622   unsigned int revoked : 1;
623
624   /* True if the user ID is invalid.  */
625   unsigned int invalid : 1;
626
627   /* Internal to GPGME, do not use.  */
628   unsigned int _unused : 30;
629
630   /* The validity of the user ID.  */
631   gpgme_validity_t validity; 
632
633   /* The user ID string.  */
634   char *uid;
635
636   /* The name part of the user ID.  */
637   char *name;
638
639   /* The email part of the user ID.  */
640   char *email;
641
642   /* The comment part of the user ID.  */
643   char *comment;
644
645   /* The signatures of the user ID.  */
646   gpgme_key_sig_t signatures;
647
648   /* Internal to GPGME, do not use.  */
649   gpgme_key_sig_t _last_keysig;
650 };
651 typedef struct _gpgme_user_id *gpgme_user_id_t;
652
653
654 /* A key from the keyring.  */
655 struct _gpgme_key
656 {
657   /* Internal to GPGME, do not use.  */
658   unsigned int _refs;
659
660   /* True if key is revoked.  */
661   unsigned int revoked : 1;
662
663   /* True if key is expired.  */
664   unsigned int expired : 1;
665
666   /* True if key is disabled.  */
667   unsigned int disabled : 1;
668
669   /* True if key is invalid.  */
670   unsigned int invalid : 1;
671
672   /* True if key can be used for encryption.  */
673   unsigned int can_encrypt : 1;
674
675   /* True if key can be used for signing.  */
676   unsigned int can_sign : 1;
677
678   /* True if key can be used for certification.  */
679   unsigned int can_certify : 1;
680
681   /* True if key is secret.  */
682   unsigned int secret : 1;
683
684   /* True if key can be used for authentication.  */
685   unsigned int can_authenticate : 1;
686
687   /* True if subkey is qualified for signatures according to German law.  */
688   unsigned int is_qualified : 1;
689
690   /* Internal to GPGME, do not use.  */
691   unsigned int _unused : 22;
692
693   /* This is the protocol supported by this key.  */
694   gpgme_protocol_t protocol;
695
696   /* If protocol is GPGME_PROTOCOL_CMS, this string contains the
697      issuer serial.  */
698   char *issuer_serial;
699
700   /* If protocol is GPGME_PROTOCOL_CMS, this string contains the
701      issuer name.  */
702   char *issuer_name;
703
704   /* If protocol is GPGME_PROTOCOL_CMS, this string contains the chain
705      ID.  */
706   char *chain_id;
707
708   /* If protocol is GPGME_PROTOCOL_OpenPGP, this field contains the
709      owner trust.  */
710   gpgme_validity_t owner_trust;
711
712   /* The subkeys of the key.  */
713   gpgme_subkey_t subkeys;
714
715   /* The user IDs of the key.  */
716   gpgme_user_id_t uids;
717
718   /* Internal to GPGME, do not use.  */
719   gpgme_subkey_t _last_subkey;
720
721   /* Internal to GPGME, do not use.  */
722   gpgme_user_id_t _last_uid;
723
724   /* The keylist mode that was active when listing the key.  */
725   gpgme_keylist_mode_t keylist_mode;
726 };
727 typedef struct _gpgme_key *gpgme_key_t;
728
729
730 \f
731 /* Types for callback functions.  */
732
733 /* Request a passphrase from the user.  */
734 typedef gpgme_error_t (*gpgme_passphrase_cb_t) (void *hook,
735                                                 const char *uid_hint,
736                                                 const char *passphrase_info,
737                                                 int prev_was_bad, int fd);
738
739 /* Inform the user about progress made.  */
740 typedef void (*gpgme_progress_cb_t) (void *opaque, const char *what,
741                                      int type, int current, int total);
742
743 /* Interact with the user about an edit operation.  */
744 typedef gpgme_error_t (*gpgme_edit_cb_t) (void *opaque,
745                                           gpgme_status_code_t status,
746                                           const char *args, int fd);
747
748 \f
749 /* Context management functions.  */
750
751 /* Create a new context and return it in CTX.  */
752 gpgme_error_t gpgme_new (gpgme_ctx_t *ctx);
753
754 /* Release the context CTX.  */
755 void gpgme_release (gpgme_ctx_t ctx);
756
757 /* Set the protocol to be used by CTX to PROTO.  */
758 gpgme_error_t gpgme_set_protocol (gpgme_ctx_t ctx, gpgme_protocol_t proto);
759
760 /* Get the protocol used with CTX */
761 gpgme_protocol_t gpgme_get_protocol (gpgme_ctx_t ctx);
762
763 /* Get the string describing protocol PROTO, or NULL if invalid.  */
764 const char *gpgme_get_protocol_name (gpgme_protocol_t proto);
765
766 /* If YES is non-zero, enable armor mode in CTX, disable it otherwise.  */
767 void gpgme_set_armor (gpgme_ctx_t ctx, int yes);
768
769 /* Return non-zero if armor mode is set in CTX.  */
770 int gpgme_get_armor (gpgme_ctx_t ctx);
771
772 /* If YES is non-zero, enable text mode in CTX, disable it otherwise.  */
773 void gpgme_set_textmode (gpgme_ctx_t ctx, int yes);
774
775 /* Return non-zero if text mode is set in CTX.  */
776 int gpgme_get_textmode (gpgme_ctx_t ctx);
777
778 /* Use whatever the default of the backend crypto engine is.  */
779 #define GPGME_INCLUDE_CERTS_DEFAULT     -256
780
781 /* Include up to NR_OF_CERTS certificates in an S/MIME message.  */
782 void gpgme_set_include_certs (gpgme_ctx_t ctx, int nr_of_certs);
783
784 /* Return the number of certs to include in an S/MIME message.  */
785 int gpgme_get_include_certs (gpgme_ctx_t ctx);
786
787 /* Set keylist mode in CTX to MODE.  */
788 gpgme_error_t gpgme_set_keylist_mode (gpgme_ctx_t ctx,
789                                       gpgme_keylist_mode_t mode);
790
791 /* Get keylist mode in CTX.  */
792 gpgme_keylist_mode_t gpgme_get_keylist_mode (gpgme_ctx_t ctx);
793
794 /* Set the passphrase callback function in CTX to CB.  HOOK_VALUE is
795    passed as first argument to the passphrase callback function.  */
796 void gpgme_set_passphrase_cb (gpgme_ctx_t ctx,
797                               gpgme_passphrase_cb_t cb, void *hook_value);
798
799 /* Get the current passphrase callback function in *CB and the current
800    hook value in *HOOK_VALUE.  */
801 void gpgme_get_passphrase_cb (gpgme_ctx_t ctx, gpgme_passphrase_cb_t *cb,
802                               void **hook_value);
803
804 /* Set the progress callback function in CTX to CB.  HOOK_VALUE is
805    passed as first argument to the progress callback function.  */
806 void gpgme_set_progress_cb (gpgme_ctx_t c, gpgme_progress_cb_t cb,
807                             void *hook_value);
808
809 /* Get the current progress callback function in *CB and the current
810    hook value in *HOOK_VALUE.  */
811 void gpgme_get_progress_cb (gpgme_ctx_t ctx, gpgme_progress_cb_t *cb,
812                             void **hook_value);
813
814 /* This function sets the locale for the context CTX, or the default
815    locale if CTX is a null pointer.  */
816 gpgme_error_t gpgme_set_locale (gpgme_ctx_t ctx, int category,
817                                 const char *value);
818
819 /* Get the information about the configured engines.  A pointer to the
820    first engine in the statically allocated linked list is returned.
821    The returned data is valid until the next gpgme_ctx_set_engine_info.  */
822 gpgme_engine_info_t gpgme_ctx_get_engine_info (gpgme_ctx_t ctx);
823
824 /* Set the engine info for the context CTX, protocol PROTO, to the
825    file name FILE_NAME and the home directory HOME_DIR.  */
826 gpgme_error_t gpgme_ctx_set_engine_info (gpgme_ctx_t ctx,
827                                          gpgme_protocol_t proto,
828                                          const char *file_name,
829                                          const char *home_dir);
830
831 \f
832 /* Return a statically allocated string with the name of the public
833    key algorithm ALGO, or NULL if that name is not known.  */
834 const char *gpgme_pubkey_algo_name (gpgme_pubkey_algo_t algo);
835
836 /* Return a statically allocated string with the name of the hash
837    algorithm ALGO, or NULL if that name is not known.  */
838 const char *gpgme_hash_algo_name (gpgme_hash_algo_t algo);
839
840 \f
841 /* Delete all signers from CTX.  */
842 void gpgme_signers_clear (gpgme_ctx_t ctx);
843
844 /* Add KEY to list of signers in CTX.  */
845 gpgme_error_t gpgme_signers_add (gpgme_ctx_t ctx, const gpgme_key_t key);
846
847 /* Return the SEQth signer's key in CTX.  */
848 gpgme_key_t gpgme_signers_enum (const gpgme_ctx_t ctx, int seq);
849
850 /* Retrieve the signature status of signature IDX in CTX after a
851    successful verify operation in R_STAT (if non-null).  The creation
852    time stamp of the signature is returned in R_CREATED (if non-null).
853    The function returns a string containing the fingerprint.
854    Deprecated, use verify result directly.  */
855 const char *gpgme_get_sig_status (gpgme_ctx_t ctx, int idx,
856                                   _gpgme_sig_stat_t *r_stat,
857                                   time_t *r_created) _GPGME_DEPRECATED;
858
859 /* Retrieve certain attributes of a signature.  IDX is the index
860    number of the signature after a successful verify operation.  WHAT
861    is an attribute where GPGME_ATTR_EXPIRE is probably the most useful
862    one.  WHATIDX is to be passed as 0 for most attributes . */
863 unsigned long gpgme_get_sig_ulong_attr (gpgme_ctx_t c, int idx,
864                                         _gpgme_attr_t what, int whatidx)
865      _GPGME_DEPRECATED;
866 const char *gpgme_get_sig_string_attr (gpgme_ctx_t c, int idx,
867                                        _gpgme_attr_t what, int whatidx)
868      _GPGME_DEPRECATED;
869
870
871 /* Get the key used to create signature IDX in CTX and return it in
872    R_KEY.  */
873 gpgme_error_t gpgme_get_sig_key (gpgme_ctx_t ctx, int idx, gpgme_key_t *r_key)
874      _GPGME_DEPRECATED;
875
876 \f
877 /* Clear all notation data from the context.  */
878 void gpgme_sig_notation_clear (gpgme_ctx_t ctx);
879
880 /* Add the human-readable notation data with name NAME and value VALUE
881    to the context CTX, using the flags FLAGS.  If NAME is NULL, then
882    VALUE should be a policy URL.  The flag
883    GPGME_SIG_NOTATION_HUMAN_READABLE is forced to be true for notation
884    data, and false for policy URLs.  */
885 gpgme_error_t gpgme_sig_notation_add (gpgme_ctx_t ctx, const char *name,
886                                       const char *value,
887                                       gpgme_sig_notation_flags_t flags);
888
889 /* Get the sig notations for this context.  */
890 gpgme_sig_notation_t gpgme_sig_notation_get (gpgme_ctx_t ctx);
891
892 \f
893 /* Run control.  */
894
895 /* The type of an I/O callback function.  */
896 typedef gpgme_error_t (*gpgme_io_cb_t) (void *data, int fd);
897
898 /* The type of a function that can register FNC as the I/O callback
899    function for the file descriptor FD with direction dir (0: for writing,
900    1: for reading).  FNC_DATA should be passed as DATA to FNC.  The
901    function should return a TAG suitable for the corresponding
902    gpgme_remove_io_cb_t, and an error value.  */
903 typedef gpgme_error_t (*gpgme_register_io_cb_t) (void *data, int fd, int dir,
904                                                  gpgme_io_cb_t fnc,
905                                                  void *fnc_data, void **tag);
906
907 /* The type of a function that can remove a previously registered I/O
908    callback function given TAG as returned by the register
909    function.  */
910 typedef void (*gpgme_remove_io_cb_t) (void *tag);
911
912 typedef enum
913   {
914     GPGME_EVENT_START,
915     GPGME_EVENT_DONE,
916     GPGME_EVENT_NEXT_KEY,
917     GPGME_EVENT_NEXT_TRUSTITEM
918   }
919 gpgme_event_io_t;
920
921 /* The type of a function that is called when a context finished an
922    operation.  */
923 typedef void (*gpgme_event_io_cb_t) (void *data, gpgme_event_io_t type,
924                                      void *type_data);
925
926 struct gpgme_io_cbs
927 {
928   gpgme_register_io_cb_t add;
929   void *add_priv;
930   gpgme_remove_io_cb_t remove;
931   gpgme_event_io_cb_t event;
932   void *event_priv;
933 };
934 typedef struct gpgme_io_cbs *gpgme_io_cbs_t;
935
936 /* Set the I/O callback functions in CTX to IO_CBS.  */
937 void gpgme_set_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs);
938
939 /* Get the current I/O callback functions.  */
940 void gpgme_get_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs);
941
942 /* Process the pending operation and, if HANG is non-zero, wait for
943    the pending operation to finish.  */
944 gpgme_ctx_t gpgme_wait (gpgme_ctx_t ctx, gpgme_error_t *status, int hang);
945
946 \f
947 /* Functions to handle data objects.  */
948
949 /* Read up to SIZE bytes into buffer BUFFER from the data object with
950    the handle HANDLE.  Return the number of characters read, 0 on EOF
951    and -1 on error.  If an error occurs, errno is set.  */
952 typedef ssize_t (*gpgme_data_read_cb_t) (void *handle, void *buffer,
953                                          size_t size);
954
955 /* Write up to SIZE bytes from buffer BUFFER to the data object with
956    the handle HANDLE.  Return the number of characters written, or -1
957    on error.  If an error occurs, errno is set.  */
958 typedef ssize_t (*gpgme_data_write_cb_t) (void *handle, const void *buffer,
959                                           size_t size);
960
961 /* Set the current position from where the next read or write starts
962    in the data object with the handle HANDLE to OFFSET, relativ to
963    WHENCE.  */
964 typedef off_t (*gpgme_data_seek_cb_t) (void *handle, off_t offset, int whence);
965
966 /* Close the data object with the handle DL.  */
967 typedef void (*gpgme_data_release_cb_t) (void *handle);
968
969 struct gpgme_data_cbs
970 {
971   gpgme_data_read_cb_t read;
972   gpgme_data_write_cb_t write;
973   gpgme_data_seek_cb_t seek;
974   gpgme_data_release_cb_t release;
975 };
976 typedef struct gpgme_data_cbs *gpgme_data_cbs_t;
977
978 /* Read up to SIZE bytes into buffer BUFFER from the data object with
979    the handle DH.  Return the number of characters read, 0 on EOF and
980    -1 on error.  If an error occurs, errno is set.  */
981 ssize_t gpgme_data_read (gpgme_data_t dh, void *buffer, size_t size);
982
983 /* Write up to SIZE bytes from buffer BUFFER to the data object with
984    the handle DH.  Return the number of characters written, or -1 on
985    error.  If an error occurs, errno is set.  */
986 ssize_t gpgme_data_write (gpgme_data_t dh, const void *buffer, size_t size);
987
988 /* Set the current position from where the next read or write starts
989    in the data object with the handle DH to OFFSET, relativ to
990    WHENCE.  */
991 off_t gpgme_data_seek (gpgme_data_t dh, off_t offset, int whence);
992
993 /* Create a new data buffer and return it in R_DH.  */
994 gpgme_error_t gpgme_data_new (gpgme_data_t *r_dh);
995
996 /* Destroy the data buffer DH.  */
997 void gpgme_data_release (gpgme_data_t dh);
998
999 /* Create a new data buffer filled with SIZE bytes starting from
1000    BUFFER.  If COPY is zero, copying is delayed until necessary, and
1001    the data is taken from the original location when needed.  */
1002 gpgme_error_t gpgme_data_new_from_mem (gpgme_data_t *r_dh,
1003                                        const char *buffer, size_t size,
1004                                        int copy);
1005
1006 /* Destroy the data buffer DH and return a pointer to its content.
1007    The memory has be to released with gpgme_free() by the user.  It's
1008    size is returned in R_LEN.  */
1009 char *gpgme_data_release_and_get_mem (gpgme_data_t dh, size_t *r_len);
1010
1011 /* Release the memory returned by gpgme_data_release_and_get_mem().  */
1012 void gpgme_free (void *buffer);
1013
1014 gpgme_error_t gpgme_data_new_from_cbs (gpgme_data_t *dh,
1015                                        gpgme_data_cbs_t cbs,
1016                                        void *handle);
1017
1018 gpgme_error_t gpgme_data_new_from_fd (gpgme_data_t *dh, int fd);
1019
1020 gpgme_error_t gpgme_data_new_from_stream (gpgme_data_t *dh, FILE *stream);
1021
1022 /* Return the encoding attribute of the data buffer DH */
1023 gpgme_data_encoding_t gpgme_data_get_encoding (gpgme_data_t dh);
1024
1025 /* Set the encoding attribute of data buffer DH to ENC */
1026 gpgme_error_t gpgme_data_set_encoding (gpgme_data_t dh,
1027                                        gpgme_data_encoding_t enc);
1028
1029 /* Get the file name associated with the data object with handle DH, or
1030    NULL if there is none.  */
1031 char *gpgme_data_get_file_name (gpgme_data_t dh);
1032
1033 /* Set the file name associated with the data object with handle DH to
1034    FILE_NAME.  */
1035 gpgme_error_t gpgme_data_set_file_name (gpgme_data_t dh,
1036                                         const char *file_name);
1037
1038
1039 /* Create a new data buffer which retrieves the data from the callback
1040    function READ_CB.  Deprecated, please use gpgme_data_new_from_cbs
1041    instead.  */
1042 gpgme_error_t gpgme_data_new_with_read_cb (gpgme_data_t *r_dh,
1043                                            int (*read_cb) (void*,char *,
1044                                                            size_t,size_t*),
1045                                            void *read_cb_value)
1046      _GPGME_DEPRECATED;
1047
1048 /* Create a new data buffer filled with the content of file FNAME.
1049    COPY must be non-zero.  For delayed read, please use
1050    gpgme_data_new_from_fd or gpgme_data_new_from stream instead.  */
1051 gpgme_error_t gpgme_data_new_from_file (gpgme_data_t *r_dh,
1052                                         const char *fname,
1053                                         int copy);
1054
1055 /* Create a new data buffer filled with LENGTH bytes starting from
1056    OFFSET within the file FNAME or stream FP (exactly one must be
1057    non-zero).  */
1058 gpgme_error_t gpgme_data_new_from_filepart (gpgme_data_t *r_dh,
1059                                             const char *fname, FILE *fp,
1060                                             off_t offset, size_t length);
1061
1062 /* Reset the read pointer in DH.  Deprecated, please use
1063    gpgme_data_seek instead.  */
1064 gpgme_error_t gpgme_data_rewind (gpgme_data_t dh) _GPGME_DEPRECATED;
1065
1066 \f
1067 /* Key and trust functions.  */
1068
1069 /* Get the key with the fingerprint FPR from the crypto backend.  If
1070    SECRET is true, get the secret key.  */
1071 gpgme_error_t gpgme_get_key (gpgme_ctx_t ctx, const char *fpr,
1072                              gpgme_key_t *r_key, int secret);
1073
1074 /* Acquire a reference to KEY.  */
1075 void gpgme_key_ref (gpgme_key_t key);
1076
1077 /* Release a reference to KEY.  If this was the last one the key is
1078    destroyed.  */
1079 void gpgme_key_unref (gpgme_key_t key);
1080 void gpgme_key_release (gpgme_key_t key);
1081
1082 /* Return the value of the attribute WHAT of KEY, which has to be
1083    representable by a string.  IDX specifies the sub key or user ID
1084    for attributes related to sub keys or user IDs.  Deprecated, use
1085    key structure directly instead. */
1086 const char *gpgme_key_get_string_attr (gpgme_key_t key, _gpgme_attr_t what,
1087                                        const void *reserved, int idx)
1088      _GPGME_DEPRECATED;
1089
1090 /* Return the value of the attribute WHAT of KEY, which has to be
1091    representable by an unsigned integer.  IDX specifies the sub key or
1092    user ID for attributes related to sub keys or user IDs.
1093    Deprecated, use key structure directly instead.  */
1094 unsigned long gpgme_key_get_ulong_attr (gpgme_key_t key, _gpgme_attr_t what,
1095                                         const void *reserved, int idx)
1096      _GPGME_DEPRECATED;
1097
1098 /* Return the value of the attribute WHAT of a signature on user ID
1099    UID_IDX in KEY, which has to be representable by a string.  IDX
1100    specifies the signature.  Deprecated, use key structure directly
1101    instead.  */
1102 const char *gpgme_key_sig_get_string_attr (gpgme_key_t key, int uid_idx,
1103                                            _gpgme_attr_t what,
1104                                            const void *reserved, int idx)
1105      _GPGME_DEPRECATED;
1106
1107 /* Return the value of the attribute WHAT of a signature on user ID
1108    UID_IDX in KEY, which has to be representable by an unsigned
1109    integer string.  IDX specifies the signature.  Deprecated, use key
1110    structure directly instead.  */
1111 unsigned long gpgme_key_sig_get_ulong_attr (gpgme_key_t key, int uid_idx,
1112                                             _gpgme_attr_t what,
1113                                             const void *reserved, int idx)
1114      _GPGME_DEPRECATED;
1115
1116 \f
1117 /* Crypto Operations.  */
1118
1119 /* Cancel a pending asynchronous operation.  */
1120 gpgme_error_t gpgme_cancel (gpgme_ctx_t ctx);
1121
1122 \f
1123 struct _gpgme_invalid_key
1124 {
1125   struct _gpgme_invalid_key *next;
1126   char *fpr;
1127   gpgme_error_t reason;
1128 };
1129 typedef struct _gpgme_invalid_key *gpgme_invalid_key_t;
1130
1131 \f
1132 /* Encryption.  */
1133 struct _gpgme_op_encrypt_result
1134 {
1135   /* The list of invalid recipients.  */
1136   gpgme_invalid_key_t invalid_recipients;
1137 };
1138 typedef struct _gpgme_op_encrypt_result *gpgme_encrypt_result_t;
1139
1140 /* Retrieve a pointer to the result of the encrypt operation.  */
1141 gpgme_encrypt_result_t gpgme_op_encrypt_result (gpgme_ctx_t ctx);
1142
1143 /* The valid encryption flags.  */
1144 typedef enum
1145   {
1146     GPGME_ENCRYPT_ALWAYS_TRUST = 1
1147   }
1148 gpgme_encrypt_flags_t;
1149
1150 /* Encrypt plaintext PLAIN within CTX for the recipients RECP and
1151    store the resulting ciphertext in CIPHER.  */
1152 gpgme_error_t gpgme_op_encrypt_start (gpgme_ctx_t ctx, gpgme_key_t recp[],
1153                                       gpgme_encrypt_flags_t flags,
1154                                       gpgme_data_t plain, gpgme_data_t cipher);
1155 gpgme_error_t gpgme_op_encrypt (gpgme_ctx_t ctx, gpgme_key_t recp[],
1156                                 gpgme_encrypt_flags_t flags,
1157                                 gpgme_data_t plain, gpgme_data_t cipher);
1158
1159 /* Encrypt plaintext PLAIN within CTX for the recipients RECP and
1160    store the resulting ciphertext in CIPHER.  Also sign the ciphertext
1161    with the signers in CTX.  */
1162 gpgme_error_t gpgme_op_encrypt_sign_start (gpgme_ctx_t ctx,
1163                                            gpgme_key_t recp[],
1164                                            gpgme_encrypt_flags_t flags,
1165                                            gpgme_data_t plain,
1166                                            gpgme_data_t cipher);
1167 gpgme_error_t gpgme_op_encrypt_sign (gpgme_ctx_t ctx, gpgme_key_t recp[],
1168                                      gpgme_encrypt_flags_t flags,
1169                                      gpgme_data_t plain, gpgme_data_t cipher);
1170
1171 \f
1172 /* Decryption.  */
1173
1174 struct _gpgme_recipient
1175 {
1176   struct _gpgme_recipient *next;
1177
1178   /* The key ID of key for which the text was encrypted.  */
1179   char *keyid;
1180
1181   /* Internal to GPGME, do not use.  */
1182   char _keyid[16 + 1];
1183
1184   /* The public key algorithm of the recipient key.  */
1185   gpgme_pubkey_algo_t pubkey_algo;
1186
1187   /* The status of the recipient.  */
1188   gpgme_error_t status;
1189 };
1190 typedef struct _gpgme_recipient *gpgme_recipient_t;
1191
1192 struct _gpgme_op_decrypt_result
1193 {
1194   char *unsupported_algorithm;
1195
1196   /* Key should not have been used for encryption.  */
1197   unsigned int wrong_key_usage : 1;
1198
1199   /* Internal to GPGME, do not use.  */
1200   int _unused : 31;
1201
1202   gpgme_recipient_t recipients;
1203
1204   /* The original file name of the plaintext message, if
1205      available.  */
1206   char *file_name;
1207 };
1208 typedef struct _gpgme_op_decrypt_result *gpgme_decrypt_result_t;
1209
1210 /* Retrieve a pointer to the result of the decrypt operation.  */
1211 gpgme_decrypt_result_t gpgme_op_decrypt_result (gpgme_ctx_t ctx);
1212
1213 /* Decrypt ciphertext CIPHER within CTX and store the resulting
1214    plaintext in PLAIN.  */
1215 gpgme_error_t gpgme_op_decrypt_start (gpgme_ctx_t ctx, gpgme_data_t cipher,
1216                                       gpgme_data_t plain);
1217 gpgme_error_t gpgme_op_decrypt (gpgme_ctx_t ctx,
1218                                 gpgme_data_t cipher, gpgme_data_t plain);
1219
1220 /* Decrypt ciphertext CIPHER and make a signature verification within
1221    CTX and store the resulting plaintext in PLAIN.  */
1222 gpgme_error_t gpgme_op_decrypt_verify_start (gpgme_ctx_t ctx,
1223                                              gpgme_data_t cipher,
1224                                              gpgme_data_t plain);
1225 gpgme_error_t gpgme_op_decrypt_verify (gpgme_ctx_t ctx, gpgme_data_t cipher,
1226                                        gpgme_data_t plain);
1227
1228 \f
1229 /* Signing.  */
1230 struct _gpgme_new_signature
1231 {
1232   struct _gpgme_new_signature *next;
1233
1234   /* The type of the signature.  */
1235   gpgme_sig_mode_t type;
1236
1237   /* The public key algorithm used to create the signature.  */
1238   gpgme_pubkey_algo_t pubkey_algo;
1239
1240   /* The hash algorithm used to create the signature.  */
1241   gpgme_hash_algo_t hash_algo;
1242
1243   /* Internal to GPGME, do not use.  Must be set to the same value as
1244      CLASS below.  */
1245   unsigned long _obsolete_class;
1246
1247   /* Signature creation time.  */
1248   long int timestamp;
1249
1250   /* The fingerprint of the signature.  */
1251   char *fpr;
1252
1253 #ifdef __cplusplus
1254   unsigned int _obsolete_class_2;
1255 #else
1256   /* Must be set to SIG_CLASS below.  */
1257   unsigned int class _GPGME_DEPRECATED;
1258 #endif
1259
1260   /* Crypto backend specific signature class.  */
1261   unsigned int sig_class;
1262 };
1263 typedef struct _gpgme_new_signature *gpgme_new_signature_t;
1264
1265 struct _gpgme_op_sign_result
1266 {
1267   /* The list of invalid signers.  */
1268   gpgme_invalid_key_t invalid_signers;
1269   gpgme_new_signature_t signatures;
1270 };
1271 typedef struct _gpgme_op_sign_result *gpgme_sign_result_t;
1272
1273 /* Retrieve a pointer to the result of the signing operation.  */
1274 gpgme_sign_result_t gpgme_op_sign_result (gpgme_ctx_t ctx);
1275
1276 /* Sign the plaintext PLAIN and store the signature in SIG.  */
1277 gpgme_error_t gpgme_op_sign_start (gpgme_ctx_t ctx,
1278                                    gpgme_data_t plain, gpgme_data_t sig,
1279                                    gpgme_sig_mode_t mode);
1280 gpgme_error_t gpgme_op_sign (gpgme_ctx_t ctx,
1281                              gpgme_data_t plain, gpgme_data_t sig,
1282                              gpgme_sig_mode_t mode);
1283
1284 \f
1285 /* Verify.  */
1286
1287 /* Flags used for the SUMMARY field in a gpgme_signature_t.  */
1288 typedef enum
1289   {
1290     GPGME_SIGSUM_VALID       = 0x0001,  /* The signature is fully valid.  */
1291     GPGME_SIGSUM_GREEN       = 0x0002,  /* The signature is good.  */
1292     GPGME_SIGSUM_RED         = 0x0004,  /* The signature is bad.  */
1293     GPGME_SIGSUM_KEY_REVOKED = 0x0010,  /* One key has been revoked.  */
1294     GPGME_SIGSUM_KEY_EXPIRED = 0x0020,  /* One key has expired.  */
1295     GPGME_SIGSUM_SIG_EXPIRED = 0x0040,  /* The signature has expired.  */
1296     GPGME_SIGSUM_KEY_MISSING = 0x0080,  /* Can't verify: key missing.  */
1297     GPGME_SIGSUM_CRL_MISSING = 0x0100,  /* CRL not available.  */
1298     GPGME_SIGSUM_CRL_TOO_OLD = 0x0200,  /* Available CRL is too old.  */
1299     GPGME_SIGSUM_BAD_POLICY  = 0x0400,  /* A policy was not met.  */
1300     GPGME_SIGSUM_SYS_ERROR   = 0x0800   /* A system error occured.  */
1301   }
1302 gpgme_sigsum_t;
1303
1304 struct _gpgme_signature
1305 {
1306   struct _gpgme_signature *next;
1307
1308   /* A summary of the signature status.  */
1309   gpgme_sigsum_t summary;
1310
1311   /* The fingerprint or key ID of the signature.  */
1312   char *fpr;
1313
1314   /* The status of the signature.  */
1315   gpgme_error_t status;
1316
1317   /* Notation data and policy URLs.  */
1318   gpgme_sig_notation_t notations;
1319
1320   /* Signature creation time.  */
1321   unsigned long timestamp;
1322
1323   /* Signature exipration time or 0.  */
1324   unsigned long exp_timestamp;
1325
1326   /* Key should not have been used for signing.  */
1327   unsigned int wrong_key_usage : 1;
1328
1329   /* PKA status: 0 = not available, 1 = bad, 2 = okay, 3 = RFU. */
1330   unsigned int pka_trust : 2;
1331
1332   /* Validity has been verified using the chain model. */
1333   unsigned int chain_model : 1;
1334
1335   /* Internal to GPGME, do not use.  */
1336   int _unused : 28;
1337
1338   gpgme_validity_t validity;
1339   gpgme_error_t validity_reason;
1340
1341   /* The public key algorithm used to create the signature.  */
1342   gpgme_pubkey_algo_t pubkey_algo;
1343
1344   /* The hash algorithm used to create the signature.  */
1345   gpgme_hash_algo_t hash_algo;
1346
1347   /* The mailbox from the PKA information or NULL. */
1348   char *pka_address;
1349 };
1350 typedef struct _gpgme_signature *gpgme_signature_t;
1351
1352 struct _gpgme_op_verify_result
1353 {
1354   gpgme_signature_t signatures;
1355
1356   /* The original file name of the plaintext message, if
1357      available.  */
1358   char *file_name;
1359 };
1360 typedef struct _gpgme_op_verify_result *gpgme_verify_result_t;
1361
1362 /* Retrieve a pointer to the result of the verify operation.  */
1363 gpgme_verify_result_t gpgme_op_verify_result (gpgme_ctx_t ctx);
1364
1365 /* Verify within CTX that SIG is a valid signature for TEXT.  */
1366 gpgme_error_t gpgme_op_verify_start (gpgme_ctx_t ctx, gpgme_data_t sig,
1367                                      gpgme_data_t signed_text,
1368                                      gpgme_data_t plaintext);
1369 gpgme_error_t gpgme_op_verify (gpgme_ctx_t ctx, gpgme_data_t sig,
1370                                gpgme_data_t signed_text,
1371                                gpgme_data_t plaintext);
1372
1373 \f
1374 /* Import.  */
1375
1376 /* The key was new.  */
1377 #define GPGME_IMPORT_NEW        1
1378
1379 /* The key contained new user IDs.  */
1380 #define GPGME_IMPORT_UID        2
1381
1382 /* The key contained new signatures.  */
1383 #define GPGME_IMPORT_SIG        4
1384
1385 /* The key contained new sub keys.  */
1386 #define GPGME_IMPORT_SUBKEY     8
1387
1388 /* The key contained a secret key.  */
1389 #define GPGME_IMPORT_SECRET     16
1390
1391
1392 struct _gpgme_import_status
1393 {
1394   struct _gpgme_import_status *next;
1395
1396   /* Fingerprint.  */
1397   char *fpr;
1398
1399   /* If a problem occured, the reason why the key could not be
1400      imported.  Otherwise GPGME_No_Error.  */
1401   gpgme_error_t result;
1402
1403   /* The result of the import, the GPGME_IMPORT_* values bit-wise
1404      ORed.  0 means the key was already known and no new components
1405      have been added.  */
1406   unsigned int status;
1407 };
1408 typedef struct _gpgme_import_status *gpgme_import_status_t;
1409
1410 /* Import.  */
1411 struct _gpgme_op_import_result
1412 {
1413   /* Number of considered keys.  */
1414   int considered;
1415
1416   /* Keys without user ID.  */
1417   int no_user_id;
1418
1419   /* Imported keys.  */
1420   int imported;
1421
1422   /* Imported RSA keys.  */
1423   int imported_rsa;
1424
1425   /* Unchanged keys.  */
1426   int unchanged;
1427
1428   /* Number of new user ids.  */
1429   int new_user_ids;
1430
1431   /* Number of new sub keys.  */
1432   int new_sub_keys;
1433
1434   /* Number of new signatures.  */
1435   int new_signatures;
1436
1437   /* Number of new revocations.  */
1438   int new_revocations;
1439
1440   /* Number of secret keys read.  */
1441   int secret_read;
1442
1443   /* Number of secret keys imported.  */
1444   int secret_imported;
1445
1446   /* Number of secret keys unchanged.  */
1447   int secret_unchanged;
1448
1449   /* Number of new keys skipped.  */
1450   int skipped_new_keys;
1451
1452   /* Number of keys not imported.  */
1453   int not_imported;
1454
1455   /* List of keys for which an import was attempted.  */
1456   gpgme_import_status_t imports;
1457 };
1458 typedef struct _gpgme_op_import_result *gpgme_import_result_t;
1459
1460 /* Retrieve a pointer to the result of the import operation.  */
1461 gpgme_import_result_t gpgme_op_import_result (gpgme_ctx_t ctx);
1462
1463 /* Import the key in KEYDATA into the keyring.  */
1464 gpgme_error_t gpgme_op_import_start (gpgme_ctx_t ctx, gpgme_data_t keydata);
1465 gpgme_error_t gpgme_op_import (gpgme_ctx_t ctx, gpgme_data_t keydata);
1466 gpgme_error_t gpgme_op_import_ext (gpgme_ctx_t ctx, gpgme_data_t keydata,
1467                                    int *nr) _GPGME_DEPRECATED;
1468
1469 \f
1470 /* Export the keys found by PATTERN into KEYDATA.  */
1471 gpgme_error_t gpgme_op_export_start (gpgme_ctx_t ctx, const char *pattern,
1472                                      unsigned int reserved,
1473                                      gpgme_data_t keydata);
1474 gpgme_error_t gpgme_op_export (gpgme_ctx_t ctx, const char *pattern,
1475                                unsigned int reserved, gpgme_data_t keydata);
1476
1477 gpgme_error_t gpgme_op_export_ext_start (gpgme_ctx_t ctx,
1478                                          const char *pattern[],
1479                                          unsigned int reserved,
1480                                          gpgme_data_t keydata);
1481 gpgme_error_t gpgme_op_export_ext (gpgme_ctx_t ctx, const char *pattern[],
1482                                    unsigned int reserved,
1483                                    gpgme_data_t keydata);
1484
1485 \f
1486 /* Key generation.  */
1487 struct _gpgme_op_genkey_result
1488 {
1489   /* A primary key was generated.  */
1490   unsigned int primary : 1;
1491
1492   /* A sub key was generated.  */
1493   unsigned int sub : 1;
1494
1495   /* Internal to GPGME, do not use.  */
1496   unsigned int _unused : 30;
1497
1498   /* The fingerprint of the generated key.  */
1499   char *fpr;
1500 };
1501 typedef struct _gpgme_op_genkey_result *gpgme_genkey_result_t;
1502
1503 /* Generate a new keypair and add it to the keyring.  PUBKEY and
1504    SECKEY should be null for now.  PARMS specifies what keys should be
1505    generated.  */
1506 gpgme_error_t gpgme_op_genkey_start (gpgme_ctx_t ctx, const char *parms,
1507                                      gpgme_data_t pubkey, gpgme_data_t seckey);
1508 gpgme_error_t gpgme_op_genkey (gpgme_ctx_t ctx, const char *parms,
1509                                gpgme_data_t pubkey, gpgme_data_t seckey);
1510
1511 /* Retrieve a pointer to the result of the genkey operation.  */
1512 gpgme_genkey_result_t gpgme_op_genkey_result (gpgme_ctx_t ctx);
1513
1514 \f
1515 /* Delete KEY from the keyring.  If ALLOW_SECRET is non-zero, secret
1516    keys are also deleted.  */
1517 gpgme_error_t gpgme_op_delete_start (gpgme_ctx_t ctx, const gpgme_key_t key,
1518                                      int allow_secret);
1519 gpgme_error_t gpgme_op_delete (gpgme_ctx_t ctx, const gpgme_key_t key,
1520                                int allow_secret);
1521
1522 \f
1523 /* Edit the key KEY.  Send status and command requests to FNC and
1524    output of edit commands to OUT.  */
1525 gpgme_error_t gpgme_op_edit_start (gpgme_ctx_t ctx, gpgme_key_t key,
1526                                    gpgme_edit_cb_t fnc, void *fnc_value,
1527                                    gpgme_data_t out);
1528 gpgme_error_t gpgme_op_edit (gpgme_ctx_t ctx, gpgme_key_t key,
1529                              gpgme_edit_cb_t fnc, void *fnc_value,
1530                              gpgme_data_t out);
1531
1532 /* Edit the card for the key KEY.  Send status and command requests to
1533    FNC and output of edit commands to OUT.  */
1534 gpgme_error_t gpgme_op_card_edit_start (gpgme_ctx_t ctx, gpgme_key_t key,
1535                                         gpgme_edit_cb_t fnc, void *fnc_value,
1536                                         gpgme_data_t out);
1537 gpgme_error_t gpgme_op_card_edit (gpgme_ctx_t ctx, gpgme_key_t key,
1538                                   gpgme_edit_cb_t fnc, void *fnc_value,
1539                                   gpgme_data_t out);
1540
1541 \f
1542 /* Key management functions.  */
1543 struct _gpgme_op_keylist_result
1544 {
1545   unsigned int truncated : 1;
1546
1547   /* Internal to GPGME, do not use.  */
1548   unsigned int _unused : 31;
1549 };
1550 typedef struct _gpgme_op_keylist_result *gpgme_keylist_result_t;
1551
1552 /* Retrieve a pointer to the result of the key listing operation.  */
1553 gpgme_keylist_result_t gpgme_op_keylist_result (gpgme_ctx_t ctx);
1554
1555 /* Start a keylist operation within CTX, searching for keys which
1556    match PATTERN.  If SECRET_ONLY is true, only secret keys are
1557    returned.  */
1558 gpgme_error_t gpgme_op_keylist_start (gpgme_ctx_t ctx, const char *pattern,
1559                                       int secret_only);
1560 gpgme_error_t gpgme_op_keylist_ext_start (gpgme_ctx_t ctx,
1561                                           const char *pattern[],
1562                                           int secret_only, int reserved);
1563
1564 /* Return the next key from the keylist in R_KEY.  */
1565 gpgme_error_t gpgme_op_keylist_next (gpgme_ctx_t ctx, gpgme_key_t *r_key);
1566
1567 /* Terminate a pending keylist operation within CTX.  */
1568 gpgme_error_t gpgme_op_keylist_end (gpgme_ctx_t ctx);
1569
1570 \f
1571 /* Trust items and operations.  */
1572
1573 struct _gpgme_trust_item
1574 {
1575   /* Internal to GPGME, do not use.  */
1576   unsigned int _refs;
1577
1578   /* The key ID to which the trust item belongs.  */
1579   char *keyid;
1580
1581   /* Internal to GPGME, do not use.  */
1582   char _keyid[16 + 1];
1583
1584   /* The type of the trust item, 1 refers to a key, 2 to a user ID.  */
1585   int type;
1586
1587   /* The trust level.  */
1588   int level;
1589
1590   /* The owner trust if TYPE is 1.  */
1591   char *owner_trust;
1592
1593   /* Internal to GPGME, do not use.  */
1594   char _owner_trust[2];
1595
1596   /* The calculated validity.  */
1597   char *validity;
1598  
1599   /* Internal to GPGME, do not use.  */
1600   char _validity[2];
1601
1602   /* The user name if TYPE is 2.  */
1603   char *name;
1604 };
1605 typedef struct _gpgme_trust_item *gpgme_trust_item_t;
1606
1607 /* Start a trustlist operation within CTX, searching for trust items
1608    which match PATTERN.  */
1609 gpgme_error_t gpgme_op_trustlist_start (gpgme_ctx_t ctx,
1610                                         const char *pattern, int max_level);
1611
1612 /* Return the next trust item from the trustlist in R_ITEM.  */
1613 gpgme_error_t gpgme_op_trustlist_next (gpgme_ctx_t ctx,
1614                                        gpgme_trust_item_t *r_item);
1615
1616 /* Terminate a pending trustlist operation within CTX.  */
1617 gpgme_error_t gpgme_op_trustlist_end (gpgme_ctx_t ctx);
1618
1619 /* Acquire a reference to ITEM.  */
1620 void gpgme_trust_item_ref (gpgme_trust_item_t item);
1621
1622 /* Release a reference to ITEM.  If this was the last one the trust
1623    item is destroyed.  */
1624 void gpgme_trust_item_unref (gpgme_trust_item_t item);
1625
1626 /* Release the trust item ITEM.  Deprecated, use
1627    gpgme_trust_item_unref.  */
1628 void gpgme_trust_item_release (gpgme_trust_item_t item) _GPGME_DEPRECATED;
1629
1630 /* Return the value of the attribute WHAT of ITEM, which has to be
1631    representable by a string.  Deprecated, use trust item structure
1632    directly.  */
1633 const char *gpgme_trust_item_get_string_attr (gpgme_trust_item_t item,
1634                                               _gpgme_attr_t what,
1635                                               const void *reserved, int idx)
1636      _GPGME_DEPRECATED;
1637
1638 /* Return the value of the attribute WHAT of KEY, which has to be
1639    representable by an integer.  IDX specifies a running index if the
1640    attribute appears more than once in the key.  Deprecated, use trust
1641    item structure directly.  */
1642 int gpgme_trust_item_get_int_attr (gpgme_trust_item_t item, _gpgme_attr_t what,
1643                                    const void *reserved, int idx)
1644      _GPGME_DEPRECATED;
1645
1646 \f
1647 /* Return the auditlog for the current session.  This may be called
1648    after a successful or failed operation.  If no audit log is
1649    available GPG_ERR_NO_DATA is returned.  */
1650 gpgme_error_t gpgme_op_getauditlog_start (gpgme_ctx_t ctx, gpgme_data_t output,
1651                                           unsigned int flags);
1652 gpgme_error_t gpgme_op_getauditlog (gpgme_ctx_t ctx, gpgme_data_t output, 
1653                                     unsigned int flags);
1654
1655
1656 \f
1657 /* Various functions.  */
1658
1659 /* Check that the library fulfills the version requirement.  */
1660 const char *gpgme_check_version (const char *req_version);
1661
1662 /* Get the information about the configured and installed engines.  A
1663    pointer to the first engine in the statically allocated linked list
1664    is returned in *INFO.  If an error occurs, it is returned.  The
1665    returned data is valid until the next gpgme_set_engine_info.  */
1666 gpgme_error_t gpgme_get_engine_info (gpgme_engine_info_t *engine_info);
1667
1668 /* Set the default engine info for the protocol PROTO to the file name
1669    FILE_NAME and the home directory HOME_DIR.  */
1670 gpgme_error_t gpgme_set_engine_info (gpgme_protocol_t proto,
1671                                      const char *file_name,
1672                                      const char *home_dir);
1673
1674 \f
1675 /* Engine support functions.  */
1676
1677 /* Verify that the engine implementing PROTO is installed and
1678    available.  */
1679 gpgme_error_t gpgme_engine_check_version (gpgme_protocol_t proto);
1680
1681 \f
1682 /* Deprecated types.  */
1683 typedef gpgme_ctx_t GpgmeCtx _GPGME_DEPRECATED;
1684 typedef gpgme_data_t GpgmeData _GPGME_DEPRECATED;
1685 typedef gpgme_error_t GpgmeError _GPGME_DEPRECATED;
1686 typedef gpgme_data_encoding_t GpgmeDataEncoding _GPGME_DEPRECATED;
1687 typedef gpgme_pubkey_algo_t GpgmePubKeyAlgo _GPGME_DEPRECATED;
1688 typedef gpgme_hash_algo_t GpgmeHashAlgo _GPGME_DEPRECATED;
1689 typedef gpgme_sig_stat_t GpgmeSigStat _GPGME_DEPRECATED;
1690 typedef gpgme_sig_mode_t GpgmeSigMode _GPGME_DEPRECATED;
1691 typedef gpgme_attr_t GpgmeAttr _GPGME_DEPRECATED;
1692 typedef gpgme_validity_t GpgmeValidity _GPGME_DEPRECATED;
1693 typedef gpgme_protocol_t GpgmeProtocol _GPGME_DEPRECATED;
1694 typedef gpgme_engine_info_t GpgmeEngineInfo _GPGME_DEPRECATED;
1695 typedef gpgme_subkey_t GpgmeSubkey _GPGME_DEPRECATED;
1696 typedef gpgme_key_sig_t GpgmeKeySig _GPGME_DEPRECATED;
1697 typedef gpgme_user_id_t GpgmeUserID _GPGME_DEPRECATED;
1698 typedef gpgme_key_t GpgmeKey _GPGME_DEPRECATED;
1699 typedef gpgme_passphrase_cb_t GpgmePassphraseCb _GPGME_DEPRECATED;
1700 typedef gpgme_progress_cb_t GpgmeProgressCb _GPGME_DEPRECATED;
1701 typedef gpgme_io_cb_t GpgmeIOCb _GPGME_DEPRECATED;
1702 typedef gpgme_register_io_cb_t GpgmeRegisterIOCb _GPGME_DEPRECATED;
1703 typedef gpgme_remove_io_cb_t GpgmeRemoveIOCb _GPGME_DEPRECATED;
1704 typedef gpgme_event_io_t GpgmeEventIO _GPGME_DEPRECATED;
1705 typedef gpgme_event_io_cb_t GpgmeEventIOCb _GPGME_DEPRECATED;
1706 #define GpgmeIOCbs gpgme_io_cbs
1707 typedef gpgme_data_read_cb_t GpgmeDataReadCb _GPGME_DEPRECATED;
1708 typedef gpgme_data_write_cb_t GpgmeDataWriteCb _GPGME_DEPRECATED;
1709 typedef gpgme_data_seek_cb_t GpgmeDataSeekCb _GPGME_DEPRECATED;
1710 typedef gpgme_data_release_cb_t GpgmeDataReleaseCb _GPGME_DEPRECATED;
1711 #define GpgmeDataCbs gpgme_data_cbs
1712 typedef gpgme_encrypt_result_t GpgmeEncryptResult _GPGME_DEPRECATED;
1713 typedef gpgme_sig_notation_t GpgmeSigNotation _GPGME_DEPRECATED;
1714 typedef gpgme_signature_t GpgmeSignature _GPGME_DEPRECATED;
1715 typedef gpgme_verify_result_t GpgmeVerifyResult _GPGME_DEPRECATED;
1716 typedef gpgme_import_status_t GpgmeImportStatus _GPGME_DEPRECATED;
1717 typedef gpgme_import_result_t GpgmeImportResult _GPGME_DEPRECATED;
1718 typedef gpgme_genkey_result_t GpgmeGenKeyResult _GPGME_DEPRECATED;
1719 typedef gpgme_trust_item_t GpgmeTrustItem _GPGME_DEPRECATED;
1720 typedef gpgme_status_code_t GpgmeStatusCode _GPGME_DEPRECATED;
1721
1722 #ifdef __cplusplus
1723 }
1724 #endif
1725 #endif /* GPGME_H */