1 /* gpgme.h - GnuPG Made Easy
2 * Copyright (C) 2000 Werner Koch (dd9jn)
3 * Copyright (C) 2001, 2002 g10 Code GmbH
5 * This file is part of GPGME.
7 * GPGME is free software; you can redistribute it and/or modify
8 * it 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.
12 * GPGME is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
25 #include <stdio.h> /* For FILE *. */
29 # include <sys/types.h>
34 #if 0 /* just to make Emacs auto-indent happy */
40 /* The version of this header should match the one of the library. Do
41 not use this symbol in your application, use gpgme_check_version
42 instead. The purpose of this macro is to let autoconf (using the
43 AM_PATH_GPGME macro) check that this header matches the installed
44 library. Warning: Do not edit the next line. configure will do
46 #define GPGME_VERSION "0.3.6"
49 /* The opaque data types used by GPGME. */
51 /* The context holds some global state and configration options as
52 well as the results of a crypto operation. */
53 struct gpgme_context_s;
54 typedef struct gpgme_context_s *GpgmeCtx;
56 /* The data object used by GPGME to exchange arbitrary data. */
58 typedef struct gpgme_data_s *GpgmeData;
60 /* A list of recipients to be used in an encryption operation. */
61 struct gpgme_recipients_s;
62 typedef struct gpgme_recipients_s *GpgmeRecipients;
64 /* A key from the keyring. */
66 typedef struct gpgme_key_s *GpgmeKey;
69 struct gpgme_trust_item_s;
70 typedef struct gpgme_trust_item_s *GpgmeTrustItem;
73 /* The error numbers used by GPGME. */
78 GPGME_General_Error = 1,
79 GPGME_Out_Of_Core = 2,
80 GPGME_Invalid_Value = 3,
84 GPGME_Too_Many_Procs = 7,
86 GPGME_No_Recipients = 9,
89 GPGME_Not_Implemented = 12,
90 GPGME_Read_Error = 13,
91 GPGME_Write_Error = 14,
92 GPGME_Invalid_Type = 15,
93 GPGME_Invalid_Mode = 16,
94 GPGME_File_Error = 17, /* errno is set in this case. */
95 GPGME_Decryption_Failed = 18,
96 GPGME_No_Passphrase = 19,
98 GPGME_Invalid_Key = 21,
99 GPGME_Invalid_Engine = 22,
100 GPGME_Invalid_Recipients = 23
104 /* The possible types of GpgmeData objects. */
107 GPGME_DATA_TYPE_NONE = 0,
108 GPGME_DATA_TYPE_MEM = 1,
109 GPGME_DATA_TYPE_FD = 2,
110 GPGME_DATA_TYPE_FILE = 3,
111 GPGME_DATA_TYPE_CB = 4
115 /* The possible encoding mode of GpgmeData objects. */
118 GPGME_DATA_ENCODING_NONE = 0, /* i.e. not specified */
119 GPGME_DATA_ENCODING_BINARY = 1,
120 GPGME_DATA_ENCODING_BASE64 = 2,
121 GPGME_DATA_ENCODING_ARMOR = 3 /* Either PEM or OpenPGP Armor */
125 /* The possible signature stati. */
128 GPGME_SIG_STAT_NONE = 0,
129 GPGME_SIG_STAT_GOOD = 1,
130 GPGME_SIG_STAT_BAD = 2,
131 GPGME_SIG_STAT_NOKEY = 3,
132 GPGME_SIG_STAT_NOSIG = 4,
133 GPGME_SIG_STAT_ERROR = 5,
134 GPGME_SIG_STAT_DIFF = 6,
135 GPGME_SIG_STAT_GOOD_EXP = 7,
136 GPGME_SIG_STAT_GOOD_EXPKEY = 8
140 /* The available signature modes. */
143 GPGME_SIG_MODE_NORMAL = 0,
144 GPGME_SIG_MODE_DETACH = 1,
145 GPGME_SIG_MODE_CLEAR = 2
149 /* The available key and signature attributes. */
152 GPGME_ATTR_KEYID = 1,
156 GPGME_ATTR_CREATED = 5,
157 GPGME_ATTR_EXPIRE = 6,
158 GPGME_ATTR_OTRUST = 7,
159 GPGME_ATTR_USERID = 8,
161 GPGME_ATTR_EMAIL = 10,
162 GPGME_ATTR_COMMENT = 11,
163 GPGME_ATTR_VALIDITY = 12,
164 GPGME_ATTR_LEVEL = 13,
165 GPGME_ATTR_TYPE = 14,
166 GPGME_ATTR_IS_SECRET = 15,
167 GPGME_ATTR_KEY_REVOKED = 16,
168 GPGME_ATTR_KEY_INVALID = 17,
169 GPGME_ATTR_UID_REVOKED = 18,
170 GPGME_ATTR_UID_INVALID = 19,
171 GPGME_ATTR_KEY_CAPS = 20,
172 GPGME_ATTR_CAN_ENCRYPT = 21,
173 GPGME_ATTR_CAN_SIGN = 22,
174 GPGME_ATTR_CAN_CERTIFY = 23,
175 GPGME_ATTR_KEY_EXPIRED = 24,
176 GPGME_ATTR_KEY_DISABLED = 25,
177 GPGME_ATTR_SERIAL = 26,
178 GPGME_ATTR_ISSUER = 27,
179 GPGME_ATTR_CHAINID = 28,
180 GPGME_ATTR_SIG_STATUS = 29
184 /* The available validities for a trust item or key. */
187 GPGME_VALIDITY_UNKNOWN = 0,
188 GPGME_VALIDITY_UNDEFINED = 1,
189 GPGME_VALIDITY_NEVER = 2,
190 GPGME_VALIDITY_MARGINAL = 3,
191 GPGME_VALIDITY_FULL = 4,
192 GPGME_VALIDITY_ULTIMATE = 5
196 /* The available protocols. */
199 GPGME_PROTOCOL_OpenPGP = 0, /* The default mode. */
200 GPGME_PROTOCOL_CMS = 1,
201 GPGME_PROTOCOL_AUTO = 2
206 /* The available keylist mode flags. */
207 #define GPGME_KEYLIST_MODE_LOCAL 1
208 #define GPGME_KEYLIST_MODE_EXTERN 2
211 /* Types for callback functions. */
213 /* Request a passphrase from the user. */
214 typedef const char *(*GpgmePassphraseCb) (void *hook, const char *desc,
217 /* Inform the user about progress made. */
218 typedef void (*GpgmeProgressCb) (void *opaque, const char *what,
219 int type, int current, int total);
222 /* Context management functions. */
224 /* Create a new context and return it in CTX. */
225 GpgmeError gpgme_new (GpgmeCtx *ctx);
227 /* Release the context CTX. */
228 void gpgme_release (GpgmeCtx ctx);
230 /* Retrieve more info about performed signature check. */
231 char *gpgme_get_notation (GpgmeCtx ctx);
233 /* Set the protocol to be used by CTX to PROTO. */
234 GpgmeError gpgme_set_protocol (GpgmeCtx ctx, GpgmeProtocol proto);
236 /* Get the protocol used with CTX */
237 GpgmeProtocol gpgme_get_protocol (GpgmeCtx ctx);
239 /* If YES is non-zero, enable armor mode in CTX, disable it otherwise. */
240 void gpgme_set_armor (GpgmeCtx ctx, int yes);
242 /* Return non-zero if armor mode is set in CTX. */
243 int gpgme_get_armor (GpgmeCtx ctx);
245 /* If YES is non-zero, enable text mode in CTX, disable it otherwise. */
246 void gpgme_set_textmode (GpgmeCtx ctx, int yes);
248 /* Return non-zero if text mode is set in CTX. */
249 int gpgme_get_textmode (GpgmeCtx ctx);
251 /* Include up to NR_OF_CERTS certificates in an S/MIME message. */
252 void gpgme_set_include_certs (GpgmeCtx ctx, int nr_of_certs);
254 /* Return the number of certs to include in an S/MIME message. */
255 int gpgme_get_include_certs (GpgmeCtx ctx);
257 /* Set keylist mode in CTX to MODE. */
258 GpgmeError gpgme_set_keylist_mode (GpgmeCtx ctx, int mode);
260 /* Get keylist mode in CTX. */
261 int gpgme_get_keylist_mode (GpgmeCtx ctx);
263 /* Set the passphrase callback function in CTX to CB. HOOK_VALUE is
264 passed as first argument to the passphrase callback function. */
265 void gpgme_set_passphrase_cb (GpgmeCtx ctx,
266 GpgmePassphraseCb cb, void *hook_value);
268 /* Get the current passphrase callback function in *CB and the current
269 hook value in *HOOK_VALUE. */
270 void gpgme_get_passphrase_cb (GpgmeCtx ctx, GpgmePassphraseCb *cb,
273 /* Set the progress callback function in CTX to CB. HOOK_VALUE is
274 passed as first argument to the progress callback function. */
275 void gpgme_set_progress_cb (GpgmeCtx c, GpgmeProgressCb cb, void *hook_value);
277 /* Get the current progress callback function in *CB and the current
278 hook value in *HOOK_VALUE. */
279 void gpgme_get_progress_cb (GpgmeCtx ctx, GpgmeProgressCb *cb,
282 /* Delete all signers from CTX. */
283 void gpgme_signers_clear (GpgmeCtx ctx);
285 /* Add KEY to list of signers in CTX. */
286 GpgmeError gpgme_signers_add (GpgmeCtx ctx, const GpgmeKey key);
288 /* Return the SEQth signer's key in CTX. */
289 GpgmeKey gpgme_signers_enum (const GpgmeCtx ctx, int seq);
291 /* Retrieve the signature status of signature IDX in CTX after a
292 successful verify operation in R_STAT (if non-null). The creation
293 time stamp of the signature is returned in R_CREATED (if non-null).
294 The function returns a string containing the fingerprint. */
295 const char *gpgme_get_sig_status (GpgmeCtx ctx, int idx,
296 GpgmeSigStat *r_stat, time_t *r_created);
298 /* Retrieve certain attributes of a signature. IDX is the index
299 number of the signature after a successful verify operation. WHAT
300 is an attribute where GPGME_ATTR_EXPIRE is probably the most useful
301 one. RESERVED must be passed as 0. */
302 unsigned long gpgme_get_sig_ulong_attr (GpgmeCtx c, int idx,
303 GpgmeAttr what, int reserved);
304 const char *gpgme_get_sig_string_attr (GpgmeCtx c, int idx,
305 GpgmeAttr what, int reserved);
308 /* Get the key used to create signature IDX in CTX and return it in
310 GpgmeError gpgme_get_sig_key (GpgmeCtx ctx, int idx, GpgmeKey *r_key);
312 /* Return a string with more info about the last crypto operating in CTX.
313 RESERVED should be zero. The user has to free the string. */
314 char *gpgme_get_op_info (GpgmeCtx ctx, int reserved);
319 /* Cancel a pending operation in CTX. */
320 void gpgme_cancel (GpgmeCtx ctx);
322 /* Process the pending operation and, if HANG is non-zero, wait for
323 the pending operation to finish. */
324 GpgmeCtx gpgme_wait (GpgmeCtx ctx, GpgmeError *status, int hang);
327 /* Functions to handle recipients. */
329 /* Create a new recipients set and return it in R_RSET. */
330 GpgmeError gpgme_recipients_new (GpgmeRecipients *r_rset);
332 /* Release the recipients set RSET. */
333 void gpgme_recipients_release (GpgmeRecipients rset);
335 /* Add NAME to the recipients set RSET. */
336 GpgmeError gpgme_recipients_add_name (GpgmeRecipients rset, const char *name);
338 /* Add NAME with validity AL to the recipients set RSET. */
339 GpgmeError gpgme_recipients_add_name_with_validity (GpgmeRecipients rset,
343 /* Return the number of recipients in RSET. */
344 unsigned int gpgme_recipients_count (const GpgmeRecipients rset);
346 /* Create a new enumeration handle for the recipients set RSET and
347 return it in ITER. */
348 GpgmeError gpgme_recipients_enum_open (const GpgmeRecipients rset,
351 /* Return the next recipient from the recipient set RSET in the
353 const char *gpgme_recipients_enum_read (const GpgmeRecipients rset,
356 /* Destroy the enumerator ITER for the recipient set RSET. */
357 GpgmeError gpgme_recipients_enum_close (const GpgmeRecipients rset,
361 /* Functions to handle data objects. */
363 /* Create a new data buffer and return it in R_DH. */
364 GpgmeError gpgme_data_new (GpgmeData *r_dh);
366 /* Create a new data buffer filled with SIZE bytes starting from
367 BUFFER. If COPY is zero, copying is delayed until necessary, and
368 the data is taken from the original location when needed. */
369 GpgmeError gpgme_data_new_from_mem (GpgmeData *r_dh,
370 const char *buffer, size_t size,
373 /* Create a new data buffer which retrieves the data from the callback
375 GpgmeError gpgme_data_new_with_read_cb (GpgmeData *r_dh,
376 int (*read_cb) (void*,char *,size_t,size_t*),
377 void *read_cb_value);
379 /* Create a new data buffer filled with the content of file FNAME.
380 COPY must be non-zero (delayed reads are not supported yet). */
381 GpgmeError gpgme_data_new_from_file (GpgmeData *r_dh,
385 /* Create a new data buffer filled with LENGTH bytes starting from
386 OFFSET within the file FNAME or stream FP (exactly one must be
388 GpgmeError gpgme_data_new_from_filepart (GpgmeData *r_dh,
389 const char *fname, FILE *fp,
390 off_t offset, size_t length);
392 /* Destroy the data buffer DH. */
393 void gpgme_data_release (GpgmeData dh);
395 /* Destroy the data buffer DH and return a pointer to its content.
396 The memory has be to released with free by the user. It's size is
397 returned in R_LEN. */
398 char *gpgme_data_release_and_get_mem (GpgmeData dh, size_t *r_len);
400 /* Return the type of the data buffer DH. */
401 GpgmeDataType gpgme_data_get_type (GpgmeData dh);
403 /* Return the encoding attribute of the data buffer DH */
404 GpgmeDataEncoding gpgme_data_get_encoding (GpgmeData dh);
406 /* Set the encoding attribute of data buffer DH to ENC */
407 GpgmeError gpgme_data_set_encoding (GpgmeData dh, GpgmeDataEncoding enc);
409 /* Reset the read pointer in DH. */
410 GpgmeError gpgme_data_rewind (GpgmeData dh);
412 /* Read LENGTH bytes from the data object DH and store them in the
413 memory starting at BUFFER. The number of bytes actually read is
414 returned in NREAD. */
415 GpgmeError gpgme_data_read (GpgmeData dh, void *buffer,
416 size_t length, size_t *nread);
418 /* Write LENGTH bytes starting from BUFFER into the data object DH. */
419 GpgmeError gpgme_data_write (GpgmeData dh, const void *buffer, size_t length);
422 /* Key and trust functions. */
424 /* Acquire a reference to KEY. */
425 void gpgme_key_ref (GpgmeKey key);
427 /* Release a reference to KEY. If this was the last one the key is
429 void gpgme_key_unref (GpgmeKey key);
430 void gpgme_key_release (GpgmeKey key);
432 /* Get the data from key KEY in a XML string, which has to be released
433 with free by the user. */
434 char *gpgme_key_get_as_xml (GpgmeKey key);
436 /* Return the value of the attribute WHAT of KEY, which has to be
437 representable by a string. IDX specifies a running index if the
438 attribute appears more than once in the key. */
439 const char *gpgme_key_get_string_attr (GpgmeKey key, GpgmeAttr what,
440 const void *reserved, int idx);
442 /* Return the value of the attribute WHAT of KEY, which has to be
443 representable by an unsigned integer. IDX specifies a running
444 index if the attribute appears more than once in the key. */
445 unsigned long gpgme_key_get_ulong_attr (GpgmeKey key, GpgmeAttr what,
446 const void *reserved, int idx);
448 /* Release the trust item ITEM. */
449 void gpgme_trust_item_release (GpgmeTrustItem item);
451 /* Return the value of the attribute WHAT of ITEM, which has to be
452 representable by a string. IDX specifies a running index if the
453 attribute appears more than once in the key. */
454 const char *gpgme_trust_item_get_string_attr (GpgmeTrustItem item,
456 const void *reserved, int idx);
458 /* Return the value of the attribute WHAT of KEY, which has to be
459 representable by an integer. IDX specifies a running index if the
460 attribute appears more than once in the key. */
461 int gpgme_trust_item_get_int_attr (GpgmeTrustItem item, GpgmeAttr what,
462 const void *reserved, int idx);
465 /* Crypto operation function. */
467 /* Encrypt plaintext PLAIN within CTX for the recipients RECP and
468 store the resulting ciphertext in CIPHER. */
469 GpgmeError gpgme_op_encrypt_start (GpgmeCtx ctx,
470 GpgmeRecipients recp,
471 GpgmeData plain, GpgmeData cipher);
472 GpgmeError gpgme_op_encrypt (GpgmeCtx ctx,
473 GpgmeRecipients recp,
474 GpgmeData plain, GpgmeData cipher);
476 /* Encrypt plaintext PLAIN within CTX for the recipients RECP and
477 store the resulting ciphertext in CIPHER. Also sign the ciphertext
478 with the signers in CTX. */
479 GpgmeError gpgme_op_encrypt_sign_start (GpgmeCtx ctx,
480 GpgmeRecipients recp,
481 GpgmeData plain, GpgmeData cipher);
482 GpgmeError gpgme_op_encrypt_sign (GpgmeCtx ctx,
483 GpgmeRecipients recp,
484 GpgmeData plain, GpgmeData cipher);
486 /* Decrypt ciphertext CIPHER within CTX and store the resulting
487 plaintext in PLAIN. */
488 GpgmeError gpgme_op_decrypt_start (GpgmeCtx ctx,
489 GpgmeData cipher, GpgmeData plain);
490 GpgmeError gpgme_op_decrypt (GpgmeCtx ctx,
491 GpgmeData cipher, GpgmeData plain);
493 /* Decrypt ciphertext CIPHER and make a signature verification within
494 CTX and store the resulting plaintext in PLAIN. */
495 GpgmeError gpgme_op_decrypt_verify_start (GpgmeCtx ctx,
496 GpgmeData cipher, GpgmeData plain);
497 GpgmeError gpgme_op_decrypt_verify (GpgmeCtx ctx,
498 GpgmeData cipher, GpgmeData plain,
499 GpgmeSigStat *r_status);
501 /* Sign the plaintext PLAIN and store the signature in SIG. Only
502 detached signatures are supported for now. */
503 GpgmeError gpgme_op_sign_start (GpgmeCtx ctx,
504 GpgmeData plain, GpgmeData sig,
506 GpgmeError gpgme_op_sign (GpgmeCtx ctx,
507 GpgmeData plain, GpgmeData sig,
510 /* Verify within CTX that SIG is a valid signature for TEXT. */
511 GpgmeError gpgme_op_verify_start (GpgmeCtx ctx,
512 GpgmeData sig, GpgmeData text);
513 GpgmeError gpgme_op_verify (GpgmeCtx ctx,
514 GpgmeData sig, GpgmeData text,
515 GpgmeSigStat *r_status);
517 /* Import the key in KEYDATA into the keyring. */
518 GpgmeError gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata);
519 GpgmeError gpgme_op_import (GpgmeCtx ctx, GpgmeData keydata);
521 /* Export the keys listed in RECP into KEYDATA. */
522 GpgmeError gpgme_op_export_start (GpgmeCtx ctx, GpgmeRecipients recp,
524 GpgmeError gpgme_op_export (GpgmeCtx ctx, GpgmeRecipients recp,
527 /* Generate a new keypair and add it to the keyring. PUBKEY and
528 SECKEY should be null for now. PARMS specifies what keys should be
530 GpgmeError gpgme_op_genkey_start (GpgmeCtx ctx, const char *parms,
531 GpgmeData pubkey, GpgmeData seckey);
532 GpgmeError gpgme_op_genkey (GpgmeCtx ctx, const char *parms,
533 GpgmeData pubkey, GpgmeData seckey);
535 /* Delete KEY from the keyring. If ALLOW_SECRET is non-zero, secret
536 keys are also deleted. */
537 GpgmeError gpgme_op_delete_start (GpgmeCtx ctx, const GpgmeKey key,
539 GpgmeError gpgme_op_delete (GpgmeCtx ctx, const GpgmeKey key,
543 /* Key management functions */
545 /* Start a keylist operation within CTX, searching for keys which
546 match PATTERN. If SECRET_ONLY is true, only secret keys are
548 GpgmeError gpgme_op_keylist_start (GpgmeCtx ctx,
549 const char *pattern, int secret_only);
550 GpgmeError gpgme_op_keylist_ext_start (GpgmeCtx ctx, const char *pattern[],
551 int secret_only, int reserved);
553 /* Return the next key from the keylist in R_KEY. */
554 GpgmeError gpgme_op_keylist_next (GpgmeCtx ctx, GpgmeKey *r_key);
556 /* Terminate a pending keylist operation within CTX. */
557 GpgmeError gpgme_op_keylist_end (GpgmeCtx ctx);
560 /* Start a trustlist operation within CTX, searching for trust items
561 which match PATTERN. */
562 GpgmeError gpgme_op_trustlist_start (GpgmeCtx ctx,
563 const char *pattern, int max_level);
565 /* Return the next trust item from the trustlist in R_ITEM. */
566 GpgmeError gpgme_op_trustlist_next (GpgmeCtx ctx, GpgmeTrustItem *r_item);
568 /* Terminate a pending trustlist operation within CTX. */
569 GpgmeError gpgme_op_trustlist_end (GpgmeCtx ctx);
572 /* Various functions. */
574 /* Check that the library fulfills the version requirement. */
575 const char *gpgme_check_version (const char *req_version);
577 /* Check that the backend engine is available. DEPRECATED. */
578 GpgmeError gpgme_check_engine (void);
580 /* Retrieve information about the backend engines. */
581 const char *gpgme_get_engine_info (void);
583 /* Return a string describing ERR. */
584 const char *gpgme_strerror (GpgmeError err);
586 /* Register an idle function. */
587 typedef void (*GpgmeIdleFunc)(void);
588 GpgmeIdleFunc gpgme_register_idle (GpgmeIdleFunc idle);
591 /* Engine support functions. */
593 /* Verify that the engine implementing PROTO is installed and
595 GpgmeError gpgme_engine_check_version (GpgmeProtocol proto);