1 \input texinfo @c -*- mode: texinfo; coding: latin-1; -*-
2 @documentencoding ISO-8859-1
3 @setfilename gpgme.info
4 @settitle The `GnuPG Made Easy' Reference Manual
6 @dircategory GNU Libraries
8 * @acronym{GPGME}: (gpgme). Adding support for cryptography to your program.
11 @c Unify some of the indices.
16 Copyright @copyright{} 2002, 2003, 2004, 2005, 2006, 2007,
17 2008, 2010, 2012, 2013 g10 Code GmbH.
20 Permission is granted to copy, distribute and/or modify this document
21 under the terms of the GNU General Public License as published by the
22 Free Software Foundation; either version 3 of the License, or (at your
23 option) any later version. The text of the license can be found in the
24 section entitled ``Copying''.
27 This document is distributed in the hope that it will be useful, but
28 WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 General Public License for more details.
35 @c Macros used by the description of the UI server protocol
48 This file documents the @acronym{GPGME} library.
50 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
51 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
54 @c NOTE: Don't forget to update the year for the TeX version, too.
59 @c We do not want that bastard short titlepage.
61 @c @shorttitlepage The `GnuPG Made Easy' Reference Manual
64 @center @titlefont{The `GnuPG Made Easy'}
66 @center @titlefont{Reference Manual}
68 @center Edition @value{EDITION}
70 @center last updated @value{UPDATED}
72 @center for version @value{VERSION}
74 @vskip 0pt plus 1filll
75 Published by g10 Code GmbH@* Hüttenstr. 61@* 40699 Erkrath, Germany
87 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
88 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
89 @value{VERSION} of the @acronym{GPGME} library.
93 * Introduction:: How to use this manual.
94 * Preparation:: What you should do before using the library.
95 * Protocols and Engines:: Supported crypto protocols.
96 * Algorithms:: Supported algorithms.
97 * Error Handling:: Error numbers and their meanings.
98 * Exchanging Data:: Passing data to and from @acronym{GPGME}.
99 * Contexts:: Handling @acronym{GPGME} contexts.
103 * UI Server Protocol:: The GnuPG UI Server Protocol.
104 * Debugging:: How to solve problems.
106 * Library Copying:: The GNU Lesser General Public License says
107 how you can copy and share `GnuPG Made Easy'.
108 * Copying:: The GNU General Public License says how you
109 can copy and share this manual.
113 * Concept Index:: Index of concepts and programs.
114 * Function and Data Index:: Index of functions, variables and data types.
118 --- The Detailed Node Listing ---
122 * Getting Started:: Purpose of the manual, and how to use it.
123 * Features:: Reasons to install and use @acronym{GPGME}.
124 * Overview:: Basic architecture of the @acronym{GPGME} library.
128 * Header:: What header file you need to include.
129 * Building the Source:: Compiler options to be used.
130 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
131 * Using Automake:: Compiler options to be used the easy way.
132 * Using Libtool:: Avoiding compiler options entirely.
133 * Library Version Check:: Getting and verifying the library version.
134 * Signal Handling:: How @acronym{GPGME} affects signal handling.
135 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
137 Protocols and Engines
139 * Engine Version Check:: Verifying the engine version.
140 * Engine Information:: Obtaining more information about the engines.
141 * Engine Configuration:: Changing the engine configuration.
142 * OpenPGP:: Support for the OpenPGP protocol.
143 * Cryptographic Message Syntax:: Support for the CMS.
147 * Public Key Algorithms:: A list of all public key algorithms.
148 * Hash Algorithms:: A list of all hash algorithms.
152 * Error Values:: The error value and what it means.
153 * Error Codes:: A list of important error codes.
154 * Error Sources:: A list of important error sources.
155 * Error Strings:: How to get a descriptive string from a value.
159 * Creating Data Buffers:: Creating new data buffers.
160 * Destroying Data Buffers:: Releasing data buffers.
161 * Manipulating Data Buffers:: Operations on data buffers.
163 Creating Data Buffers
165 * Memory Based Data Buffers:: Creating memory based data buffers.
166 * File Based Data Buffers:: Creating file based data buffers.
167 * Callback Based Data Buffers:: Creating callback based data buffers.
169 Manipulating Data Buffers
171 * Data Buffer I/O Operations:: I/O operations on data buffers.
172 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
176 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
177 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
178 * Result Management:: Managing the result of crypto operations.
179 * Context Attributes:: Setting properties of a context.
180 * Key Management:: Managing keys with @acronym{GPGME}.
181 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
182 * Crypto Operations:: Using a context for cryptography.
183 * Run Control:: Controlling how operations are run.
187 * Protocol Selection:: Selecting the protocol used by a context.
188 * Crypto Engine:: Configuring the crypto engine.
189 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
190 * Text Mode:: Choosing canonical text mode.
191 * Included Certificates:: Including a number of certificates.
192 * Key Listing Mode:: Selecting key listing mode.
193 * Passphrase Callback:: Getting the passphrase from the user.
194 * Progress Meter Callback:: Being informed about the progress.
195 * Locale:: Setting the locale of a context.
199 * Listing Keys:: Browsing the list of available keys.
200 * Information About Keys:: Requesting detailed information about keys.
201 * Key Signatures:: Listing the signatures on a key.
202 * Manipulating Keys:: Operations on keys.
203 * Generating Keys:: Creating new key pairs.
204 * Exporting Keys:: Retrieving key data from the key ring.
205 * Importing Keys:: Adding keys to the key ring.
206 * Deleting Keys:: Removing keys from the key ring.
207 * Advanced Key Editing:: Advanced key edit operation.
209 Trust Item Management
211 * Listing Trust Items:: Browsing the list of available trust items.
212 * Information About Trust Items:: Requesting information about trust items.
213 * Manipulating Trust Items:: Operations on trust items.
217 * Decrypt:: Decrypting a ciphertext.
218 * Verify:: Verifying a signature.
219 * Decrypt and Verify:: Decrypting a signed ciphertext.
220 * Sign:: Creating a signature.
221 * Encrypt:: Encrypting a plaintext.
225 * Selecting Signers:: How to choose the keys to sign with.
226 * Creating a Signature:: How to create a signature.
227 * Signature Notation Data:: How to add notation data to a signature.
231 * Encrypting a Plaintext:: How to encrypt a plaintext.
235 * Waiting For Completion:: Waiting until an operation is completed.
236 * Using External Event Loops:: Advanced control over what happens when.
237 * Cancellation:: How to end pending operations prematurely.
239 Using External Event Loops
241 * I/O Callback Interface:: How I/O callbacks are registered.
242 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
243 * I/O Callback Example:: An example how to use I/O callbacks.
244 * I/O Callback Example GTK+:: How to integrate @acronym{GPGME} in GTK+.
245 * I/O Callback Example GDK:: How to integrate @acronym{GPGME} in GDK.
246 * I/O Callback Example Qt:: How to integrate @acronym{GPGME} in Qt.
252 @chapter Introduction
254 `GnuPG Made Easy' (@acronym{GPGME}) is a C language library that
255 allows to add support for cryptography to a program. It is designed
256 to make access to public key crypto engines like GnuPG or GpgSM easier
257 for applications. @acronym{GPGME} provides a high-level crypto API
258 for encryption, decryption, signing, signature verification and key
261 @acronym{GPGME} uses GnuPG and GpgSM as its backends to support
262 OpenPGP and the Cryptographic Message Syntax (CMS).
265 * Getting Started:: Purpose of the manual, and how to use it.
266 * Features:: Reasons to install and use @acronym{GPGME}.
267 * Overview:: Basic architecture of the @acronym{GPGME} library.
271 @node Getting Started
272 @section Getting Started
274 This manual documents the @acronym{GPGME} library programming
275 interface. All functions and data types provided by the library are
278 The reader is assumed to possess basic knowledge about cryptography in
279 general, and public key cryptography in particular. The underlying
280 cryptographic engines that are used by the library are not explained,
281 but where necessary, special features or requirements by an engine are
282 mentioned as far as they are relevant to @acronym{GPGME} or its users.
284 This manual can be used in several ways. If read from the beginning
285 to the end, it gives a good introduction into the library and how it
286 can be used in an application. Forward references are included where
287 necessary. Later on, the manual can be used as a reference manual to
288 get just the information needed about any particular interface of the
289 library. Experienced programmers might want to start looking at the
290 examples at the end of the manual, and then only read up those parts
291 of the interface which are unclear.
297 @acronym{GPGME} has a couple of advantages over other libraries doing
298 a similar job, and over implementing support for GnuPG or other crypto
299 engines into your application directly.
302 @item it's free software
303 Anybody can use, modify, and redistribute it under the terms of the GNU
304 Lesser General Public License (@pxref{Library Copying}).
307 @acronym{GPGME} provides transparent support for several cryptographic
308 protocols by different engines. Currently, @acronym{GPGME} supports
309 the OpenPGP protocol using GnuPG as the backend, and the Cryptographic
310 Message Syntax using GpgSM as the backend.
313 @acronym{GPGME} hides the differences between the protocols and
314 engines from the programmer behind an easy-to-use interface. This way
315 the programmer can focus on the other parts of the program, and still
316 integrate strong cryptography in his application. Once support for
317 @acronym{GPGME} has been added to a program, it is easy to add support
318 for other crypto protocols once @acronym{GPGME} backends provide them.
325 @acronym{GPGME} provides a data abstraction that is used to pass data
326 to the crypto engine, and receive returned data from it. Data can be
327 read from memory or from files, but it can also be provided by a
330 The actual cryptographic operations are always set within a context.
331 A context provides configuration parameters that define the behaviour
332 of all operations performed within it. Only one operation per context
333 is allowed at any time, but when one operation is finished, you can
334 run the next operation in the same context. There can be more than
335 one context, and all can run different operations at the same time.
337 Furthermore, @acronym{GPGME} has rich key management facilities
338 including listing keys, querying their attributes, generating,
339 importing, exporting and deleting keys, and acquiring information
340 about the trust path.
342 With some precautions, @acronym{GPGME} can be used in a multi-threaded
343 environment, although it is not completely thread safe and thus needs
344 the support of the application.
350 To use @acronym{GPGME}, you have to perform some changes to your
351 sources and the build system. The necessary changes are small and
352 explained in the following sections. At the end of this chapter, it
353 is described how the library is initialized, and how the requirements
354 of the library are verified.
357 * Header:: What header file you need to include.
358 * Building the Source:: Compiler options to be used.
359 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
360 * Using Automake:: Compiler options to be used the easy way.
361 * Using Libtool:: Avoiding compiler options entirely.
362 * Library Version Check:: Getting and verifying the library version.
363 * Signal Handling:: How @acronym{GPGME} affects signal handling.
364 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
373 All interfaces (data types and functions) of the library are defined
374 in the header file `gpgme.h'. You must include this in all programs
375 using the library, either directly or through some other header file,
382 The name space of @acronym{GPGME} is @code{gpgme_*} for function names
383 and data types and @code{GPGME_*} for other symbols. Symbols internal
384 to @acronym{GPGME} take the form @code{_gpgme_*} and @code{_GPGME_*}.
386 Because @acronym{GPGME} makes use of the GPG Error library, using
387 @acronym{GPGME} will also use the @code{GPG_ERR_*} name space
388 directly, and the @code{gpg_err*} and @code{gpg_str*} name space
392 @node Building the Source
393 @section Building the Source
394 @cindex compiler options
395 @cindex compiler flags
397 If you want to compile a source file including the `gpgme.h' header
398 file, you must make sure that the compiler can find it in the
399 directory hierarchy. This is accomplished by adding the path to the
400 directory in which the header file is located to the compilers include
401 file search path (via the @option{-I} option).
403 However, the path to the include file is determined at the time the
404 source is configured. To solve this problem, gpgme ships with a small
405 helper program @command{gpgme-config} that knows about the path to the
406 include file and other configuration options. The options that need
407 to be added to the compiler invocation at compile time are output by
408 the @option{--cflags} option to @command{gpgme-config}. The following
409 example shows how it can be used at the command line:
412 gcc -c foo.c `gpgme-config --cflags`
415 Adding the output of @samp{gpgme-config --cflags} to the compiler
416 command line will ensure that the compiler can find the
417 @acronym{GPGME} header file.
419 A similar problem occurs when linking the program with the library.
420 Again, the compiler has to find the library files. For this to work,
421 the path to the library files has to be added to the library search
422 path (via the @option{-L} option). For this, the option
423 @option{--libs} to @command{gpgme-config} can be used. For
424 convenience, this option also outputs all other options that are
425 required to link the program with @acronym{GPGME} (in particular, the
426 @samp{-lgpgme} option). The example shows how to link @file{foo.o}
427 with the @acronym{GPGME} library to a program @command{foo}.
430 gcc -o foo foo.o `gpgme-config --libs`
433 Of course you can also combine both examples to a single command by
434 specifying both options to @command{gpgme-config}:
437 gcc -o foo foo.c `gpgme-config --cflags --libs`
440 If you want to link to one of the thread-safe versions of
441 @acronym{GPGME}, you must specify the @option{--thread} option before
442 any other option to select the thread package you want to link with.
443 Supported thread packages are @option{--thread=pth} and
444 @option{--thread=pthread}.
447 @node Largefile Support (LFS)
448 @section Largefile Support (LFS)
449 @cindex largefile support
452 @acronym{GPGME} is compiled with largefile support by default, if it
453 is available on the system. This means that GPGME supports files
454 larger than two gigabyte in size, if the underlying operating system
455 can. On some systems, largefile support is already the default. On
456 such systems, nothing special is required. However, some systems
457 provide only support for files up to two gigabyte in size by default.
458 Support for larger file sizes has to be specifically enabled.
460 To make a difficult situation even more complex, such systems provide
461 two different types of largefile support. You can either get all
462 relevant functions replaced with alternatives that are largefile
463 capable, or you can get new functions and data types for largefile
464 support added. Those new functions have the same name as their
465 smallfile counterparts, but with a suffix of 64.
467 An example: The data type @code{off_t} is 32 bit wide on GNU/Linux PC
468 systems. To address offsets in large files, you can either enable
469 largefile support add-on. Then a new data type @code{off64_t} is
470 provided, which is 64 bit wide. Or you can replace the existing
471 @code{off_t} data type with its 64 bit wide counterpart. All
472 occurences of @code{off_t} are then automagically replaced.
474 As if matters were not complex enough, there are also two different
475 types of file descriptors in such systems. This is important because
476 if file descriptors are exchanged between programs that use a
477 different maximum file size, certain errors must be produced on some
478 file descriptors to prevent subtle overflow bugs from occuring.
480 As you can see, supporting two different maximum file sizes at the
481 same time is not at all an easy task. However, the maximum file size
482 does matter for @acronym{GPGME}, because some data types it uses in
483 its interfaces are affected by that. For example, the @code{off_t}
484 data type is used in the @code{gpgme_data_seek} function, to match its
485 @acronym{POSIX} counterpart. This affects the call-frame of the
486 function, and thus the ABI of the library. Furthermore, file
487 descriptors can be exchanged between GPGME and the application.
489 For you as the user of the library, this means that your program must
490 be compiled in the same file size mode as the library. Luckily, there
491 is absolutely no valid reason for new programs to not enable largefile
492 support by default and just use that. The compatibility modes (small
493 file sizes or dual mode) can be considered an historic artefact, only
494 useful to allow for a transitional period.
496 On POSIX platforms @acronym{GPGME} is compiled using largefile support
497 by default. This means that your application must do the same, at
498 least as far as it is relevant for using the @file{gpgme.h} header
499 file. All types in this header files refer to their largefile
500 counterparts, if they are different from any default types on the
503 On 32 and 64 bit Windows platforms @code{off_t} is declared as 32 bit
504 signed integer. There is no specific support for LFS in the C
505 library. The recommendation from Microsoft is to use the native
506 interface (@code{CreateFile} et al.) for large files. Released binary
507 versions of @acronym{GPGME} (libgpgme-11.dll) have always been build
508 with a 32 bit @code{off_t}. To avoid an ABI break we stick to this
509 convention for 32 bit Windows by using @code{long} there.
510 @acronym{GPGME} versions for 64 bit Windows have never been released
511 and thus we are able to use @code{int64_t} instead of @code{off_t}
512 there. For easier migration the typedef @code{gpgme_off_t} has been
513 defined. The reason we cannot use @code{off_t} directly is that some
514 toolchains (e.g. mingw64) introduce a POSIX compatible hack for
515 @code{off_t}. Some widely used toolkits make use of this hack and in
516 turn @acronym{GPGME} would need to use it also. However, this would
517 introduce an ABI break and existing software making use of libgpgme
518 might suffer from a severe break. Thus with version 1.4.2 we
519 redefined all functions using @code{off_t} to use @code{gpgme_off_t}
520 which is defined as explained above. This way we keep the ABI well
521 defined and independent of any toolchain hacks. The bottom line is
522 that LFS support in @acronym{GPGME} is only available on 64 bit
525 On POSIX platforms you can enable largefile support, if it is
526 different from the default on the system the application is compiled
527 on, by using the Autoconf macro @code{AC_SYS_LARGEFILE}. If you do
528 this, then you don't need to worry about anything else: It will just
529 work. In this case you might also want to use @code{AC_FUNC_FSEEKO}
530 to take advantage of some new interfaces, and @code{AC_TYPE_OFF_T}
533 If you do not use Autoconf, you can define the preprocessor symbol
534 @code{_FILE_OFFSET_BITS} to 64 @emph{before} including any header
535 files, for example by specifying the option
536 @code{-D_FILE_OFFSET_BITS=64} on the compiler command line. You will
537 also want to define the preprocessor symbol @code{LARGEFILE_SOURCE} to
538 1 in this case, to take advantage of some new interfaces.
540 If you do not want to do either of the above, you probably know enough
541 about the issue to invent your own solution. Just keep in mind that
542 the @acronym{GPGME} header file expects that largefile support is
543 enabled, if it is available. In particular, we do not support dual
544 mode (@code{_LARGEFILE64_SOURCE}).
548 @section Using Automake
552 It is much easier if you use GNU Automake instead of writing your own
553 Makefiles. If you do that you do not have to worry about finding and
554 invoking the @command{gpgme-config} script at all. @acronym{GPGME}
555 provides an extension to Automake that does all the work for you.
557 @c A simple macro for optional variables.
559 @r{[}@var{\varname\}@r{]}
561 @defmac AM_PATH_GPGME (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
562 @defmacx AM_PATH_GPGME_PTH (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
563 @defmacx AM_PATH_GPGME_PTHREAD (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
564 Check whether @acronym{GPGME} (at least version @var{minimum-version},
565 if given) exists on the host system. If it is found, execute
566 @var{action-if-found}, otherwise do @var{action-if-not-found}, if
569 Additionally, the function defines @code{GPGME_CFLAGS} to the flags
570 needed for compilation of the program to find the @file{gpgme.h}
571 header file, and @code{GPGME_LIBS} to the linker flags needed to link
572 the program to the @acronym{GPGME} library.
574 @code{AM_PATH_GPGME_PTH} checks for the version of @acronym{GPGME}
575 that can be used with GNU Pth, and defines @code{GPGME_PTH_CFLAGS} and
576 @code{GPGME_PTH_LIBS}.
578 @code{AM_PATH_GPGME_PTHREAD} checks for the version of @acronym{GPGME}
579 that can be used with the native pthread implementation, and defines
580 @code{GPGME_PTHREAD_CFLAGS} and @code{GPGME_PTHREAD_LIBS}.
583 You can use the defined Autoconf variables like this in your
587 AM_CPPFLAGS = $(GPGME_CFLAGS)
588 LDADD = $(GPGME_LIBS)
593 @section Using Libtool
596 The easiest way is to just use GNU Libtool. If you use libtool, and
597 link to @code{libgpgme.la}, @code{libgpgme-pth.la} or
598 @code{libgpgme-pthread.la} respectively, everything will be done
599 automatically by Libtool.
602 @node Library Version Check
603 @section Library Version Check
604 @cindex version check, of the library
606 @deftypefun {const char *} gpgme_check_version (@w{const char *@var{required_version}})
607 The function @code{gpgme_check_version} has four purposes. It can be
608 used to retrieve the version number of the library. In addition it
609 can verify that the version number is higher than a certain required
610 version number. In either case, the function initializes some
611 sub-systems, and for this reason alone it must be invoked early in
612 your program, before you make use of the other functions in
613 @acronym{GPGME}. The last purpose is to run selftests.
615 As a side effect for W32 based systems, the socket layer will get
619 If @var{required_version} is @code{NULL}, the function returns a
620 pointer to a statically allocated string containing the version number
623 If @var{required_version} is not @code{NULL}, it should point to a
624 string containing a version number, and the function checks that the
625 version of the library is at least as high as the version number
626 provided. In this case, the function returns a pointer to a
627 statically allocated string containing the version number of the
628 library. If @var{REQUIRED_VERSION} is not a valid version number, or
629 if the version requirement is not met, the function returns
632 If you use a version of a library that is backwards compatible with
633 older releases, but contains additional interfaces which your program
634 uses, this function provides a run-time check if the necessary
635 features are provided by the installed version of the library.
637 If a selftest fails, the function may still succeed. Selftest errors
638 are returned later when invoking @code{gpgme_new}, so that a detailed
639 error code can be returned (historically, @code{gpgme_check_version}
640 does not return a detailed error code).
644 @deftypefun {int} gpgme_set_global_flag @
645 (@w{const char *@var{name}}, @
646 @w{const char *@var{value}})
648 On some systems it is not easy to set environment variables and thus
649 hard to use @acronym{GPGME}'s internal trace facility for debugging.
650 This function has been introduced as an alternative way to enable
651 debugging. It is important to assure that only one thread accesses
652 @acronym{GPGME} functions between a call to this function and after
653 the return from the call to @code{gpgme_check_version}.
655 To enable debugging, you need to call this function as early as
656 possible --- even before @code{gpgme_check_version} --- with the
657 string ``debug'' for @var{name} and @var{value} identical to the value
658 used with the environment variable @code{GPGME_DEBUG}.
660 This function returns @code{0} on success. In contrast to other
661 functions the non-zero return value on failure does not convey any
662 error code. For setting ``debug'' the only possible error cause is an
663 out of memory condition; which would exhibit itself later anyway.
664 Thus the return value may be ignored.
668 After initializing @acronym{GPGME}, you should set the locale
669 information to the locale required for your output terminal. This
670 locale information is needed for example for the curses and Gtk
671 pinentry. Here is an example of a complete initialization:
680 /* Initialize the locale environment. */
681 setlocale (LC_ALL, "");
682 gpgme_check_version (NULL);
683 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
685 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
690 Note that you are highly recommended to initialize the locale settings
691 like this. @acronym{GPGME} can not do this for you because it would
692 not be thread safe. The conditional on LC_MESSAGES is only necessary
693 for portability to W32 systems.
696 @node Signal Handling
697 @section Signal Handling
699 @cindex signal handling
701 The @acronym{GPGME} library communicates with child processes (the
702 crypto engines). If a child process dies unexpectedly, for example
703 due to a bug, or system problem, a @code{SIGPIPE} signal will be
704 delivered to the application. The default action is to abort the
705 program. To protect against this, @code{gpgme_check_version} sets the
706 @code{SIGPIPE} signal action to @code{SIG_IGN}, which means that the
707 signal will be ignored.
709 @acronym{GPGME} will only do that if the signal action for
710 @code{SIGPIPE} is @code{SIG_DEF} at the time
711 @code{gpgme_check_version} is called. If it is something different,
712 @code{GPGME} will take no action.
714 This means that if your application does not install any signal
715 handler for @code{SIGPIPE}, you don't need to take any precautions.
716 If you do install a signal handler for @code{SIGPIPE}, you must be
717 prepared to handle any @code{SIGPIPE} events that occur due to
718 @acronym{GPGME} writing to a defunct pipe. Furthermore, if your
719 application is multi-threaded, and you install a signal action for
720 @code{SIGPIPE}, you must make sure you do this either before
721 @code{gpgme_check_version} is called or afterwards.
724 @node Multi Threading
725 @section Multi Threading
726 @cindex thread-safeness
727 @cindex multi-threading
729 The @acronym{GPGME} library is not entirely thread-safe, but it can
730 still be used in a multi-threaded environment if some care is taken.
731 If the following requirements are met, there should be no race
732 conditions to worry about:
736 @acronym{GPGME} supports the thread libraries pthread and GNU Pth.
737 The support for this has to be enabled at compile time.
738 @acronym{GPGME} will automatically detect the location in which the
739 thread libraries are installed and activate the support for them at
742 Support for other thread libraries is very easy to add. Please
743 contact us if you have the need.
746 If you want to use @acronym{GPGME} with threads, you must link to the
747 right version of the library. The name of the right library is
748 @code{libgpgme-} followed by the name of the thread package you use.
749 For example, if you use GNU Pth, the right name is
750 @code{libgpgme-pth}. Use the Automake macros or
751 @command{gpgme-config} program for simplicity.
755 The function @code{gpgme_check_version} must be called before any
756 other function in the library, because it initializes the thread
757 support subsystem in @acronym{GPGME}. To achieve this in
758 multi-threaded programs, you must synchronize the memory with respect
759 to other threads that also want to use @acronym{GPGME}. For this, it
760 is sufficient to call @code{gpgme_check_version} before creating the
761 other threads using @acronym{GPGME}@footnote{At least this is true for
762 POSIX threads, as @code{pthread_create} is a function that
763 synchronizes memory with respects to other threads. There are many
764 functions which have this property, a complete list can be found in
765 POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the
766 definition of the term ``Memory Synchronization''. For other thread
767 packages other, more relaxed or more strict rules may apply.}.
770 Any @code{gpgme_data_t} and @code{gpgme_ctx_t} object must only be
771 accessed by one thread at a time. If multiple threads want to deal
772 with the same object, the caller has to make sure that operations on
773 that object are fully synchronized.
776 Only one thread at any time is allowed to call @code{gpgme_wait}. If
777 multiple threads call this function, the caller must make sure that
778 all invocations are fully synchronized. It is safe to start
779 asynchronous operations while a thread is running in gpgme_wait.
782 The function @code{gpgme_strerror} is not thread safe. You have to
783 use @code{gpgme_strerror_r} instead.
787 @node Protocols and Engines
788 @chapter Protocols and Engines
791 @cindex crypto engine
793 @cindex crypto backend
795 @acronym{GPGME} supports several cryptographic protocols, however, it
796 does not implement them. Rather it uses backends (also called
797 engines) which implement the protocol. @acronym{GPGME} uses
798 inter-process communication to pass data back and forth between the
799 application and the backend, but the details of the communication
800 protocol and invocation of the backend is completely hidden by the
801 interface. All complexity is handled by @acronym{GPGME}. Where an
802 exchange of information between the application and the backend is
803 necessary, @acronym{GPGME} provides the necessary callback function
804 hooks and further interfaces.
806 @deftp {Data type} {enum gpgme_protocol_t}
807 @tindex gpgme_protocol_t
808 The @code{gpgme_protocol_t} type specifies the set of possible protocol
809 values that are supported by @acronym{GPGME}. The following protocols
813 @item GPGME_PROTOCOL_OpenPGP
814 This specifies the OpenPGP protocol.
816 @item GPGME_PROTOCOL_CMS
817 This specifies the Cryptographic Message Syntax.
819 @item GPGME_PROTOCOL_ASSUAN
820 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
822 @item GPGME_PROTOCOL_G13
823 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
825 @item GPGME_PROTOCOL_UISERVER
826 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
828 @item GPGME_PROTOCOL_UNKNOWN
829 Reserved for future extension. You may use this to indicate that the
830 used protocol is not known to the application. Currently,
831 @acronym{GPGME} does not accept this value in any operation, though,
832 except for @code{gpgme_get_protocol_name}.
837 @deftypefun {const char *} gpgme_get_protocol_name (@w{gpgme_protocol_t @var{protocol}})
838 The function @code{gpgme_get_protocol_name} returns a statically
839 allocated string describing the protocol @var{protocol}, or
840 @code{NULL} if the protocol number is not valid.
844 * Engine Version Check:: Verifying the engine version.
845 * Engine Information:: Obtaining more information about the engines.
846 * Engine Configuration:: Changing the engine configuration.
847 * OpenPGP:: Support for the OpenPGP protocol.
848 * Cryptographic Message Syntax:: Support for the CMS.
852 @node Engine Version Check
853 @section Engine Version Check
854 @cindex version check, of the engines
856 @deftypefun gpgme_error_t gpgme_engine_check_version (@w{gpgme_protocol_t @var{protocol}})
857 The function @code{gpgme_engine_check_version} verifies that the
858 engine implementing the protocol @var{PROTOCOL} is installed in the
859 expected path and meets the version requirement of @acronym{GPGME}.
861 This function returns the error code @code{GPG_ERR_NO_ERROR} if the
862 engine is available and @code{GPG_ERR_INV_ENGINE} if it is not.
866 @node Engine Information
867 @section Engine Information
868 @cindex engine, information about
870 @deftp {Data type} {gpgme_engine_info_t}
871 @tindex gpgme_protocol_t
872 The @code{gpgme_engine_info_t} type specifies a pointer to a structure
873 describing a crypto engine. The structure contains the following
877 @item gpgme_engine_info_t next
878 This is a pointer to the next engine info structure in the linked
879 list, or @code{NULL} if this is the last element.
881 @item gpgme_protocol_t protocol
882 This is the protocol for which the crypto engine is used. You can
883 convert this to a string with @code{gpgme_get_protocol_name} for
886 @item const char *file_name
887 This is a string holding the file name of the executable of the crypto
888 engine. Currently, it is never @code{NULL}, but using @code{NULL} is
889 reserved for future use, so always check before you use it.
891 @item const char *home_dir
892 This is a string holding the directory name of the crypto engine's
893 configuration directory. If it is @code{NULL}, then the default
896 @item const char *version
897 This is a string containing the version number of the crypto engine.
898 It might be @code{NULL} if the version number can not be determined,
899 for example because the executable doesn't exist or is invalid.
901 @item const char *req_version
902 This is a string containing the minimum required version number of the
903 crypto engine for @acronym{GPGME} to work correctly. This is the
904 version number that @code{gpgme_engine_check_version} verifies
905 against. Currently, it is never @code{NULL}, but using @code{NULL} is
906 reserved for future use, so always check before you use it.
910 @deftypefun gpgme_error_t gpgme_get_engine_info (@w{gpgme_engine_info_t *@var{info}})
911 The function @code{gpgme_get_engine_info} returns a linked list of
912 engine info structures in @var{info}. Each info structure describes
913 the defaults of one configured backend.
915 The memory for the info structures is allocated the first time this
916 function is invoked, and must not be freed by the caller.
918 This function returns the error code @code{GPG_ERR_NO_ERROR} if
919 successful, and a system error if the memory could not be allocated.
922 Here is an example how you can provide more diagnostics if you receive
923 an error message which indicates that the crypto engine is invalid.
931 if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
933 gpgme_engine_info_t info;
934 err = gpgme_get_engine_info (&info);
937 while (info && info->protocol != gpgme_get_protocol (ctx))
940 fprintf (stderr, "GPGME compiled without support for protocol %s",
941 gpgme_get_protocol_name (info->protocol));
942 else if (info->file_name && !info->version)
943 fprintf (stderr, "Engine %s not installed properly",
945 else if (info->file_name && info->version && info->req_version)
946 fprintf (stderr, "Engine %s version %s installed, "
947 "but at least version %s required", info->file_name,
948 info->version, info->req_version);
950 fprintf (stderr, "Unknown problem with engine for protocol %s",
951 gpgme_get_protocol_name (info->protocol));
957 @node Engine Configuration
958 @section Engine Configuration
959 @cindex engine, configuration of
960 @cindex configuration of crypto backend
962 You can change the configuration of a backend engine, and thus change
963 the executable program and configuration directory to be used. You
964 can make these changes the default or set them for some contexts
967 @deftypefun gpgme_error_t gpgme_set_engine_info (@w{gpgme_protocol_t @var{proto}}, @w{const char *@var{file_name}}, @w{const char *@var{home_dir}})
968 The function @code{gpgme_set_engine_info} changes the default
969 configuration of the crypto engine implementing the protocol
972 @var{file_name} is the file name of the executable program
973 implementing this protocol, and @var{home_dir} is the directory name
974 of the configuration directory for this crypto engine. If
975 @var{home_dir} is @code{NULL}, the engine's default will be used.
977 The new defaults are not applied to already created GPGME contexts.
979 This function returns the error code @code{GPG_ERR_NO_ERROR} if
980 successful, or an eror code on failure.
983 The functions @code{gpgme_ctx_get_engine_info} and
984 @code{gpgme_ctx_set_engine_info} can be used to change the engine
985 configuration per context. @xref{Crypto Engine}.
992 @cindex protocol, GnuPG
993 @cindex engine, GnuPG
995 OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard.
996 This is the first protocol that was supported by @acronym{GPGME}.
998 The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}.
1001 @node Cryptographic Message Syntax
1002 @section Cryptographic Message Syntax
1004 @cindex cryptographic message syntax
1006 @cindex protocol, CMS
1007 @cindex engine, GpgSM
1009 @cindex protocol, S/MIME
1011 @acronym{CMS} is implemented by GpgSM, the S/MIME implementation for
1014 The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}.
1021 The crypto backends support a variety of algorithms used in public key
1022 cryptography.@footnote{Some engines also provide symmetric only
1023 encryption; see the description of the encryption function on how to use
1024 this.} The following sections list the identifiers used to denote such
1028 * Public Key Algorithms:: A list of all public key algorithms.
1029 * Hash Algorithms:: A list of all hash algorithms.
1033 @node Public Key Algorithms
1034 @section Public Key Algorithms
1035 @cindex algorithms, public key
1036 @cindex public key algorithms
1038 Public key algorithms are used for encryption, decryption, signing and
1039 verification of signatures.
1041 @deftp {Data type} {enum gpgme_pubkey_algo_t}
1042 @tindex gpgme_pubkey_algo_t
1043 The @code{gpgme_pubkey_algo_t} type specifies the set of all public key
1044 algorithms that are supported by @acronym{GPGME}. Possible values
1049 This value indicates the RSA (Rivest, Shamir, Adleman) algorithm.
1051 @item GPGME_PK_RSA_E
1052 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
1053 algorithm for encryption and decryption only.
1055 @item GPGME_PK_RSA_S
1056 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
1057 algorithm for signing and verification only.
1060 This value indicates DSA, the Digital Signature Algorithm.
1063 This value indicates ElGamal.
1065 @item GPGME_PK_ELG_E
1066 This value also indicates ElGamal and is used specifically in GnuPG.
1068 @item GPGME_PK_ELG_E
1069 This value also indicates ElGamal and is used specifically in GnuPG.
1071 @item GPGME_PK_ECDSA
1072 This value indicates ECDSA, the Elliptic Curve Digital Signature
1073 Algorithm as defined by FIPS 186-2.
1076 This value indicates ECDH, the Eliptic Curve Diffie-Hellmann encryption
1077 algorithm as defined by the ECC in OpenPGP draft.
1082 @deftypefun {const char *} gpgme_pubkey_algo_name (@w{gpgme_pubkey_algo_t @var{algo}})
1083 The function @code{gpgme_pubkey_algo_name} returns a pointer to a
1084 statically allocated string containing a description of the public key
1085 algorithm @var{algo}. This string can be used to output the name of
1086 the public key algorithm to the user.
1088 If @var{algo} is not a valid public key algorithm, @code{NULL} is
1093 @node Hash Algorithms
1094 @section Hash Algorithms
1095 @cindex algorithms, hash
1096 @cindex algorithms, message digest
1097 @cindex hash algorithms
1098 @cindex message digest algorithms
1100 Hash (message digest) algorithms are used to compress a long message
1101 to make it suitable for public key cryptography.
1103 @deftp {Data type} {enum gpgme_hash_algo_t}
1104 @tindex gpgme_hash_algo_t
1105 The @code{gpgme_hash_algo_t} type specifies the set of all hash algorithms
1106 that are supported by @acronym{GPGME}. Possible values are:
1111 @item GPGME_MD_RMD160
1113 @item GPGME_MD_TIGER
1114 @item GPGME_MD_HAVAL
1115 @item GPGME_MD_SHA256
1116 @item GPGME_MD_SHA384
1117 @item GPGME_MD_SHA512
1119 @item GPGME_MD_CRC32
1120 @item GPGME_MD_CRC32_RFC1510
1121 @item GPGME_MD_CRC24_RFC2440
1125 @deftypefun {const char *} gpgme_hash_algo_name (@w{gpgme_hash_algo_t @var{algo}})
1126 The function @code{gpgme_hash_algo_name} returns a pointer to a
1127 statically allocated string containing a description of the hash
1128 algorithm @var{algo}. This string can be used to output the name of
1129 the hash algorithm to the user.
1131 If @var{algo} is not a valid hash algorithm, @code{NULL} is returned.
1135 @node Error Handling
1136 @chapter Error Handling
1137 @cindex error handling
1139 Many functions in @acronym{GPGME} can return an error if they fail.
1140 For this reason, the application should always catch the error
1141 condition and take appropriate measures, for example by releasing the
1142 resources and passing the error up to the caller, or by displaying a
1143 descriptive message to the user and cancelling the operation.
1145 Some error values do not indicate a system error or an error in the
1146 operation, but the result of an operation that failed properly. For
1147 example, if you try to decrypt a tempered message, the decryption will
1148 fail. Another error value actually means that the end of a data
1149 buffer or list has been reached. The following descriptions explain
1150 for many error codes what they mean usually. Some error values have
1151 specific meanings if returned by a certain functions. Such cases are
1152 described in the documentation of those functions.
1154 @acronym{GPGME} uses the @code{libgpg-error} library. This allows to
1155 share the error codes with other components of the GnuPG system, and
1156 thus pass error values transparently from the crypto engine, or some
1157 helper application of the crypto engine, to the user. This way no
1158 information is lost. As a consequence, @acronym{GPGME} does not use
1159 its own identifiers for error codes, but uses those provided by
1160 @code{libgpg-error}. They usually start with @code{GPG_ERR_}.
1162 However, @acronym{GPGME} does provide aliases for the functions
1163 defined in libgpg-error, which might be preferred for name space
1167 * Error Values:: The error value and what it means.
1168 * Error Sources:: A list of important error sources.
1169 * Error Codes:: A list of important error codes.
1170 * Error Strings:: How to get a descriptive string from a value.
1175 @section Error Values
1176 @cindex error values
1178 @cindex error sources
1180 @deftp {Data type} {gpgme_err_code_t}
1181 The @code{gpgme_err_code_t} type is an alias for the @code{libgpg-error}
1182 type @code{gpg_err_code_t}. The error code indicates the type of an
1183 error, or the reason why an operation failed.
1185 A list of important error codes can be found in the next section.
1188 @deftp {Data type} {gpgme_err_source_t}
1189 The @code{gpgme_err_source_t} type is an alias for the
1190 @code{libgpg-error} type @code{gpg_err_source_t}. The error source
1191 has not a precisely defined meaning. Sometimes it is the place where
1192 the error happened, sometimes it is the place where an error was
1193 encoded into an error value. Usually the error source will give an
1194 indication to where to look for the problem. This is not always true,
1195 but it is attempted to achieve this goal.
1197 A list of important error sources can be found in the next section.
1200 @deftp {Data type} {gpgme_error_t}
1201 The @code{gpgme_error_t} type is an alias for the @code{libgpg-error}
1202 type @code{gpg_error_t}. An error value like this has always two
1203 components, an error code and an error source. Both together form the
1206 Thus, the error value can not be directly compared against an error
1207 code, but the accessor functions described below must be used.
1208 However, it is guaranteed that only 0 is used to indicate success
1209 (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of
1210 the error value are set to 0, too.
1212 Note that in @acronym{GPGME}, the error source is used purely for
1213 diagnostical purposes. Only the error code should be checked to test
1214 for a certain outcome of a function. The manual only documents the
1215 error code part of an error value. The error source is left
1216 unspecified and might be anything.
1219 @deftypefun {static inline gpgme_err_code_t} gpgme_err_code (@w{gpgme_error_t @var{err}})
1220 The static inline function @code{gpgme_err_code} returns the
1221 @code{gpgme_err_code_t} component of the error value @var{err}. This
1222 function must be used to extract the error code from an error value in
1223 order to compare it with the @code{GPG_ERR_*} error code macros.
1226 @deftypefun {static inline gpgme_err_source_t} gpgme_err_source (@w{gpgme_error_t @var{err}})
1227 The static inline function @code{gpgme_err_source} returns the
1228 @code{gpgme_err_source_t} component of the error value @var{err}. This
1229 function must be used to extract the error source from an error value in
1230 order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros.
1233 @deftypefun {static inline gpgme_error_t} gpgme_err_make (@w{gpgme_err_source_t @var{source}}, @w{gpgme_err_code_t @var{code}})
1234 The static inline function @code{gpgme_err_make} returns the error
1235 value consisting of the error source @var{source} and the error code
1238 This function can be used in callback functions to construct an error
1239 value to return it to the library.
1242 @deftypefun {static inline gpgme_error_t} gpgme_error (@w{gpgme_err_code_t @var{code}})
1243 The static inline function @code{gpgme_error} returns the error value
1244 consisting of the default error source and the error code @var{code}.
1246 For @acronym{GPGME} applications, the default error source is
1247 @code{GPG_ERR_SOURCE_USER_1}. You can define
1248 @code{GPGME_ERR_SOURCE_DEFAULT} before including @file{gpgme.h} to
1249 change this default.
1251 This function can be used in callback functions to construct an error
1252 value to return it to the library.
1255 The @code{libgpg-error} library provides error codes for all system
1256 error numbers it knows about. If @var{err} is an unknown error
1257 number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The
1258 following functions can be used to construct error values from system
1261 @deftypefun {gpgme_error_t} gpgme_err_make_from_errno (@w{gpgme_err_source_t @var{source}}, @w{int @var{err}})
1262 The function @code{gpgme_err_make_from_errno} is like
1263 @code{gpgme_err_make}, but it takes a system error like @code{errno}
1264 instead of a @code{gpgme_err_code_t} error code.
1267 @deftypefun {gpgme_error_t} gpgme_error_from_errno (@w{int @var{err}})
1268 The function @code{gpgme_error_from_errno} is like @code{gpgme_error},
1269 but it takes a system error like @code{errno} instead of a
1270 @code{gpgme_err_code_t} error code.
1273 Sometimes you might want to map system error numbers to error codes
1274 directly, or map an error code representing a system error back to the
1275 system error number. The following functions can be used to do that.
1277 @deftypefun {gpgme_err_code_t} gpgme_err_code_from_errno (@w{int @var{err}})
1278 The function @code{gpgme_err_code_from_errno} returns the error code
1279 for the system error @var{err}. If @var{err} is not a known system
1280 error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}.
1283 @deftypefun {int} gpgme_err_code_to_errno (@w{gpgme_err_code_t @var{err}})
1284 The function @code{gpgme_err_code_to_errno} returns the system error
1285 for the error code @var{err}. If @var{err} is not an error code
1286 representing a system error, or if this system error is not defined on
1287 this system, the function returns @code{0}.
1292 @section Error Sources
1293 @cindex error codes, list of
1295 The library @code{libgpg-error} defines an error source for every
1296 component of the GnuPG system. The error source part of an error
1297 value is not well defined. As such it is mainly useful to improve the
1298 diagnostic error message for the user.
1300 If the error code part of an error value is @code{0}, the whole error
1301 value will be @code{0}. In this case the error source part is of
1302 course @code{GPG_ERR_SOURCE_UNKNOWN}.
1304 The list of error sources that might occur in applications using
1308 @item GPG_ERR_SOURCE_UNKNOWN
1309 The error source is not known. The value of this error source is
1312 @item GPG_ERR_SOURCE_GPGME
1313 The error source is @acronym{GPGME} itself. This is the default for
1314 errors that occur in the @acronym{GPGME} library.
1316 @item GPG_ERR_SOURCE_GPG
1317 The error source is GnuPG, which is the crypto engine used for the
1320 @item GPG_ERR_SOURCE_GPGSM
1321 The error source is GPGSM, which is the crypto engine used for the
1324 @item GPG_ERR_SOURCE_GCRYPT
1325 The error source is @code{libgcrypt}, which is used by crypto engines
1326 to perform cryptographic operations.
1328 @item GPG_ERR_SOURCE_GPGAGENT
1329 The error source is @command{gpg-agent}, which is used by crypto
1330 engines to perform operations with the secret key.
1332 @item GPG_ERR_SOURCE_PINENTRY
1333 The error source is @command{pinentry}, which is used by
1334 @command{gpg-agent} to query the passphrase to unlock a secret key.
1336 @item GPG_ERR_SOURCE_SCD
1337 The error source is the SmartCard Daemon, which is used by
1338 @command{gpg-agent} to delegate operations with the secret key to a
1341 @item GPG_ERR_SOURCE_KEYBOX
1342 The error source is @code{libkbx}, a library used by the crypto
1343 engines to manage local keyrings.
1345 @item GPG_ERR_SOURCE_USER_1
1346 @item GPG_ERR_SOURCE_USER_2
1347 @item GPG_ERR_SOURCE_USER_3
1348 @item GPG_ERR_SOURCE_USER_4
1349 These error sources are not used by any GnuPG component and can be
1350 used by other software. For example, applications using
1351 @acronym{GPGME} can use them to mark error values coming from callback
1352 handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors
1353 created with @code{gpgme_error} and @code{gpgme_error_from_errno},
1354 unless you define @code{GPGME_ERR_SOURCE_DEFAULT} before including
1360 @section Error Codes
1361 @cindex error codes, list of
1363 The library @code{libgpg-error} defines many error values. Most of
1364 them are not used by @code{GPGME} directly, but might be returned by
1365 @acronym{GPGME} because it received them from the crypto engine. The
1366 below list only includes such error codes that have a specific meaning
1367 in @code{GPGME}, or which are so common that you should know about
1372 This value indicates the end of a list, buffer or file.
1374 @item GPG_ERR_NO_ERROR
1375 This value indicates success. The value of this error code is
1376 @code{0}. Also, it is guaranteed that an error value made from the
1377 error code @code{0} will be @code{0} itself (as a whole). This means
1378 that the error source information is lost for this error code,
1379 however, as this error code indicates that no error occured, this is
1380 generally not a problem.
1382 @item GPG_ERR_GENERAL
1383 This value means that something went wrong, but either there is not
1384 enough information about the problem to return a more useful error
1385 value, or there is no separate error value for this type of problem.
1387 @item GPG_ERR_ENOMEM
1388 This value means that an out-of-memory condition occurred.
1391 System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
1394 @item GPG_ERR_INV_VALUE
1395 This value means that some user provided data was out of range. This
1396 can also refer to objects. For example, if an empty
1397 @code{gpgme_data_t} object was expected, but one containing data was
1398 provided, this error value is returned.
1400 @item GPG_ERR_UNUSABLE_PUBKEY
1401 This value means that some recipients for a message were invalid.
1403 @item GPG_ERR_UNUSABLE_SECKEY
1404 This value means that some signers were invalid.
1406 @item GPG_ERR_NO_DATA
1407 This value means that a @code{gpgme_data_t} object which was expected
1408 to have content was found empty.
1410 @item GPG_ERR_CONFLICT
1411 This value means that a conflict of some sort occurred.
1413 @item GPG_ERR_NOT_IMPLEMENTED
1414 This value indicates that the specific function (or operation) is not
1415 implemented. This error should never happen. It can only occur if
1416 you use certain values or configuration options which do not work,
1417 but for which we think that they should work at some later time.
1419 @item GPG_ERR_DECRYPT_FAILED
1420 This value indicates that a decryption operation was unsuccessful.
1422 @item GPG_ERR_BAD_PASSPHRASE
1423 This value means that the user did not provide a correct passphrase
1426 @item GPG_ERR_CANCELED
1427 This value means that the operation was canceled.
1429 @item GPG_ERR_INV_ENGINE
1430 This value means that the engine that implements the desired protocol
1431 is currently not available. This can either be because the sources
1432 were configured to exclude support for this engine, or because the
1433 engine is not installed properly.
1435 @item GPG_ERR_AMBIGUOUS_NAME
1436 This value indicates that a user ID or other specifier did not specify
1439 @item GPG_ERR_WRONG_KEY_USAGE
1440 This value indicates that a key is not used appropriately.
1442 @item GPG_ERR_CERT_REVOKED
1443 This value indicates that a key signature was revoced.
1445 @item GPG_ERR_CERT_EXPIRED
1446 This value indicates that a key signature expired.
1448 @item GPG_ERR_NO_CRL_KNOWN
1449 This value indicates that no certificate revocation list is known for
1452 @item GPG_ERR_NO_POLICY_MATCH
1453 This value indicates that a policy issue occured.
1455 @item GPG_ERR_NO_SECKEY
1456 This value indicates that no secret key for the user ID is available.
1458 @item GPG_ERR_MISSING_CERT
1459 This value indicates that a key could not be imported because the
1460 issuer certificate is missing.
1462 @item GPG_ERR_BAD_CERT_CHAIN
1463 This value indicates that a key could not be imported because its
1464 certificate chain is not good, for example it could be too long.
1466 @item GPG_ERR_UNSUPPORTED_ALGORITHM
1467 This value means a verification failed because the cryptographic
1468 algorithm is not supported by the crypto backend.
1470 @item GPG_ERR_BAD_SIGNATURE
1471 This value means a verification failed because the signature is bad.
1473 @item GPG_ERR_NO_PUBKEY
1474 This value means a verification failed because the public key is not
1477 @item GPG_ERR_USER_1
1478 @item GPG_ERR_USER_2
1480 @item GPG_ERR_USER_16
1481 These error codes are not used by any GnuPG component and can be
1482 freely used by other software. Applications using @acronym{GPGME}
1483 might use them to mark specific errors returned by callback handlers
1484 if no suitable error codes (including the system errors) for
1485 these errors exist already.
1490 @section Error Strings
1491 @cindex error values, printing of
1492 @cindex error codes, printing of
1493 @cindex error sources, printing of
1494 @cindex error strings
1496 @deftypefun {const char *} gpgme_strerror (@w{gpgme_error_t @var{err}})
1497 The function @code{gpgme_strerror} returns a pointer to a statically
1498 allocated string containing a description of the error code contained
1499 in the error value @var{err}. This string can be used to output a
1500 diagnostic message to the user.
1502 This function is not thread safe. Use @code{gpgme_strerror_r} in
1503 multi-threaded programs.
1507 @deftypefun {int} gpgme_strerror_r (@w{gpgme_error_t @var{err}}, @w{char *@var{buf}}, @w{size_t @var{buflen}})
1508 The function @code{gpgme_strerror_r} returns the error string for
1509 @var{err} in the user-supplied buffer @var{buf} of size @var{buflen}.
1510 This function is, in contrast to @code{gpgme_strerror}, thread-safe if
1511 a thread-safe @code{strerror_r} function is provided by the system.
1512 If the function succeeds, 0 is returned and @var{buf} contains the
1513 string describing the error. If the buffer was not large enough,
1514 ERANGE is returned and @var{buf} contains as much of the beginning of
1515 the error string as fits into the buffer.
1519 @deftypefun {const char *} gpgme_strsource (@w{gpgme_error_t @var{err}})
1520 The function @code{gpgme_strerror} returns a pointer to a statically
1521 allocated string containing a description of the error source
1522 contained in the error value @var{err}. This string can be used to
1523 output a diagnostic message to the user.
1526 The following example illustrates the use of @code{gpgme_strerror}:
1530 gpgme_error_t err = gpgme_new (&ctx);
1533 fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
1534 argv[0], gpgme_strsource (err), gpgme_strerror (err));
1540 @node Exchanging Data
1541 @chapter Exchanging Data
1542 @cindex data, exchanging
1544 A lot of data has to be exchanged between the user and the crypto
1545 engine, like plaintext messages, ciphertext, signatures and
1546 information about the keys. The technical details about exchanging
1547 the data information are completely abstracted by @acronym{GPGME}.
1548 The user provides and receives the data via @code{gpgme_data_t} objects,
1549 regardless of the communication protocol between @acronym{GPGME} and
1550 the crypto engine in use.
1552 @deftp {Data type} {gpgme_data_t}
1553 The @code{gpgme_data_t} type is a handle for a container for generic
1554 data, which is used by @acronym{GPGME} to exchange data with the user.
1557 @code{gpgme_data_t} objects do not provide notifications on events.
1558 It is assumed that read and write operations are blocking until data
1559 is available. If this is undesirable, the application must ensure
1560 that all GPGME data operations always have data available, for example
1561 by using memory buffers or files rather than pipes or sockets. This
1562 might be relevant, for example, if the external event loop mechanism
1565 @deftp {Data type} {gpgme_off_t}
1566 On POSIX platforms the @code{gpgme_off_t} type is an alias for
1567 @code{off_t}; it may be used interchangeable. On Windows platforms
1568 @code{gpgme_off_t} is defined as a long (i.e. 32 bit) for 32 bit
1569 Windows and as a 64 bit signed integer for 64 bit Windows.
1572 @deftp {Data type} {gpgme_ssize_t}
1573 The @code{gpgme_ssize_t} type is an alias for @code{ssize_t}. It has
1574 only been introduced to overcome portability problems pertaining to
1575 the declaration of @code{ssize_t} by different toolchains.
1580 * Creating Data Buffers:: Creating new data buffers.
1581 * Destroying Data Buffers:: Releasing data buffers.
1582 * Manipulating Data Buffers:: Operations on data buffers.
1586 @node Creating Data Buffers
1587 @section Creating Data Buffers
1588 @cindex data buffer, creation
1590 Data objects can be based on memory, files, or callback functions
1591 provided by the user. Not all operations are supported by all
1596 * Memory Based Data Buffers:: Creating memory based data buffers.
1597 * File Based Data Buffers:: Creating file based data buffers.
1598 * Callback Based Data Buffers:: Creating callback based data buffers.
1602 @node Memory Based Data Buffers
1603 @subsection Memory Based Data Buffers
1605 Memory based data objects store all data in allocated memory. This is
1606 convenient, but only practical for an amount of data that is a
1607 fraction of the available physical memory. The data has to be copied
1608 from its source and to its destination, which can often be avoided by
1609 using one of the other data object
1611 @deftypefun gpgme_error_t gpgme_data_new (@w{gpgme_data_t *@var{dh}})
1612 The function @code{gpgme_data_new} creates a new @code{gpgme_data_t}
1613 object and returns a handle for it in @var{dh}. The data object is
1614 memory based and initially empty.
1616 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1617 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1618 @var{dh} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1619 enough memory is available.
1622 @deftypefun gpgme_error_t gpgme_data_new_from_mem (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{buffer}}, @w{size_t @var{size}}, @w{int @var{copy}})
1623 The function @code{gpgme_data_new_from_mem} creates a new
1624 @code{gpgme_data_t} object and fills it with @var{size} bytes starting
1627 If @var{copy} is not zero, a private copy of the data is made. If
1628 @var{copy} is zero, the data is taken from the specified buffer as
1629 needed, and the user has to ensure that the buffer remains valid for
1630 the whole life span of the data object.
1632 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1633 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1634 @var{dh} or @var{buffer} is not a valid pointer, and
1635 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1638 @deftypefun gpgme_error_t gpgme_data_new_from_file (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}})
1639 The function @code{gpgme_data_new_from_file} creates a new
1640 @code{gpgme_data_t} object and fills it with the content of the file
1643 If @var{copy} is not zero, the whole file is read in at initialization
1644 time and the file is not used anymore after that. This is the only
1645 mode supported currently. Later, a value of zero for @var{copy} might
1646 cause all reads to be delayed until the data is needed, but this is
1647 not yet implemented.
1649 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1650 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1651 @var{dh} or @var{filename} is not a valid pointer,
1652 @code{GPG_ERR_NOT_IMPLEMENTED} if @var{code} is zero, and
1653 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1656 @deftypefun gpgme_error_t gpgme_data_new_from_filepart (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{FILE *@var{fp}}, @w{off_t @var{offset}}, @w{size_t @var{length}})
1657 The function @code{gpgme_data_new_from_filepart} creates a new
1658 @code{gpgme_data_t} object and fills it with a part of the file specified
1659 by @var{filename} or @var{fp}.
1661 Exactly one of @var{filename} and @var{fp} must be non-zero, the other
1662 must be zero. The argument that is not zero specifies the file from
1663 which @var{length} bytes are read into the data object, starting from
1666 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1667 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1668 @var{dh} and exactly one of @var{filename} and @var{fp} is not a valid
1669 pointer, and @code{GPG_ERR_ENOMEM} if not enough memory is available.
1673 @node File Based Data Buffers
1674 @subsection File Based Data Buffers
1676 File based data objects operate directly on file descriptors or
1677 streams. Only a small amount of data is stored in core at any time,
1678 so the size of the data objects is not limited by @acronym{GPGME}.
1680 @deftypefun gpgme_error_t gpgme_data_new_from_fd (@w{gpgme_data_t *@var{dh}}, @w{int @var{fd}})
1681 The function @code{gpgme_data_new_from_fd} creates a new
1682 @code{gpgme_data_t} object and uses the file descriptor @var{fd} to read
1683 from (if used as an input data object) and write to (if used as an
1684 output data object).
1686 When using the data object as an input buffer, the function might read
1687 a bit more from the file descriptor than is actually needed by the
1688 crypto engine in the desired operation because of internal buffering.
1690 Note that GPGME assumes that the file descriptor is set to blocking
1691 mode. Errors during I/O operations, except for EINTR, are usually
1692 fatal for crypto operations.
1694 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1695 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1696 enough memory is available.
1699 @deftypefun gpgme_error_t gpgme_data_new_from_stream (@w{gpgme_data_t *@var{dh}}, @w{FILE *@var{stream}})
1700 The function @code{gpgme_data_new_from_stream} creates a new
1701 @code{gpgme_data_t} object and uses the I/O stream @var{stream} to read
1702 from (if used as an input data object) and write to (if used as an
1703 output data object).
1705 When using the data object as an input buffer, the function might read
1706 a bit more from the stream than is actually needed by the crypto
1707 engine in the desired operation because of internal buffering.
1709 Note that GPGME assumes that the stream is in blocking mode. Errors
1710 during I/O operations, except for EINTR, are usually fatal for crypto
1713 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1714 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1715 enough memory is available.
1719 @node Callback Based Data Buffers
1720 @subsection Callback Based Data Buffers
1722 If neither memory nor file based data objects are a good fit for your
1723 application, you can implement the functions a data object provides
1724 yourself and create a data object from these callback functions.
1726 @deftp {Data type} {ssize_t (*gpgme_data_read_cb_t) (@w{void *@var{handle}}, @w{void @var{*buffer}}, @w{size_t @var{size}})}
1727 @tindex gpgme_data_read_cb_t
1728 The @code{gpgme_data_read_cb_t} type is the type of functions which
1729 @acronym{GPGME} calls if it wants to read data from a user-implemented
1730 data object. The function should read up to @var{size} bytes from the
1731 current read position into the space starting at @var{buffer}. The
1732 @var{handle} is provided by the user at data object creation time.
1734 Note that GPGME assumes that the read blocks until data is available.
1735 Errors during I/O operations, except for EINTR, are usually fatal for
1738 The function should return the number of bytes read, 0 on EOF, and -1
1739 on error. If an error occurs, @var{errno} should be set to describe
1740 the type of the error.
1743 @deftp {Data type} {ssize_t (*gpgme_data_write_cb_t) (@w{void *@var{handle}}, @w{const void @var{*buffer}}, @w{size_t @var{size}})}
1744 @tindex gpgme_data_write_cb_t
1745 The @code{gpgme_data_write_cb_t} type is the type of functions which
1746 @acronym{GPGME} calls if it wants to write data to a user-implemented
1747 data object. The function should write up to @var{size} bytes to the
1748 current write position from the space starting at @var{buffer}. The
1749 @var{handle} is provided by the user at data object creation time.
1751 Note that GPGME assumes that the write blocks until data is available.
1752 Errors during I/O operations, except for EINTR, are usually fatal for
1755 The function should return the number of bytes written, and -1 on
1756 error. If an error occurs, @var{errno} should be set to describe the
1760 @deftp {Data type} {off_t (*gpgme_data_seek_cb_t) (@w{void *@var{handle}}, @w{off_t @var{offset}}, @w{int @var{whence}})}
1761 @tindex gpgme_data_seek_cb_t
1762 The @code{gpgme_data_seek_cb_t} type is the type of functions which
1763 @acronym{GPGME} calls if it wants to change the current read/write
1764 position in a user-implemented data object, just like the @code{lseek}
1767 The function should return the new read/write position, and -1 on
1768 error. If an error occurs, @var{errno} should be set to describe the
1772 @deftp {Data type} {void (*gpgme_data_release_cb_t) (@w{void *@var{handle}})}
1773 @tindex gpgme_data_release_cb_t
1774 The @code{gpgme_data_release_cb_t} type is the type of functions which
1775 @acronym{GPGME} calls if it wants to destroy a user-implemented data
1776 object. The @var{handle} is provided by the user at data object
1780 @deftp {Data type} {struct gpgme_data_cbs}
1781 This structure is used to store the data callback interface functions
1782 described above. It has the following members:
1785 @item gpgme_data_read_cb_t read
1786 This is the function called by @acronym{GPGME} to read data from the
1787 data object. It is only required for input data object.
1789 @item gpgme_data_write_cb_t write
1790 This is the function called by @acronym{GPGME} to write data to the
1791 data object. It is only required for output data object.
1793 @item gpgme_data_seek_cb_t seek
1794 This is the function called by @acronym{GPGME} to change the current
1795 read/write pointer in the data object (if available). It is optional.
1797 @item gpgme_data_release_cb_t release
1798 This is the function called by @acronym{GPGME} to release a data
1799 object. It is optional.
1803 @deftypefun gpgme_error_t gpgme_data_new_from_cbs (@w{gpgme_data_t *@var{dh}}, @w{gpgme_data_cbs_t @var{cbs}}, @w{void *@var{handle}})
1804 The function @code{gpgme_data_new_from_cbs} creates a new
1805 @code{gpgme_data_t} object and uses the user-provided callback functions
1806 to operate on the data object.
1808 The handle @var{handle} is passed as first argument to the callback
1809 functions. This can be used to identify this data object.
1811 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1812 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1813 enough memory is available.
1816 The following interface is deprecated and only provided for backward
1817 compatibility. Don't use it. It will be removed in a future version
1820 @deftypefun gpgme_error_t gpgme_data_new_with_read_cb (@w{gpgme_data_t *@var{dh}}, @w{int (*@var{readfunc})} (@w{void *@var{hook}}, @w{char *@var{buffer}}, @w{size_t @var{count}}, @w{size_t *@var{nread}}), @w{void *@var{hook_value}})
1821 The function @code{gpgme_data_new_with_read_cb} creates a new
1822 @code{gpgme_data_t} object and uses the callback function @var{readfunc}
1823 to retrieve the data on demand. As the callback function can supply
1824 the data in any way it wants, this is the most flexible data type
1825 @acronym{GPGME} provides. However, it can not be used to write data.
1827 The callback function receives @var{hook_value} as its first argument
1828 whenever it is invoked. It should return up to @var{count} bytes in
1829 @var{buffer}, and return the number of bytes actually read in
1830 @var{nread}. It may return @code{0} in @var{nread} if no data is
1831 currently available. To indicate @code{EOF} the function should
1832 return with an error code of @code{-1} and set @var{nread} to
1833 @code{0}. The callback function may support to reset its internal
1834 read pointer if it is invoked with @var{buffer} and @var{nread} being
1835 @code{NULL} and @var{count} being @code{0}.
1837 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1838 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1839 @var{dh} or @var{readfunc} is not a valid pointer, and
1840 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1844 @node Destroying Data Buffers
1845 @section Destroying Data Buffers
1846 @cindex data buffer, destruction
1848 @deftypefun void gpgme_data_release (@w{gpgme_data_t @var{dh}})
1849 The function @code{gpgme_data_release} destroys the data object with
1850 the handle @var{dh}. It releases all associated resources that were
1851 not provided by the user in the first place.
1854 @deftypefun {char *} gpgme_data_release_and_get_mem (@w{gpgme_data_t @var{dh}}, @w{size_t *@var{length}})
1855 The function @code{gpgme_data_release_and_get_mem} is like
1856 @code{gpgme_data_release}, except that it returns the data buffer and
1857 its length that was provided by the object.
1859 The user has to release the buffer with @code{gpgme_free}. In case
1860 the user provided the data buffer in non-copy mode, a copy will be
1861 made for this purpose.
1863 In case an error returns, or there is no suitable data buffer that can
1864 be returned to the user, the function will return @code{NULL}. In any
1865 case, the data object @var{dh} is destroyed.
1869 @deftypefun void gpgme_free (@w{void *@var{buffer}})
1870 The function @code{gpgme_free} releases the memory returned by
1871 @code{gpgme_data_release_and_get_mem}. It should be used instead of
1872 the system libraries @code{free} function in case different allocators
1873 are used in a single program.
1877 @node Manipulating Data Buffers
1878 @section Manipulating Data Buffers
1879 @cindex data buffer, manipulation
1881 Data buffers contain data and meta-data. The following operations can
1882 be used to manipulate both.
1886 * Data Buffer I/O Operations:: I/O operations on data buffers.
1887 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
1891 @node Data Buffer I/O Operations
1892 @subsection Data Buffer I/O Operations
1893 @cindex data buffer, I/O operations
1894 @cindex data buffer, read
1895 @cindex data buffer, write
1896 @cindex data buffer, seek
1898 @deftypefun ssize_t gpgme_data_read (@w{gpgme_data_t @var{dh}}, @w{void *@var{buffer}}, @w{size_t @var{length}})
1899 The function @code{gpgme_data_read} reads up to @var{length} bytes
1900 from the data object with the handle @var{dh} into the space starting
1903 If no error occurs, the actual amount read is returned. If the end of
1904 the data object is reached, the function returns 0.
1906 In all other cases, the function returns -1 and sets @var{errno}.
1909 @deftypefun ssize_t gpgme_data_write (@w{gpgme_data_t @var{dh}}, @w{const void *@var{buffer}}, @w{size_t @var{size}})
1910 The function @code{gpgme_data_write} writes up to @var{size} bytes
1911 starting from @var{buffer} into the data object with the handle
1912 @var{dh} at the current write position.
1914 The function returns the number of bytes actually written, or -1 if an
1915 error occurs. If an error occurs, @var{errno} is set.
1918 @deftypefun off_t gpgme_data_seek (@w{gpgme_data_t @var{dh}}, @w{off_t @var{offset}}, @w{int @var{whence}})
1919 The function @code{gpgme_data_seek} changes the current read/write
1922 The @var{whence} argument specifies how the @var{offset} should be
1923 interpreted. It must be one of the following symbolic constants:
1927 Specifies that @var{offset} is a count of characters from the
1928 beginning of the data object.
1931 Specifies that @var{offset} is a count of characters from the current
1932 file position. This count may be positive or negative.
1935 Specifies that @var{offset} is a count of characters from the end of
1936 the data object. A negative count specifies a position within the
1937 current extent of the data object; a positive count specifies a
1938 position past the current end. If you set the position past the
1939 current end, and actually write data, you will extend the data object
1940 with zeros up to that position.
1943 If successful, the function returns the resulting file position,
1944 measured in bytes from the beginning of the data object. You can use
1945 this feature together with @code{SEEK_CUR} to read the current
1946 read/write position.
1948 If the function fails, -1 is returned and @var{errno} is set.
1951 The following function is deprecated and should not be used. It will
1952 be removed in a future version of @acronym{GPGME}.
1954 @deftypefun gpgme_error_t gpgme_data_rewind (@w{gpgme_data_t @var{dh}})
1955 The function @code{gpgme_data_rewind} is equivalent to:
1958 return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
1959 ? gpgme_error_from_errno (errno) : 0;
1966 @node Data Buffer Meta-Data
1967 @subsection Data Buffer Meta-Data
1968 @cindex data buffer, meta-data
1969 @cindex data buffer, file name
1970 @cindex data buffer, encoding
1972 @deftypefun {char *} gpgme_data_get_file_name (@w{gpgme_data_t @var{dh}})
1973 The function @code{gpgme_data_get_file_name} returns a pointer to a
1974 string containing the file name associated with the data object. The
1975 file name will be stored in the output when encrypting or signing the
1976 data and will be returned to the user when decrypting or verifying the
1979 If no error occurs, the string containing the file name is returned.
1980 Otherwise, @code{NULL} will be returned.
1984 @deftypefun gpgme_error_t gpgme_data_set_file_name (@w{gpgme_data_t @var{dh}}, @w{const char *@var{file_name}})
1985 The function @code{gpgme_data_set_file_name} sets the file name
1986 associated with the data object. The file name will be stored in the
1987 output when encrypting or signing the data and will be returned to the
1988 user when decrypting or verifying the output data.
1990 The function returns the error code @code{GPG_ERR_INV_VALUE} if
1991 @var{dh} is not a valid pointer and @code{GPG_ERR_ENOMEM} if not
1992 enough memory is available.
1996 @deftp {Data type} {enum gpgme_data_encoding_t}
1997 @tindex gpgme_data_encoding_t
1998 The @code{gpgme_data_encoding_t} type specifies the encoding of a
1999 @code{gpgme_data_t} object. For input data objects, the encoding is
2000 useful to give the backend a hint on the type of data. For output
2001 data objects, the encoding can specify the output data format on
2002 certain operations. Please note that not all backends support all
2003 encodings on all operations. The following data types are available:
2006 @item GPGME_DATA_ENCODING_NONE
2007 This specifies that the encoding is not known. This is the default
2008 for a new data object. The backend will try its best to detect the
2009 encoding automatically.
2011 @item GPGME_DATA_ENCODING_BINARY
2012 This specifies that the data is encoding in binary form; i.e. there is
2013 no special encoding.
2015 @item GPGME_DATA_ENCODING_BASE64
2016 This specifies that the data is encoded using the Base-64 encoding
2017 scheme as used by @acronym{MIME} and other protocols.
2019 @item GPGME_DATA_ENCODING_ARMOR
2020 This specifies that the data is encoded in an armored form as used by
2023 @item GPGME_DATA_ENCODING_URL
2024 The data is a list of linefeed delimited URLs. This is only useful with
2025 @code{gpgme_op_import}.
2027 @item GPGME_DATA_ENCODING_URL0
2028 The data is a list of binary zero delimited URLs. This is only useful
2029 with @code{gpgme_op_import}.
2031 @item GPGME_DATA_ENCODING_URLESC
2032 The data is a list of linefeed delimited URLs with all control and space
2033 characters percent escaped. This mode is is not yet implemented.
2038 @deftypefun gpgme_data_encoding_t gpgme_data_get_encoding (@w{gpgme_data_t @var{dh}})
2039 The function @code{gpgme_data_get_encoding} returns the encoding of
2040 the data object with the handle @var{dh}. If @var{dh} is not a valid
2041 pointer (e.g. @code{NULL}) @code{GPGME_DATA_ENCODING_NONE} is
2045 @deftypefun gpgme_error_t gpgme_data_set_encoding (@w{gpgme_data_t @var{dh}, gpgme_data_encoding_t @var{enc}})
2046 The function @code{gpgme_data_set_encoding} changes the encoding of
2047 the data object with the handle @var{dh} to @var{enc}.
2058 All cryptographic operations in @acronym{GPGME} are performed within a
2059 context, which contains the internal state of the operation as well as
2060 configuration parameters. By using several contexts you can run
2061 several cryptographic operations in parallel, with different
2064 @deftp {Data type} {gpgme_ctx_t}
2065 The @code{gpgme_ctx_t} type is a handle for a @acronym{GPGME} context,
2066 which is used to hold the configuration, status and result of
2067 cryptographic operations.
2071 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
2072 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
2073 * Result Management:: Managing the result of crypto operations.
2074 * Context Attributes:: Setting properties of a context.
2075 * Key Management:: Managing keys with @acronym{GPGME}.
2076 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
2077 * Crypto Operations:: Using a context for cryptography.
2078 * Run Control:: Controlling how operations are run.
2082 @node Creating Contexts
2083 @section Creating Contexts
2084 @cindex context, creation
2086 @deftypefun gpgme_error_t gpgme_new (@w{gpgme_ctx_t *@var{ctx}})
2087 The function @code{gpgme_new} creates a new @code{gpgme_ctx_t} object
2088 and returns a handle for it in @var{ctx}.
2090 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2091 context was successfully created, @code{GPG_ERR_INV_VALUE} if
2092 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
2093 enough memory is available. Also, it returns
2094 @code{GPG_ERR_NOT_OPERATIONAL} if @code{gpgme_check_version} was not
2095 called to initialize GPGME, and @code{GPG_ERR_SELFTEST_FAILED} if a
2096 selftest failed. Currently, the only selftest is for Windows MingW32
2097 targets to see if @code{-mms-bitfields} was used (as required).
2101 @node Destroying Contexts
2102 @section Destroying Contexts
2103 @cindex context, destruction
2105 @deftypefun void gpgme_release (@w{gpgme_ctx_t @var{ctx}})
2106 The function @code{gpgme_release} destroys the context with the handle
2107 @var{ctx} and releases all associated resources.
2111 @node Result Management
2112 @section Result Management
2113 @cindex context, result of operation
2115 The detailed result of an operation is returned in operation-specific
2116 structures such as @code{gpgme_decrypt_result_t}. The corresponding
2117 retrieval functions such as @code{gpgme_op_decrypt_result} provide
2118 static access to the results after an operation completes. The
2119 following interfaces make it possible to detach a result structure
2120 from its associated context and give it a lifetime beyond that of the
2121 current operation or context.
2123 @deftypefun void gpgme_result_ref (@w{void *@var{result}})
2124 The function @code{gpgme_result_ref} acquires an additional reference
2125 for the result @var{result}, which may be of any type
2126 @code{gpgme_*_result_t}. As long as the user holds a reference, the
2127 result structure is guaranteed to be valid and unmodified.
2130 @deftypefun void gpgme_result_unref (@w{void *@var{result}})
2131 The function @code{gpgme_result_unref} releases a reference for the
2132 result @var{result}. If this was the last reference, the result
2133 structure will be destroyed and all resources associated to it will be
2137 Note that a context may hold its own references to result structures,
2138 typically until the context is destroyed or the next operation is
2139 started. In fact, these references are accessed through the
2140 @code{gpgme_op_*_result} functions.
2143 @node Context Attributes
2144 @section Context Attributes
2145 @cindex context, attributes
2148 * Protocol Selection:: Selecting the protocol used by a context.
2149 * Crypto Engine:: Configuring the crypto engine.
2150 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
2151 * Text Mode:: Choosing canonical text mode.
2152 * Included Certificates:: Including a number of certificates.
2153 * Key Listing Mode:: Selecting key listing mode.
2154 * Passphrase Callback:: Getting the passphrase from the user.
2155 * Progress Meter Callback:: Being informed about the progress.
2156 * Locale:: Setting the locale of a context.
2160 @node Protocol Selection
2161 @subsection Protocol Selection
2162 @cindex context, selecting protocol
2163 @cindex protocol, selecting
2165 @deftypefun gpgme_error_t gpgme_set_protocol (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}})
2166 The function @code{gpgme_set_protocol} sets the protocol used within
2167 the context @var{ctx} to @var{proto}. All crypto operations will be
2168 performed by the crypto engine configured for that protocol.
2169 @xref{Protocols and Engines}.
2171 Setting the protocol with @code{gpgme_set_protocol} does not check if
2172 the crypto engine for that protocol is available and installed
2173 correctly. @xref{Engine Version Check}.
2175 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2176 protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if
2177 @var{protocol} is not a valid protocol.
2180 @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}})
2181 The function @code{gpgme_get_protocol} retrieves the protocol currently
2182 use with the context @var{ctx}.
2187 @subsection Crypto Engine
2188 @cindex context, configuring engine
2189 @cindex engine, configuration per context
2191 The following functions can be used to set and retrieve the
2192 configuration of the crypto engines of a specific context. The
2193 default can also be retrieved without any particular context.
2194 @xref{Engine Information}. The default can also be changed globally.
2195 @xref{Engine Configuration}.
2197 @deftypefun gpgme_engine_info_t gpgme_ctx_get_engine_info (@w{gpgme_ctx_t @var{ctx}})
2198 The function @code{gpgme_ctx_get_engine_info} returns a linked list of
2199 engine info structures. Each info structure describes the
2200 configuration of one configured backend, as used by the context
2203 The result is valid until the next invocation of
2204 @code{gpgme_ctx_set_engine_info} for this particular context.
2206 This function can not fail.
2209 @deftypefun gpgme_error_t gpgme_ctx_set_engine_info (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}}, @w{const char *@var{file_name}}, @w{const char *@var{home_dir}})
2210 The function @code{gpgme_ctx_set_engine_info} changes the
2211 configuration of the crypto engine implementing the protocol
2212 @var{proto} for the context @var{ctx}.
2214 @var{file_name} is the file name of the executable program
2215 implementing this protocol, and @var{home_dir} is the directory name
2216 of the configuration directory for this crypto engine. If
2217 @var{home_dir} is @code{NULL}, the engine's default will be used.
2219 Currently this function must be used before starting the first crypto
2220 operation. It is unspecified if and when the changes will take effect
2221 if the function is called after starting the first operation on the
2224 This function returns the error code @code{GPG_ERR_NO_ERROR} if
2225 successful, or an eror code on failure.
2229 @c FIXME: Unfortunately, using @acronym here breaks texi2dvi.
2231 @subsection @acronym{ASCII} Armor
2232 @cindex context, armor mode
2233 @cindex @acronym{ASCII} armor
2236 @deftypefun void gpgme_set_armor (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2237 The function @code{gpgme_set_armor} specifies if the output should be
2238 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
2241 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
2245 @deftypefun int gpgme_get_armor (@w{gpgme_ctx_t @var{ctx}})
2246 The function @code{gpgme_get_armor} returns 1 if the output is
2247 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
2248 not a valid pointer.
2253 @subsection Text Mode
2254 @cindex context, text mode
2256 @cindex canonical text mode
2258 @deftypefun void gpgme_set_textmode (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2259 The function @code{gpgme_set_textmode} specifies if canonical text mode
2260 should be used. By default, text mode is not used.
2262 Text mode is for example used for the RFC2015 signatures; note that
2263 the updated RFC 3156 mandates that the mail user agent does some
2264 preparations so that text mode is not needed anymore.
2266 This option is only relevant to the OpenPGP crypto engine, and ignored
2267 by all other engines.
2269 Canonical text mode is disabled if @var{yes} is zero, and enabled
2273 @deftypefun int gpgme_get_textmode (@w{gpgme_ctx_t @var{ctx}})
2274 The function @code{gpgme_get_textmode} returns 1 if canonical text
2275 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2280 @node Included Certificates
2281 @subsection Included Certificates
2282 @cindex certificates, included
2284 @deftypefun void gpgme_set_include_certs (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{nr_of_certs}})
2285 The function @code{gpgme_set_include_certs} specifies how many
2286 certificates should be included in an S/MIME signed message. By
2287 default, only the sender's certificate is included. The possible
2288 values of @var{nr_of_certs} are:
2291 @item GPGME_INCLUDE_CERTS_DEFAULT
2292 Fall back to the default of the crypto backend. This is the default
2295 Include all certificates except the root certificate.
2297 Include all certificates.
2299 Include no certificates.
2301 Include the sender's certificate only.
2303 Include the first n certificates of the certificates path, starting
2304 from the sender's certificate. The number @code{n} must be positive.
2307 Values of @var{nr_of_certs} smaller than -2 are undefined.
2309 This option is only relevant to the CMS crypto engine, and ignored by
2313 @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}})
2314 The function @code{gpgme_get_include_certs} returns the number of
2315 certificates to include into an S/MIME signed message.
2319 @node Key Listing Mode
2320 @subsection Key Listing Mode
2321 @cindex key listing mode
2322 @cindex key listing, mode of
2324 @deftypefun gpgme_error_t gpgme_set_keylist_mode (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_keylist_mode_t @var{mode}})
2325 The function @code{gpgme_set_keylist_mode} changes the default
2326 behaviour of the key listing functions. The value in @var{mode} is a
2327 bitwise-or combination of one or multiple of the following bit values:
2330 @item GPGME_KEYLIST_MODE_LOCAL
2331 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
2332 keyring should be searched for keys in the keylisting operation. This
2335 @item GPGME_KEYLIST_MODE_EXTERN
2336 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
2337 source should be searched for keys in the keylisting operation. The
2338 type of external source is dependant on the crypto engine used and
2339 whether it is combined with @code{GPGME_KEYLIST_MODE_LOCAL}. For
2340 example, it can be a remote keyserver or LDAP certificate server.
2342 @item GPGME_KEYLIST_MODE_SIGS
2343 The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key
2344 signatures should be included in the listed keys.
2346 @item GPGME_KEYLIST_MODE_SIG_NOTATIONS
2347 The @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} symbol specifies that the
2348 signature notations on key signatures should be included in the listed
2349 keys. This only works if @code{GPGME_KEYLIST_MODE_SIGS} is also
2352 @item GPGME_KEYLIST_MODE_EPHEMERAL
2353 The @code{GPGME_KEYLIST_MODE_EPHEMERAL} symbol specifies that keys
2354 flagged as ephemeral are included in the listing.
2356 @item GPGME_KEYLIST_MODE_VALIDATE
2357 The @code{GPGME_KEYLIST_MODE_VALIDATE} symbol specifies that the
2358 backend should do key or certificate validation and not just get the
2359 validity information from an internal cache. This might be an
2360 expensive operation and is in general not useful. Currently only
2361 implemented for the S/MIME backend and ignored for other backends.
2365 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
2366 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
2367 compatibility, you should get the current mode with
2368 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
2369 appropriate bits, and then using that calculated value in the
2370 @code{gpgme_set_keylisting_mode} operation. This will leave all other
2371 bits in the mode value intact (in particular those that are not used
2372 in the current version of the library).
2374 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2375 mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx}
2376 is not a valid pointer or @var{mode} is not a valid mode.
2380 @deftypefun gpgme_keylist_mode_t gpgme_get_keylist_mode (@w{gpgme_ctx_t @var{ctx}})
2381 The function @code{gpgme_get_keylist_mode} returns the current key
2382 listing mode of the context @var{ctx}. This value can then be
2383 modified and used in a subsequent @code{gpgme_set_keylist_mode}
2384 operation to only affect the desired bits (and leave all others
2387 The function returns 0 if @var{ctx} is not a valid pointer, and the
2388 current mode otherwise. Note that 0 is not a valid mode value.
2392 @node Passphrase Callback
2393 @subsection Passphrase Callback
2394 @cindex callback, passphrase
2395 @cindex passphrase callback
2397 @deftp {Data type} {gpgme_error_t (*gpgme_passphrase_cb_t)(void *@var{hook}, const char *@var{uid_hint}, const char *@var{passphrase_info}, @w{int @var{prev_was_bad}}, @w{int @var{fd}})}
2398 @tindex gpgme_passphrase_cb_t
2399 The @code{gpgme_passphrase_cb_t} type is the type of functions usable as
2400 passphrase callback function.
2402 The argument @var{uid_hint} might contain a string that gives an
2403 indication for which user ID the passphrase is required. If this is
2404 not available, or not applicable (in the case of symmetric encryption,
2405 for example), @var{uid_hint} will be @code{NULL}.
2407 The argument @var{passphrase_info}, if not @code{NULL}, will give
2408 further information about the context in which the passphrase is
2409 required. This information is engine and operation specific.
2411 If this is the repeated attempt to get the passphrase, because
2412 previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
2415 The user must write the passphrase, followed by a newline character,
2416 to the file descriptor @var{fd}. The function @code{gpgme_io_writen}
2417 should be used for the write operation. Note that if the user returns
2418 0 to indicate success, the user must at least write a newline
2419 character before returning from the callback.
2421 If an error occurs, return the corresponding @code{gpgme_error_t}
2422 value. You can use the error code @code{GPG_ERR_CANCELED} to abort
2423 the operation. Otherwise, return @code{0}.
2426 @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}})
2427 The function @code{gpgme_set_passphrase_cb} sets the function that is
2428 used when a passphrase needs to be provided by the user to
2429 @var{passfunc}. The function @var{passfunc} needs to implemented by
2430 the user, and whenever it is called, it is called with its first
2431 argument being @var{hook_value}. By default, no passphrase callback
2434 Not all crypto engines require this callback to retrieve the
2435 passphrase. It is better if the engine retrieves the passphrase from
2436 a trusted agent (a daemon process), rather than having each user to
2437 implement their own passphrase query. Some engines do not even
2438 support an external passphrase callback at all, in this case the error
2439 code @code{GPG_ERR_NOT_SUPPORTED} is returned.
2441 The user can disable the use of a passphrase callback function by
2442 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
2446 @deftypefun void gpgme_get_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t *@var{passfunc}}, @w{void **@var{hook_value}})
2447 The function @code{gpgme_get_passphrase_cb} returns the function that
2448 is used when a passphrase needs to be provided by the user in
2449 @var{*passfunc}, and the first argument for this function in
2450 @var{*hook_value}. If no passphrase callback is set, or @var{ctx} is
2451 not a valid pointer, @code{NULL} is returned in both variables.
2453 @var{passfunc} or @var{hook_value} can be @code{NULL}. In this case,
2454 the corresponding value will not be returned.
2458 @node Progress Meter Callback
2459 @subsection Progress Meter Callback
2460 @cindex callback, progress meter
2461 @cindex progress meter callback
2463 @deftp {Data type} {void (*gpgme_progress_cb_t)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
2464 @tindex gpgme_progress_cb_t
2465 The @code{gpgme_progress_cb_t} type is the type of functions usable as
2466 progress callback function.
2468 The arguments are specific to the crypto engine. More information
2469 about the progress information returned from the GnuPG engine can be
2470 found in the GnuPG source code in the file @file{doc/DETAILS} in the
2474 @deftypefun void gpgme_set_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t @var{progfunc}}, @w{void *@var{hook_value}})
2475 The function @code{gpgme_set_progress_cb} sets the function that is
2476 used when progress information about a cryptographic operation is
2477 available. The function @var{progfunc} needs to implemented by the
2478 user, and whenever it is called, it is called with its first argument
2479 being @var{hook_value}. By default, no progress callback function
2482 Setting a callback function allows an interactive program to display
2483 progress information about a long operation to the user.
2485 The user can disable the use of a progress callback function by
2486 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
2490 @deftypefun void gpgme_get_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t *@var{progfunc}}, @w{void **@var{hook_value}})
2491 The function @code{gpgme_get_progress_cb} returns the function that is
2492 used to inform the user about the progress made in @var{*progfunc},
2493 and the first argument for this function in @var{*hook_value}. If no
2494 progress callback is set, or @var{ctx} is not a valid pointer,
2495 @code{NULL} is returned in both variables.
2497 @var{progfunc} or @var{hook_value} can be @code{NULL}. In this case,
2498 the corresponding value will not be returned.
2504 @cindex locale, default
2505 @cindex locale, of a context
2507 A locale setting can be associated with a context. This locale is
2508 passed to the crypto engine, and used for applications like the PIN
2509 entry, which is displayed to the user when entering a passphrase is
2512 The default locale is used to initialize the locale setting of all
2513 contexts created afterwards.
2515 @deftypefun gpgme_error_t gpgme_set_locale (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{category}}, @w{const char *@var{value}})
2516 The function @code{gpgme_set_locale} sets the locale of the context
2517 @var{ctx}, or the default locale if @var{ctx} is a null pointer.
2519 The locale settings that should be changed are specified by
2520 @var{category}. Supported categories are @code{LC_CTYPE},
2521 @code{LC_MESSAGES}, and @code{LC_ALL}, which is a wildcard you can use
2522 if you want to change all the categories at once.
2524 The value to be used for the locale setting is @var{value}, which will
2525 be copied to @acronym{GPGME}'s internal data structures. @var{value}
2526 can be a null pointer, which disables setting the locale, and will
2527 make PIN entry and other applications use their default setting, which
2528 is usually not what you want.
2530 Note that the settings are only used if the application runs on a text
2531 terminal, and that the settings should fit the configuration of the
2532 output terminal. Normally, it is sufficient to initialize the default
2535 The function returns an error if not enough memory is available.
2539 @node Key Management
2540 @section Key Management
2541 @cindex key management
2543 Some of the cryptographic operations require that recipients or
2544 signers are specified. This is always done by specifying the
2545 respective keys that should be used for the operation. The following
2546 section describes how such keys can be selected and manipulated.
2548 @deftp {Data type} gpgme_subkey_t
2549 The @code{gpgme_subkey_t} type is a pointer to a subkey structure.
2550 Sub keys are one component of a @code{gpgme_key_t} object. In fact,
2551 subkeys are those parts that contains the real information about the
2552 individual cryptographic keys that belong to the same key object. One
2553 @code{gpgme_key_t} can contain several subkeys. The first subkey in
2554 the linked list is also called the primary key.
2556 The subkey structure has the following members:
2559 @item gpgme_subkey_t next
2560 This is a pointer to the next subkey structure in the linked list, or
2561 @code{NULL} if this is the last element.
2563 @item unsigned int revoked : 1
2564 This is true if the subkey is revoked.
2566 @item unsigned int expired : 1
2567 This is true if the subkey is expired.
2569 @item unsigned int disabled : 1
2570 This is true if the subkey is disabled.
2572 @item unsigned int invalid : 1
2573 This is true if the subkey is invalid.
2575 @item unsigned int can_encrypt : 1
2576 This is true if the subkey can be used for encryption.
2578 @item unsigned int can_sign : 1
2579 This is true if the subkey can be used to create data signatures.
2581 @item unsigned int can_certify : 1
2582 This is true if the subkey can be used to create key certificates.
2584 @item unsigned int can_authenticate : 1
2585 This is true if the subkey can be used for authentication.
2587 @item unsigned int is_qualified : 1
2588 This is true if the subkey can be used for qualified signatures
2589 according to local government regulations.
2591 @item unsigned int secret : 1
2592 This is true if the subkey is a secret key. Note that it will be false
2593 if the key is actually a stub key; i.e. a secret key operation is
2594 currently not possible (offline-key).
2596 @item gpgme_pubkey_algo_t pubkey_algo
2597 This is the public key algorithm supported by this subkey.
2599 @item unsigned int length
2600 This is the length of the subkey (in bits).
2603 This is the key ID of the subkey in hexadecimal digits.
2606 This is the fingerprint of the subkey in hexadecimal digits, if
2609 @item long int timestamp
2610 This is the creation timestamp of the subkey. This is -1 if the
2611 timestamp is invalid, and 0 if it is not available.
2613 @item long int expires
2614 This is the expiration timestamp of the subkey, or 0 if the subkey
2619 @deftp {Data type} gpgme_key_sig_t
2620 The @code{gpgme_key_sig_t} type is a pointer to a key signature structure.
2621 Key signatures are one component of a @code{gpgme_key_t} object, and
2622 validate user IDs on the key.
2624 The signatures on a key are only available if the key was retrieved
2625 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
2626 enabled, because it can be expensive to retrieve all signatures of a
2629 The signature notations on a key signature are only available if the
2630 key was retrieved via a listing operation with the
2631 @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} mode enabled, because it can
2632 be expensive to retrieve all signature notations.
2634 The key signature structure has the following members:
2637 @item gpgme_key_sig_t next
2638 This is a pointer to the next key signature structure in the linked
2639 list, or @code{NULL} if this is the last element.
2641 @item unsigned int revoked : 1
2642 This is true if the key signature is a revocation signature.
2644 @item unsigned int expired : 1
2645 This is true if the key signature is expired.
2647 @item unsigned int invalid : 1
2648 This is true if the key signature is invalid.
2650 @item unsigned int exportable : 1
2651 This is true if the key signature is exportable.
2653 @item gpgme_pubkey_algo_t pubkey_algo
2654 This is the public key algorithm used to create the signature.
2657 This is the key ID of the key (in hexadecimal digits) used to create
2660 @item long int timestamp
2661 This is the creation timestamp of the key signature. This is -1 if
2662 the timestamp is invalid, and 0 if it is not available.
2664 @item long int expires
2665 This is the expiration timestamp of the key signature, or 0 if the key
2666 signature does not expire.
2668 @item gpgme_error_t status
2669 This is the status of the signature and has the same meaning as the
2670 member of the same name in a @code{gpgme_signature_t} object.
2672 @item unsigned int sig_class
2673 This specifies the signature class of the key signature. The meaning
2674 is specific to the crypto engine.
2677 This is the main user ID of the key used to create the signature.
2680 This is the name component of @code{uid}, if available.
2683 This is the comment component of @code{uid}, if available.
2686 This is the email component of @code{uid}, if available.
2688 @item gpgme_sig_notation_t notations
2689 This is a linked list with the notation data and policy URLs.
2693 @deftp {Data type} gpgme_user_id_t
2694 A user ID is a component of a @code{gpgme_key_t} object. One key can
2695 have many user IDs. The first one in the list is the main (or
2698 The user ID structure has the following members.
2701 @item gpgme_user_id_t next
2702 This is a pointer to the next user ID structure in the linked list, or
2703 @code{NULL} if this is the last element.
2705 @item unsigned int revoked : 1
2706 This is true if the user ID is revoked.
2708 @item unsigned int invalid : 1
2709 This is true if the user ID is invalid.
2711 @item gpgme_validity_t validity
2712 This specifies the validity of the user ID.
2715 This is the user ID string.
2718 This is the name component of @code{uid}, if available.
2721 This is the comment component of @code{uid}, if available.
2724 This is the email component of @code{uid}, if available.
2726 @item gpgme_key_sig_t signatures
2727 This is a linked list with the signatures on this user ID.
2731 @deftp {Data type} gpgme_key_t
2732 The @code{gpgme_key_t} type is a pointer to a key object. It has the
2736 @item gpgme_keylist_mode_t keylist_mode
2737 The keylist mode that was active when the key was retrieved.
2739 @item unsigned int revoked : 1
2740 This is true if the key is revoked.
2742 @item unsigned int expired : 1
2743 This is true if the key is expired.
2745 @item unsigned int disabled : 1
2746 This is true if the key is disabled.
2748 @item unsigned int invalid : 1
2749 This is true if the key is invalid. This might have several reasons,
2750 for a example for the S/MIME backend, it will be set in during key
2751 listsing if the key could not be validated due to a missing
2752 certificates or unmatched policies.
2754 @item unsigned int can_encrypt : 1
2755 This is true if the key (ie one of its subkeys) can be used for
2758 @item unsigned int can_sign : 1
2759 This is true if the key (ie one of its subkeys) can be used to create
2762 @item unsigned int can_certify : 1
2763 This is true if the key (ie one of its subkeys) can be used to create
2766 @item unsigned int can_authenticate : 1
2767 This is true if the key (ie one of its subkeys) can be used for
2770 @item unsigned int is_qualified : 1
2771 This is true if the key can be used for qualified signatures according
2772 to local government regulations.
2774 @item unsigned int secret : 1
2775 This is true if the key is a secret key. Note, that this will always be
2776 true even if the corresponding subkey flag may be false (offline/stub
2779 @item gpgme_protocol_t protocol
2780 This is the protocol supported by this key.
2782 @item char *issuer_serial
2783 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2786 @item char *issuer_name
2787 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2790 @item char *chain_id
2791 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2792 chain ID, which can be used to built the certificate chain.
2794 @item gpgme_validity_t owner_trust
2795 If @code{protocol} is @code{GPGME_PROTOCOL_OpenPGP}, then this is the
2798 @item gpgme_subkey_t subkeys
2799 This is a linked list with the subkeys of the key. The first subkey
2800 in the list is the primary key and usually available.
2802 @item gpgme_user_id_t uids
2803 This is a linked list with the user IDs of the key. The first user ID
2804 in the list is the main (or primary) user ID.
2809 * Listing Keys:: Browsing the list of available keys.
2810 * Information About Keys:: Requesting detailed information about keys.
2811 * Key Signatures:: Listing the signatures on a key.
2812 * Manipulating Keys:: Operations on keys.
2813 * Generating Keys:: Creating new key pairs.
2814 * Exporting Keys:: Retrieving key data from the key ring.
2815 * Importing Keys:: Adding keys to the key ring.
2816 * Deleting Keys:: Removing keys from the key ring.
2817 * Changing Passphrases:: Change the passphrase of a key.
2818 * Advanced Key Editing:: Advanced key edit operation.
2823 @subsection Listing Keys
2824 @cindex listing keys
2826 @cindex key listing, start
2827 @cindex key ring, list
2828 @cindex key ring, search
2830 @deftypefun gpgme_error_t gpgme_op_keylist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
2831 The function @code{gpgme_op_keylist_start} initiates a key listing
2832 operation inside the context @var{ctx}. It sets everything up so that
2833 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
2836 If @var{pattern} is @code{NULL}, all available keys are returned.
2837 Otherwise, @var{pattern} contains an engine specific expression that
2838 is used to limit the list to all keys matching the pattern. Note that
2839 the total length of the pattern is restricted to an engine-specific
2840 maximum (a couple of hundred characters are usually accepted). The
2841 pattern should be used to restrict the search to a certain common name
2842 or user, not to list many specific keys at once by listing their
2843 fingerprints or key IDs.
2845 If @var{secret_only} is not @code{0}, the list is restricted to secret
2848 The context will be busy until either all keys are received (and
2849 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2850 @code{gpgme_op_keylist_end} is called to finish the operation.
2852 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2853 @var{ctx} is not a valid pointer, and passes through any errors that
2854 are reported by the crypto engine support routines.
2857 @deftypefun gpgme_error_t gpgme_op_keylist_ext_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{int @var{secret_only}}, @w{int @var{reserved}})
2858 The function @code{gpgme_op_keylist_ext_start} initiates an extended
2859 key listing operation inside the context @var{ctx}. It sets
2860 everything up so that subsequent invocations of
2861 @code{gpgme_op_keylist_next} return the keys in the list.
2863 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
2864 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
2865 array of strings that are used to limit the list to all keys matching
2866 at least one of the patterns verbatim. Note that the total length of
2867 all patterns is restricted to an engine-specific maximum (the exact
2868 limit also depends on the number of patterns and amount of quoting
2869 required, but a couple of hundred characters are usually accepted).
2870 Patterns should be used to restrict the search to a certain common
2871 name or user, not to list many specific keys at once by listing their
2872 fingerprints or key IDs.
2874 If @var{secret_only} is not @code{0}, the list is restricted to secret
2877 The value of @var{reserved} must be @code{0}.
2879 The context will be busy until either all keys are received (and
2880 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2881 @code{gpgme_op_keylist_end} is called to finish the operation.
2883 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2884 @var{ctx} is not a valid pointer, and passes through any errors that
2885 are reported by the crypto engine support routines.
2888 @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}})
2889 The function @code{gpgme_op_keylist_next} returns the next key in the
2890 list created by a previous @code{gpgme_op_keylist_start} operation in
2891 the context @var{ctx}. The key will have one reference for the user.
2892 @xref{Manipulating Keys}.
2894 This is the only way to get at @code{gpgme_key_t} objects in
2897 If the last key in the list has already been returned,
2898 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}.
2900 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2901 @var{ctx} or @var{r_key} is not a valid pointer, and
2902 @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation.
2905 @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}})
2906 The function @code{gpgme_op_keylist_end} ends a pending key list
2907 operation in the context @var{ctx}.
2909 After the operation completed successfully, the result of the key
2910 listing operation can be retrieved with
2911 @code{gpgme_op_keylist_result}.
2913 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2914 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
2915 time during the operation there was not enough memory available.
2918 The following example illustrates how all keys containing a certain
2919 string (@code{g10code}) can be listed with their key ID and the name
2920 and e-mail address of the main user ID:
2925 gpgme_error_t err = gpgme_new (&ctx);
2929 err = gpgme_op_keylist_start (ctx, "g10code", 0);
2932 err = gpgme_op_keylist_next (ctx, &key);
2935 printf ("%s:", key->subkeys->keyid);
2936 if (key->uids && key->uids->name)
2937 printf (" %s", key->uids->name);
2938 if (key->uids && key->uids->email)
2939 printf (" <%s>", key->uids->email);
2941 gpgme_key_release (key);
2943 gpgme_release (ctx);
2945 if (gpg_err_code (err) != GPG_ERR_EOF)
2947 fprintf (stderr, "can not list keys: %s\n", gpgme_strerror (err));
2952 @deftp {Data type} {gpgme_keylist_result_t}
2953 This is a pointer to a structure used to store the result of a
2954 @code{gpgme_op_keylist_*} operation. After successfully ending a key
2955 listing operation, you can retrieve the pointer to the result with
2956 @code{gpgme_op_keylist_result}. The structure contains the following
2960 @item unsigned int truncated : 1
2961 This is true if the crypto backend had to truncate the result, and
2962 less than the desired keys could be listed.
2966 @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}})
2967 The function @code{gpgme_op_keylist_result} returns a
2968 @code{gpgme_keylist_result_t} pointer to a structure holding the
2969 result of a @code{gpgme_op_keylist_*} operation. The pointer is only
2970 valid if the last operation on the context was a key listing
2971 operation, and if this operation finished successfully. The returned
2972 pointer is only valid until the next operation is started on the
2976 In a simple program, for which a blocking operation is acceptable, the
2977 following function can be used to retrieve a single key.
2979 @deftypefun gpgme_error_t gpgme_get_key (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{fpr}}, @w{gpgme_key_t *@var{r_key}}, @w{int @var{secret}})
2980 The function @code{gpgme_get_key} gets the key with the fingerprint
2981 (or key ID) @var{fpr} from the crypto backend and return it in
2982 @var{r_key}. If @var{secret} is true, get the secret key. The
2983 currently active keylist mode is used to retrieve the key. The key
2984 will have one reference for the user.
2986 If the key is not found in the keyring, @code{gpgme_get_key} returns
2987 the error code @code{GPG_ERR_EOF} and *@var{r_key} will be set to
2990 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2991 @var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a
2992 fingerprint or key ID, @code{GPG_ERR_AMBIGUOUS_NAME} if the key ID was
2993 not a unique specifier for a key, and @code{GPG_ERR_ENOMEM} if at some
2994 time during the operation there was not enough memory available.
2998 @node Information About Keys
2999 @subsection Information About Keys
3000 @cindex key, information about
3001 @cindex key, attributes
3002 @cindex attributes, of a key
3004 Please see the beginning of this section for more information about
3005 @code{gpgme_key_t} objects.
3007 @deftp {Data type} gpgme_validity_t
3008 The @code{gpgme_validity_t} type is used to specify the validity of a user ID
3009 in a key. The following validities are defined:
3012 @item GPGME_VALIDITY_UNKNOWN
3013 The user ID is of unknown validity. The string representation of this
3016 @item GPGME_VALIDITY_UNDEFINED
3017 The validity of the user ID is undefined. The string representation of this
3020 @item GPGME_VALIDITY_NEVER
3021 The user ID is never valid. The string representation of this
3024 @item GPGME_VALIDITY_MARGINAL
3025 The user ID is marginally valid. The string representation of this
3028 @item GPGME_VALIDITY_FULL
3029 The user ID is fully valid. The string representation of this
3032 @item GPGME_VALIDITY_ULTIMATE
3033 The user ID is ultimately valid. The string representation of this
3039 The following interfaces are deprecated and only provided for backward
3040 compatibility. Don't use them. They will be removed in a future
3041 version of @acronym{GPGME}.
3043 @deftp {Data type} gpgme_attr_t
3044 The @code{gpgme_attr_t} type is used to specify a key or trust item
3045 attribute. The following attributes are defined:
3048 @item GPGME_ATTR_KEYID
3049 This is the key ID of a sub key. It is representable as a string.
3051 For trust items, the trust item refers to the key with this ID.
3053 @item GPGME_ATTR_FPR
3054 This is the fingerprint of a sub key. It is representable as a
3057 @item GPGME_ATTR_ALGO
3058 This is the crypto algorithm for which the sub key can be used. It
3059 is representable as a string and as a number. The numbers correspond
3060 to the @code{enum gcry_pk_algos} values in the gcrypt library.
3062 @item GPGME_ATTR_LEN
3063 This is the key length of a sub key. It is representable as a
3066 @item GPGME_ATTR_CREATED
3067 This is the timestamp at creation time of a sub key. It is
3068 representable as a number.
3070 @item GPGME_ATTR_EXPIRE
3071 This is the expiration time of a sub key. It is representable as a
3074 @item GPGME_ATTR_OTRUST
3075 XXX FIXME (also for trust items)
3077 @item GPGME_ATTR_USERID
3078 This is a user ID. There can be more than one user IDs in a
3079 @var{gpgme_key_t} object. The first one (with index 0) is the primary
3080 user ID. The user ID is representable as a number.
3082 For trust items, this is the user ID associated with this trust item.
3084 @item GPGME_ATTR_NAME
3085 This is the name belonging to a user ID. It is representable as a string.
3087 @item GPGME_ATTR_EMAIL
3088 This is the email address belonging to a user ID. It is representable
3091 @item GPGME_ATTR_COMMENT
3092 This is the comment belonging to a user ID. It is representable as a
3095 @item GPGME_ATTR_VALIDITY
3096 This is the validity belonging to a user ID. It is representable as a
3097 string and as a number. See below for a list of available validities.
3099 For trust items, this is the validity that is associated with this
3102 @item GPGME_ATTR_UID_REVOKED
3103 This specifies if a user ID is revoked. It is representable as a
3104 number, and is @code{1} if the user ID is revoked, and @code{0}
3107 @item GPGME_ATTR_UID_INVALID
3108 This specifies if a user ID is invalid. It is representable as a
3109 number, and is @code{1} if the user ID is invalid, and @code{0}
3112 @item GPGME_ATTR_LEVEL
3113 This is the trust level of a trust item.
3115 @item GPGME_ATTR_TYPE
3116 This returns information about the type of key. For the string function
3117 this will eother be "PGP" or "X.509". The integer function returns 0
3118 for PGP and 1 for X.509. It is also used for the type of a trust item.
3120 @item GPGME_ATTR_IS_SECRET
3121 This specifies if the key is a secret key. It is representable as a
3122 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
3124 @item GPGME_ATTR_KEY_REVOKED
3125 This specifies if a sub key is revoked. It is representable as a
3126 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
3128 @item GPGME_ATTR_KEY_INVALID
3129 This specifies if a sub key is invalid. It is representable as a
3130 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
3132 @item GPGME_ATTR_KEY_EXPIRED
3133 This specifies if a sub key is expired. It is representable as a
3134 number, and is @code{1} if the key is expired, and @code{0} otherwise.
3136 @item GPGME_ATTR_KEY_DISABLED
3137 This specifies if a sub key is disabled. It is representable as a
3138 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
3140 @item GPGME_ATTR_KEY_CAPS
3141 This is a description of the capabilities of a sub key. It is
3142 representable as a string. The string contains the letter ``e'' if
3143 the key can be used for encryption, ``s'' if the key can be used for
3144 signatures, and ``c'' if the key can be used for certifications.
3146 @item GPGME_ATTR_CAN_ENCRYPT
3147 This specifies if a sub key can be used for encryption. It is
3148 representable as a number, and is @code{1} if the sub key can be used
3149 for encryption, and @code{0} otherwise.
3151 @item GPGME_ATTR_CAN_SIGN
3152 This specifies if a sub key can be used to create data signatures. It
3153 is representable as a number, and is @code{1} if the sub key can be
3154 used for signatures, and @code{0} otherwise.
3156 @item GPGME_ATTR_CAN_CERTIFY
3157 This specifies if a sub key can be used to create key certificates.
3158 It is representable as a number, and is @code{1} if the sub key can be
3159 used for certifications, and @code{0} otherwise.
3161 @item GPGME_ATTR_SERIAL
3162 The X.509 issuer serial attribute of the key. It is representable as
3165 @item GPGME_ATTR_ISSUE
3166 The X.509 issuer name attribute of the key. It is representable as a
3169 @item GPGME_ATTR_CHAINID
3170 The X.509 chain ID can be used to build the certification chain. It
3171 is representable as a string.
3175 @deftypefun {const char *} gpgme_key_get_string_attr (@w{gpgme_key_t @var{key}}, @w{gpgme_attr_t @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
3176 The function @code{gpgme_key_get_string_attr} returns the value of the
3177 string-representable attribute @var{what} of key @var{key}. If the
3178 attribute is an attribute of a sub key or an user ID, @var{idx}
3179 specifies the sub key or user ID of which the attribute value is
3180 returned. The argument @var{reserved} is reserved for later use and
3181 should be @code{NULL}.
3183 The string returned is only valid as long as the key is valid.
3185 The function returns @code{0} if an attribute can't be returned as a
3186 string, @var{key} is not a valid pointer, @var{idx} out of range,
3187 or @var{reserved} not @code{NULL}.
3190 @deftypefun {unsigned long} gpgme_key_get_ulong_attr (@w{gpgme_key_t @var{key}}, @w{gpgme_attr_t @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
3191 The function @code{gpgme_key_get_ulong_attr} returns the value of the
3192 number-representable attribute @var{what} of key @var{key}. If the
3193 attribute is an attribute of a sub key or an user ID, @var{idx}
3194 specifies the sub key or user ID of which the attribute value is
3195 returned. The argument @var{reserved} is reserved for later use and
3196 should be @code{NULL}.
3198 The function returns @code{0} if the attribute can't be returned as a
3199 number, @var{key} is not a valid pointer, @var{idx} out of range, or
3200 @var{reserved} not @code{NULL}.
3204 @node Key Signatures
3205 @subsection Key Signatures
3206 @cindex key, signatures
3207 @cindex signatures, on a key
3209 The following interfaces are deprecated and only provided for backward
3210 compatibility. Don't use them. They will be removed in a future
3211 version of @acronym{GPGME}.
3213 The signatures on a key are only available if the key was retrieved
3214 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
3215 enabled, because it is expensive to retrieve all signatures of a key.
3217 So, before using the below interfaces to retrieve the signatures on a
3218 key, you have to make sure that the key was listed with signatures
3219 enabled. One convenient, but blocking, way to do this is to use the
3220 function @code{gpgme_get_key}.
3222 @deftp {Data type} gpgme_attr_t
3223 The @code{gpgme_attr_t} type is used to specify a key signature
3224 attribute. The following attributes are defined:
3227 @item GPGME_ATTR_KEYID
3228 This is the key ID of the key which was used for the signature. It is
3229 representable as a string.
3231 @item GPGME_ATTR_ALGO
3232 This is the crypto algorithm used to create the signature. It is
3233 representable as a string and as a number. The numbers correspond to
3234 the @code{enum gcry_pk_algos} values in the gcrypt library.
3236 @item GPGME_ATTR_CREATED
3237 This is the timestamp at creation time of the signature. It is
3238 representable as a number.
3240 @item GPGME_ATTR_EXPIRE
3241 This is the expiration time of the signature. It is representable as
3244 @item GPGME_ATTR_USERID
3245 This is the user ID associated with the signing key. The user ID is
3246 representable as a number.
3248 @item GPGME_ATTR_NAME
3249 This is the name belonging to a user ID. It is representable as a string.
3251 @item GPGME_ATTR_EMAIL
3252 This is the email address belonging to a user ID. It is representable
3255 @item GPGME_ATTR_COMMENT
3256 This is the comment belonging to a user ID. It is representable as a
3259 @item GPGME_ATTR_KEY_REVOKED
3260 This specifies if a key signature is a revocation signature. It is
3261 representable as a number, and is @code{1} if the key is revoked, and
3264 @c @item GPGME_ATTR_KEY_EXPIRED
3265 @c This specifies if a key signature is expired. It is representable as
3266 @c a number, and is @code{1} if the key is revoked, and @code{0}
3269 @item GPGME_ATTR_SIG_CLASS
3270 This specifies the signature class of a key signature. It is
3271 representable as a number. The meaning is specific to the crypto
3274 @item GPGME_ATTR_SIG_CLASS
3275 This specifies the signature class of a key signature. It is
3276 representable as a number. The meaning is specific to the crypto
3279 @item GPGME_ATTR_SIG_STATUS
3280 This is the same value as returned by @code{gpgme_get_sig_status}.
3284 @deftypefun {const char *} gpgme_key_sig_get_string_attr (@w{gpgme_key_t @var{key}}, @w{int @var{uid_idx}}, @w{gpgme_attr_t @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
3285 The function @code{gpgme_key_sig_get_string_attr} returns the value of
3286 the string-representable attribute @var{what} of the signature
3287 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3288 argument @var{reserved} is reserved for later use and should be
3291 The string returned is only valid as long as the key is valid.
3293 The function returns @code{0} if an attribute can't be returned as a
3294 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3295 out of range, or @var{reserved} not @code{NULL}.
3298 @deftypefun {unsigned long} gpgme_key_sig_get_ulong_attr (@w{gpgme_key_t @var{key}}, @w{int @var{uid_idx}}, @w{gpgme_attr_t @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
3299 The function @code{gpgme_key_sig_get_ulong_attr} returns the value of
3300 the number-representable attribute @var{what} of the signature
3301 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3302 argument @var{reserved} is reserved for later use and should be
3305 The function returns @code{0} if an attribute can't be returned as a
3306 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3307 out of range, or @var{reserved} not @code{NULL}.
3311 @node Manipulating Keys
3312 @subsection Manipulating Keys
3313 @cindex key, manipulation
3315 @deftypefun void gpgme_key_ref (@w{gpgme_key_t @var{key}})
3316 The function @code{gpgme_key_ref} acquires an additional reference for
3320 @deftypefun void gpgme_key_unref (@w{gpgme_key_t @var{key}})
3321 The function @code{gpgme_key_unref} releases a reference for the key
3322 @var{key}. If this was the last reference, the key will be destroyed
3323 and all resources associated to it will be released.
3327 The following interface is deprecated and only provided for backward
3328 compatibility. Don't use it. It will be removed in a future version
3331 @deftypefun void gpgme_key_release (@w{gpgme_key_t @var{key}})
3332 The function @code{gpgme_key_release} is equivalent to
3333 @code{gpgme_key_unref}.
3337 @node Generating Keys
3338 @subsection Generating Keys
3339 @cindex key, creation
3340 @cindex key ring, add
3342 @deftypefun gpgme_error_t gpgme_op_genkey (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{parms}}, @w{gpgme_data_t @var{public}}, @w{gpgme_data_t @var{secret}})
3343 The function @code{gpgme_op_genkey} generates a new key pair in the
3344 context @var{ctx}. The meaning of @var{public} and @var{secret}
3345 depends on the crypto backend.
3347 GnuPG does not support @var{public} and @var{secret}, they should be
3348 @code{NULL}. GnuPG will generate a key pair and add it to the
3349 standard key ring. The fingerprint of the generated key is available
3350 with @code{gpgme_op_genkey_result}.
3352 GpgSM requires @var{public} to be a writable data object. GpgSM will
3353 generate a secret key (which will be stored by @command{gpg-agent},
3354 and return a certificate request in @var{public}, which then needs to
3355 be signed by the certification authority and imported before it can be
3356 used. GpgSM does not make the fingerprint available.
3358 The argument @var{parms} specifies parameters for the key in an XML
3359 string. The details about the format of @var{parms} are specific to
3360 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
3361 the crypto engine (all parameters of OpenPGP key generation are
3362 documented in the GPG manual):
3365 <GnupgKeyParms format="internal">
3367 Subkey-Type: default
3368 Name-Real: Joe Tester
3369 Name-Comment: with stupid passphrase
3370 Name-Email: joe@@foo.bar
3376 Here is an example for GpgSM as the crypto engine (all parameters of
3377 OpenPGP key generation are documented in the GPGSM manual):
3380 <GnupgKeyParms format="internal">
3383 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3384 Name-Email: joe@@foo.bar
3388 Strings should be given in UTF-8 encoding. The only format supported
3389 for now is ``internal''. The content of the @code{GnupgKeyParms}
3390 container is passed verbatim to the crypto backend. Control
3391 statements are not allowed.
3393 After the operation completed successfully, the result can be
3394 retrieved with @code{gpgme_op_genkey_result}.
3396 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3397 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3398 @var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if
3399 @var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL}
3400 if no key was created by the backend.
3403 @deftypefun gpgme_error_t gpgme_op_genkey_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{parms}}, @w{gpgme_data_t @var{public}}, @w{gpgme_data_t @var{secret}})
3404 The function @code{gpgme_op_genkey_start} initiates a
3405 @code{gpgme_op_genkey} operation. It can be completed by calling
3406 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3408 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3409 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3410 @var{parms} is not a valid XML string, and
3411 @code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not
3415 @deftp {Data type} {gpgme_genkey_result_t}
3416 This is a pointer to a structure used to store the result of a
3417 @code{gpgme_op_genkey} operation. After successfully generating a
3418 key, you can retrieve the pointer to the result with
3419 @code{gpgme_op_genkey_result}. The structure contains the following
3423 @item unsigned int primary : 1
3424 This is a flag that is set to 1 if a primary key was created and to 0
3427 @item unsigned int sub : 1
3428 This is a flag that is set to 1 if a subkey was created and to 0
3432 This is the fingerprint of the key that was created. If both a
3433 primary and a sub key were generated, the fingerprint of the primary
3434 key will be returned. If the crypto engine does not provide the
3435 fingerprint, @code{fpr} will be a null pointer.
3439 @deftypefun gpgme_genkey_result_t gpgme_op_genkey_result (@w{gpgme_ctx_t @var{ctx}})
3440 The function @code{gpgme_op_genkey_result} returns a
3441 @code{gpgme_genkey_result_t} pointer to a structure holding the result of
3442 a @code{gpgme_op_genkey} operation. The pointer is only valid if the
3443 last operation on the context was a @code{gpgme_op_genkey} or
3444 @code{gpgme_op_genkey_start} operation, and if this operation finished
3445 successfully. The returned pointer is only valid until the next
3446 operation is started on the context.
3450 @node Exporting Keys
3451 @subsection Exporting Keys
3453 @cindex key ring, export from
3455 Exporting keys means the same as running @command{gpg} with the command
3456 @option{--export}. However, a mode flag can be used to change the way
3457 the export works. The available mode flags are described below, they
3458 may be or-ed together.
3462 @item GPGME_EXPORT_MODE_EXTERN
3463 If this bit is set, the output is send directly to the default
3464 keyserver. This is currently only allowed for OpenPGP keys. It is good
3465 practise to not send more than a few dozens key to a keyserver at one
3466 time. Using this flag requires that the @var{keydata} argument of the
3467 export function is set to @code{NULL}.
3469 @item GPGME_EXPORT_MODE_MINIMAL
3470 If this bit is set, the smallest possible key is exported. For OpenPGP
3471 keys it removes all signatures except for the latest self-signatures.
3472 For X.509 keys it has no effect.
3479 @deftypefun gpgme_error_t gpgme_op_export (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3480 The function @code{gpgme_op_export} extracts public keys and returns
3481 them in the data buffer @var{keydata}. The output format of the key
3482 data returned is determined by the @acronym{ASCII} armor attribute set
3483 for the context @var{ctx}, or, if that is not set, by the encoding
3484 specified for @var{keydata}.
3486 If @var{pattern} is @code{NULL}, all available keys are returned.
3487 Otherwise, @var{pattern} contains an engine specific expression that
3488 is used to limit the list to all keys matching the pattern.
3490 @var{mode} is usually 0; other values are described above.
3492 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3493 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3494 @var{keydata} is not a valid empty data buffer, and passes through any
3495 errors that are reported by the crypto engine support routines.
3498 @deftypefun gpgme_error_t gpgme_op_export_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3499 The function @code{gpgme_op_export_start} initiates a
3500 @code{gpgme_op_export} operation. It can be completed by calling
3501 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3503 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3504 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3505 if @var{keydata} is not a valid empty data buffer.
3508 @deftypefun gpgme_error_t gpgme_op_export_ext (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3509 The function @code{gpgme_op_export} extracts public keys and returns
3510 them in the data buffer @var{keydata}. The output format of the key
3511 data returned is determined by the @acronym{ASCII} armor attribute set
3512 for the context @var{ctx}, or, if that is not set, by the encoding
3513 specified for @var{keydata}.
3515 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3516 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3517 array of strings that are used to limit the list to all keys matching
3518 at least one of the patterns verbatim.
3520 @var{mode} is usually 0; other values are described above.
3522 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3523 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3524 @var{keydata} is not a valid empty data buffer, and passes through any
3525 errors that are reported by the crypto engine support routines.
3528 @deftypefun gpgme_error_t gpgme_op_export_ext_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3529 The function @code{gpgme_op_export_ext_start} initiates a
3530 @code{gpgme_op_export_ext} operation. It can be completed by calling
3531 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3533 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3534 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3535 if @var{keydata} is not a valid empty data buffer.
3539 @deftypefun gpgme_error_t gpgme_op_export_keys (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t keys[]}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3540 The function @code{gpgme_op_export_keys} extracts public keys and returns
3541 them in the data buffer @var{keydata}. The output format of the key
3542 data returned is determined by the @acronym{ASCII} armor attribute set
3543 for the context @var{ctx}, or, if that is not set, by the encoding
3544 specified for @var{keydata}.
3546 The keys to export are taken form the @code{NULL} terminated array
3547 @var{keys}. Only keys of the the currently selected protocol of
3548 @var{ctx} which do have a fingerprint set are considered for export.
3549 Other keys specified by the @var{keys} are ignored. In particular
3550 OpenPGP keys retrieved via an external key listing are not included.
3552 @var{mode} is usually 0; other values are described above.
3554 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3555 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3556 @var{keydata} is not a valid empty data buffer, @code{GPG_ERR_NO_DATA}
3557 if no useful keys are in @var{keys} and passes through any errors that
3558 are reported by the crypto engine support routines.
3561 @deftypefun gpgme_error_t gpgme_op_export_keys_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{keys}[]}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3562 The function @code{gpgme_op_export_keys_start} initiates a
3563 @code{gpgme_op_export_ext} operation. It can be completed by calling
3564 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3566 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3567 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3568 if @var{keydata} is not a valid empty data buffer, @code{GPG_ERR_NO_DATA}
3569 if no useful keys are in @var{keys} and passes through any errors that
3570 are reported by the crypto engine support routines.
3574 @node Importing Keys
3575 @subsection Importing Keys
3577 @cindex key ring, import to
3579 Importing keys means the same as running @command{gpg} with the command
3583 @deftypefun gpgme_error_t gpgme_op_import (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3584 The function @code{gpgme_op_import} adds the keys in the data buffer
3585 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
3586 The format of @var{keydata} can be @acronym{ASCII} armored, for example,
3587 but the details are specific to the crypto engine.
3589 After the operation completed successfully, the result can be
3590 retrieved with @code{gpgme_op_import_result}.
3592 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3593 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3594 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3595 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3598 @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3599 The function @code{gpgme_op_import_start} initiates a
3600 @code{gpgme_op_import} operation. It can be completed by calling
3601 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3603 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3604 import could be started successfully, @code{GPG_ERR_INV_VALUE} if
3605 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3606 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3609 @deftypefun gpgme_error_t gpgme_op_import_keys (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{keys}})
3610 The function @code{gpgme_op_import_keys} adds the keys described by the
3611 @code{NULL} terminated array @var{keys} to the key ring of the crypto
3612 engine used by @var{ctx}. This function is the general interface to
3613 move a key from one crypto engine to another as long as they are
3614 compatible. In particular it is used to actually import and make keys
3615 permanent which have been retrieved from an external source (i.e. using
3616 @code{GPGME_KEYLIST_MODE_EXTERN}). @footnote{Thus it is a replacement
3617 for the usual workaround of exporting and then importing a key to make
3618 an X.509 key permanent.}
3620 Only keys of the the currently selected protocol of @var{ctx} are
3621 considered for import. Other keys specified by the @var{keys} are
3622 ignored. As of now all considered keys must have been retrieved using
3623 the same method, that is the used key listing mode must be identical.
3625 After the operation completed successfully, the result can be
3626 retrieved with @code{gpgme_op_import_result}.
3628 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3629 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3630 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3631 @code{GPG_ERR_CONFLICT} if the key listing mode does not match, and
3632 @code{GPG_ERR_NO_DATA} if no keys are considered for export.
3635 @deftypefun gpgme_error_t gpgme_op_import_keys_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{keys}})
3636 The function @code{gpgme_op_import_keys_start} initiates a
3637 @code{gpgme_op_import_keys} operation. It can be completed by calling
3638 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3640 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3641 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3642 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3643 @code{GPG_ERR_CONFLICT} if the key listing mode does not match, and
3644 @code{GPG_ERR_NO_DATA} if no keys are considered for export.
3647 @deftp {Data type} {gpgme_import_status_t}
3648 This is a pointer to a structure used to store a part of the result of
3649 a @code{gpgme_op_import} operation. For each considered key one
3650 status is added that contains information about the result of the
3651 import. The structure contains the following members:
3654 @item gpgme_import_status_t next
3655 This is a pointer to the next status structure in the linked list, or
3656 @code{NULL} if this is the last element.
3659 This is the fingerprint of the key that was considered.
3661 @item gpgme_error_t result
3662 If the import was not successful, this is the error value that caused
3663 the import to fail. Otherwise the error code is
3664 @code{GPG_ERR_NO_ERROR}.
3666 @item unsigned int status
3667 This is a bit-wise OR of the following flags that give more
3668 information about what part of the key was imported. If the key was
3669 already known, this might be 0.
3672 @item GPGME_IMPORT_NEW
3675 @item GPGME_IMPORT_UID
3676 The key contained new user IDs.
3678 @item GPGME_IMPORT_SIG
3679 The key contained new signatures.
3681 @item GPGME_IMPORT_SUBKEY
3682 The key contained new sub keys.
3684 @item GPGME_IMPORT_SECRET
3685 The key contained a secret key.
3690 @deftp {Data type} {gpgme_import_result_t}
3691 This is a pointer to a structure used to store the result of a
3692 @code{gpgme_op_import} operation. After a successful import
3693 operation, you can retrieve the pointer to the result with
3694 @code{gpgme_op_import_result}. The structure contains the following
3698 @item int considered
3699 The total number of considered keys.
3701 @item int no_user_id
3702 The number of keys without user ID.
3705 The total number of imported keys.
3708 The number of imported RSA keys.
3711 The number of unchanged keys.
3714 The number of new user IDs.
3717 The number of new sub keys.
3719 @item new_signatures
3720 The number of new signatures.
3722 @item new_revocations
3723 The number of new revocations.
3726 The total number of secret keys read.
3728 @item secret_imported
3729 The number of imported secret keys.
3731 @item secret_unchanged
3732 The number of unchanged secret keys.
3735 The number of keys not imported.
3737 @item gpgme_import_status_t imports
3738 A list of gpgme_import_status_t objects which contain more information
3739 about the keys for which an import was attempted.
3743 @deftypefun gpgme_import_result_t gpgme_op_import_result (@w{gpgme_ctx_t @var{ctx}})
3744 The function @code{gpgme_op_import_result} returns a
3745 @code{gpgme_import_result_t} pointer to a structure holding the result
3746 of a @code{gpgme_op_import} operation. The pointer is only valid if
3747 the last operation on the context was a @code{gpgme_op_import} or
3748 @code{gpgme_op_import_start} operation, and if this operation finished
3749 successfully. The returned pointer is only valid until the next
3750 operation is started on the context.
3753 The following interface is deprecated and only provided for backward
3754 compatibility. Don't use it. It will be removed in a future version
3757 @deftypefun gpgme_error_t gpgme_op_import_ext (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}}, @w{int *@var{nr}})
3758 The function @code{gpgme_op_import_ext} is equivalent to:
3761 gpgme_error_t err = gpgme_op_import (ctx, keydata);
3764 gpgme_import_result_t result = gpgme_op_import_result (ctx);
3765 *nr = result->considered;
3772 @subsection Deleting Keys
3774 @cindex key ring, delete from
3776 @deftypefun gpgme_error_t gpgme_op_delete (@w{gpgme_ctx_t @var{ctx}}, @w{const gpgme_key_t @var{key}}, @w{int @var{allow_secret}})
3777 The function @code{gpgme_op_delete} deletes the key @var{key} from the
3778 key ring of the crypto engine used by @var{ctx}. If
3779 @var{allow_secret} is @code{0}, only public keys are deleted,
3780 otherwise secret keys are deleted as well, if that is supported.
3782 The function returns the error code @code{GPG_ERR_NO_ERROR} if the key
3783 was deleted successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3784 @var{key} is not a valid pointer, @code{GPG_ERR_NO_PUBKEY} if
3785 @var{key} could not be found in the keyring,
3786 @code{GPG_ERR_AMBIGUOUS_NAME} if the key was not specified
3787 unambiguously, and @code{GPG_ERR_CONFLICT} if the secret key for
3788 @var{key} is available, but @var{allow_secret} is zero.
3791 @deftypefun gpgme_error_t gpgme_op_delete_start (@w{gpgme_ctx_t @var{ctx}}, @w{const gpgme_key_t @var{key}}, @w{int @var{allow_secret}})
3792 The function @code{gpgme_op_delete_start} initiates a
3793 @code{gpgme_op_delete} operation. It can be completed by calling
3794 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3796 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3797 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3798 @var{ctx} or @var{key} is not a valid pointer.
3802 @node Changing Passphrases
3803 @subsection Changing Passphrases
3804 @cindex passphrase, change
3806 @deftypefun gpgme_error_t gpgme_op_passwd @
3807 (@w{gpgme_ctx_t @var{ctx}}, @
3808 @w{const gpgme_key_t @var{key}}, @
3809 @w{unsigned int @var{flags}})
3811 The function @code{gpgme_op_passwd} changes the passphrase of the
3812 private key associated with @var{key}. The only allowed value for
3813 @var{flags} is @code{0}. The backend engine will usually popup a window
3814 to ask for the old and the new passphrase. Thus this function is not
3815 useful in a server application (where passphrases are not required
3818 Note that old @code{gpg} engines (before version 2.0.15) do not support
3819 this command and will silently ignore it.
3822 @deftypefun gpgme_error_t gpgme_op_passwd_start @
3823 (@w{gpgme_ctx_t @var{ctx}}, @
3824 @w{const gpgme_key_t @var{key}}, @
3825 @w{unsigned int @var{flags}})
3827 The function @code{gpgme_op_passwd_start} initiates a
3828 @code{gpgme_op_passwd} operation. It can be completed by calling
3829 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3831 The function returns @code{0} if the operation was started successfully,
3832 and an error code if one of the arguments is not valid or the oepration
3833 could not be started.
3837 @node Advanced Key Editing
3838 @subsection Advanced Key Editing
3841 @deftp {Data type} {gpgme_error_t (*gpgme_edit_cb_t) (@w{void *@var{handle}}, @w{gpgme_status_code_t @var{status}}, @w{const char *@var{args}}, @w{int @var{fd}})}
3842 @tindex gpgme_edit_cb_t
3843 The @code{gpgme_edit_cb_t} type is the type of functions which
3844 @acronym{GPGME} calls if it a key edit operation is on-going. The
3845 status code @var{status} and the argument line @var{args} are passed
3846 through by @acronym{GPGME} from the crypto engine. The file
3847 descriptor @var{fd} is -1 for normal status messages. If @var{status}
3848 indicates a command rather than a status message, the response to the
3849 command should be written to @var{fd}. The @var{handle} is provided
3850 by the user at start of operation.
3852 The function should return @code{GPG_ERR_NO_ERROR} or an error value.
3855 @deftypefun gpgme_error_t gpgme_op_edit (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3856 The function @code{gpgme_op_edit} processes the key @var{KEY}
3857 interactively, using the edit callback function @var{FNC} with the
3858 handle @var{HANDLE}. The callback is invoked for every status and
3859 command request from the crypto engine. The output of the crypto
3860 engine is written to the data object @var{out}.
3862 Note that the protocol between the callback function and the crypto
3863 engine is specific to the crypto engine and no further support in
3864 implementing this protocol correctly is provided by @acronym{GPGME}.
3866 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3867 edit operation completes successfully, @code{GPG_ERR_INV_VALUE} if
3868 @var{ctx} or @var{key} is not a valid pointer, and any error returned
3869 by the crypto engine or the edit callback handler.
3872 @deftypefun gpgme_error_t gpgme_op_edit_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3873 The function @code{gpgme_op_edit_start} initiates a
3874 @code{gpgme_op_edit} operation. It can be completed by calling
3875 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3877 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3878 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3879 @var{ctx} or @var{key} is not a valid pointer.
3883 @deftypefun gpgme_error_t gpgme_op_card_edit (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3884 The function @code{gpgme_op_card_edit} is analogous to
3885 @code{gpgme_op_edit}, but should be used to process the smart card corresponding to the key @var{key}.
3888 @deftypefun gpgme_error_t gpgme_op_card_edit_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3889 The function @code{gpgme_op_card_edit_start} initiates a
3890 @code{gpgme_op_card_edit} operation. It can be completed by calling
3891 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3893 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3894 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3895 @var{ctx} or @var{key} is not a valid pointer.
3899 @node Trust Item Management
3900 @section Trust Item Management
3903 @strong{Caution:} The trust items interface is experimental.
3905 @deftp {Data type} gpgme_trust_item_t
3906 The @code{gpgme_trust_item_t} type is a pointer to a trust item object.
3907 It has the following members:
3911 This is a string describing the key to which this trust items belongs.
3914 This is the type of the trust item. A value of 1 refers to a key, a
3915 value of 2 refers to a user ID.
3918 This is the trust level.
3920 @item char *owner_trust
3921 The owner trust if @code{type} is 1.
3923 @item char *validity
3924 The calculated validity.
3927 The user name if @code{type} is 2.
3932 * Listing Trust Items:: Browsing the list of available trust items.
3933 * Information About Trust Items:: Requesting information about trust items.
3934 * Manipulating Trust Items:: Operations on trust items.
3938 @node Listing Trust Items
3939 @subsection Listing Trust Items
3940 @cindex trust item list
3942 @deftypefun gpgme_error_t gpgme_op_trustlist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}})
3943 The function @code{gpgme_op_trustlist_start} initiates a trust item
3944 listing operation inside the context @var{ctx}. It sets everything up
3945 so that subsequent invocations of @code{gpgme_op_trustlist_next} return
3946 the trust items in the list.
3948 The string @var{pattern} contains an engine specific expression that
3949 is used to limit the list to all trust items matching the pattern. It
3950 can not be the empty string.
3952 The argument @var{max_level} is currently ignored.
3954 The context will be busy until either all trust items are received
3955 (and @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}), or
3956 @code{gpgme_op_trustlist_end} is called to finish the operation.
3958 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3959 @var{ctx} is not a valid pointer, and passes through any errors that
3960 are reported by the crypto engine support routines.
3963 @deftypefun gpgme_error_t gpgme_op_trustlist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_trust_item_t *@var{r_item}})
3964 The function @code{gpgme_op_trustlist_next} returns the next trust
3965 item in the list created by a previous @code{gpgme_op_trustlist_start}
3966 operation in the context @var{ctx}. The trust item can be destroyed
3967 with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}.
3969 This is the only way to get at @code{gpgme_trust_item_t} objects in
3972 If the last trust item in the list has already been returned,
3973 @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}.
3975 The function returns the error code @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3976 @var{r_item} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if
3977 there is not enough memory for the operation.
3980 @deftypefun gpgme_error_t gpgme_op_trustlist_end (@w{gpgme_ctx_t @var{ctx}})
3981 The function @code{gpgme_op_trustlist_end} ends a pending trust list
3982 operation in the context @var{ctx}.
3984 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3985 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
3986 time during the operation there was not enough memory available.
3990 @node Information About Trust Items
3991 @subsection Information About Trust Items
3992 @cindex trust item, information about
3993 @cindex trust item, attributes
3994 @cindex attributes, of a trust item
3996 The following interfaces are deprecated and only provided for backward
3997 compatibility. Don't use them. They will be removed in a future
3998 version of @acronym{GPGME}.
4000 Trust items have attributes which can be queried using the interfaces
4001 below. The attribute identifiers are shared with those for key
4002 attributes. @xref{Information About Keys}.
4004 @deftypefun {const char *} gpgme_trust_item_get_string_attr (@w{gpgme_trust_item_t @var{item}}, @w{gpgme_attr_t @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
4005 The function @code{gpgme_trust_item_get_string_attr} returns the value
4006 of the string-representable attribute @var{what} of trust item
4007 @var{item}. The arguments @var{idx} and @var{reserved} are reserved
4008 for later use and should be @code{0} and @code{NULL} respectively.
4010 The string returned is only valid as long as the key is valid.
4012 The function returns @code{0} if an attribute can't be returned as a
4013 string, @var{key} is not a valid pointer, @var{idx} out of range,
4014 or @var{reserved} not @code{NULL}.
4017 @deftypefun int gpgme_trust_item_get_int_attr (@w{gpgme_trust_item_t @var{item}}, @w{gpgme_attr_t @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
4018 The function @code{gpgme_trust_item_get_int_attr} returns the value of
4019 the number-representable attribute @var{what} of trust item
4020 @var{item}. If the attribute occurs more than once in the trust item,
4021 the index is specified by @var{idx}. However, currently no such
4022 attribute exists, so @var{idx} should be @code{0}. The argument
4023 @var{reserved} is reserved for later use and should be @code{NULL}.
4025 The function returns @code{0} if the attribute can't be returned as a
4026 number, @var{key} is not a valid pointer, @var{idx} out of range,
4027 or @var{reserved} not @code{NULL}.
4031 @node Manipulating Trust Items
4032 @subsection Manipulating Trust Items
4033 @cindex trust item, manipulation
4035 @deftypefun void gpgme_trust_item_ref (@w{gpgme_trust_item_t @var{item}})
4036 The function @code{gpgme_trust_item_ref} acquires an additional
4037 reference for the trust item @var{item}.
4040 @deftypefun void gpgme_trust_item_unref (@w{gpgme_trust_item_t @var{item}})
4041 The function @code{gpgme_trust_item_unref} releases a reference for
4042 the trust item @var{item}. If this was the last reference, the trust
4043 item will be destroyed and all resources associated to it will be
4048 The following interface is deprecated and only provided for backward
4049 compatibility. Don't use it. It will be removed in a future version
4052 @deftypefun void gpgme_trust_item_release (@w{gpgme_trust_item_t @var{item}})
4053 The function @code{gpgme_trust_item_release} is an alias for
4054 @code{gpgme_trust_item_unref}.
4058 @node Crypto Operations
4059 @section Crypto Operations
4060 @cindex cryptographic operation
4062 Sometimes, the result of a crypto operation returns a list of invalid
4063 keys encountered in processing the request. The following structure
4064 is used to hold information about such a key.
4066 @deftp {Data type} {gpgme_invalid_key_t}
4067 This is a pointer to a structure used to store a part of the result of
4068 a crypto operation which takes user IDs as one input parameter. The
4069 structure contains the following members:
4072 @item gpgme_invalid_key_t next
4073 This is a pointer to the next invalid key structure in the linked
4074 list, or @code{NULL} if this is the last element.
4077 The fingerprint or key ID of the invalid key encountered.
4079 @item gpgme_error_t reason
4080 An error code describing the reason why the key was found invalid.
4086 * Decrypt:: Decrypting a ciphertext.
4087 * Verify:: Verifying a signature.
4088 * Decrypt and Verify:: Decrypting a signed ciphertext.
4089 * Sign:: Creating a signature.
4090 * Encrypt:: Encrypting a plaintext.
4097 @cindex cryptographic operation, decryption
4099 @deftypefun gpgme_error_t gpgme_op_decrypt (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{cipher}}, @w{gpgme_data_t @var{plain}})
4100 The function @code{gpgme_op_decrypt} decrypts the ciphertext in the
4101 data object @var{cipher} and stores it into the data object
4104 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4105 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
4106 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
4107 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
4108 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
4109 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
4110 secret key could not be retrieved, and passes through any errors that
4111 are reported by the crypto engine support routines.
4114 @deftypefun gpgme_error_t gpgme_op_decrypt_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{cipher}}, @w{gpgme_data_t @var{plain}})
4115 The function @code{gpgme_op_decrypt_start} initiates a
4116 @code{gpgme_op_decrypt} operation. It can be completed by calling
4117 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4119 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4120 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
4121 if @var{cipher} or @var{plain} is not a valid pointer.
4124 @deftp {Data type} {gpgme_recipient_t}
4125 This is a pointer to a structure used to store information about the
4126 recipient of an encrypted text which is decrypted in a
4127 @code{gpgme_op_decrypt} operation. This information (except for the
4128 status field) is even available before the operation finished
4129 successfully, for example in a passphrase callback. The structure
4130 contains the following members:
4133 @item gpgme_recipient_t next
4134 This is a pointer to the next recipient structure in the linked list,
4135 or @code{NULL} if this is the last element.
4137 @item gpgme_pubkey_algo_t
4138 The public key algorithm used in the encryption.
4140 @item unsigned int wrong_key_usage : 1
4141 This is true if the key was not used according to its policy.
4144 This is the key ID of the key (in hexadecimal digits) used as
4147 @item gpgme_error_t status
4148 This is an error number with the error code GPG_ERR_NO_SECKEY if the
4149 secret key for this recipient is not available, and 0 otherwise.
4153 @deftp {Data type} {gpgme_decrypt_result_t}
4154 This is a pointer to a structure used to store the result of a
4155 @code{gpgme_op_decrypt} operation. After successfully decrypting
4156 data, you can retrieve the pointer to the result with
4157 @code{gpgme_op_decrypt_result}. The structure contains the following
4161 @item char *unsupported_algorithm
4162 If an unsupported algorithm was encountered, this string describes the
4163 algorithm that is not supported.
4165 @item unsigned int wrong_key_usage : 1
4166 This is true if the key was not used according to its policy.
4168 @item gpgme_recipient_t recipients
4169 This is a linked list of recipients to which this message was encrypted.
4171 @item char *file_name
4172 This is the filename of the original plaintext message file if it is
4173 known, otherwise this is a null pointer.
4177 @deftypefun gpgme_decrypt_result_t gpgme_op_decrypt_result (@w{gpgme_ctx_t @var{ctx}})
4178 The function @code{gpgme_op_decrypt_result} returns a
4179 @code{gpgme_decrypt_result_t} pointer to a structure holding the
4180 result of a @code{gpgme_op_decrypt} operation. The pointer is only
4181 valid if the last operation on the context was a
4182 @code{gpgme_op_decrypt} or @code{gpgme_op_decrypt_start} operation.
4183 If the operation failed this might be a @code{NULL} pointer. The
4184 returned pointer is only valid until the next operation is started on
4191 @cindex verification
4192 @cindex signature, verification
4193 @cindex cryptographic operation, verification
4194 @cindex cryptographic operation, signature check
4195 @cindex signature notation data
4196 @cindex notation data
4198 @deftypefun gpgme_error_t gpgme_op_verify (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{sig}}, @w{gpgme_data_t @var{signed_text}}, @w{gpgme_data_t @var{plain}})
4199 The function @code{gpgme_op_verify} verifies that the signature in the
4200 data object @var{sig} is a valid signature. If @var{sig} is a
4201 detached signature, then the signed text should be provided in
4202 @var{signed_text} and @var{plain} should be a null pointer.
4203 Otherwise, if @var{sig} is a normal (or cleartext) signature,
4204 @var{signed_text} should be a null pointer and @var{plain} should be a
4205 writable data object that will contain the plaintext after successful
4208 The results of the individual signature verifications can be retrieved
4209 with @code{gpgme_op_verify_result}.
4211 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4212 operation could be completed successfully, @code{GPG_ERR_INV_VALUE} if
4213 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer,
4214 @code{GPG_ERR_NO_DATA} if @var{sig} does not contain any data to
4215 verify, and passes through any errors that are reported by the crypto
4216 engine support routines.
4219 @deftypefun gpgme_error_t gpgme_op_verify_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{sig}}, @w{gpgme_data_t @var{signed_text}}, @w{gpgme_data_t @var{plain}})
4220 The function @code{gpgme_op_verify_start} initiates a
4221 @code{gpgme_op_verify} operation. It can be completed by calling
4222 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4224 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4225 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
4226 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer, and
4227 @code{GPG_ERR_NO_DATA} if @var{sig} or @var{plain} does not contain
4231 @deftp {Data type} {gpgme_sig_notation_t}
4232 This is a pointer to a structure used to store a part of the result of
4233 a @code{gpgme_op_verify} operation. The structure contains the
4237 @item gpgme_sig_notation_t next
4238 This is a pointer to the next new signature notation structure in the
4239 linked list, or @code{NULL} if this is the last element.
4242 The name of the notation field. If this is @code{NULL}, then the
4243 member @code{value} will contain a policy URL.
4246 The length of the @code{name} field. For strings the length is
4247 counted without the trailing binary zero.
4250 The value of the notation field. If @code{name} is @code{NULL}, then
4251 this is a policy URL.
4254 The length of the @code{value} field. For strings the length is
4255 counted without the trailing binary zero.
4257 @item gpgme_sig_notation_flags_t flags
4258 The accumulated flags field. This field contains the flags associated
4259 with the notation data in an accumulated form which can be used as an
4260 argument to the function @code{gpgme_sig_notation_add}. The value
4261 @code{flags} is a bitwise-or combination of one or multiple of the
4262 following bit values:
4265 @item GPGME_SIG_NOTATION_HUMAN_READABLE
4266 The @code{GPGME_SIG_NOTATION_HUMAN_READABLE} symbol specifies that the
4267 notation data is in human readable form
4269 @item GPGME_SIG_NOTATION_CRITICAL
4270 The @code{GPGME_SIG_NOTATION_CRITICAL} symbol specifies that the
4271 notation data is critical.
4275 @item unsigned int human_readable : 1
4276 This is true if the @code{GPGME_SIG_NOTATION_HUMAN_READABLE} flag is
4277 set and false otherwise. This flag is only valid for notation data,
4278 not for policy URLs.
4280 @item unsigned int critical : 1
4281 This is true if the @code{GPGME_SIG_NOTATION_CRITICAL} flag is set and
4282 false otherwise. This flag is valid for notation data and policy URLs.
4287 @deftp {Data type} {gpgme_signature_t}
4288 This is a pointer to a structure used to store a part of the result of
4289 a @code{gpgme_op_verify} operation. The structure contains the
4293 @item gpgme_signature_t next
4294 This is a pointer to the next new signature structure in the linked
4295 list, or @code{NULL} if this is the last element.
4297 @item gpgme_sigsum_t summary
4298 This is a bit vector giving a summary of the signature status. It
4299 provides an easy interface to a defined semantic of the signature
4300 status. Checking just one bit is sufficient to see whether a
4301 signature is valid without any restrictions.
4303 The defined bits are:
4305 @item GPGME_SIGSUM_VALID
4306 The signature is fully valid.
4308 @item GPGME_SIGSUM_GREEN
4309 The signature is good but one might want to display some extra
4310 information. Check the other bits.
4312 @item GPGME_SIGSUM_RED
4313 The signature is bad. It might be useful to check other bits and
4314 display more information, i.e. a revoked certificate might not render a
4315 signature invalid when the message was received prior to the cause for
4318 @item GPGME_SIGSUM_KEY_REVOKED
4319 The key or at least one certificate has been revoked.
4321 @item GPGME_SIGSUM_KEY_EXPIRED
4322 The key or one of the certificates has expired. It is probably a good
4323 idea to display the date of the expiration.
4325 @item GPGME_SIGSUM_SIG_EXPIRED
4326 The signature has expired.
4328 @item GPGME_SIGSUM_KEY_MISSING
4329 Can't verify due to a missing key or certificate.
4331 @item GPGME_SIGSUM_CRL_MISSING
4332 The CRL (or an equivalent mechanism) is not available.
4334 @item GPGME_SIGSUM_CRL_TOO_OLD
4335 Available CRL is too old.
4337 @item GPGME_SIGSUM_BAD_POLICY
4338 A policy requirement was not met.
4340 @item GPGME_SIGSUM_SYS_ERROR
4341 A system error occured.
4345 This is the fingerprint or key ID of the signature.
4347 @item gpgme_error_t status
4348 This is the status of the signature. In particular, the following
4349 status codes are of interest:
4352 @item GPG_ERR_NO_ERROR
4353 This status indicates that the signature is valid. For the combined
4354 result this status means that all signatures are valid.
4356 @item GPG_ERR_SIG_EXPIRED
4357 This status indicates that the signature is valid but expired. For
4358 the combined result this status means that all signatures are valid
4361 @item GPG_ERR_KEY_EXPIRED
4362 This status indicates that the signature is valid but the key used to
4363 verify the signature has expired. For the combined result this status
4364 means that all signatures are valid and all keys are expired.
4366 @item GPG_ERR_CERT_REVOKED
4367 This status indicates that the signature is valid but the key used
4368 to verify the signature has been revoked. For the combined result
4369 this status means that all signatures are valid and all keys are
4372 @item GPG_ERR_BAD_SIGNATURE
4373 This status indicates that the signature is invalid. For the combined
4374 result this status means that all signatures are invalid.
4376 @item GPG_ERR_NO_PUBKEY
4377 This status indicates that the signature could not be verified due to
4378 a missing key. For the combined result this status means that all
4379 signatures could not be checked due to missing keys.
4381 @item GPG_ERR_GENERAL
4382 This status indicates that there was some other error which prevented
4383 the signature verification.
4386 @item gpgme_sig_notation_t notations
4387 This is a linked list with the notation data and policy URLs.
4389 @item unsigned long timestamp
4390 The creation timestamp of this signature.
4392 @item unsigned long exp_timestamp
4393 The expiration timestamp of this signature, or 0 if the signature does
4396 @item unsigned int wrong_key_usage : 1
4397 This is true if the key was not used according to its policy.
4399 @item unsigned int pka_trust : 2
4400 This is set to the trust information gained by means of the PKA system.
4404 No PKA information available or verification not possible.
4406 PKA verification failed.
4408 PKA verification succeeded.
4410 Reserved for future use.
4412 Depending on the configuration of the engine, this metric may also be
4413 reflected by the validity of the signature.
4415 @item unsigned int chain_model : 1
4416 This is true if the validity of the signature has been checked using the
4417 chain model. In the chain model the time the signature has been created
4418 must be within the validity period of the certificate and the time the
4419 certificate itself has been created must be within the validity period
4420 of the issuing certificate. In contrast the default validation model
4421 checks the validity of signature as well at the entire certificate chain
4422 at the current time.
4425 @item gpgme_validity_t validity
4426 The validity of the signature.
4428 @item gpgme_error_t validity_reason
4429 If a signature is not valid, this provides a reason why.
4431 @item gpgme_pubkey_algo_t
4432 The public key algorithm used to create this signature.
4434 @item gpgme_hash_algo_t
4435 The hash algorithm used to create this signature.
4439 @deftp {Data type} {gpgme_verify_result_t}
4440 This is a pointer to a structure used to store the result of a
4441 @code{gpgme_op_verify} operation. After verifying a signature, you
4442 can retrieve the pointer to the result with
4443 @code{gpgme_op_verify_result}. If the operation failed this might be
4444 a @code{NULL} pointer. The structure contains the following member:
4447 @item gpgme_signature_t signatures
4448 A linked list with information about all signatures for which a
4449 verification was attempted.
4451 @item char *file_name
4452 This is the filename of the original plaintext message file if it is
4453 known, otherwise this is a null pointer.
4457 @deftypefun gpgme_verify_result_t gpgme_op_verify_result (@w{gpgme_ctx_t @var{ctx}})
4458 The function @code{gpgme_op_verify_result} returns a
4459 @code{gpgme_verify_result_t} pointer to a structure holding the result
4460 of a @code{gpgme_op_verify} operation. The pointer is only valid if
4461 the last operation on the context was a @code{gpgme_op_verify},
4462 @code{gpgme_op_verify_start}, @code{gpgme_op_decrypt_verify} or
4463 @code{gpgme_op_decrypt_verify_start} operation, and if this operation
4464 finished successfully (for @code{gpgme_op_decrypt_verify} and
4465 @code{gpgme_op_decrypt_verify_start}, the error code
4466 @code{GPG_ERR_NO_DATA} counts as successful in this context). The
4467 returned pointer is only valid until the next operation is started on
4472 The following interfaces are deprecated and only provided for backward
4473 compatibility. Don't use them. They will be removed in a future
4474 version of @acronym{GPGME}.
4476 @deftp {Data type} {enum gpgme_sig_stat_t}
4477 @tindex gpgme_sig_stat_t
4478 The @code{gpgme_sig_stat_t} type holds the result of a signature check, or
4479 the combined result of all signatures. The following results are
4483 @item GPGME_SIG_STAT_NONE
4484 This status should not occur in normal operation.
4486 @item GPGME_SIG_STAT_GOOD
4487 This status indicates that the signature is valid. For the combined
4488 result this status means that all signatures are valid.
4490 @item GPGME_SIG_STAT_GOOD_EXP
4491 This status indicates that the signature is valid but expired. For
4492 the combined result this status means that all signatures are valid
4495 @item GPGME_SIG_STAT_GOOD_EXPKEY
4496 This status indicates that the signature is valid but the key used to
4497 verify the signature has expired. For the combined result this status
4498 means that all signatures are valid and all keys are expired.
4500 @item GPGME_SIG_STAT_BAD
4501 This status indicates that the signature is invalid. For the combined
4502 result this status means that all signatures are invalid.
4504 @item GPGME_SIG_STAT_NOKEY
4505 This status indicates that the signature could not be verified due to
4506 a missing key. For the combined result this status means that all
4507 signatures could not be checked due to missing keys.
4509 @item GPGME_SIG_STAT_NOSIG
4510 This status indicates that the signature data provided was not a real
4513 @item GPGME_SIG_STAT_ERROR
4514 This status indicates that there was some other error which prevented
4515 the signature verification.
4517 @item GPGME_SIG_STAT_DIFF
4518 For the combined result this status means that at least two signatures
4519 have a different status. You can get each key's status with
4520 @code{gpgme_get_sig_status}.
4524 @deftypefun {const char *} gpgme_get_sig_status (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_sig_stat_t *@var{r_stat}}, @w{time_t *@var{r_created}})
4525 The function @code{gpgme_get_sig_status} is equivalent to:
4528 gpgme_verify_result_t result;
4529 gpgme_signature_t sig;
4531 result = gpgme_op_verify_result (ctx);
4532 sig = result->signatures;
4544 switch (gpg_err_code (sig->status))
4546 case GPG_ERR_NO_ERROR:
4547 *r_stat = GPGME_SIG_STAT_GOOD;
4550 case GPG_ERR_BAD_SIGNATURE:
4551 *r_stat = GPGME_SIG_STAT_BAD;
4554 case GPG_ERR_NO_PUBKEY:
4555 *r_stat = GPGME_SIG_STAT_NOKEY;
4558 case GPG_ERR_NO_DATA:
4559 *r_stat = GPGME_SIG_STAT_NOSIG;
4562 case GPG_ERR_SIG_EXPIRED:
4563 *r_stat = GPGME_SIG_STAT_GOOD_EXP;
4566 case GPG_ERR_KEY_EXPIRED:
4567 *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY;
4571 *r_stat = GPGME_SIG_STAT_ERROR;
4576 *r_created = sig->timestamp;
4581 @deftypefun {const char *} gpgme_get_sig_string_attr (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_attr_t @var{what}}, @w{int @var{whatidx}})
4582 The function @code{gpgme_get_sig_string_attr} is equivalent to:
4585 gpgme_verify_result_t result;
4586 gpgme_signature_t sig;
4588 result = gpgme_op_verify_result (ctx);
4589 sig = result->signatures;
4601 case GPGME_ATTR_FPR:
4604 case GPGME_ATTR_ERRTOK:
4606 return sig->wrong_key_usage ? "Wrong_Key_Usage" : "";
4617 @deftypefun {const char *} gpgme_get_sig_ulong_attr (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_attr_t @var{waht}}, @w{int @var{whatidx}})
4618 The function @code{gpgme_get_sig_ulong_attr} is equivalent to:
4621 gpgme_verify_result_t result;
4622 gpgme_signature_t sig;
4624 result = gpgme_op_verify_result (ctx);
4625 sig = result->signatures;
4637 case GPGME_ATTR_CREATED:
4638 return sig->timestamp;
4640 case GPGME_ATTR_EXPIRE:
4641 return sig->exp_timestamp;
4643 case GPGME_ATTR_VALIDITY:
4644 return (unsigned long) sig->validity;
4646 case GPGME_ATTR_SIG_STATUS:
4647 switch (sig->status)
4649 case GPG_ERR_NO_ERROR:
4650 return GPGME_SIG_STAT_GOOD;
4652 case GPG_ERR_BAD_SIGNATURE:
4653 return GPGME_SIG_STAT_BAD;
4655 case GPG_ERR_NO_PUBKEY:
4656 return GPGME_SIG_STAT_NOKEY;
4658 case GPG_ERR_NO_DATA:
4659 return GPGME_SIG_STAT_NOSIG;
4661 case GPG_ERR_SIG_EXPIRED:
4662 return GPGME_SIG_STAT_GOOD_EXP;
4664 case GPG_ERR_KEY_EXPIRED:
4665 return GPGME_SIG_STAT_GOOD_EXPKEY;
4668 return GPGME_SIG_STAT_ERROR;
4671 case GPGME_ATTR_SIG_SUMMARY:
4672 return sig->summary;
4681 @deftypefun {const char *} gpgme_get_sig_key (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_key_t *@var{r_key}})
4682 The function @code{gpgme_get_sig_key} is equivalent to:
4685 gpgme_verify_result_t result;
4686 gpgme_signature_t sig;
4688 result = gpgme_op_verify_result (ctx);
4689 sig = result->signatures;
4697 return gpg_error (GPG_ERR_EOF);
4699 return gpgme_get_key (ctx, sig->fpr, r_key, 0);
4704 @node Decrypt and Verify
4705 @subsection Decrypt and Verify
4706 @cindex decryption and verification
4707 @cindex verification and decryption
4708 @cindex signature check
4709 @cindex cryptographic operation, decryption and verification
4711 @deftypefun gpgme_error_t gpgme_op_decrypt_verify (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{cipher}}, @w{gpgme_data_t @var{plain}})
4712 The function @code{gpgme_op_decrypt_verify} decrypts the ciphertext in
4713 the data object @var{cipher} and stores it into the data object
4714 @var{plain}. If @var{cipher} contains signatures, they will be
4717 After the operation completed, @code{gpgme_op_decrypt_result} and
4718 @code{gpgme_op_verify_result} can be used to retrieve more information
4719 about the signatures.
4721 If the error code @code{GPG_ERR_NO_DATA} is returned, @var{cipher}
4722 does not contain any data to decrypt. However, it might still be
4723 signed. The information about detected signatures is available with
4724 @code{gpgme_op_verify_result} in this case.
4726 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4727 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
4728 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
4729 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
4730 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
4731 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
4732 secret key could not be retrieved, and passes through any errors that
4733 are reported by the crypto engine support routines.
4736 @deftypefun gpgme_error_t gpgme_op_decrypt_verify (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{cipher}}, @w{gpgme_data_t @var{plain}})
4737 The function @code{gpgme_op_decrypt_verify_start} initiates a
4738 @code{gpgme_op_decrypt_verify} operation. It can be completed by
4739 calling @code{gpgme_wait} on the context. @xref{Waiting For
4742 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4743 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
4744 @var{ctx}, @var{cipher}, @var{plain} or @var{r_stat} is not a valid
4745 pointer, and @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain
4746 any data to decrypt.
4752 @cindex signature, creation
4754 @cindex cryptographic operation, signing
4756 A signature can contain signatures by one or more keys. The set of
4757 keys used to create a signatures is contained in a context, and is
4758 applied to all following signing operations in this context (until the
4762 * Selecting Signers:: How to choose the keys to sign with.
4763 * Creating a Signature:: How to create a signature.
4764 * Signature Notation Data:: How to add notation data to a signature.
4768 @node Selecting Signers
4769 @subsubsection Selecting Signers
4770 @cindex signature, selecting signers
4771 @cindex signers, selecting
4773 @deftypefun void gpgme_signers_clear (@w{gpgme_ctx_t @var{ctx}})
4774 The function @code{gpgme_signers_clear} releases a reference for each
4775 key on the signers list and removes the list of signers from the
4778 Every context starts with an empty list.
4781 @deftypefun gpgme_error_t gpgme_signers_add (@w{gpgme_ctx_t @var{ctx}}, @w{const gpgme_key_t @var{key}})
4782 The function @code{gpgme_signers_add} adds the key @var{key} to the
4783 list of signers in the context @var{ctx}.
4785 Calling this function acquires an additional reference for the key.
4788 @deftypefun gpgme_key_t gpgme_signers_enum (@w{const gpgme_ctx_t @var{ctx}}, @w{int @var{seq}})
4789 The function @code{gpgme_signers_enum} returns the @var{seq}th key in
4790 the list of signers in the context @var{ctx}. An additional reference
4791 is acquired for the user.
4793 If @var{seq} is out of range, @code{NULL} is returned.
4797 @node Creating a Signature
4798 @subsubsection Creating a Signature
4800 @deftp {Data type} {enum gpgme_sig_mode_t}
4801 @tindex gpgme_sig_mode_t
4802 The @code{gpgme_sig_mode_t} type is used to specify the desired type of a
4803 signature. The following modes are available:
4806 @item GPGME_SIG_MODE_NORMAL
4807 A normal signature is made, the output includes the plaintext and the
4810 @item GPGME_SIG_MODE_DETACH
4811 A detached signature is made.
4813 @item GPGME_SIG_MODE_CLEAR
4814 A clear text signature is made. The @acronym{ASCII} armor and text
4815 mode settings of the context are ignored.
4819 @deftypefun gpgme_error_t gpgme_op_sign (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{sig}}, @w{gpgme_sig_mode_t @var{mode}})
4820 The function @code{gpgme_op_sign} creates a signature for the text in
4821 the data object @var{plain} and returns it in the data object
4822 @var{sig}. The type of the signature created is determined by the
4823 @acronym{ASCII} armor (or, if that is not set, by the encoding
4824 specified for @var{sig}), the text mode attributes set for the context
4825 @var{ctx} and the requested signature mode @var{mode}.
4827 After the operation completed successfully, the result can be
4828 retrieved with @code{gpgme_op_sign_result}.
4830 If an S/MIME signed message is created using the CMS crypto engine,
4831 the number of certificates to include in the message can be specified
4832 with @code{gpgme_set_include_certs}. @xref{Included Certificates}.
4834 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4835 signature could be created successfully, @code{GPG_ERR_INV_VALUE} if
4836 @var{ctx}, @var{plain} or @var{sig} is not a valid pointer,
4837 @code{GPG_ERR_NO_DATA} if the signature could not be created,
4838 @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the secret key
4839 could not be retrieved, @code{GPG_ERR_UNUSABLE_SECKEY} if there are
4840 invalid signers, and passes through any errors that are reported by the
4841 crypto engine support routines.
4844 @deftypefun gpgme_error_t gpgme_op_sign_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{sig}}, @w{gpgme_sig_mode_t @var{mode}})
4845 The function @code{gpgme_op_sign_start} initiates a
4846 @code{gpgme_op_sign} operation. It can be completed by calling
4847 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4849 The function returns the error code @code{GPG_ERR_NO_ERROR} if the operation could be
4850 started successfully, and @code{GPG_ERR_INV_VALUE} if @var{ctx},
4851 @var{plain} or @var{sig} is not a valid pointer.
4854 @deftp {Data type} {gpgme_new_signature_t}
4855 This is a pointer to a structure used to store a part of the result of
4856 a @code{gpgme_op_sign} operation. The structure contains the
4860 @item gpgme_new_signature_t next
4861 This is a pointer to the next new signature structure in the linked
4862 list, or @code{NULL} if this is the last element.
4864 @item gpgme_sig_mode_t type
4865 The type of this signature.
4867 @item gpgme_pubkey_algo_t
4868 The public key algorithm used to create this signature.
4870 @item gpgme_hash_algo_t
4871 The hash algorithm used to create this signature.
4873 @item unsigned int sig_class
4874 The signature class of this signature.
4876 @item long int timestamp
4877 The creation timestamp of this signature.
4880 The fingerprint of the key which was used to create this signature.
4884 @deftp {Data type} {gpgme_sign_result_t}
4885 This is a pointer to a structure used to store the result of a
4886 @code{gpgme_op_sign} operation. After successfully generating a
4887 signature, you can retrieve the pointer to the result with
4888 @code{gpgme_op_sign_result}. The structure contains the following
4892 @item gpgme_invalid_key_t invalid_signers
4893 A linked list with information about all invalid keys for which a
4894 signature could not be created.
4896 @item gpgme_new_signature_t signatures
4897 A linked list with information about all signatures created.
4901 @deftypefun gpgme_sign_result_t gpgme_op_sign_result (@w{gpgme_ctx_t @var{ctx}})
4902 The function @code{gpgme_op_sign_result} returns a
4903 @code{gpgme_sign_result_t} pointer to a structure holding the result
4904 of a @code{gpgme_op_sign} operation. The pointer is only valid if the
4905 last operation on the context was a @code{gpgme_op_sign},
4906 @code{gpgme_op_sign_start}, @code{gpgme_op_encrypt_sign} or
4907 @code{gpgme_op_encrypt_sign_start} operation. If that operation
4908 failed, the function might return a @code{NULL} pointer. The returned
4909 pointer is only valid until the next operation is started on the
4914 @node Signature Notation Data
4915 @subsubsection Signature Notation Data
4916 @cindex notation data
4917 @cindex signature notation data
4920 Using the following functions, you can attach arbitrary notation data
4921 to a signature. This information is then available to the user when
4922 the signature is verified.
4924 @deftypefun void gpgme_sig_notation_clear (@w{gpgme_ctx_t @var{ctx}})
4925 The function @code{gpgme_sig_notation_clear} removes the notation data
4926 from the context @var{ctx}. Subsequent signing operations from this
4927 context will not include any notation data.
4929 Every context starts with an empty notation data list.
4932 @deftypefun gpgme_error_t gpgme_sig_notation_add (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{name}}, @w{const char *@var{value}}, @w{gpgme_sig_notation_flags_t @var{flags}})
4933 The function @code{gpgme_sig_notation_add} adds the notation data with
4934 the name @var{name} and the value @var{value} to the context
4937 Subsequent signing operations will include this notation data, as well
4938 as any other notation data that was added since the creation of the
4939 context or the last @code{gpgme_sig_notation_clear} operation.
4941 The arguments @var{name} and @var{value} must be @code{NUL}-terminated
4942 strings in human-readable form. The flag
4943 @code{GPGME_SIG_NOTATION_HUMAN_READABLE} is implied
4944 (non-human-readable notation data is currently not supported). The
4945 strings must be in UTF-8 encoding.
4947 If @var{name} is @code{NULL}, then @var{value} should be a policy URL.
4949 The function @code{gpgme_sig_notation_add} returns the error code
4950 @code{GPG_ERR_NO_ERROR} if the notation data could be added
4951 successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} is not a valid
4952 pointer, or if @var{name}, @var{value} and @var{flags} are an invalid
4953 combination. The function also passes through any errors that are
4954 reported by the crypto engine support routines.
4957 @deftypefun gpgme_sig_notation_t gpgme_sig_notation_get (@w{const gpgme_ctx_t @var{ctx}})
4958 The function @code{gpgme_sig_notation_get} returns the linked list of
4959 notation data structures that are contained in the context @var{ctx}.
4961 If @var{ctx} is not a valid pointer, or there is no notation data
4962 added for this context, @code{NULL} is returned.
4969 @cindex cryptographic operation, encryption
4971 One plaintext can be encrypted for several recipients at the same
4972 time. The list of recipients is created independently of any context,
4973 and then passed to the encryption operation.
4976 * Encrypting a Plaintext:: How to encrypt a plaintext.
4980 @node Encrypting a Plaintext
4981 @subsubsection Encrypting a Plaintext
4983 @deftypefun gpgme_error_t gpgme_op_encrypt (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{recp}[]}, @w{gpgme_encrypt_flags_t @var{flags}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
4984 The function @code{gpgme_op_encrypt} encrypts the plaintext in the
4985 data object @var{plain} for the recipients @var{recp} and stores the
4986 ciphertext in the data object @var{cipher}. The type of the
4987 ciphertext created is determined by the @acronym{ASCII} armor (or, if
4988 that is not set, by the encoding specified for @var{cipher}) and the
4989 text mode attributes set for the context @var{ctx}.
4991 @var{key} must be a @code{NULL}-terminated array of keys. The user
4992 must keep references for all keys during the whole duration of the
4993 call (but see @code{gpgme_op_encrypt_start} for the requirements with
4994 the asynchronous variant).
4996 The value in @var{flags} is a bitwise-or combination of one or
4997 multiple of the following bit values:
5000 @item GPGME_ENCRYPT_ALWAYS_TRUST
5001 The @code{GPGME_ENCRYPT_ALWAYS_TRUST} symbol specifies that all the
5002 recipients in @var{recp} should be trusted, even if the keys do not
5003 have a high enough validity in the keyring. This flag should be used
5004 with care; in general it is not a good idea to use any untrusted keys.
5006 @item GPGME_ENCRYPT_NO_ENCRYPT_TO
5007 The @code{GPGME_ENCRYPT_NO_ENCRYPT_TO} symbol specifies that no
5008 default or hidden default recipients as configured in the crypto
5009 backend should be included. This can be useful for managing different
5013 If @code{GPG_ERR_UNUSABLE_PUBKEY} is returned, some recipients in
5014 @var{recp} are invalid, but not all. In this case the plaintext might
5015 be encrypted for all valid recipients and returned in @var{cipher} (if
5016 this happens depends on the crypto engine). More information about
5017 the invalid recipients is available with
5018 @code{gpgme_op_encrypt_result}.
5020 If @var{recp} is @code{NULL}, symmetric rather than public key
5021 encryption is performed. Symmetrically encrypted cipher text can be
5022 deciphered with @code{gpgme_op_decrypt}. Note that in this case the
5023 crypto backend needs to retrieve a passphrase from the user.
5024 Symmetric encryption is currently only supported for the OpenPGP
5027 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
5028 ciphertext could be created successfully, @code{GPG_ERR_INV_VALUE} if
5029 @var{ctx}, @var{recp}, @var{plain} or @var{cipher} is not a valid
5030 pointer, @code{GPG_ERR_UNUSABLE_PUBKEY} if @var{recp} contains some
5031 invalid recipients, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase
5032 for the symmetric key could not be retrieved, and passes through any
5033 errors that are reported by the crypto engine support routines.
5036 @deftypefun gpgme_error_t gpgme_op_encrypt_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{recp}[]}, @w{gpgme_encrypt_flags_t @var{flags}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
5037 The function @code{gpgme_op_encrypt_start} initiates a
5038 @code{gpgme_op_encrypt} operation. It can be completed by calling
5039 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
5041 References to the keys only need to be held for the duration of this
5042 call. The user can release its references to the keys after this
5043 function returns, even if the operation is not yet finished.
5045 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
5046 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
5047 @var{ctx}, @var{rset}, @var{plain} or @var{cipher} is not a valid
5048 pointer, and @code{GPG_ERR_UNUSABLE_PUBKEY} if @var{rset} does not
5049 contain any valid recipients.
5052 @deftp {Data type} {gpgme_encrypt_result_t}
5053 This is a pointer to a structure used to store the result of a
5054 @code{gpgme_op_encrypt} operation. After successfully encrypting
5055 data, you can retrieve the pointer to the result with
5056 @code{gpgme_op_encrypt_result}. The structure contains the following
5060 @item gpgme_invalid_key_t invalid_recipients
5061 A linked list with information about all invalid keys for which
5062 the data could not be encrypted.
5066 @deftypefun gpgme_encrypt_result_t gpgme_op_encrypt_result (@w{gpgme_ctx_t @var{ctx}})
5067 The function @code{gpgme_op_encrypt_result} returns a
5068 @code{gpgme_encrypt_result_t} pointer to a structure holding the
5069 result of a @code{gpgme_op_encrypt} operation. The pointer is only
5070 valid if the last operation on the context was a
5071 @code{gpgme_op_encrypt}, @code{gpgme_op_encrypt_start},
5072 @code{gpgme_op_sign} or @code{gpgme_op_sign_start} operation. If this
5073 operation failed, this might be a @code{NULL} pointer. The returned
5074 pointer is only valid until the next operation is started on the
5079 @deftypefun gpgme_error_t gpgme_op_encrypt_sign (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{recp}[]}, @w{gpgme_encrypt_flags_t @var{flags}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
5080 The function @code{gpgme_op_encrypt_sign} does a combined encrypt and
5081 sign operation. It is used like @code{gpgme_op_encrypt}, but the
5082 ciphertext also contains signatures for the signers listed in
5085 The combined encrypt and sign operation is currently only available
5086 for the OpenPGP crypto engine.
5089 @deftypefun gpgme_error_t gpgme_op_encrypt_sign_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{recp}}, @w{gpgme_encrypt_flags_t @var{flags}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
5090 The function @code{gpgme_op_encrypt_sign_start} initiates a
5091 @code{gpgme_op_encrypt_sign} operation. It can be completed by
5092 calling @code{gpgme_wait} on the context. @xref{Waiting For
5095 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
5096 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
5097 if @var{ctx}, @var{rset}, @var{plain} or @var{cipher} is not a valid
5103 @section Run Control
5105 @cindex cryptographic operation, running
5107 @acronym{GPGME} supports running operations synchronously and
5108 asynchronously. You can use asynchronous operation to set up a
5109 context up to initiating the desired operation, but delay performing
5110 it to a later point.
5112 Furthermore, you can use an external event loop to control exactly
5113 when @acronym{GPGME} runs. This ensures that @acronym{GPGME} only
5114 runs when necessary and also prevents it from blocking for a long
5118 * Waiting For Completion:: Waiting until an operation is completed.
5119 * Using External Event Loops:: Advanced control over what happens when.
5120 * Cancellation:: How to end pending operations prematurely.
5124 @node Waiting For Completion
5125 @subsection Waiting For Completion
5126 @cindex cryptographic operation, wait for
5127 @cindex wait for completion
5129 @deftypefun gpgme_ctx_t gpgme_wait (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_error_t *@var{status}}, @w{int @var{hang}})
5130 The function @code{gpgme_wait} continues the pending operation within
5131 the context @var{ctx}. In particular, it ensures the data exchange
5132 between @acronym{GPGME} and the crypto backend and watches over the
5133 run time status of the backend process.
5135 If @var{hang} is true, the function does not return until the
5136 operation is completed or cancelled. Otherwise the function will not
5137 block for a long time.
5139 The error status of the finished operation is returned in @var{status}
5140 if @code{gpgme_wait} does not return @code{NULL}.
5142 The @var{ctx} argument can be @code{NULL}. In that case,
5143 @code{gpgme_wait} waits for any context to complete its operation.
5145 @code{gpgme_wait} can be used only in conjunction with any context
5146 that has a pending operation initiated with one of the
5147 @code{gpgme_op_*_start} functions except @code{gpgme_op_keylist_start}
5148 and @code{gpgme_op_trustlist_start} (for which you should use the
5149 corresponding @code{gpgme_op_*_next} functions). If @var{ctx} is
5150 @code{NULL}, all of such contexts are waited upon and possibly
5151 returned. Synchronous operations running in parallel, as well as key
5152 and trust item list operations, do not affect @code{gpgme_wait}.
5154 In a multi-threaded environment, only one thread should ever call
5155 @code{gpgme_wait} at any time, irregardless if @var{ctx} is specified
5156 or not. This means that all calls to this function should be fully
5157 synchronized by locking primitives. It is safe to start asynchronous
5158 operations while a thread is running in @code{gpgme_wait}.
5160 The function returns the @var{ctx} of the context which has finished
5161 the operation. If @var{hang} is false, and the timeout expires,
5162 @code{NULL} is returned and @code{*status} will be set to 0. If an
5163 error occurs, @code{NULL} is returned and the error is returned in
5168 @node Using External Event Loops
5169 @subsection Using External Event Loops
5170 @cindex event loop, external
5172 @acronym{GPGME} hides the complexity of the communication between the
5173 library and the crypto engine. The price of this convenience is that
5174 the calling thread can block arbitrary long waiting for the data
5175 returned by the crypto engine. In single-threaded programs, in
5176 particular if they are interactive, this is an unwanted side-effect.
5177 OTOH, if @code{gpgme_wait} is used without the @var{hang} option being
5178 enabled, it might be called unnecessarily often, wasting CPU time that
5179 could be used otherwise.
5181 The I/O callback interface described in this section lets the user
5182 take control over what happens when. @acronym{GPGME} will provide the
5183 user with the file descriptors that should be monitored, and the
5184 callback functions that should be invoked when a file descriptor is
5185 ready for reading or writing. It is then the user's responsibility to
5186 decide when to check the file descriptors and when to invoke the
5187 callback functions. Usually this is done in an event loop, that also
5188 checks for events in other parts of the program. If the callback
5189 functions are only called when the file descriptors are ready,
5190 @acronym{GPGME} will never block. This gives the user more control
5191 over the program flow, and allows to perform other tasks when
5192 @acronym{GPGME} would block otherwise.
5194 By using this advanced mechanism, @acronym{GPGME} can be integrated
5195 smoothly into GUI toolkits like GTK+ even for single-threaded
5199 * I/O Callback Interface:: How I/O callbacks are registered.
5200 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
5201 * I/O Callback Example:: An example how to use I/O callbacks.
5202 * I/O Callback Example GTK+:: How to use @acronym{GPGME} with GTK+.
5203 * I/O Callback Example GDK:: How to use @acronym{GPGME} with GDK.
5204 * I/O Callback Example Qt:: How to use @acronym{GPGME} with Qt.
5208 @node I/O Callback Interface
5209 @subsubsection I/O Callback Interface
5211 @deftp {Data type} {gpgme_error_t (*gpgme_io_cb_t) (@w{void *@var{data}}, @w{int @var{fd}})}
5212 @tindex gpgme_io_cb_t
5213 The @code{gpgme_io_cb_t} type is the type of functions which
5214 @acronym{GPGME} wants to register as I/O callback handlers using the
5215 @code{gpgme_register_io_cb_t} functions provided by the user.
5217 @var{data} and @var{fd} are provided by @acronym{GPGME} when the I/O
5218 callback handler is registered, and should be passed through to the
5219 handler when it is invoked by the user because it noticed activity on
5220 the file descriptor @var{fd}.
5222 The callback handler always returns @code{0}, but you should consider
5223 the return value to be reserved for later use.
5226 @deftp {Data type} {gpgme_error_t (*gpgme_register_io_cb_t) (@w{void *@var{data}}, @w{int @var{fd}}, @w{int @var{dir}}, @w{gpgme_io_cb_t @var{fnc}}, @w{void *@var{fnc_data}}, @w{void **@var{tag}})}
5227 @tindex gpgme_register_io_cb_t
5228 The @code{gpgme_register_io_cb_t} type is the type of functions which can
5229 be called by @acronym{GPGME} to register an I/O callback function
5230 @var{fnc} for the file descriptor @var{fd} with the user.
5231 @var{fnc_data} should be passed as the first argument to @var{fnc}
5232 when the handler is invoked (the second argument should be @var{fd}).
5233 If @var{dir} is 0, @var{fnc} should be called by the user when
5234 @var{fd} is ready for writing. If @var{dir} is 1, @var{fnc} should be
5235 called when @var{fd} is ready for reading.
5237 @var{data} was provided by the user when registering the
5238 @code{gpgme_register_io_cb_t} function with @acronym{GPGME} and will always
5239 be passed as the first argument when registering a callback function.
5240 For example, the user can use this to determine the event loop to
5241 which the file descriptor should be added.
5243 @acronym{GPGME} will call this function when a crypto operation is
5244 initiated in a context for which the user has registered I/O callback
5245 handler functions with @code{gpgme_set_io_cbs}. It can also call this
5246 function when it is in an I/O callback handler for a file descriptor
5247 associated to this context.
5249 The user should return a unique handle in @var{tag} identifying this
5250 I/O callback registration, which will be passed to the
5251 @code{gpgme_register_io_cb_t} function without interpretation when the file
5252 descriptor should not be monitored anymore.
5255 @deftp {Data type} {void (*gpgme_remove_io_cb_t) (@w{void *@var{tag}})}
5256 The @code{gpgme_remove_io_cb_t} type is the type of functions which can be
5257 called by @acronym{GPGME} to remove an I/O callback handler that was
5258 registered before. @var{tag} is the handle that was returned by the
5259 @code{gpgme_register_io_cb_t} for this I/O callback.
5261 @acronym{GPGME} can call this function when a crypto operation is in
5262 an I/O callback. It will also call this function when the context is
5263 destroyed while an operation is pending.
5266 @deftp {Data type} {enum gpgme_event_io_t}
5267 @tindex gpgme_event_io_t
5268 The @code{gpgme_event_io_t} type specifies the type of an event that is
5269 reported to the user by @acronym{GPGME} as a consequence of an I/O
5270 operation. The following events are defined:
5273 @item GPGME_EVENT_START
5274 The operation is fully initialized now, and you can start to run the
5275 registered I/O callback handlers now. Note that registered I/O
5276 callback handlers must not be run before this event is signalled.
5277 @var{type_data} is @code{NULL} and reserved for later use.
5279 @item GPGME_EVENT_DONE
5280 The operation is finished, the last I/O callback for this operation
5281 was removed. The accompanying @var{type_data} points to a
5282 @code{gpgme_error_t} variable that contains the status of the operation
5283 that finished. This event is signalled after the last I/O callback
5286 @item GPGME_EVENT_NEXT_KEY
5287 In a @code{gpgme_op_keylist_start} operation, the next key was
5288 received from the crypto engine. The accompanying @var{type_data} is
5289 a @code{gpgme_key_t} variable that contains the key with one reference
5292 @item GPGME_EVENT_NEXT_TRUSTITEM
5293 In a @code{gpgme_op_trustlist_start} operation, the next trust item
5294 was received from the crypto engine. The accompanying @var{type_data}
5295 is a @code{gpgme_trust_item_t} variable that contains the trust item with
5296 one reference for the user.
5300 @deftp {Data type} {void (*gpgme_event_io_cb_t) (@w{void *@var{data}}, @w{gpgme_event_io_t @var{type}}, @w{void *@var{type_data}})}
5301 The @code{gpgme_event_io_cb_t} type is the type of functions which can be
5302 called by @acronym{GPGME} to signal an event for an operation running
5303 in a context which has I/O callback functions registered by the user.
5305 @var{data} was provided by the user when registering the
5306 @code{gpgme_event_io_cb_t} function with @acronym{GPGME} and will always be
5307 passed as the first argument when registering a callback function.
5308 For example, the user can use this to determine the context in which
5309 this event has occured.
5311 @var{type} will specify the type of event that has occured.
5312 @var{type_data} specifies the event further, as described in the above
5313 list of possible @code{gpgme_event_io_t} types.
5315 @acronym{GPGME} can call this function in an I/O callback handler.
5319 @node Registering I/O Callbacks
5320 @subsubsection Registering I/O Callbacks
5322 @deftp {Data type} {struct gpgme_io_cb_ts}
5323 @tindex gpgme_event_io_t
5324 This structure is used to store the I/O callback interface functions
5325 described in the previous section. It has the following members:
5328 @item gpgme_register_io_cb_t add
5329 This is the function called by @acronym{GPGME} to register an I/O
5330 callback handler. It must be specified.
5332 @item void *add_data
5333 This is passed as the first argument to the @code{add} function when
5334 it is called by @acronym{GPGME}. For example, it can be used to
5335 determine the event loop to which the file descriptor should be added.
5337 @item gpgme_remove_io_cb_t remove
5338 This is the function called by @acronym{GPGME} to remove an I/O
5339 callback handler. It must be specified.
5341 @item gpgme_event_io_cb_t event
5342 This is the function called by @acronym{GPGME} to signal an event for
5343 an operation. It must be specified, because at least the start event
5346 @item void *event_data
5347 This is passed as the first argument to the @code{event} function when
5348 it is called by @acronym{GPGME}. For example, it can be used to
5349 determine the context in which the event has occured.
5353 @deftypefun void gpgme_set_io_cbs (@w{gpgme_ctx_t @var{ctx}}, @w{struct gpgme_io_cb_ts *@var{io_cbs}})
5354 The function @code{gpgme_set_io_cbs} enables the I/O callback
5355 interface for the context @var{ctx}. The I/O callback functions are
5356 specified by @var{io_cbs}.
5358 If @var{io_cbs}->@code{add} is @code{NULL}, the I/O callback interface
5359 is disabled for the context, and normal operation is restored.
5362 @deftypefun void gpgme_get_io_cbs (@w{gpgme_ctx_t @var{ctx}}, @w{struct gpgme_io_cb_ts *@var{io_cbs}})
5363 The function @code{gpgme_get_io_cbs} returns the I/O callback
5364 functions set with @code{gpgme_set_io_cbs} in @var{io_cbs}.
5368 @node I/O Callback Example
5369 @subsubsection I/O Callback Example
5371 To actually use an external event loop, you have to implement the I/O
5372 callback functions that are used by @acronym{GPGME} to register and
5373 unregister file descriptors. Furthermore, you have to actually
5374 monitor these file descriptors for activity and call the appropriate
5377 The following example illustrates how to do that. The example uses
5378 locking to show in which way the callbacks and the event loop can
5379 run concurrently. For the event loop, we use a fixed array. For a
5380 real-world implementation, you should use a dynamically sized
5381 structure because the number of file descriptors needed for a crypto
5382 operation in @acronym{GPGME} is not predictable.
5388 #include <pthread.h>
5389 #include <sys/types.h>
5392 /* The following structure holds the result of a crypto operation. */
5399 /* The following structure holds the data associated with one I/O
5412 pthread_mutex_t lock;
5414 /* Unused slots are marked with FD being -1. */
5415 struct one_fd fds[MAX_FDS];
5419 The following functions implement the I/O callback interface.
5423 add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc, void *fnc_data,
5426 struct event_loop *loop = data;
5427 struct one_fd *fds = loop->fds;
5430 pthread_mutex_lock (&loop->lock);
5431 for (i = 0; i < MAX_FDS; i++)
5433 if (fds[i].fd == -1)
5438 fds[i].fnc_data = fnc_data;
5443 pthread_mutex_unlock (&loop->lock);
5445 return gpg_error (GPG_ERR_GENERAL);
5451 remove_io_cb (void *tag)
5453 struct one_fd *fd = tag;
5454 struct event_loop *loop = fd->loop;
5456 pthread_mutex_lock (&loop->lock);
5458 pthread_mutex_unlock (&loop->lock);
5462 event_io_cb (void *data, gpgme_event_io_t type, void *type_data)
5464 struct op_result *result = data;
5466 /* We don't support list operations here. */
5467 if (type == GPGME_EVENT_DONE)
5470 result->err = *type_data;
5475 The final missing piece is the event loop, which will be presented
5476 next. We only support waiting for the success of a single operation.
5480 do_select (struct event_loop *loop)
5486 struct one_fd *fdlist = loop->fds;
5488 pthread_mutex_lock (&loop->lock);
5491 for (i = 0; i < MAX_FDS; i++)
5492 if (fdlist[i].fd != -1)
5493 FD_SET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds);
5494 pthread_mutex_unlock (&loop->unlock);
5498 n = select (FD_SETSIZE, &rfds, &wfds, NULL, 0);
5500 while (n < 0 && errno == EINTR);
5503 return n; /* Error or timeout. */
5505 pthread_mutex_lock (&loop->lock);
5506 for (i = 0; i < MAX_FDS && n; i++)
5508 if (fdlist[i].fd != -1)
5510 if (FD_ISSET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds))
5515 /* The I/O callback handler can register/remove callbacks,
5516 so we have to unlock the file descriptor list. */
5517 pthread_mutex_unlock (&loop->lock);
5518 (*fdlist[i].fnc) (fdlist[i].fnc_data, fdlist[i].fd);
5519 pthread_mutex_lock (&loop->lock);
5523 pthread_mutex_unlock (&loop->lock);
5528 wait_for_op (struct event_loop *loop, struct op_result *result)
5534 ret = do_select (loop);
5536 while (ret >= 0 && !result->done);
5540 The main function shows how to put it all together.
5544 main (int argc, char *argv[])
5546 struct event_loop loop;
5547 struct op_result result;
5550 gpgme_data_t sig, text;
5552 struct gpgme_io_cb_ts io_cbs =
5563 /* Initialize the loop structure. */
5564 pthread_mutex_init (&loop.lock, NULL);
5565 for (i = 0; i < MAX_FDS; i++)
5566 loop->fds[i].fd = -1;
5568 /* Initialize the result structure. */
5571 err = gpgme_data_new_from_file (&sig, "signature", 1);
5573 err = gpgme_data_new_from_file (&text, "text", 1);
5575 err = gpgme_new (&ctx);
5578 gpgme_set_io_cbs (ctx, &io_cbs);
5579 err = gpgme_op_verify_start (ctx, sig, text, NULL);
5583 fprintf (stderr, "gpgme error: %s: %s\n",
5584 gpgme_strsource (err), gpgme_strerror (err));
5588 wait_for_op (&loop, &result);
5591 fprintf (stderr, "select error\n");
5596 fprintf (stderr, "verification failed: %s: %s\n",
5597 gpgme_strsource (result.err), gpgme_strerror (result.err));
5600 /* Evaluate verify result. */
5607 @node I/O Callback Example GTK+
5608 @subsubsection I/O Callback Example GTK+
5609 @cindex GTK+, using @acronym{GPGME} with
5611 The I/O callback interface can be used to integrate @acronym{GPGME}
5612 with the GTK+ event loop. The following code snippets shows how this
5613 can be done using the appropriate register and remove I/O callback
5614 functions. In this example, the private data of the register I/O
5615 callback function is unused. The event notifications is missing
5616 because it does not require any GTK+ specific setup.
5619 #include <gtk/gtk.h>
5621 struct my_gpgme_io_cb
5625 guint input_handler_id
5629 my_gpgme_io_cb (gpointer data, gint source, GdkInputCondition condition)
5631 struct my_gpgme_io_cb *iocb = data;
5632 (*(iocb->fnc)) (iocb->data, source);
5636 my_gpgme_remove_io_cb (void *data)
5638 struct my_gpgme_io_cb *iocb = data;
5639 gtk_input_remove (data->input_handler_id);
5643 my_gpgme_register_io_callback (void *data, int fd, int dir, gpgme_io_cb_t fnc,
5644 void *fnc_data, void **tag)
5646 struct my_gpgme_io_cb *iocb = g_malloc (sizeof (struct my_gpgme_io_cb));
5648 iocb->data = fnc_data;
5649 iocb->input_handler_id = gtk_input_add_full (fd, dir
5652 my_gpgme_io_callback,
5660 @node I/O Callback Example GDK
5661 @subsubsection I/O Callback Example GDK
5662 @cindex GDK, using @acronym{GPGME} with
5664 The I/O callback interface can also be used to integrate
5665 @acronym{GPGME} with the GDK event loop. The following code snippets
5666 shows how this can be done using the appropriate register and remove
5667 I/O callback functions. In this example, the private data of the
5668 register I/O callback function is unused. The event notifications is
5669 missing because it does not require any GDK specific setup.
5671 It is very similar to the GTK+ example in the previous section.
5674 #include <gdk/gdk.h>
5676 struct my_gpgme_io_cb
5684 my_gpgme_io_cb (gpointer data, gint source, GdkInputCondition condition)
5686 struct my_gpgme_io_cb *iocb = data;
5687 (*(iocb->fnc)) (iocb->data, source);
5691 my_gpgme_remove_io_cb (void *data)
5693 struct my_gpgme_io_cb *iocb = data;
5694 gdk_input_remove (data->tag);
5698 my_gpgme_register_io_callback (void *data, int fd, int dir, gpgme_io_cb_t fnc,
5699 void *fnc_data, void **tag)
5701 struct my_gpgme_io_cb *iocb = g_malloc (sizeof (struct my_gpgme_io_cb));
5703 iocb->data = fnc_data;
5704 iocb->tag = gtk_input_add_full (fd, dir ? GDK_INPUT_READ : GDK_INPUT_WRITE,
5705 my_gpgme_io_callback, iocb, NULL);
5712 @node I/O Callback Example Qt
5713 @subsubsection I/O Callback Example Qt
5714 @cindex Qt, using @acronym{GPGME} with
5716 The I/O callback interface can also be used to integrate
5717 @acronym{GPGME} with the Qt event loop. The following code snippets
5718 show how this can be done using the appropriate register and remove
5719 I/O callback functions. In this example, the private data of the
5720 register I/O callback function is unused. The event notifications is
5721 missing because it does not require any Qt specific setup.
5724 #include <qsocketnotifier.h>
5725 #include <qapplication.h>
5728 IOCB( GpgmeIOCb f, void * d, QSocketNotifier * n )
5729 : func( f ), data( d ), notifier( n ) @{@}
5732 QSocketNotifier * notifier;
5735 class MyApp : public QApplication @{
5739 static void registerGpgmeIOCallback( void * data, int fd, int dir,
5740 GpgmeIOCb func, void * func_data,
5742 QSocketNotifier * n =
5743 new QSocketNotifier( fd, dir ? QSocketNotifier::Read
5744 : QSocketNotifier::Write );
5745 connect( n, SIGNAL(activated(int)),
5746 qApp, SLOT(slotGpgmeIOCallback(int)) );
5747 qApp->mIOCBs.push_back( IOCB( func, func_data, n ) );
5751 static void removeGpgmeIOCallback( void * tag ) @{
5753 QSocketNotifier * n = static_cast<QSocketNotifier*>( tag );
5754 for ( QValueList<IOCB>::iterator it = qApp->mIOCBs.begin() ;
5755 it != qApp->mIOCBs.end() ; ++it )
5756 if ( it->notifier == n ) @{
5757 delete it->notifier;
5758 qApp->mIOCBs.erase( it );
5764 void slotGpgmeIOCallback( int fd ) @{
5765 for ( QValueList<IOCB>::const_iterator it = mIOCBs.begin() ;
5766 it != mIOCBs.end() ; ++it )
5767 if ( it->notifier && it->notifier->socket() == fd )
5768 (*(it->func)) ( it->func_data, fd );
5774 QValueList<IOCB> mIOCBs;
5781 @subsection Cancellation
5782 @cindex cryptographic operation, aborting
5783 @cindex cryptographic operation, cancelling
5784 @cindex aborting operations
5785 @cindex cancelling operations
5787 Sometimes you do not want to wait for an operation to finish.
5788 @acronym{GPGME} provides two different functions to achieve that. The
5789 function @code{gpgme_cancel} takes effect immediately. When it
5790 returns, the operation is effectively canceled. However, it has some
5791 limitations and can not be used with synchronous operations. In
5792 contrast, the function @code{gpgme_cancel_async} can be used with any
5793 context and from any thread, but it is not guaranteed to take effect
5794 immediately. Instead, cancellation occurs at the next possible time
5795 (typically the next time I/O occurs in the target context).
5797 @deftypefun gpgme_ctx_t gpgme_cancel (@w{gpgme_ctx_t @var{ctx}})
5798 The function @code{gpgme_cancel} attempts to cancel a pending
5799 operation in the context @var{ctx}. This only works if you use the
5800 global event loop or your own event loop.
5802 If you use the global event loop, you must not call @code{gpgme_wait}
5803 or @code{gpgme_wait} during cancellation. After successful
5804 cancellation, you can call @code{gpgme_wait} (optionally waiting on
5805 @var{ctx}), and the context @var{ctx} will appear as if it had
5806 finished with the error code @code{GPG_ERR_CANCEL}.
5808 If you use your an external event loop, you must ensure that no I/O
5809 callbacks are invoked for this context (for example by halting the
5810 event loop). On successful cancellation, all registered I/O callbacks
5811 for this context will be unregistered, and a @code{GPGME_EVENT_DONE}
5812 event with the error code @code{GPG_ERR_CANCEL} will be signaled.
5814 The function returns an error code if the cancellation failed (in this
5815 case the state of @var{ctx} is not modified).
5819 @deftypefun gpgme_ctx_t gpgme_cancel_async (@w{gpgme_ctx_t @var{ctx}})
5820 The function @code{gpgme_cancel} attempts to cancel a pending
5821 operation in the context @var{ctx}. This can be called by any thread
5822 at any time after starting an operation on the context, but will not
5823 take effect immediately. The actual cancellation happens at the next
5824 time GPGME processes I/O in that context.
5826 The function returns an error code if the cancellation failed (in this
5827 case the state of @var{ctx} is not modified).
5830 @c **********************************************************
5831 @c ******************* Appendices *************************
5832 @c **********************************************************
5834 @include uiserver.texi
5837 @appendix How to solve problems
5841 Everyone knows that software often does not do what it should do and thus
5842 there is a need to track down problems. This is in particular true
5843 for applications using a complex library like @acronym{GPGME} and of
5844 course also for the library itself. Here we give a few hints on how
5845 to solve such problems.
5847 First of all you should make sure that the keys you want to use are
5848 installed in the GnuPG engine and are usable. Thus the first test is
5849 to run the desired operation using @command{gpg} or @command{gpgsm} on
5850 the command line. If you can't figure out why things don't work, you
5851 may use @acronym{GPGME}'s built in trace feature. This feature is
5852 either enabled using the environment variable @code{GPGME_DEBUG} or,
5853 if this is not possible, by calling the function
5854 @code{gpgme_set_global_flag}. The value is the trace level and
5855 an optional file name.
5860 GPGME_DEBUG=9:/home/user/mygpgme.log
5863 (Note that under Windows you use a semicolon in place of the colon to
5864 separate the fields.)
5866 A trace level of 9 is pretty verbose and thus you may want to start
5867 off with a lower level. The exact definition of the trace levels and
5868 the output format may change with any release; you need to check the
5869 source code for details. In any case the trace log should be helpful
5870 to understand what is going going on. Warning: The trace log may
5871 reveal sensitive details like passphrases or other data you use in
5872 your application. If you are asked to send a log file, make sure that
5873 you run your tests only with play data.
5877 @include lesser.texi
5881 @node Function and Data Index
5882 @unnumbered Function and Data Index
5887 @unnumbered Concept Index