1 \input texinfo @c -*- Texinfo -*-
2 @setfilename gpgme.info
3 @settitle The `GnuPG Made Easy' Reference Manual
5 @dircategory GNU Libraries
7 * @acronym{GPGME}: (gpgme). Adding support for cryptography to your program.
12 @c Unify some of the indices.
17 This file documents the @acronym{GPGME} library.
19 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
20 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
23 @c NOTE: Don't forget to update the year for the TeX version, too.
24 Copyright @copyright{} 2002, 2003, 2004, 2005 g10 Code GmbH.
26 The GPGME reference manual is free software; you can redistribute it
27 and/or modify it under the terms of the GNU Lesser General Public
28 License as published by the Free Software Foundation; either version
29 2.1 of the License, or (at your option) any later version.
31 The GPGME reference manual is distributed in the hope that it will be
32 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34 Lesser General Public License for more details.
36 You should have received a copy of the GNU Lesser General Public
37 License along with this program; if not, write to the Free Software
38 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
43 @shorttitlepage The `GnuPG Made Easy' Reference Manual
46 @center @titlefont{The `GnuPG Made Easy'}
48 @center @titlefont{Reference Manual}
50 @center Edition @value{EDITION}
52 @center last updated @value{UPDATED}
54 @center for version @value{VERSION}
56 @vskip 0pt plus 1filll
57 Copyright @copyright{} 2002, 2003, 2004, 2005 g10 Code GmbH.
60 The GPGME reference manual is free software; you can redistribute it
61 and/or modify it under the terms of the GNU Lesser General Public
62 License as published by the Free Software Foundation; either version
63 2.1 of the License, or (at your option) any later version.
65 The GPGME reference manual is distributed in the hope that it will be
66 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
67 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
68 Lesser General Public License for more details.
70 You should have received a copy of the GNU Lesser General Public
71 License along with this program; if not, write to the Free Software
72 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
79 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
80 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
81 @value{VERSION} of the @acronym{GPGME} library.
85 * Introduction:: How to use this manual.
86 * Preparation:: What you should do before using the library.
87 * Protocols and Engines:: Supported crypto protocols.
88 * Algorithms:: Supported algorithms.
89 * Error Handling:: Error numbers and their meanings.
90 * Exchanging Data:: Passing data to and from @acronym{GPGME}.
91 * Contexts:: Handling @acronym{GPGME} contexts.
95 * Library Copying:: The GNU Lesser General Public License says
96 how you can copy and share `GnuPG Made Easy'.
100 * Concept Index:: Index of concepts and programs.
101 * Function and Data Index:: Index of functions, variables and data types.
105 --- The Detailed Node Listing ---
109 * Getting Started:: Purpose of the manual, and how to use it.
110 * Features:: Reasons to install and use @acronym{GPGME}.
111 * Overview:: Basic architecture of the @acronym{GPGME} library.
115 * Header:: What header file you need to include.
116 * Building the Source:: Compiler options to be used.
117 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
118 * Using Automake:: Compiler options to be used the easy way.
119 * Using Libtool:: Avoiding compiler options entirely.
120 * Library Version Check:: Getting and verifying the library version.
121 * Signal Handling:: How @acronym{GPGME} affects signal handling.
122 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
124 Protocols and Engines
126 * Engine Version Check:: Verifying the engine version.
127 * Engine Information:: Obtaining more information about the engines.
128 * Engine Configuration:: Changing the engine configuration.
129 * OpenPGP:: Support for the OpenPGP protocol.
130 * Cryptographic Message Syntax:: Support for the CMS.
134 * Public Key Algorithms:: A list of all public key algorithms.
135 * Hash Algorithms:: A list of all hash algorithms.
139 * Error Values:: The error value and what it means.
140 * Error Codes:: A list of important error codes.
141 * Error Sources:: A list of important error sources.
142 * Error Strings:: How to get a descriptive string from a value.
146 * Creating Data Buffers:: Creating new data buffers.
147 * Destroying Data Buffers:: Releasing data buffers.
148 * Manipulating Data Buffers:: Operations on data buffers.
150 Creating Data Buffers
152 * Memory Based Data Buffers:: Creating memory based data buffers.
153 * File Based Data Buffers:: Creating file based data buffers.
154 * Callback Based Data Buffers:: Creating callback based data buffers.
156 Manipulating Data Buffers
158 * Data Buffer I/O Operations:: I/O operations on data buffers.
159 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
163 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
164 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
165 * Context Attributes:: Setting properties of a context.
166 * Key Management:: Managing keys with @acronym{GPGME}.
167 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
168 * Crypto Operations:: Using a context for cryptography.
169 * Run Control:: Controlling how operations are run.
173 * Protocol Selection:: Selecting the protocol used by a context.
174 * Crypto Engine:: Configuring the crypto engine.
175 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
176 * Text Mode:: Choosing canonical text mode.
177 * Included Certificates:: Including a number of certificates.
178 * Key Listing Mode:: Selecting key listing mode.
179 * Passphrase Callback:: Getting the passphrase from the user.
180 * Progress Meter Callback:: Being informed about the progress.
181 * Locale:: Setting the locale of a context.
185 * Listing Keys:: Browsing the list of available keys.
186 * Information About Keys:: Requesting detailed information about keys.
187 * Key Signatures:: Listing the signatures on a key.
188 * Manipulating Keys:: Operations on keys.
189 * Generating Keys:: Creating new key pairs.
190 * Exporting Keys:: Retrieving key data from the key ring.
191 * Importing Keys:: Adding keys to the key ring.
192 * Deleting Keys:: Removing keys from the key ring.
194 Trust Item Management
196 * Listing Trust Items:: Browsing the list of available trust items.
197 * Information About Trust Items:: Requesting information about trust items.
198 * Manipulating Trust Items:: Operations on trust items.
202 * Decrypt:: Decrypting a ciphertext.
203 * Verify:: Verifying a signature.
204 * Decrypt and Verify:: Decrypting a signed ciphertext.
205 * Sign:: Creating a signature.
206 * Encrypt:: Encrypting a plaintext.
210 * Selecting Signers:: How to choose the keys to sign with.
211 * Creating a Signature:: How to create a signature.
212 * Signature Notation Data:: How to add notation data to a signature.
216 * Encrypting a Plaintext:: How to encrypt a plaintext.
220 * Waiting For Completion:: Waiting until an operation is completed.
221 * Using External Event Loops:: Advanced control over what happens when.
222 * Cancellation:: How to end pending operations prematurely.
224 Using External Event Loops
226 * I/O Callback Interface:: How I/O callbacks are registered.
227 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
228 * I/O Callback Example:: An example how to use I/O callbacks.
229 * I/O Callback Example GTK+:: How to integrate @acronym{GPGME} in GTK+.
230 * I/O Callback Example GDK:: How to integrate @acronym{GPGME} in GDK.
231 * I/O Callback Example Qt:: How to integrate @acronym{GPGME} in Qt.
237 @chapter Introduction
239 `GnuPG Made Easy' (@acronym{GPGME}) is a C language library that
240 allows to add support for cryptography to a program. It is designed
241 to make access to public key crypto engines like GnuPG or GpgSM easier
242 for applications. @acronym{GPGME} provides a high-level crypto API
243 for encryption, decryption, signing, signature verification and key
246 @acronym{GPGME} uses GnuPG and GpgSM as its backends to support
247 OpenPGP and the Cryptographic Message Syntax (CMS).
250 * Getting Started:: Purpose of the manual, and how to use it.
251 * Features:: Reasons to install and use @acronym{GPGME}.
252 * Overview:: Basic architecture of the @acronym{GPGME} library.
256 @node Getting Started
257 @section Getting Started
259 This manual documents the @acronym{GPGME} library programming
260 interface. All functions and data types provided by the library are
263 The reader is assumed to possess basic knowledge about cryptography in
264 general, and public key cryptography in particular. The underlying
265 cryptographic engines that are used by the library are not explained,
266 but where necessary, special features or requirements by an engine are
267 mentioned as far as they are relevant to @acronym{GPGME} or its users.
269 This manual can be used in several ways. If read from the beginning
270 to the end, it gives a good introduction into the library and how it
271 can be used in an application. Forward references are included where
272 necessary. Later on, the manual can be used as a reference manual to
273 get just the information needed about any particular interface of the
274 library. Experienced programmers might want to start looking at the
275 examples at the end of the manual, and then only read up those parts
276 of the interface which are unclear.
282 @acronym{GPGME} has a couple of advantages over other libraries doing
283 a similar job, and over implementing support for GnuPG or other crypto
284 engines into your application directly.
287 @item it's free software
288 Anybody can use, modify, and redistribute it under the terms of the GNU
289 Lesser General Public License (@pxref{Library Copying}).
292 @acronym{GPGME} provides transparent support for several cryptographic
293 protocols by different engines. Currently, @acronym{GPGME} supports
294 the OpenPGP protocol using GnuPG as the backend, and the Cryptographic
295 Message Syntax using GpgSM as the backend.
298 @acronym{GPGME} hides the differences between the protocols and
299 engines from the programmer behind an easy-to-use interface. This way
300 the programmer can focus on the other parts of the program, and still
301 integrate strong cryptography in his application. Once support for
302 @acronym{GPGME} has been added to a program, it is easy to add support
303 for other crypto protocols once @acronym{GPGME} backends provide them.
310 @acronym{GPGME} provides a data abstraction that is used to pass data
311 to the crypto engine, and receive returned data from it. Data can be
312 read from memory or from files, but it can also be provided by a
315 The actual cryptographic operations are always set within a context.
316 A context provides configuration parameters that define the behaviour
317 of all operations performed within it. Only one operation per context
318 is allowed at any time, but when one operation is finished, you can
319 run the next operation in the same context. There can be more than
320 one context, and all can run different operations at the same time.
322 Furthermore, @acronym{GPGME} has rich key management facilities
323 including listing keys, querying their attributes, generating,
324 importing, exporting and deleting keys, and acquiring information
325 about the trust path.
327 With some precautions, @acronym{GPGME} can be used in a multi-threaded
328 environment, although it is not completely thread safe and thus needs
329 the support of the application.
335 To use @acronym{GPGME}, you have to perform some changes to your
336 sources and the build system. The necessary changes are small and
337 explained in the following sections. At the end of this chapter, it
338 is described how the library is initialized, and how the requirements
339 of the library are verified.
342 * Header:: What header file you need to include.
343 * Building the Source:: Compiler options to be used.
344 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
345 * Using Automake:: Compiler options to be used the easy way.
346 * Using Libtool:: Avoiding compiler options entirely.
347 * Library Version Check:: Getting and verifying the library version.
348 * Signal Handling:: How @acronym{GPGME} affects signal handling.
349 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
358 All interfaces (data types and functions) of the library are defined
359 in the header file `gpgme.h'. You must include this in all programs
360 using the library, either directly or through some other header file,
367 The name space of @acronym{GPGME} is @code{gpgme_*} for function names
368 and data types and @code{GPGME_*} for other symbols. Symbols internal
369 to @acronym{GPGME} take the form @code{_gpgme_*} and @code{_GPGME_*}.
371 Because @acronym{GPGME} makes use of the GPG Error library, using
372 @acronym{GPGME} will also use the @code{GPG_ERR_*} name space
373 directly, and the @code{gpg_err*} and @code{gpg_str*} name space
377 @node Building the Source
378 @section Building the Source
379 @cindex compiler options
380 @cindex compiler flags
382 If you want to compile a source file including the `gpgme.h' header
383 file, you must make sure that the compiler can find it in the
384 directory hierarchy. This is accomplished by adding the path to the
385 directory in which the header file is located to the compilers include
386 file search path (via the @option{-I} option).
388 However, the path to the include file is determined at the time the
389 source is configured. To solve this problem, gpgme ships with a small
390 helper program @command{gpgme-config} that knows about the path to the
391 include file and other configuration options. The options that need
392 to be added to the compiler invocation at compile time are output by
393 the @option{--cflags} option to @command{gpgme-config}. The following
394 example shows how it can be used at the command line:
397 gcc -c foo.c `gpgme-config --cflags`
400 Adding the output of @samp{gpgme-config --cflags} to the compiler
401 command line will ensure that the compiler can find the
402 @acronym{GPGME} header file.
404 A similar problem occurs when linking the program with the library.
405 Again, the compiler has to find the library files. For this to work,
406 the path to the library files has to be added to the library search
407 path (via the @option{-L} option). For this, the option
408 @option{--libs} to @command{gpgme-config} can be used. For
409 convenience, this option also outputs all other options that are
410 required to link the program with @acronym{GPGME} (in particular, the
411 @samp{-lgpgme} option). The example shows how to link @file{foo.o}
412 with the @acronym{GPGME} library to a program @command{foo}.
415 gcc -o foo foo.o `gpgme-config --libs`
418 Of course you can also combine both examples to a single command by
419 specifying both options to @command{gpgme-config}:
422 gcc -o foo foo.c `gpgme-config --cflags --libs`
425 If you want to link to one of the thread-safe versions of
426 @acronym{GPGME}, you must specify the @option{--thread} option before
427 any other option to select the thread package you want to link with.
428 Supported thread packages are @option{--thread=pth} and
429 @option{--thread=pthread}.
432 @node Largefile Support (LFS)
433 @section Largefile Support (LFS)
434 @cindex largefile support
437 @acronym{GPGME} is compiled with largefile support by default, if it
438 is available on the system. This means that GPGME supports files
439 larger than two gigabyte in size, if the underlying operating system
440 can. On some systems, largefile support is already the default. On
441 such systems, nothing special is required. However, some systems
442 provide only support for files up to two gigabyte in size by default.
443 Support for larger file sizes has to be specifically enabled.
445 To make a difficult situation even more complex, such systems provide
446 two different types of largefile support. You can either get all
447 relevant functions replaced with alternatives that are largefile
448 capable, or you can get new functions and data types for largefile
449 support added. Those new functions have the same name as their
450 smallfile counterparts, but with a suffix of 64.
452 An example: The data type @code{off_t} is 32 bit wide on GNU/Linux PC
453 systems. To address offsets in large files, you can either enable
454 largefile support add-on. Then a new data type @code{off64_t} is
455 provided, which is 64 bit wide. Or you can replace the existing
456 @code{off_t} data type with its 64 bit wide counterpart. All
457 occurences of @code{off_t} are then automagically replaced.
459 As if matters were not complex enough, there are also two different
460 types of file descriptors in such systems. This is important because
461 if file descriptors are exchanged between programs that use a
462 different maximum file size, certain errors must be produced on some
463 file descriptors to prevent subtle overflow bugs from occuring.
465 As you can see, supporting two different maximum file sizes at the
466 same time is not at all an easy task. However, the maximum file size
467 does matter for @acronym{GPGME}, because some data types it uses in
468 its interfaces are affected by that. For example, the @code{off_t}
469 data type is used in the @code{gpgme_data_seek} function, to match its
470 @acronym{POSIX} counterpart. This affects the call-frame of the
471 function, and thus the ABI of the library. Furthermore, file
472 descriptors can be exchanged between GPGME and the application.
474 For you as the user of the library, this means that your program must
475 be compiled in the same file size mode as the library. Luckily, there
476 is absolutely no valid reason for new programs to not enable largefile
477 support by default and just use that. The compatibility modes (small
478 file sizes or dual mode) can be considered an historic artefact, only
479 useful to allow for a transitional period.
481 @acronym{GPGME} is compiled using largefile support by default. This
482 means that your application must do the same, at least as far as it is
483 relevant for using the @file{gpgme.h} header file. All types in this
484 header files refer to their largefile counterparts, if they are
485 different from any default types on the system.
487 You can enable largefile support, if it is different from the default
488 on the system the application is compiled on, by using the Autoconf
489 macro @code{AC_SYS_LARGEFILE}. If you do this, then you don't need to
490 worry about anything else: It will just work. In this case you might
491 also want to use @code{AC_FUNC_FSEEKO} to take advantage of some new
492 interfaces, and @code{AC_TYPE_OFF_T} (just in case).
494 If you do not use Autoconf, you can define the preprocessor symbol
495 @code{_FILE_OFFSET_BITS} to 64 @emph{before} including any header
496 files, for example by specifying the option
497 @code{-D_FILE_OFFSET_BITS=64} on the compiler command line. You will
498 also want to define the preprocessor symbol @code{LARGEFILE_SOURCE} to
499 1 in this case, to take advantage of some new interfaces.
501 If you do not want to do either of the above, you probably know enough
502 about the issue to invent your own solution. Just keep in mind that
503 the @acronym{GPGME} header file expects that largefile support is
504 enabled, if it is available. In particular, we do not support dual
505 mode (@code{_LARGEFILE64_SOURCE}).
509 @section Using Automake
513 It is much easier if you use GNU Automake instead of writing your own
514 Makefiles. If you do that you do not have to worry about finding and
515 invoking the @command{gpgme-config} script at all. @acronym{GPGME}
516 provides an extension to Automake that does all the work for you.
518 @c A simple macro for optional variables.
520 @r{[}@var{\varname\}@r{]}
522 @defmac AM_PATH_GPGME (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
523 @defmacx AM_PATH_GPGME_PTH (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
524 @defmacx AM_PATH_GPGME_PTHREAD (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
525 Check whether @acronym{GPGME} (at least version @var{minimum-version},
526 if given) exists on the host system. If it is found, execute
527 @var{action-if-found}, otherwise do @var{action-if-not-found}, if
530 Additionally, the function defines @code{GPGME_CFLAGS} to the flags
531 needed for compilation of the program to find the @file{gpgme.h}
532 header file, and @code{GPGME_LIBS} to the linker flags needed to link
533 the program to the @acronym{GPGME} library.
535 @code{AM_PATH_GPGME_PTH} checks for the version of @acronym{GPGME}
536 that can be used with GNU Pth, and defines @code{GPGME_PTH_CFLAGS} and
537 @code{GPGME_PTH_LIBS}.
539 @code{AM_PATH_GPGME_PTHREAD} checks for the version of @acronym{GPGME}
540 that can be used with the native pthread implementation, and defines
541 @code{GPGME_PTHREAD_CFLAGS} and @code{GPGME_PTHREAD_LIBS}.
544 You can use the defined Autoconf variables like this in your
548 AM_CPPFLAGS = $(GPGME_CFLAGS)
549 LDADD = $(GPGME_LIBS)
554 @section Using Libtool
557 The easiest way is to just use GNU Libtool. If you use libtool, and
558 link to @code{libgpgme.la}, @code{libgpgme-pth.la} or
559 @code{libgpgme-pthread.la} respectively, everything will be done
560 automatically by Libtool.
563 @node Library Version Check
564 @section Library Version Check
565 @cindex version check, of the library
567 @deftypefun {const char *} gpgme_check_version (@w{const char *@var{required_version}})
568 The function @code{gpgme_check_version} has three purposes. It can be
569 used to retrieve the version number of the library. In addition it
570 can verify that the version number is higher than a certain required
571 version number. In either case, the function initializes some
572 sub-systems, and for this reason alone it must be invoked early in
573 your program, before you make use of the other functions in
576 If @var{required_version} is @code{NULL}, the function returns a
577 pointer to a statically allocated string containing the version number
580 If @var{required_version} is not @code{NULL}, it should point to a
581 string containing a version number, and the function checks that the
582 version of the library is at least as high as the version number
583 provided. In this case, the function returns a pointer to a
584 statically allocated string containing the version number of the
585 library. If @var{REQUIRED_VERSION} is not a valid version number, or
586 if the version requirement is not met, the function returns
589 If you use a version of a library that is backwards compatible with
590 older releases, but contains additional interfaces which your program
591 uses, this function provides a run-time check if the necessary
592 features are provided by the installed version of the library.
596 After initializing @acronym{GPGME}, you should set the locale
597 information to the locale required for your output terminal. This
598 locale information is needed for example for the curses and Gtk
599 pinentry. Here is an example of a complete initialization:
608 /* Initialize the locale environment. */
609 setlocale (LC_ALL, "");
610 gpgme_check_version (NULL);
611 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
612 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
616 Note that you are highly recommended to initialize the locale settings
617 like this. @acronym{GPGME} can not do this for you because it would
621 @node Signal Handling
622 @section Signal Handling
624 @cindex signal handling
626 The @acronym{GPGME} library communicates with child processes (the
627 crypto engines). If a child process dies unexpectedly, for example
628 due to a bug, or system problem, a @code{SIGPIPE} signal will be
629 delivered to the application. The default action is to abort the
630 program. To protect against this, @code{gpgme_check_version} sets the
631 @code{SIGPIPE} signal action to @code{SIG_IGN}, which means that the
632 signal will be ignored.
634 @acronym{GPGME} will only do that if the signal action for
635 @code{SIGPIPE} is @code{SIG_DEF} at the time
636 @code{gpgme_check_version} is called. If it is something different,
637 @code{GPGME} will take no action.
639 This means that if your application does not install any signal
640 handler for @code{SIGPIPE}, you don't need to take any precautions.
641 If you do install a signal handler for @code{SIGPIPE}, you must be
642 prepared to handle any @code{SIGPIPE} events that occur due to
643 @acronym{GPGME} writing to a defunct pipe. Furthermore, if your
644 application is multi-threaded, and you install a signal action for
645 @code{SIGPIPE}, you must make sure you do this either before
646 @code{gpgme_check_version} is called or afterwards.
649 @node Multi Threading
650 @section Multi Threading
651 @cindex thread-safeness
652 @cindex multi-threading
654 The @acronym{GPGME} library is not entirely thread-safe, but it can
655 still be used in a multi-threaded environment if some care is taken.
656 If the following requirements are met, there should be no race
657 conditions to worry about:
661 @acronym{GPGME} supports the thread libraries pthread and GNU Pth.
662 The support for this has to be enabled at compile time.
663 @acronym{GPGME} will automatically detect the location in which the
664 thread libraries are installed and activate the support for them at
667 Support for other thread libraries is very easy to add. Please
668 contact us if you have the need.
671 If you want to use @acronym{GPGME} with threads, you must link to the
672 right version of the library. The name of the right library is
673 @code{libgpgme-} followed by the name of the thread package you use.
674 For example, if you use GNU Pth, the right name is
675 @code{libgpgme-pth}. Use the Automake macros or
676 @command{gpgme-config} program for simplicity.
680 The function @code{gpgme_check_version} must be called before any
681 other function in the library, because it initializes the thread
682 support subsystem in @acronym{GPGME}. To achieve this in
683 multi-threaded programs, you must synchronize the memory with respect
684 to other threads that also want to use @acronym{GPGME}. For this, it
685 is sufficient to call @code{gpgme_check_version} before creating the
686 other threads using @acronym{GPGME}@footnote{At least this is true for
687 POSIX threads, as @code{pthread_create} is a function that
688 synchronizes memory with respects to other threads. There are many
689 functions which have this property, a complete list can be found in
690 POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the
691 definition of the term ``Memory Synchronization''. For other thread
692 packages other, more relaxed or more strict rules may apply.}.
695 Any @code{gpgme_data_t} and @code{gpgme_ctx_t} object must only be
696 accessed by one thread at a time. If multiple threads want to deal
697 with the same object, the caller has to make sure that operations on
698 that object are fully synchronized.
701 Only one thread at any time is allowed to call @code{gpgme_wait}. If
702 multiple threads call this function, the caller must make sure that
703 all invocations are fully synchronized. It is safe to start
704 asynchronous operations while a thread is running in gpgme_wait.
707 The function @code{gpgme_strerror} is not thread safe. You have to
708 use @code{gpgme_strerror_r} instead.
712 @node Protocols and Engines
713 @chapter Protocols and Engines
716 @cindex crypto engine
718 @cindex crypto backend
720 @acronym{GPGME} supports several cryptographic protocols, however, it
721 does not implement them. Rather it uses backends (also called
722 engines) which implement the protocol. @acronym{GPGME} uses
723 inter-process communication to pass data back and forth between the
724 application and the backend, but the details of the communication
725 protocol and invocation of the backend is completely hidden by the
726 interface. All complexity is handled by @acronym{GPGME}. Where an
727 exchange of information between the application and the backend is
728 necessary, @acronym{GPGME} provides the necessary callback function
729 hooks and further interfaces.
731 @deftp {Data type} {enum gpgme_protocol_t}
732 @tindex gpgme_protocol_t
733 The @code{gpgme_protocol_t} type specifies the set of possible protocol
734 values that are supported by @acronym{GPGME}. The following protocols
738 @item GPGME_PROTOCOL_OpenPGP
739 This specifies the OpenPGP protocol.
741 @item GPGME_PROTOCOL_CMS
742 This specifies the Cryptographic Message Syntax.
747 @deftypefun {const char *} gpgme_get_protocol_name (@w{gpgme_protocol_t @var{protocol}})
748 The function @code{gpgme_get_protocol_name} returns a statically
749 allocated string describing the protocol @var{protocol}, or
750 @code{NULL} if the protocol number is not valid.
754 * Engine Version Check:: Verifying the engine version.
755 * Engine Information:: Obtaining more information about the engines.
756 * Engine Configuration:: Changing the engine configuration.
757 * OpenPGP:: Support for the OpenPGP protocol.
758 * Cryptographic Message Syntax:: Support for the CMS.
762 @node Engine Version Check
763 @section Engine Version Check
764 @cindex version check, of the engines
766 @deftypefun gpgme_error_t gpgme_engine_check_version (@w{gpgme_protocol_t @var{protocol}})
767 The function @code{gpgme_engine_check_version} verifies that the
768 engine implementing the protocol @var{PROTOCOL} is installed in the
769 expected path and meets the version requirement of @acronym{GPGME}.
771 This function returns the error code @code{GPG_ERR_NO_ERROR} if the
772 engine is available and @code{GPG_ERR_INV_ENGINE} if it is not.
776 @node Engine Information
777 @section Engine Information
778 @cindex engine, information about
780 @deftp {Data type} {gpgme_engine_info_t}
781 @tindex gpgme_protocol_t
782 The @code{gpgme_engine_info_t} type specifies a pointer to a structure
783 describing a crypto engine. The structure contains the following
787 @item gpgme_engine_info_t next
788 This is a pointer to the next engine info structure in the linked
789 list, or @code{NULL} if this is the last element.
791 @item gpgme_protocol_t protocol
792 This is the protocol for which the crypto engine is used. You can
793 convert this to a string with @code{gpgme_get_protocol_name} for
796 @item const char *file_name
797 This is a string holding the file name of the executable of the crypto
798 engine. Currently, it is never @code{NULL}, but using @code{NULL} is
799 reserved for future use, so always check before you use it.
801 @item const char *home_dir
802 This is a string holding the directory name of the crypto engine's
803 configuration directory. If it is @code{NULL}, then the default
806 @item const char *version
807 This is a string containing the version number of the crypto engine.
808 It might be @code{NULL} if the version number can not be determined,
809 for example because the executable doesn't exist or is invalid.
811 @item const char *req_version
812 This is a string containing the minimum required version number of the
813 crypto engine for @acronym{GPGME} to work correctly. This is the
814 version number that @code{gpgme_engine_check_version} verifies
815 against. Currently, it is never @code{NULL}, but using @code{NULL} is
816 reserved for future use, so always check before you use it.
820 @deftypefun gpgme_error_t gpgme_get_engine_info (@w{gpgme_engine_info_t *@var{info}})
821 The function @code{gpgme_get_engine_info} returns a linked list of
822 engine info structures in @var{info}. Each info structure describes
823 the defaults of one configured backend.
825 The memory for the info structures is allocated the first time this
826 function is invoked, and must not be freed by the caller.
828 This function returns the error code @code{GPG_ERR_NO_ERROR} if
829 successful, and a system error if the memory could not be allocated.
832 Here is an example how you can provide more diagnostics if you receive
833 an error message which indicates that the crypto engine is invalid.
841 if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
843 gpgme_engine_info_t info;
844 err = gpgme_get_engine_info (&info);
847 while (info && info->protocol != gpgme_get_protocol (ctx))
850 fprintf (stderr, "GPGME compiled without support for protocol %s",
851 gpgme_get_protocol_name (info->protocol));
852 else if (info->path && !info->version)
853 fprintf (stderr, "Engine %s not installed properly",
855 else if (info->path && info->version && info->req_version)
856 fprintf (stderr, "Engine %s version %s installed, "
857 "but at least version %s required", info->path,
858 info->version, info->req_version);
860 fprintf (stderr, "Unknown problem with engine for protocol %s",
861 gpgme_get_protocol_name (info->protocol));
867 @node Engine Configuration
868 @section Engine Configuration
869 @cindex engine, configuration of
870 @cindex configuration of crypto backend
872 You can change the configuration of a backend engine, and thus change
873 the executable program and configuration directory to be used. You
874 can make these changes the default or set them for some contexts
877 @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}})
878 The function @code{gpgme_set_engine_info} changes the default
879 configuration of the crypto engine implementing the protocol
882 @var{file_name} is the file name of the executable program
883 implementing this protocol, and @var{home_dir} is the directory name
884 of the configuration directory for this crypto engine. If
885 @var{home_dir} is @code{NULL}, the engine's default will be used.
887 The new defaults are not applied to already created GPGME contexts.
889 This function returns the error code @code{GPG_ERR_NO_ERROR} if
890 successful, or an eror code on failure.
893 The functions @code{gpgme_ctx_get_engine_info} and
894 @code{gpgme_ctx_set_engine_info} can be used to change the engine
895 configuration per context. @xref{Crypto Engine}.
902 @cindex protocol, GnuPG
903 @cindex engine, GnuPG
905 OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard.
906 This is the first protocol that was supported by @acronym{GPGME}.
908 The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}.
911 @node Cryptographic Message Syntax
912 @section Cryptographic Message Syntax
914 @cindex cryptographic message syntax
916 @cindex protocol, CMS
917 @cindex engine, GpgSM
919 @cindex protocol, S/MIME
921 @acronym{CMS} is implemented by GpgSM, the S/MIME implementation for
924 The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}.
931 The crypto backends support a variety of algorithms used in public key
932 cryptography. The following sections list the identifiers used to
933 denote such an algorithm.
936 * Public Key Algorithms:: A list of all public key algorithms.
937 * Hash Algorithms:: A list of all hash algorithms.
941 @node Public Key Algorithms
942 @section Public Key Algorithms
943 @cindex algorithms, public key
944 @cindex public key algorithms
946 Public key algorithms are used for encryption, decryption, signing and
947 verification of signatures.
949 @deftp {Data type} {enum gpgme_pubkey_algo_t}
950 @tindex gpgme_pubkey_algo_t
951 The @code{gpgme_pubkey_algo_t} type specifies the set of all public key
952 algorithms that are supported by @acronym{GPGME}. Possible values
957 This value indicates the RSA (Rivest, Shamir, Adleman) algorithm.
960 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
961 algorithm for encryption and decryption only.
964 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
965 algorithm for signing and verification only.
968 This value indicates DSA, the Digital Signature Algorithm.
971 This value indicates ElGamal.
974 This value also indicates ElGamal and is used specifically in GnuPG.
978 @deftypefun {const char *} gpgme_pubkey_algo_name (@w{gpgme_pubkey_algo_t @var{algo}})
979 The function @code{gpgme_pubkey_algo_name} returns a pointer to a
980 statically allocated string containing a description of the public key
981 algorithm @var{algo}. This string can be used to output the name of
982 the public key algorithm to the user.
984 If @var{algo} is not a valid public key algorithm, @code{NULL} is
989 @node Hash Algorithms
990 @section Hash Algorithms
991 @cindex algorithms, hash
992 @cindex algorithms, message digest
993 @cindex hash algorithms
994 @cindex message digest algorithms
996 Hash (message digest) algorithms are used to compress a long message
997 to make it suitable for public key cryptography.
999 @deftp {Data type} {enum gpgme_hash_algo_t}
1000 @tindex gpgme_hash_algo_t
1001 The @code{gpgme_hash_algo_t} type specifies the set of all hash algorithms
1002 that are supported by @acronym{GPGME}. Possible values are:
1007 @item GPGME_MD_RMD160
1009 @item GPGME_MD_TIGER
1010 @item GPGME_MD_HAVAL
1011 @item GPGME_MD_SHA256
1012 @item GPGME_MD_SHA384
1013 @item GPGME_MD_SHA512
1015 @item GPGME_MD_CRC32
1016 @item GPGME_MD_CRC32_RFC1510
1017 @item GPGME_MD_CRC24_RFC2440
1021 @deftypefun {const char *} gpgme_hash_algo_name (@w{gpgme_hash_algo_t @var{algo}})
1022 The function @code{gpgme_hash_algo_name} returns a pointer to a
1023 statically allocated string containing a description of the hash
1024 algorithm @var{algo}. This string can be used to output the name of
1025 the hash algorithm to the user.
1027 If @var{algo} is not a valid hash algorithm, @code{NULL} is returned.
1031 @node Error Handling
1032 @chapter Error Handling
1033 @cindex error handling
1035 Many functions in @acronym{GPGME} can return an error if they fail.
1036 For this reason, the application should always catch the error
1037 condition and take appropriate measures, for example by releasing the
1038 resources and passing the error up to the caller, or by displaying a
1039 descriptive message to the user and cancelling the operation.
1041 Some error values do not indicate a system error or an error in the
1042 operation, but the result of an operation that failed properly. For
1043 example, if you try to decrypt a tempered message, the decryption will
1044 fail. Another error value actually means that the end of a data
1045 buffer or list has been reached. The following descriptions explain
1046 for many error codes what they mean usually. Some error values have
1047 specific meanings if returned by a certain functions. Such cases are
1048 described in the documentation of those functions.
1050 @acronym{GPGME} uses the @code{libgpg-error} library. This allows to
1051 share the error codes with other components of the GnuPG system, and
1052 thus pass error values transparently from the crypto engine, or some
1053 helper application of the crypto engine, to the user. This way no
1054 information is lost. As a consequence, @acronym{GPGME} does not use
1055 its own identifiers for error codes, but uses those provided by
1056 @code{libgpg-error}. They usually start with @code{GPG_ERR_}.
1058 However, @acronym{GPGME} does provide aliases for the functions
1059 defined in libgpg-error, which might be preferred for name space
1063 * Error Values:: The error value and what it means.
1064 * Error Sources:: A list of important error sources.
1065 * Error Codes:: A list of important error codes.
1066 * Error Strings:: How to get a descriptive string from a value.
1071 @section Error Values
1072 @cindex error values
1074 @cindex error sources
1076 @deftp {Data type} {gpgme_err_code_t}
1077 The @code{gpgme_err_code_t} type is an alias for the @code{libgpg-error}
1078 type @code{gpg_err_code_t}. The error code indicates the type of an
1079 error, or the reason why an operation failed.
1081 A list of important error codes can be found in the next section.
1084 @deftp {Data type} {gpgme_err_source_t}
1085 The @code{gpgme_err_source_t} type is an alias for the
1086 @code{libgpg-error} type @code{gpg_err_source_t}. The error source
1087 has not a precisely defined meaning. Sometimes it is the place where
1088 the error happened, sometimes it is the place where an error was
1089 encoded into an error value. Usually the error source will give an
1090 indication to where to look for the problem. This is not always true,
1091 but it is attempted to achieve this goal.
1093 A list of important error sources can be found in the next section.
1096 @deftp {Data type} {gpgme_error_t}
1097 The @code{gpgme_error_t} type is an alias for the @code{libgpg-error}
1098 type @code{gpg_error_t}. An error value like this has always two
1099 components, an error code and an error source. Both together form the
1102 Thus, the error value can not be directly compared against an error
1103 code, but the accessor functions described below must be used.
1104 However, it is guaranteed that only 0 is used to indicate success
1105 (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of
1106 the error value are set to 0, too.
1108 Note that in @acronym{GPGME}, the error source is used purely for
1109 diagnostical purposes. Only the error code should be checked to test
1110 for a certain outcome of a function. The manual only documents the
1111 error code part of an error value. The error source is left
1112 unspecified and might be anything.
1115 @deftypefun {static inline gpgme_err_code_t} gpgme_err_code (@w{gpgme_error_t @var{err}})
1116 The static inline function @code{gpgme_err_code} returns the
1117 @code{gpgme_err_code_t} component of the error value @var{err}. This
1118 function must be used to extract the error code from an error value in
1119 order to compare it with the @code{GPG_ERR_*} error code macros.
1122 @deftypefun {static inline gpgme_err_source_t} gpgme_err_source (@w{gpgme_error_t @var{err}})
1123 The static inline function @code{gpgme_err_source} returns the
1124 @code{gpgme_err_source_t} component of the error value @var{err}. This
1125 function must be used to extract the error source from an error value in
1126 order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros.
1129 @deftypefun {static inline gpgme_error_t} gpgme_err_make (@w{gpgme_err_source_t @var{source}}, @w{gpgme_err_code_t @var{code}})
1130 The static inline function @code{gpgme_err_make} returns the error
1131 value consisting of the error source @var{source} and the error code
1134 This function can be used in callback functions to construct an error
1135 value to return it to the library.
1138 @deftypefun {static inline gpgme_error_t} gpgme_error (@w{gpgme_err_code_t @var{code}})
1139 The static inline function @code{gpgme_error} returns the error value
1140 consisting of the default error source and the error code @var{code}.
1142 For @acronym{GPGME} applications, the default error source is
1143 @code{GPG_ERR_SOURCE_USER_1}. You can define
1144 @code{GPGME_ERR_SOURCE_DEFAULT} before including @file{gpgme.h} to
1145 change this default.
1147 This function can be used in callback functions to construct an error
1148 value to return it to the library.
1151 The @code{libgpg-error} library provides error codes for all system
1152 error numbers it knows about. If @var{err} is an unknown error
1153 number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The
1154 following functions can be used to construct error values from system
1157 @deftypefun {gpgme_error_t} gpgme_err_make_from_errno (@w{gpgme_err_source_t @var{source}}, @w{int @var{err}})
1158 The function @code{gpgme_err_make_from_errno} is like
1159 @code{gpgme_err_make}, but it takes a system error like @code{errno}
1160 instead of a @code{gpgme_err_code_t} error code.
1163 @deftypefun {gpgme_error_t} gpgme_error_from_errno (@w{int @var{err}})
1164 The function @code{gpgme_error_from_errno} is like @code{gpgme_error},
1165 but it takes a system error like @code{errno} instead of a
1166 @code{gpgme_err_code_t} error code.
1169 Sometimes you might want to map system error numbers to error codes
1170 directly, or map an error code representing a system error back to the
1171 system error number. The following functions can be used to do that.
1173 @deftypefun {gpgme_err_code_t} gpgme_err_code_from_errno (@w{int @var{err}})
1174 The function @code{gpgme_err_code_from_errno} returns the error code
1175 for the system error @var{err}. If @var{err} is not a known system
1176 error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}.
1179 @deftypefun {int} gpgme_err_code_to_errno (@w{gpgme_err_code_t @var{err}})
1180 The function @code{gpgme_err_code_to_errno} returns the system error
1181 for the error code @var{err}. If @var{err} is not an error code
1182 representing a system error, or if this system error is not defined on
1183 this system, the function returns @code{0}.
1188 @section Error Sources
1189 @cindex error codes, list of
1191 The library @code{libgpg-error} defines an error source for every
1192 component of the GnuPG system. The error source part of an error
1193 value is not well defined. As such it is mainly useful to improve the
1194 diagnostic error message for the user.
1196 If the error code part of an error value is @code{0}, the whole error
1197 value will be @code{0}. In this case the error source part is of
1198 course @code{GPG_ERR_SOURCE_UNKNOWN}.
1200 The list of error sources that might occur in applications using
1204 @item GPG_ERR_SOURCE_UNKNOWN
1205 The error source is not known. The value of this error source is
1208 @item GPG_ERR_SOURCE_GPGME
1209 The error source is @acronym{GPGME} itself. This is the default for
1210 errors that occur in the @acronym{GPGME} library.
1212 @item GPG_ERR_SOURCE_GPG
1213 The error source is GnuPG, which is the crypto engine used for the
1216 @item GPG_ERR_SOURCE_GPGSM
1217 The error source is GPGSM, which is the crypto engine used for the
1220 @item GPG_ERR_SOURCE_GCRYPT
1221 The error source is @code{libgcrypt}, which is used by crypto engines
1222 to perform cryptographic operations.
1224 @item GPG_ERR_SOURCE_GPGAGENT
1225 The error source is @command{gpg-agent}, which is used by crypto
1226 engines to perform operations with the secret key.
1228 @item GPG_ERR_SOURCE_PINENTRY
1229 The error source is @command{pinentry}, which is used by
1230 @command{gpg-agent} to query the passphrase to unlock a secret key.
1232 @item GPG_ERR_SOURCE_SCD
1233 The error source is the SmartCard Daemon, which is used by
1234 @command{gpg-agent} to delegate operations with the secret key to a
1237 @item GPG_ERR_SOURCE_KEYBOX
1238 The error source is @code{libkbx}, a library used by the crypto
1239 engines to manage local keyrings.
1241 @item GPG_ERR_SOURCE_USER_1
1242 @item GPG_ERR_SOURCE_USER_2
1243 @item GPG_ERR_SOURCE_USER_3
1244 @item GPG_ERR_SOURCE_USER_4
1245 These error sources are not used by any GnuPG component and can be
1246 used by other software. For example, applications using
1247 @acronym{GPGME} can use them to mark error values coming from callback
1248 handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors
1249 created with @code{gpgme_error} and @code{gpgme_error_from_errno},
1250 unless you define @code{GPGME_ERR_SOURCE_DEFAULT} before including
1256 @section Error Codes
1257 @cindex error codes, list of
1259 The library @code{libgpg-error} defines many error values. Most of
1260 them are not used by @code{GPGME} directly, but might be returned by
1261 @acronym{GPGME} because it received them from the crypto engine. The
1262 below list only includes such error codes that have a specific meaning
1263 in @code{GPGME}, or which are so common that you should know about
1268 This value indicates the end of a list, buffer or file.
1270 @item GPG_ERR_NO_ERROR
1271 This value indicates success. The value of this error code is
1272 @code{0}. Also, it is guaranteed that an error value made from the
1273 error code @code{0} will be @code{0} itself (as a whole). This means
1274 that the error source information is lost for this error code,
1275 however, as this error code indicates that no error occured, this is
1276 generally not a problem.
1278 @item GPG_ERR_GENERAL
1279 This value means that something went wrong, but either there is not
1280 enough information about the problem to return a more useful error
1281 value, or there is no separate error value for this type of problem.
1283 @item GPG_ERR_ENOMEM
1284 This value means that an out-of-memory condition occurred.
1287 System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
1290 @item GPG_ERR_INV_VALUE
1291 This value means that some user provided data was out of range. This
1292 can also refer to objects. For example, if an empty
1293 @code{gpgme_data_t} object was expected, but one containing data was
1294 provided, this error value is returned.
1296 @item GPG_ERR_UNUSABLE_PUBKEY
1297 This value means that some recipients for a message were invalid.
1299 @item GPG_ERR_UNUSABLE_SECKEY
1300 This value means that some signers were invalid.
1302 @item GPG_ERR_NO_DATA
1303 This value means that a @code{gpgme_data_t} object which was expected
1304 to have content was found empty.
1306 @item GPG_ERR_CONFLICT
1307 This value means that a conflict of some sort occurred.
1309 @item GPG_ERR_NOT_IMPLEMENTED
1310 This value indicates that the specific function (or operation) is not
1311 implemented. This error should never happen. It can only occur if
1312 you use certain values or configuration options which do not work,
1313 but for which we think that they should work at some later time.
1315 @item GPG_ERR_DECRYPT_FAILED
1316 This value indicates that a decryption operation was unsuccessful.
1318 @item GPG_ERR_BAD_PASSPHRASE
1319 This value means that the user did not provide a correct passphrase
1322 @item GPG_ERR_CANCELED
1323 This value means that the operation was canceled.
1325 @item GPG_ERR_INV_ENGINE
1326 This value means that the engine that implements the desired protocol
1327 is currently not available. This can either be because the sources
1328 were configured to exclude support for this engine, or because the
1329 engine is not installed properly.
1331 @item GPG_ERR_AMBIGUOUS_NAME
1332 This value indicates that a user ID or other specifier did not specify
1335 @item GPG_ERR_WRONG_KEY_USAGE
1336 This value indicates that a key is not used appropriately.
1338 @item GPG_ERR_CERT_REVOKED
1339 This value indicates that a key signature was revoced.
1341 @item GPG_ERR_CERT_EXPIRED
1342 This value indicates that a key signature expired.
1344 @item GPG_ERR_NO_CRL_KNOWN
1345 This value indicates that no certificate revocation list is known for
1348 @item GPG_ERR_NO_POLICY_MATCH
1349 This value indicates that a policy issue occured.
1351 @item GPG_ERR_NO_SECKEY
1352 This value indicates that no secret key for the user ID is available.
1354 @item GPG_ERR_MISSING_CERT
1355 This value indicates that a key could not be imported because the
1356 issuer certificate is missing.
1358 @item GPG_ERR_BAD_CERT_CHAIN
1359 This value indicates that a key could not be imported because its
1360 certificate chain is not good, for example it could be too long.
1362 @item GPG_ERR_UNSUPPORTED_ALGORITHM
1363 This value means a verification failed because the cryptographic
1364 algorithm is not supported by the crypto backend.
1366 @item GPG_ERR_BAD_SIGNATURE
1367 This value means a verification failed because the signature is bad.
1369 @item GPG_ERR_NO_PUBKEY
1370 This value means a verification failed because the public key is not
1373 @item GPG_ERR_USER_1
1374 @item GPG_ERR_USER_2
1376 @item GPG_ERR_USER_16
1377 These error codes are not used by any GnuPG component and can be
1378 freely used by other software. Applications using @acronym{GPGME}
1379 might use them to mark specific errors returned by callback handlers
1380 if no suitable error codes (including the system errors) for
1381 these errors exist already.
1386 @section Error Strings
1387 @cindex error values, printing of
1388 @cindex error codes, printing of
1389 @cindex error sources, printing of
1390 @cindex error strings
1392 @deftypefun {const char *} gpgme_strerror (@w{gpgme_error_t @var{err}})
1393 The function @code{gpgme_strerror} returns a pointer to a statically
1394 allocated string containing a description of the error code contained
1395 in the error value @var{err}. This string can be used to output a
1396 diagnostic message to the user.
1398 This function is not thread safe. Use @code{gpgme_strerror_r} in
1399 multi-threaded programs.
1403 @deftypefun {char *} gpgme_strerror_r (@w{gpgme_error_t @var{err}})
1404 The function @code{gpgme_strerror_r} returns a pointer to a
1405 dynamically allocated string containing a description of the error
1406 code contained in the error value @var{err}. This string can be used
1407 to output a diagnostic message to the user. When it is not needed
1408 anymore, the user must deallocate it with @code{free}.
1412 @deftypefun {const char *} gpgme_strsource (@w{gpgme_error_t @var{err}})
1413 The function @code{gpgme_strerror} returns a pointer to a statically
1414 allocated string containing a description of the error source
1415 contained in the error value @var{err}. This string can be used to
1416 output a diagnostic message to the user.
1419 The following example illustrates the use of @code{gpgme_strerror}:
1423 gpgme_error_t err = gpgme_new (&ctx);
1426 fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
1427 argv[0], gpgme_strsource (err), gpgme_strerror (err));
1433 @node Exchanging Data
1434 @chapter Exchanging Data
1435 @cindex data, exchanging
1437 A lot of data has to be exchanged between the user and the crypto
1438 engine, like plaintext messages, ciphertext, signatures and
1439 information about the keys. The technical details about exchanging
1440 the data information are completely abstracted by @acronym{GPGME}.
1441 The user provides and receives the data via @code{gpgme_data_t} objects,
1442 regardless of the communication protocol between @acronym{GPGME} and
1443 the crypto engine in use.
1445 @deftp {Data type} {gpgme_data_t}
1446 The @code{gpgme_data_t} type is a handle for a container for generic
1447 data, which is used by @acronym{GPGME} to exchange data with the user.
1451 * Creating Data Buffers:: Creating new data buffers.
1452 * Destroying Data Buffers:: Releasing data buffers.
1453 * Manipulating Data Buffers:: Operations on data buffers.
1457 @node Creating Data Buffers
1458 @section Creating Data Buffers
1459 @cindex data buffer, creation
1461 Data objects can be based on memory, files, or callback functions
1462 provided by the user. Not all operations are supported by all
1467 * Memory Based Data Buffers:: Creating memory based data buffers.
1468 * File Based Data Buffers:: Creating file based data buffers.
1469 * Callback Based Data Buffers:: Creating callback based data buffers.
1473 @node Memory Based Data Buffers
1474 @subsection Memory Based Data Buffers
1476 Memory based data objects store all data in allocated memory. This is
1477 convenient, but only practical for an amount of data that is a
1478 fraction of the available physical memory. The data has to be copied
1479 from its source and to its destination, which can often be avoided by
1480 using one of the other data object
1482 @deftypefun gpgme_error_t gpgme_data_new (@w{gpgme_data_t *@var{dh}})
1483 The function @code{gpgme_data_new} creates a new @code{gpgme_data_t}
1484 object and returns a handle for it in @var{dh}. The data object is
1485 memory based and initially empty.
1487 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1488 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1489 @var{dh} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1490 enough memory is available.
1493 @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}})
1494 The function @code{gpgme_data_new_from_mem} creates a new
1495 @code{gpgme_data_t} object and fills it with @var{size} bytes starting
1498 If @var{copy} is not zero, a private copy of the data is made. If
1499 @var{copy} is zero, the data is taken from the specified buffer as
1500 needed, and the user has to ensure that the buffer remains valid for
1501 the whole life span of the data object.
1503 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1504 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1505 @var{dh} or @var{buffer} is not a valid pointer, and
1506 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1509 @deftypefun gpgme_error_t gpgme_data_new_from_file (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}})
1510 The function @code{gpgme_data_new_from_file} creates a new
1511 @code{gpgme_data_t} object and fills it with the content of the file
1514 If @var{copy} is not zero, the whole file is read in at initialization
1515 time and the file is not used anymore after that. This is the only
1516 mode supported currently. Later, a value of zero for @var{copy} might
1517 cause all reads to be delayed until the data is needed, but this is
1518 not yet implemented.
1520 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1521 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1522 @var{dh} or @var{filename} is not a valid pointer,
1523 @code{GPG_ERR_NOT_IMPLEMENTED} if @var{code} is zero, and
1524 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1527 @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}})
1528 The function @code{gpgme_data_new_from_filepart} creates a new
1529 @code{gpgme_data_t} object and fills it with a part of the file specified
1530 by @var{filename} or @var{fp}.
1532 Exactly one of @var{filename} and @var{fp} must be non-zero, the other
1533 must be zero. The argument that is not zero specifies the file from
1534 which @var{length} bytes are read into the data object, starting from
1537 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1538 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1539 @var{dh} and exactly one of @var{filename} and @var{fp} is not a valid
1540 pointer, and @code{GPG_ERR_ENOMEM} if not enough memory is available.
1544 @node File Based Data Buffers
1545 @subsection File Based Data Buffers
1547 File based data objects operate directly on file descriptors or
1548 streams. Only a small amount of data is stored in core at any time,
1549 so the size of the data objects is not limited by @acronym{GPGME}.
1551 @deftypefun gpgme_error_t gpgme_data_new_from_fd (@w{gpgme_data_t *@var{dh}}, @w{int @var{fd}})
1552 The function @code{gpgme_data_new_from_fd} creates a new
1553 @code{gpgme_data_t} object and uses the file descriptor @var{fd} to read
1554 from (if used as an input data object) and write to (if used as an
1555 output data object).
1557 When using the data object as an input buffer, the function might read
1558 a bit more from the file descriptor than is actually needed by the
1559 crypto engine in the desired operation because of internal buffering.
1561 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1562 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1563 enough memory is available.
1566 @deftypefun gpgme_error_t gpgme_data_new_from_stream (@w{gpgme_data_t *@var{dh}}, @w{FILE *@var{stream}})
1567 The function @code{gpgme_data_new_from_stream} creates a new
1568 @code{gpgme_data_t} object and uses the I/O stream @var{stream} to read
1569 from (if used as an input data object) and write to (if used as an
1570 output data object).
1572 When using the data object as an input buffer, the function might read
1573 a bit more from the stream than is actually needed by the crypto
1574 engine in the desired operation because of internal buffering.
1576 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1577 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1578 enough memory is available.
1582 @node Callback Based Data Buffers
1583 @subsection Callback Based Data Buffers
1585 If neither memory nor file based data objects are a good fit for your
1586 application, you can implement the functions a data object provides
1587 yourself and create a data object from these callback functions.
1589 @deftp {Data type} {ssize_t (*gpgme_data_read_cb_t) (@w{void *@var{handle}}, @w{void @var{*buffer}}, @w{size_t @var{size}})}
1590 @tindex gpgme_data_read_cb_t
1591 The @code{gpgme_data_read_cb_t} type is the type of functions which
1592 @acronym{GPGME} calls if it wants to read data from a user-implemented
1593 data object. The function should read up to @var{size} bytes from the
1594 current read position into the space starting at @var{buffer}. The
1595 @var{handle} is provided by the user at data object creation time.
1597 The function should return the number of bytes read, 0 on EOF, and -1
1598 on error. If an error occurs, @var{errno} should be set to describe
1599 the type of the error.
1602 @deftp {Data type} {ssize_t (*gpgme_data_write_cb_t) (@w{void *@var{handle}}, @w{const void @var{*buffer}}, @w{size_t @var{size}})}
1603 @tindex gpgme_data_write_cb_t
1604 The @code{gpgme_data_write_cb_t} type is the type of functions which
1605 @acronym{GPGME} calls if it wants to write data to a user-implemented
1606 data object. The function should write up to @var{size} bytes to the
1607 current write position from the space starting at @var{buffer}. The
1608 @var{handle} is provided by the user at data object creation time.
1610 The function should return the number of bytes written, and -1 on
1611 error. If an error occurs, @var{errno} should be set to describe the
1615 @deftp {Data type} {off_t (*gpgme_data_seek_cb_t) (@w{void *@var{handle}}, @w{off_t @var{offset}}, @w{int @var{whence}})}
1616 @tindex gpgme_data_seek_cb_t
1617 The @code{gpgme_data_seek_cb_t} type is the type of functions which
1618 @acronym{GPGME} calls if it wants to change the current read/write
1619 position in a user-implemented data object, just like the @code{lseek}
1622 The function should return the new read/write position, and -1 on
1623 error. If an error occurs, @var{errno} should be set to describe the
1627 @deftp {Data type} {void (*gpgme_data_release_cb_t) (@w{void *@var{handle}})}
1628 @tindex gpgme_data_release_cb_t
1629 The @code{gpgme_data_release_cb_t} type is the type of functions which
1630 @acronym{GPGME} calls if it wants to destroy a user-implemented data
1631 object. The @var{handle} is provided by the user at data object
1635 @deftp {Data type} {struct gpgme_data_cbs}
1636 This structure is used to store the data callback interface functions
1637 described above. It has the following members:
1640 @item gpgme_data_read_cb_t read
1641 This is the function called by @acronym{GPGME} to read data from the
1642 data object. It is only required for input data object.
1644 @item gpgme_data_write_cb_t write
1645 This is the function called by @acronym{GPGME} to write data to the
1646 data object. It is only required for output data object.
1648 @item gpgme_data_seek_cb_t seek
1649 This is the function called by @acronym{GPGME} to change the current
1650 read/write pointer in the data object (if available). It is optional.
1652 @item gpgme_data_release_cb_t release
1653 This is the function called by @acronym{GPGME} to release a data
1654 object. It is optional.
1658 @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}})
1659 The function @code{gpgme_data_new_from_cbs} creates a new
1660 @code{gpgme_data_t} object and uses the user-provided callback functions
1661 to operate on the data object.
1663 The handle @var{handle} is passed as first argument to the callback
1664 functions. This can be used to identify this data object.
1666 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1667 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1668 enough memory is available.
1671 The following interface is deprecated and only provided for backward
1672 compatibility. Don't use it. It will be removed in a future version
1675 @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}})
1676 The function @code{gpgme_data_new_with_read_cb} creates a new
1677 @code{gpgme_data_t} object and uses the callback function @var{readfunc}
1678 to retrieve the data on demand. As the callback function can supply
1679 the data in any way it wants, this is the most flexible data type
1680 @acronym{GPGME} provides. However, it can not be used to write data.
1682 The callback function receives @var{hook_value} as its first argument
1683 whenever it is invoked. It should return up to @var{count} bytes in
1684 @var{buffer}, and return the number of bytes actually read in
1685 @var{nread}. It may return @code{0} in @var{nread} if no data is
1686 currently available. To indicate @code{EOF} the function should
1687 return with an error code of @code{-1} and set @var{nread} to
1688 @code{0}. The callback function may support to reset its internal
1689 read pointer if it is invoked with @var{buffer} and @var{nread} being
1690 @code{NULL} and @var{count} being @code{0}.
1692 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1693 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1694 @var{dh} or @var{readfunc} is not a valid pointer, and
1695 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1699 @node Destroying Data Buffers
1700 @section Destroying Data Buffers
1701 @cindex data buffer, destruction
1703 @deftypefun void gpgme_data_release (@w{gpgme_data_t @var{dh}})
1704 The function @code{gpgme_data_release} destroys the data object with
1705 the handle @var{dh}. It releases all associated resources that were
1706 not provided by the user in the first place.
1709 @deftypefun {char *} gpgme_data_release_and_get_mem (@w{gpgme_data_t @var{dh}}, @w{size_t *@var{length}})
1710 The function @code{gpgme_data_release_and_get_mem} is like
1711 @code{gpgme_data_release}, except that it returns the data buffer and
1712 its length that was provided by the object.
1714 The user has to release the buffer with @code{gpgme_free}. In case
1715 the user provided the data buffer in non-copy mode, a copy will be
1716 made for this purpose.
1718 In case an error returns, or there is no suitable data buffer that can
1719 be returned to the user, the function will return @code{NULL}.
1723 @deftypefun void gpgme_free (@w{void *@var{buffer}})
1724 The function @code{gpgme_free} releases the memory returned by
1725 @code{gpgme_data_release_and_get_mem}. It should be used instead of
1726 the system libraries @code{free} function in case different allocators
1727 are used in a single program.
1731 @node Manipulating Data Buffers
1732 @section Manipulating Data Buffers
1733 @cindex data buffer, manipulation
1735 Data buffers contain data and meta-data. The following operations can
1736 be used to manipulate both.
1740 * Data Buffer I/O Operations:: I/O operations on data buffers.
1741 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
1745 @node Data Buffer I/O Operations
1746 @subsection Data Buffer I/O Operations
1747 @cindex data buffer, I/O operations
1748 @cindex data buffer, read
1749 @cindex data buffer, write
1750 @cindex data buffer, seek
1752 @deftypefun ssize_t gpgme_data_read (@w{gpgme_data_t @var{dh}}, @w{void *@var{buffer}}, @w{size_t @var{length}})
1753 The function @code{gpgme_data_read} reads up to @var{length} bytes
1754 from the data object with the handle @var{dh} into the space starting
1757 If no error occurs, the actual amount read is returned. If the end of
1758 the data object is reached, the function returns 0.
1760 In all other cases, the function returns -1 and sets @var{errno}.
1763 @deftypefun ssize_t gpgme_data_write (@w{gpgme_data_t @var{dh}}, @w{const void *@var{buffer}}, @w{size_t @var{size}})
1764 The function @code{gpgme_data_write} writes up to @var{size} bytes
1765 starting from @var{buffer} into the data object with the handle
1766 @var{dh} at the current write position.
1768 The function returns the number of bytes actually written, or -1 if an
1769 error occurs. If an error occurs, @var{errno} is set.
1772 @deftypefun off_t gpgme_data_seek (@w{gpgme_data_t @var{dh}}, @w{off_t *@var{offset}}, @w{int @var{whence}})
1773 The function @code{gpgme_data_seek} changes the current read/write
1776 The @var{whence} argument specifies how the @var{offset} should be
1777 interpreted. It must be one of the following symbolic constants:
1781 Specifies that @var{whence} is a count of characters from the
1782 beginning of the data object.
1785 Specifies that @var{whence} is a count of characters from the current
1786 file position. This count may be positive or negative.
1789 Specifies that @var{whence} is a count of characters from the end of
1790 the data object. A negative count specifies a position within the
1791 current extent of the data object; a positive count specifies a
1792 position past the current end. If you set the position past the
1793 current end, and actually write data, you will extend the data object
1794 with zeros up to that position.
1797 If successful, the function returns the resulting file position,
1798 measured in bytes from the beginning of the data object. You can use
1799 this feature together with @code{SEEK_CUR} to read the current
1800 read/write position.
1802 If the function fails, -1 is returned and @var{errno} is set.
1805 The following function is deprecated and should not be used. It will
1806 be removed in a future version of @acronym{GPGME}.
1808 @deftypefun gpgme_error_t gpgme_data_rewind (@w{gpgme_data_t @var{dh}})
1809 The function @code{gpgme_data_rewind} is equivalent to:
1812 return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
1813 ? gpgme_error_from_errno (errno) : 0;
1820 @node Data Buffer Meta-Data
1821 @subsection Data Buffer Meta-Data
1822 @cindex data buffer, meta-data
1823 @cindex data buffer, file name
1824 @cindex data buffer, encoding
1826 @deftypefun {char *} gpgme_data_get_file_name (@w{gpgme_data_t @var{dh}})
1827 The function @code{gpgme_data_get_file_name} returns a pointer to a
1828 string containing the file name associated with the data object. The
1829 file name will be stored in the output when encrypting or signing the
1830 data and will be returned to the user when decrypting or verifying the
1833 If no error occurs, the string containing the file name is returned.
1834 Otherwise, @code{NULL} will be returned.
1838 @deftypefun gpgme_error_t gpgme_data_set_file_name (@w{gpgme_data_t @var{dh}}, @w{const char *@var{file_name}})
1839 The function @code{gpgme_data_set_file_name} sets the file name
1840 associated with the data object. The file name will be stored in the
1841 output when encrypting or signing the data and will be returned to the
1842 user when decrypting or verifying the output data.
1844 The function returns the error code @code{GPG_ERR_INV_VALUE} if
1845 @var{dh} is not a valid pointer and @code{GPG_ERR_ENOMEM} if not
1846 enough memory is available.
1850 @deftp {Data type} {enum gpgme_data_encoding_t}
1851 @tindex gpgme_data_encoding_t
1852 The @code{gpgme_data_encoding_t} type specifies the encoding of a
1853 @code{gpgme_data_t} object. This encoding is useful to give the backend
1854 a hint on the type of data. The following data types are available:
1857 @item GPGME_DATA_ENCODING_NONE
1858 This specifies that the encoding is not known. This is the default
1859 for a new data object. The backend will try its best to detect the
1860 encoding automatically.
1862 @item GPGME_DATA_ENCODING_BINARY
1863 This specifies that the data is encoding in binary form; i.e. there is
1864 no special encoding.
1866 @item GPGME_DATA_ENCODING_BASE64
1867 This specifies that the data is encoded using the Base-64 encoding
1868 scheme as used by @acronym{MIME} and other protocols.
1870 @item GPGME_DATA_ENCODING_ARMOR
1871 This specifies that the data is encoded in an armored form as used by
1876 @deftypefun gpgme_data_encoding_t gpgme_data_get_encoding (@w{gpgme_data_t @var{dh}})
1877 The function @code{gpgme_data_get_encoding} returns the encoding of
1878 the data object with the handle @var{dh}. If @var{dh} is not a valid
1879 pointer (e.g. @code{NULL}) @code{GPGME_DATA_ENCODING_NONE} is
1883 @deftypefun gpgme_error_t gpgme_data_set_encoding (@w{gpgme_data_t @var{dh}, gpgme_data_encoding_t @var{enc}})
1884 The function @code{gpgme_data_set_encoding} changes the encoding of
1885 the data object with the handle @var{dh} to @var{enc}.
1896 All cryptographic operations in @acronym{GPGME} are performed within a
1897 context, which contains the internal state of the operation as well as
1898 configuration parameters. By using several contexts you can run
1899 several cryptographic operations in parallel, with different
1902 @deftp {Data type} {gpgme_ctx_t}
1903 The @code{gpgme_ctx_t} type is a handle for a @acronym{GPGME} context,
1904 which is used to hold the configuration, status and result of
1905 cryptographic operations.
1909 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
1910 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
1911 * Context Attributes:: Setting properties of a context.
1912 * Key Management:: Managing keys with @acronym{GPGME}.
1913 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
1914 * Crypto Operations:: Using a context for cryptography.
1915 * Run Control:: Controlling how operations are run.
1919 @node Creating Contexts
1920 @section Creating Contexts
1921 @cindex context, creation
1923 @deftypefun gpgme_error_t gpgme_new (@w{gpgme_ctx_t *@var{ctx}})
1924 The function @code{gpgme_new} creates a new @code{gpgme_ctx_t} object
1925 and returns a handle for it in @var{ctx}.
1927 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1928 context was successfully created, @code{GPG_ERR_INV_VALUE} if
1929 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1930 enough memory is available.
1934 @node Destroying Contexts
1935 @section Destroying Contexts
1936 @cindex context, destruction
1938 @deftypefun void gpgme_release (@w{gpgme_ctx_t @var{ctx}})
1939 The function @code{gpgme_release} destroys the context with the handle
1940 @var{ctx} and releases all associated resources.
1944 @node Context Attributes
1945 @section Context Attributes
1946 @cindex context, attributes
1949 * Protocol Selection:: Selecting the protocol used by a context.
1950 * Crypto Engine:: Configuring the crypto engine.
1951 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
1952 * Text Mode:: Choosing canonical text mode.
1953 * Included Certificates:: Including a number of certificates.
1954 * Key Listing Mode:: Selecting key listing mode.
1955 * Passphrase Callback:: Getting the passphrase from the user.
1956 * Progress Meter Callback:: Being informed about the progress.
1957 * Locale:: Setting the locale of a context.
1961 @node Protocol Selection
1962 @subsection Protocol Selection
1963 @cindex context, selecting protocol
1964 @cindex protocol, selecting
1966 @deftypefun gpgme_error_t gpgme_set_protocol (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}})
1967 The function @code{gpgme_set_protocol} sets the protocol used within
1968 the context @var{ctx} to @var{proto}. All crypto operations will be
1969 performed by the crypto engine configured for that protocol.
1970 @xref{Protocols and Engines}.
1972 Setting the protocol with @code{gpgme_set_protocol} does not check if
1973 the crypto engine for that protocol is available and installed
1974 correctly. @xref{Engine Version Check}.
1976 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1977 protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if
1978 @var{protocol} is not a valid protocol.
1981 @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}})
1982 The function @code{gpgme_get_protocol} retrieves the protocol currently
1983 use with the context @var{ctx}.
1988 @subsection Crypto Engine
1989 @cindex context, configuring engine
1990 @cindex engine, configuration per context
1992 The following functions can be used to set and retrieve the
1993 configuration of the crypto engines of a specific context. The
1994 default can also be retrieved without any particular context.
1995 @xref{Engine Information}. The default can also be changed globally.
1996 @xref{Engine Configuration}.
1998 @deftypefun gpgme_engine_info_t gpgme_ctx_get_engine_info (@w{gpgme_ctx_t @var{ctx}})
1999 The function @code{gpgme_ctx_get_engine_info} returns a linked list of
2000 engine info structures. Each info structure describes the
2001 configuration of one configured backend, as used by the context
2004 The result is valid until the next invocation of
2005 @code{gpgme_ctx_set_engine_info} for this particular context.
2007 This function can not fail.
2010 @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}})
2011 The function @code{gpgme_ctx_set_engine_info} changes the
2012 configuration of the crypto engine implementing the protocol
2013 @var{proto} for the context @var{ctx}.
2015 @var{file_name} is the file name of the executable program
2016 implementing this protocol, and @var{home_dir} is the directory name
2017 of the configuration directory for this crypto engine. If
2018 @var{home_dir} is @code{NULL}, the engine's default will be used.
2020 Currently this function must be used before starting the first crypto
2021 operation. It is unspecified if and when the changes will take effect
2022 if the function is called after starting the first operation on the
2025 This function returns the error code @code{GPG_ERR_NO_ERROR} if
2026 successful, or an eror code on failure.
2030 @c FIXME: Unfortunately, using @acronym here breaks texi2dvi.
2032 @subsection @acronym{ASCII} Armor
2033 @cindex context, armor mode
2034 @cindex @acronym{ASCII} armor
2037 @deftypefun void gpgme_set_armor (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2038 The function @code{gpgme_set_armor} specifies if the output should be
2039 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
2042 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
2046 @deftypefun int gpgme_get_armor (@w{gpgme_ctx_t @var{ctx}})
2047 The function @code{gpgme_get_armor} returns 1 if the output is
2048 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
2049 not a valid pointer.
2054 @subsection Text Mode
2055 @cindex context, text mode
2057 @cindex canonical text mode
2059 @deftypefun void gpgme_set_textmode (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2060 The function @code{gpgme_set_textmode} specifies if canonical text mode
2061 should be used. By default, text mode is not used.
2063 Text mode is for example used for the RFC2015 signatures; note that
2064 the updated RFC 3156 mandates that the mail user agent does some
2065 preparations so that text mode is not needed anymore.
2067 This option is only relevant to the OpenPGP crypto engine, and ignored
2068 by all other engines.
2070 Canonical text mode is disabled if @var{yes} is zero, and enabled
2074 @deftypefun int gpgme_get_textmode (@w{gpgme_ctx_t @var{ctx}})
2075 The function @code{gpgme_get_textmode} returns 1 if canonical text
2076 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2081 @node Included Certificates
2082 @subsection Included Certificates
2083 @cindex certificates, included
2085 @deftypefun void gpgme_set_include_certs (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{nr_of_certs}})
2086 The function @code{gpgme_set_include_certs} specifies how many
2087 certificates should be included in an S/MIME signed message. By
2088 default, only the sender's certificate is included. The possible
2089 values of @var{nr_of_certs} are:
2092 @item GPGME_INCLUDE_CERTS_DEFAULT
2093 Fall back to the default of the crypto backend. This is the default
2096 Include all certificates except the root certificate.
2098 Include all certificates.
2100 Include no certificates.
2102 Include the sender's certificate only.
2104 Include the first n certificates of the certificates path, starting
2105 from the sender's certificate. The number @code{n} must be positive.
2108 Values of @var{nr_of_certs} smaller than -2 are undefined.
2110 This option is only relevant to the CMS crypto engine, and ignored by
2114 @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}})
2115 The function @code{gpgme_get_include_certs} returns the number of
2116 certificates to include into an S/MIME signed message.
2120 @node Key Listing Mode
2121 @subsection Key Listing Mode
2122 @cindex key listing mode
2123 @cindex key listing, mode of
2125 @deftypefun gpgme_error_t gpgme_set_keylist_mode (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_keylist_mode_t @var{mode}})
2126 The function @code{gpgme_set_keylist_mode} changes the default
2127 behaviour of the key listing functions. The value in @var{mode} is a
2128 bitwise-or combination of one or multiple of the following bit values:
2131 @item GPGME_KEYLIST_MODE_LOCAL
2132 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
2133 keyring should be searched for keys in the keylisting operation. This
2136 @item GPGME_KEYLIST_MODE_EXTERN
2137 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
2138 source should be searched for keys in the keylisting
2139 operation. The type of external source is dependant on the crypto
2140 engine used. For example, it can be a remote keyserver or LDAP
2143 @item GPGME_KEYLIST_MODE_SIGS
2144 The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key
2145 signatures should be included in the listed keys.
2147 @item GPGME_KEYLIST_MODE_SIG_NOTATIONS
2148 The @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} symbol specifies that the
2149 signature notations on key signatures should be included in the listed
2150 keys. This only works if @code{GPGME_KEYLIST_MODE_SIGS} is also
2153 @item GPGME_KEYLIST_MODE_VALIDATE
2154 The @code{GPGME_KEYLIST_MODE_VALIDATE} symbol specifies that the
2155 backend should do key or certificate validation and not just get the
2156 validity information from an internal cache. This might be an
2157 expensive operation and is in general not useful. Currently only
2158 implemented for the S/MIME backend and ignored for other backends.
2162 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
2163 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
2164 compatibility, you should get the current mode with
2165 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
2166 appropriate bits, and then using that calulcated value in the
2167 @code{gpgme_set_keylisting_mode} operation. This will leave all other
2168 bits in the mode value intact (in particular those that are not used
2169 in the current version of the library).
2171 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2172 mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx}
2173 is not a valid pointer or @var{mode} is not a valid mode.
2177 @deftypefun gpgme_keylist_mode_t gpgme_get_keylist_mode (@w{gpgme_ctx_t @var{ctx}})
2178 The function @code{gpgme_get_keylist_mode} returns the current key
2179 listing mode of the context @var{ctx}. This value can then be
2180 modified and used in a subsequent @code{gpgme_set_keylist_mode}
2181 operation to only affect the desired bits (and leave all others
2184 The function returns 0 if @var{ctx} is not a valid pointer, and the
2185 current mode otherwise. Note that 0 is not a valid mode value.
2189 @node Passphrase Callback
2190 @subsection Passphrase Callback
2191 @cindex callback, passphrase
2192 @cindex passphrase callback
2194 @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}})}
2195 @tindex gpgme_passphrase_cb_t
2196 The @code{gpgme_passphrase_cb_t} type is the type of functions usable as
2197 passphrase callback function.
2199 The argument @var{uid_hint} might contain a string that gives an
2200 indication for which user ID the passphrase is required. If this is
2201 not available, or not applicable (in the case of symmetric encryption,
2202 for example), @var{uid_hint} will be @code{NULL}.
2204 The argument @var{passphrase_info}, if not @code{NULL}, will give
2205 further information about the context in which the passphrase is
2206 required. This information is engine and operation specific.
2208 If this is the repeated attempt to get the passphrase, because
2209 previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
2212 The user must write the passphrase, followed by a newline character,
2213 to the file descriptor @var{fd}. If the user does not return 0
2214 indicating success, the user must at least write a newline character
2215 before returning from the callback.
2217 If an error occurs, return the corresponding @code{gpgme_error_t}
2218 value. You can use the error code @code{GPG_ERR_CANCELED} to abort
2219 the operation. Otherwise, return @code{0}.
2222 @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}})
2223 The function @code{gpgme_set_passphrase_cb} sets the function that is
2224 used when a passphrase needs to be provided by the user to
2225 @var{passfunc}. The function @var{passfunc} needs to implemented by
2226 the user, and whenever it is called, it is called with its first
2227 argument being @var{hook_value}. By default, no passphrase callback
2230 Not all crypto engines require this callback to retrieve the
2231 passphrase. It is better if the engine retrieves the passphrase from
2232 a trusted agent (a daemon process), rather than having each user to
2233 implement their own passphrase query. Some engines do not even
2234 support an external passphrase callback at all, in this case the error
2235 code @code{GPG_ERR_NOT_SUPPORTED} is returned.
2237 The user can disable the use of a passphrase callback function by
2238 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
2242 @deftypefun void gpgme_get_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t *@var{passfunc}}, @w{void **@var{hook_value}})
2243 The function @code{gpgme_get_passphrase_cb} returns the function that
2244 is used when a passphrase needs to be provided by the user in
2245 @var{*passfunc}, and the first argument for this function in
2246 @var{*hook_value}. If no passphrase callback is set, or @var{ctx} is
2247 not a valid pointer, @code{NULL} is returned in both variables.
2249 @var{passfunc} or @var{hook_value} can be @code{NULL}. In this case,
2250 the corresponding value will not be returned.
2254 @node Progress Meter Callback
2255 @subsection Progress Meter Callback
2256 @cindex callback, progress meter
2257 @cindex progress meter callback
2259 @deftp {Data type} {void (*gpgme_progress_cb_t)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
2260 @tindex gpgme_progress_cb_t
2261 The @code{gpgme_progress_cb_t} type is the type of functions usable as
2262 progress callback function.
2264 The arguments are specific to the crypto engine. More information
2265 about the progress information returned from the GnuPG engine can be
2266 found in the GnuPG source code in the file @file{doc/DETAILS} in the
2270 @deftypefun void gpgme_set_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t @var{progfunc}}, @w{void *@var{hook_value}})
2271 The function @code{gpgme_set_progress_cb} sets the function that is
2272 used when progress information about a cryptographic operation is
2273 available. The function @var{progfunc} needs to implemented by the
2274 user, and whenever it is called, it is called with its first argument
2275 being @var{hook_value}. By default, no progress callback function
2278 Setting a callback function allows an interactive program to display
2279 progress information about a long operation to the user.
2281 The user can disable the use of a progress callback function by
2282 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
2286 @deftypefun void gpgme_get_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t *@var{progfunc}}, @w{void **@var{hook_value}})
2287 The function @code{gpgme_get_progress_cb} returns the function that is
2288 used to inform the user about the progress made in @var{*progfunc},
2289 and the first argument for this function in @var{*hook_value}. If no
2290 progress callback is set, or @var{ctx} is not a valid pointer,
2291 @code{NULL} is returned in both variables.
2293 @var{progfunc} or @var{hook_value} can be @code{NULL}. In this case,
2294 the corresponding value will not be returned.
2300 @cindex locale, default
2301 @cindex locale, of a context
2303 A locale setting can be associated with a context. This locale is
2304 passed to the crypto engine, and used for applications like the PIN
2305 entry, which is displayed to the user when entering a passphrase is
2308 The default locale is used to initialize the locale setting of all
2309 contexts created afterwards.
2311 @deftypefun gpgme_error_t gpgme_set_locale (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{category}}, @w{const char *@var{value}})
2312 The function @code{gpgme_set_locale} sets the locale of the context
2313 @var{ctx}, or the default locale if @var{ctx} is a null pointer.
2315 The locale settings that should be changed are specified by
2316 @var{category}. Supported categories are @code{LC_CTYPE},
2317 @code{LC_MESSAGES}, and @code{LC_ALL}, which is a wildcard you can use
2318 if you want to change all the categories at once.
2320 The value to be used for the locale setting is @var{value}, which will
2321 be copied to @acronym{GPGME}'s internal data structures. @var{value}
2322 can be a null pointer, which disables setting the locale, and will
2323 make PIN entry and other applications use their default setting, which
2324 is usually not what you want.
2326 Note that the settings are only used if the application runs on a text
2327 terminal, and that the settings should fit the configuration of the
2328 output terminal. Normally, it is sufficient to initialize the default
2331 The function returns an error if not enough memory is available.
2335 @node Key Management
2336 @section Key Management
2337 @cindex key management
2339 Some of the cryptographic operations require that recipients or
2340 signers are specified. This is always done by specifying the
2341 respective keys that should be used for the operation. The following
2342 section describes how such keys can be selected and manipulated.
2344 @deftp {Data type} gpgme_sub_key_t
2345 The @code{gpgme_sub_key_t} type is a pointer to a subkey structure.
2346 Sub keys are one component of a @code{gpgme_key_t} object. In fact,
2347 subkeys are those parts that contains the real information about the
2348 individual cryptographic keys that belong to the same key object. One
2349 @code{gpgme_key_t} can contain several subkeys. The first subkey in
2350 the linked list is also called the primary key.
2352 The subkey structure has the following members:
2355 @item gpgme_sub_key_t next
2356 This is a pointer to the next subkey structure in the linked list, or
2357 @code{NULL} if this is the last element.
2359 @item unsigned int revoked : 1
2360 This is true if the subkey is revoked.
2362 @item unsigned int expired : 1
2363 This is true if the subkey is expired.
2365 @item unsigned int disabled : 1
2366 This is true if the subkey is disabled.
2368 @item unsigned int invalid : 1
2369 This is true if the subkey is invalid.
2371 @item unsigned int can_encrypt : 1
2372 This is true if the subkey can be used for encryption.
2374 @item unsigned int can_sign : 1
2375 This is true if the subkey can be used to create data signatures.
2377 @item unsigned int can_certify : 1
2378 This is true if the subkey can be used to create key certificates.
2380 @item unsigned int can_authenticate : 1
2381 This is true if the subkey can be used for authentication.
2383 @item unsigned int is_qualified : 1
2384 This is true if the subkey can be used for qualified signatures
2385 according to local government regulations.
2387 @item unsigned int secret : 1
2388 This is true if the subkey is a secret key.
2390 @item gpgme_pubkey_algo_t pubkey_algo
2391 This is the public key algorithm supported by this subkey.
2393 @item unsigned int length
2394 This is the length of the subkey (in bits).
2397 This is the key ID of the subkey in hexadecimal digits.
2400 This is the fingerprint of the subkey in hexadecimal digits, if
2401 available. This is usually only available for the primary key.
2403 @item long int timestamp
2404 This is the creation timestamp of the subkey. This is -1 if the
2405 timestamp is invalid, and 0 if it is not available.
2407 @item long int expires
2408 This is the expiration timestamp of the subkey, or 0 if the subkey
2413 @deftp {Data type} gpgme_key_sig_t
2414 The @code{gpgme_key_sig_t} type is a pointer to a key signature structure.
2415 Key signatures are one component of a @code{gpgme_key_t} object, and
2416 validate user IDs on the key.
2418 The signatures on a key are only available if the key was retrieved
2419 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
2420 enabled, because it can be expensive to retrieve all signatures of a
2423 The signature notations on a key signature are only available if the
2424 key was retrieved via a listing operation with the
2425 @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} mode enabled, because it can
2426 be expensive to retrieve all signature notations.
2428 The key signature structure has the following members:
2431 @item gpgme_key_sig_t next
2432 This is a pointer to the next key signature structure in the linked
2433 list, or @code{NULL} if this is the last element.
2435 @item unsigned int revoked : 1
2436 This is true if the key signature is a revocation signature.
2438 @item unsigned int expired : 1
2439 This is true if the key signature is expired.
2441 @item unsigned int invalid : 1
2442 This is true if the key signature is invalid.
2444 @item unsigned int exportable : 1
2445 This is true if the key signature is exportable.
2447 @item gpgme_pubkey_algo_t pubkey_algo
2448 This is the public key algorithm used to create the signature.
2451 This is the key ID of the key (in hexadecimal digits) used to create
2454 @item long int timestamp
2455 This is the creation timestamp of the key signature. This is -1 if
2456 the timestamp is invalid, and 0 if it is not available.
2458 @item long int expires
2459 This is the expiration timestamp of the key signature, or 0 if the key
2460 signature does not expire.
2462 @item gpgme_error_t status
2463 This is the status of the signature and has the same meaning as the
2464 member of the same name in a @code{gpgme_signature_t} object.
2466 @item unsigned int sig_class
2467 This specifies the signature class of the key signature. The meaning
2468 is specific to the crypto engine.
2471 This is the main user ID of the key used to create the signature.
2474 This is the name component of @code{uid}, if available.
2477 This is the comment component of @code{uid}, if available.
2480 This is the email component of @code{uid}, if available.
2482 @item gpgme_sig_notation_t notations
2483 This is a linked list with the notation data and policy URLs.
2487 @deftp {Data type} gpgme_user_id_t
2488 A user ID is a component of a @code{gpgme_key_t} object. One key can
2489 have many user IDs. The first one in the list is the main (or
2492 The user ID structure has the following members.
2495 @item gpgme_user_id_t next
2496 This is a pointer to the next user ID structure in the linked list, or
2497 @code{NULL} if this is the last element.
2499 @item unsigned int revoked : 1
2500 This is true if the user ID is revoked.
2502 @item unsigned int invalid : 1
2503 This is true if the user ID is invalid.
2505 @item gpgme_validity_t validity
2506 This specifies the validity of the user ID.
2509 This is the user ID string.
2512 This is the name component of @code{uid}, if available.
2515 This is the comment component of @code{uid}, if available.
2518 This is the email component of @code{uid}, if available.
2520 @item gpgme_key_sig_t signatures
2521 This is a linked list with the signatures on this user ID.
2525 @deftp {Data type} gpgme_key_t
2526 The @code{gpgme_key_t} type is a pointer to a key object. It has the
2530 @item gpgme_keylist_mode_t keylist_mode
2531 The keylist mode that was active when the key was retrieved.
2533 @item unsigned int revoked : 1
2534 This is true if the key is revoked.
2536 @item unsigned int expired : 1
2537 This is true if the key is expired.
2539 @item unsigned int disabled : 1
2540 This is true if the key is disabled.
2542 @item unsigned int invalid : 1
2543 This is true if the key is invalid. This might have several reasons,
2544 for a example for the S/MIME backend, it will be set in during key
2545 listsing if the key could not be validated due to a missing
2546 certificates or unmatched policies.
2548 @item unsigned int can_encrypt : 1
2549 This is true if the key (ie one of its subkeys) can be used for
2552 @item unsigned int can_sign : 1
2553 This is true if the key (ie one of its subkeys) can be used to create
2556 @item unsigned int can_certify : 1
2557 This is true if the key (ie one of its subkeys) can be used to create
2560 @item unsigned int can_authenticate : 1
2561 This is true if the key (ie one of its subkeys) can be used for
2564 @item unsigned int is_qualified : 1
2565 This is true if the key can be used for qualified signatures according
2566 to local government regulations.
2568 @item unsigned int secret : 1
2569 This is true if the key is a secret key.
2571 @item gpgme_protocol_t protocol
2572 This is the protocol supported by this key.
2574 @item char *issuer_serial
2575 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2578 @item char *issuer_name
2579 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2582 @item char *chain_id
2583 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2584 chain ID, which can be used to built the certificate chain.
2586 @item gpgme_validity_t owner_trust
2587 If @code{protocol} is @code{GPGME_PROTOCOL_OpenPGP}, then this is the
2590 @item gpgme_sub_key_t subkeys
2591 This is a linked list with the subkeys of the key. The first subkey
2592 in the list is the primary key and usually available.
2594 @item gpgme_user_id_t uids
2595 This is a linked list with the user IDs of the key. The first user ID
2596 in the list is the main (or primary) user ID.
2601 * Listing Keys:: Browsing the list of available keys.
2602 * Information About Keys:: Requesting detailed information about keys.
2603 * Key Signatures:: Listing the signatures on a key.
2604 * Manipulating Keys:: Operations on keys.
2605 * Generating Keys:: Creating new key pairs.
2606 * Exporting Keys:: Retrieving key data from the key ring.
2607 * Importing Keys:: Adding keys to the key ring.
2608 * Deleting Keys:: Removing keys from the key ring.
2613 @subsection Listing Keys
2614 @cindex listing keys
2616 @cindex key listing, start
2617 @cindex key ring, list
2618 @cindex key ring, search
2620 @deftypefun gpgme_error_t gpgme_op_keylist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
2621 The function @code{gpgme_op_keylist_start} initiates a key listing
2622 operation inside the context @var{ctx}. It sets everything up so that
2623 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
2626 If @var{pattern} is @code{NULL}, all available keys are returned.
2627 Otherwise, @var{pattern} contains an engine specific expression that
2628 is used to limit the list to all keys matching the pattern. Note that
2629 the total length of the pattern is restricted to an engine-specific
2630 maximum (a couple of hundred characters are usually accepted). The
2631 pattern should be used to restrict the search to a certain common name
2632 or user, not to list many specific keys at once by listing their
2633 fingerprints or key IDs.
2635 If @var{secret_only} is not @code{0}, the list is restricted to secret
2638 The context will be busy until either all keys are received (and
2639 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2640 @code{gpgme_op_keylist_end} is called to finish the operation.
2642 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2643 @var{ctx} is not a valid pointer, and passes through any errors that
2644 are reported by the crypto engine support routines.
2647 @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}})
2648 The function @code{gpgme_op_keylist_ext_start} initiates an extended
2649 key listing operation inside the context @var{ctx}. It sets
2650 everything up so that subsequent invocations of
2651 @code{gpgme_op_keylist_next} return the keys in the list.
2653 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
2654 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
2655 array of strings that are used to limit the list to all keys matching
2656 at least one of the patterns verbatim. Note that the total length of
2657 all patterns is restricted to an engine-specific maximum (the exact
2658 limit also depends on the number of patterns and amount of quoting
2659 required, but a couple of hundred characters are usually accepted).
2660 Patterns should be used to restrict the search to a certain common
2661 name or user, not to list many specific keys at once by listing their
2662 fingerprints or key IDs.
2664 If @var{secret_only} is not @code{0}, the list is restricted to secret
2667 The value of @var{reserved} must be @code{0}.
2669 The context will be busy until either all keys are received (and
2670 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2671 @code{gpgme_op_keylist_end} is called to finish the operation.
2673 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2674 @var{ctx} is not a valid pointer, and passes through any errors that
2675 are reported by the crypto engine support routines.
2678 @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}})
2679 The function @code{gpgme_op_keylist_next} returns the next key in the
2680 list created by a previous @code{gpgme_op_keylist_start} operation in
2681 the context @var{ctx}. The key will have one reference for the user.
2682 @xref{Manipulating Keys}.
2684 This is the only way to get at @code{gpgme_key_t} objects in
2687 If the last key in the list has already been returned,
2688 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}.
2690 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2691 @var{ctx} or @var{r_key} is not a valid pointer, and
2692 @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation.
2695 @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}})
2696 The function @code{gpgme_op_keylist_next} ends a pending key list
2697 operation in the context @var{ctx}.
2699 After the operation completed successfully, the result of the key
2700 listing operation can be retrieved with
2701 @code{gpgme_op_keylist_result}.
2703 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2704 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
2705 time during the operation there was not enough memory available.
2708 The following example illustrates how all keys containing a certain
2709 string (@code{g10code}) can be listed with their key ID and the name
2710 and e-mail address of the main user ID:
2714 gpgme_error_t err = gpgme_new (&ctx);
2718 err = gpgme_op_keylist_start (ctx, "g10code", 0);
2721 err = gpgme_op_keylist_next (ctx, &key);
2724 printf ("%s: %s <%s>\n", key->keyid, key->name, key->email);
2725 gpgme_key_release (key);
2727 gpgme_release (ctx);
2729 if (gpg_err_code (err) != GPG_ERR_EOF)
2731 fprintf (stderr, "%s: can not list keys: %s\n",
2732 argv[0], gpgme_strerror (err));
2737 @deftp {Data type} {gpgme_keylist_result_t}
2738 This is a pointer to a structure used to store the result of a
2739 @code{gpgme_op_keylist_*} operation. After successfully ending a key
2740 listing operation, you can retrieve the pointer to the result with
2741 @code{gpgme_op_keylist_result}. The structure contains the following
2745 @item unsigned int truncated : 1
2746 This is true if the crypto backend had to truncate the result, and
2747 less than the desired keys could be listed.
2751 @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}})
2752 The function @code{gpgme_op_keylist_result} returns a
2753 @code{gpgme_keylist_result_t} pointer to a structure holding the
2754 result of a @code{gpgme_op_keylist_*} operation. The pointer is only
2755 valid if the last operation on the context was a key listing
2756 operation, and if this operation finished successfully. The returned
2757 pointer is only valid until the next operation is started on the
2761 In a simple program, for which a blocking operation is acceptable, the
2762 following function can be used to retrieve a single key.
2764 @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}})
2765 The function @code{gpgme_get_key} gets the key with the fingerprint
2766 (or key ID) @var{fpr} from the crypto backend and return it in
2767 @var{r_key}. If @var{secret} is true, get the secret key. The
2768 currently active keylist mode is used to retrieve the key. The key
2769 will have one reference for the user.
2771 If the key is not found in the keyring, @code{gpgme_get_key} returns
2772 the error code @code{GPG_ERR_NO_ERROR} and *@var{r_key} will be set to
2775 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2776 @var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a
2777 fingerprint or key ID, @code{GPG_ERR_AMBIGUOUS_NAME} if the key ID was
2778 not a unique specifier for a key, and @code{GPG_ERR_ENOMEM} if at some
2779 time during the operation there was not enough memory available.
2783 @node Information About Keys
2784 @subsection Information About Keys
2785 @cindex key, information about
2786 @cindex key, attributes
2787 @cindex attributes, of a key
2789 Please see the beginning of this section for more information about
2790 @code{gpgme_key_t} objects.
2792 @deftp {Data type} gpgme_validity_t
2793 The @code{gpgme_validity_t} type is used to specify the validity of a user ID
2794 in a key. The following validities are defined:
2797 @item GPGME_VALIDITY_UNKNOWN
2798 The user ID is of unknown validity. The string representation of this
2801 @item GPGME_VALIDITY_UNDEFINED
2802 The validity of the user ID is undefined. The string representation of this
2805 @item GPGME_VALIDITY_NEVER
2806 The user ID is never valid. The string representation of this
2809 @item GPGME_VALIDITY_MARGINAL
2810 The user ID is marginally valid. The string representation of this
2813 @item GPGME_VALIDITY_FULL
2814 The user ID is fully valid. The string representation of this
2817 @item GPGME_VALIDITY_ULTIMATE
2818 The user ID is ultimately valid. The string representation of this
2824 The following interfaces are deprecated and only provided for backward
2825 compatibility. Don't use them. They will be removed in a future
2826 version of @acronym{GPGME}.
2828 @deftp {Data type} gpgme_attr_t
2829 The @code{gpgme_attr_t} type is used to specify a key or trust item
2830 attribute. The following attributes are defined:
2833 @item GPGME_ATTR_KEYID
2834 This is the key ID of a sub key. It is representable as a string.
2836 For trust items, the trust item refers to the key with this ID.
2838 @item GPGME_ATTR_FPR
2839 This is the fingerprint of a sub key. It is representable as a
2842 @item GPGME_ATTR_ALGO
2843 This is the crypto algorithm for which the sub key can be used. It
2844 is representable as a string and as a number. The numbers correspond
2845 to the @code{enum gcry_pk_algos} values in the gcrypt library.
2847 @item GPGME_ATTR_LEN
2848 This is the key length of a sub key. It is representable as a
2851 @item GPGME_ATTR_CREATED
2852 This is the timestamp at creation time of a sub key. It is
2853 representable as a number.
2855 @item GPGME_ATTR_EXPIRE
2856 This is the expiration time of a sub key. It is representable as a
2859 @item GPGME_ATTR_OTRUST
2860 XXX FIXME (also for trust items)
2862 @item GPGME_ATTR_USERID
2863 This is a user ID. There can be more than one user IDs in a
2864 @var{gpgme_key_t} object. The first one (with index 0) is the primary
2865 user ID. The user ID is representable as a number.
2867 For trust items, this is the user ID associated with this trust item.
2869 @item GPGME_ATTR_NAME
2870 This is the name belonging to a user ID. It is representable as a string.
2872 @item GPGME_ATTR_EMAIL
2873 This is the email address belonging to a user ID. It is representable
2876 @item GPGME_ATTR_COMMENT
2877 This is the comment belonging to a user ID. It is representable as a
2880 @item GPGME_ATTR_VALIDITY
2881 This is the validity belonging to a user ID. It is representable as a
2882 string and as a number. See below for a list of available validities.
2884 For trust items, this is the validity that is associated with this
2887 @item GPGME_ATTR_UID_REVOKED
2888 This specifies if a user ID is revoked. It is representable as a
2889 number, and is @code{1} if the user ID is revoked, and @code{0}
2892 @item GPGME_ATTR_UID_INVALID
2893 This specifies if a user ID is invalid. It is representable as a
2894 number, and is @code{1} if the user ID is invalid, and @code{0}
2897 @item GPGME_ATTR_LEVEL
2898 This is the trust level of a trust item.
2900 @item GPGME_ATTR_TYPE
2901 This returns information about the type of key. For the string function
2902 this will eother be "PGP" or "X.509". The integer function returns 0
2903 for PGP and 1 for X.509. It is also used for the type of a trust item.
2905 @item GPGME_ATTR_IS_SECRET
2906 This specifies if the key is a secret key. It is representable as a
2907 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
2909 @item GPGME_ATTR_KEY_REVOKED
2910 This specifies if a sub key is revoked. It is representable as a
2911 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
2913 @item GPGME_ATTR_KEY_INVALID
2914 This specifies if a sub key is invalid. It is representable as a
2915 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
2917 @item GPGME_ATTR_KEY_EXPIRED
2918 This specifies if a sub key is expired. It is representable as a
2919 number, and is @code{1} if the key is expired, and @code{0} otherwise.
2921 @item GPGME_ATTR_KEY_DISABLED
2922 This specifies if a sub key is disabled. It is representable as a
2923 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
2925 @item GPGME_ATTR_KEY_CAPS
2926 This is a description of the capabilities of a sub key. It is
2927 representable as a string. The string contains the letter ``e'' if
2928 the key can be used for encryption, ``s'' if the key can be used for
2929 signatures, and ``c'' if the key can be used for certifications.
2931 @item GPGME_ATTR_CAN_ENCRYPT
2932 This specifies if a sub key can be used for encryption. It is
2933 representable as a number, and is @code{1} if the sub key can be used
2934 for encryption, and @code{0} otherwise.
2936 @item GPGME_ATTR_CAN_SIGN
2937 This specifies if a sub key can be used to create data signatures. It
2938 is representable as a number, and is @code{1} if the sub key can be
2939 used for signatures, and @code{0} otherwise.
2941 @item GPGME_ATTR_CAN_CERTIFY
2942 This specifies if a sub key can be used to create key certificates.
2943 It is representable as a number, and is @code{1} if the sub key can be
2944 used for certifications, and @code{0} otherwise.
2946 @item GPGME_ATTR_SERIAL
2947 The X.509 issuer serial attribute of the key. It is representable as
2950 @item GPGME_ATTR_ISSUE
2951 The X.509 issuer name attribute of the key. It is representable as a
2954 @item GPGME_ATTR_CHAINID
2955 The X.509 chain ID can be used to build the certification chain. It
2956 is representable as a string.
2960 @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}})
2961 The function @code{gpgme_key_get_string_attr} returns the value of the
2962 string-representable attribute @var{what} of key @var{key}. If the
2963 attribute is an attribute of a sub key or an user ID, @var{idx}
2964 specifies the sub key or user ID of which the attribute value is
2965 returned. The argument @var{reserved} is reserved for later use and
2966 should be @code{NULL}.
2968 The string returned is only valid as long as the key is valid.
2970 The function returns @code{0} if an attribute can't be returned as a
2971 string, @var{key} is not a valid pointer, @var{idx} out of range,
2972 or @var{reserved} not @code{NULL}.
2975 @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}})
2976 The function @code{gpgme_key_get_ulong_attr} returns the value of the
2977 number-representable attribute @var{what} of key @var{key}. If the
2978 attribute is an attribute of a sub key or an user ID, @var{idx}
2979 specifies the sub key or user ID of which the attribute value is
2980 returned. The argument @var{reserved} is reserved for later use and
2981 should be @code{NULL}.
2983 The function returns @code{0} if the attribute can't be returned as a
2984 number, @var{key} is not a valid pointer, @var{idx} out of range, or
2985 @var{reserved} not @code{NULL}.
2989 @node Key Signatures
2990 @subsection Key Signatures
2991 @cindex key, signatures
2992 @cindex signatures, on a key
2994 The following interfaces are deprecated and only provided for backward
2995 compatibility. Don't use them. They will be removed in a future
2996 version of @acronym{GPGME}.
2998 The signatures on a key are only available if the key was retrieved
2999 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
3000 enabled, because it is expensive to retrieve all signatures of a key.
3002 So, before using the below interfaces to retrieve the signatures on a
3003 key, you have to make sure that the key was listed with signatures
3004 enabled. One convenient, but blocking, way to do this is to use the
3005 function @code{gpgme_get_key}.
3007 @deftp {Data type} gpgme_attr_t
3008 The @code{gpgme_attr_t} type is used to specify a key signature
3009 attribute. The following attributes are defined:
3012 @item GPGME_ATTR_KEYID
3013 This is the key ID of the key which was used for the signature. It is
3014 representable as a string.
3016 @item GPGME_ATTR_ALGO
3017 This is the crypto algorithm used to create the signature. It is
3018 representable as a string and as a number. The numbers correspond to
3019 the @code{enum gcry_pk_algos} values in the gcrypt library.
3021 @item GPGME_ATTR_CREATED
3022 This is the timestamp at creation time of the signature. It is
3023 representable as a number.
3025 @item GPGME_ATTR_EXPIRE
3026 This is the expiration time of the signature. It is representable as
3029 @item GPGME_ATTR_USERID
3030 This is the user ID associated with the signing key. The user ID is
3031 representable as a number.
3033 @item GPGME_ATTR_NAME
3034 This is the name belonging to a user ID. It is representable as a string.
3036 @item GPGME_ATTR_EMAIL
3037 This is the email address belonging to a user ID. It is representable
3040 @item GPGME_ATTR_COMMENT
3041 This is the comment belonging to a user ID. It is representable as a
3044 @item GPGME_ATTR_KEY_REVOKED
3045 This specifies if a key signature is a revocation signature. It is
3046 representable as a number, and is @code{1} if the key is revoked, and
3049 @c @item GPGME_ATTR_KEY_EXPIRED
3050 @c This specifies if a key signature is expired. It is representable as
3051 @c a number, and is @code{1} if the key is revoked, and @code{0}
3054 @item GPGME_ATTR_SIG_CLASS
3055 This specifies the signature class of a key signature. It is
3056 representable as a number. The meaning is specific to the crypto
3059 @item GPGME_ATTR_SIG_CLASS
3060 This specifies the signature class of a key signature. It is
3061 representable as a number. The meaning is specific to the crypto
3064 @item GPGME_ATTR_SIG_STATUS
3065 This is the same value as returned by @code{gpgme_get_sig_status}.
3069 @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}})
3070 The function @code{gpgme_key_sig_get_string_attr} returns the value of
3071 the string-representable attribute @var{what} of the signature
3072 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3073 argument @var{reserved} is reserved for later use and should be
3076 The string returned is only valid as long as the key is valid.
3078 The function returns @code{0} if an attribute can't be returned as a
3079 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3080 out of range, or @var{reserved} not @code{NULL}.
3083 @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}})
3084 The function @code{gpgme_key_sig_get_ulong_attr} returns the value of
3085 the number-representable attribute @var{what} of the signature
3086 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3087 argument @var{reserved} is reserved for later use and should be
3090 The function returns @code{0} if an attribute can't be returned as a
3091 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3092 out of range, or @var{reserved} not @code{NULL}.
3096 @node Manipulating Keys
3097 @subsection Manipulating Keys
3098 @cindex key, manipulation
3100 @deftypefun void gpgme_key_ref (@w{gpgme_key_t @var{key}})
3101 The function @code{gpgme_key_ref} acquires an additional reference for
3105 @deftypefun void gpgme_key_unref (@w{gpgme_key_t @var{key}})
3106 The function @code{gpgme_key_unref} releases a reference for the key
3107 @var{key}. If this was the last reference, the key will be destroyed
3108 and all resources associated to it will be released.
3112 The following interface is deprecated and only provided for backward
3113 compatibility. Don't use it. It will be removed in a future version
3116 @deftypefun void gpgme_key_release (@w{gpgme_key_t @var{key}})
3117 The function @code{gpgme_key_release} is equivalent to
3118 @code{gpgme_key_unref}.
3122 @node Generating Keys
3123 @subsection Generating Keys
3124 @cindex key, creation
3125 @cindex key ring, add
3127 @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}})
3128 The function @code{gpgme_op_genkey} generates a new key pair in the
3129 context @var{ctx}. The meaning of @var{public} and @var{secret}
3130 depends on the crypto backend.
3132 GnuPG does not support @var{public} and @var{secret}, they should be
3133 @code{NULL}. GnuPG will generate a key pair and add it to the
3134 standard key ring. The fingerprint of the generated key is available
3135 with @code{gpgme_op_genkey_result}.
3137 GpgSM requires @var{public} to be a writable data object. GpgSM will
3138 generate a secret key (which will be stored by @command{gpg-agent},
3139 and return a certificate request in @var{public}, which then needs to
3140 be signed by the certification authority and imported before it can be
3141 used. GpgSM does not make the fingerprint available.
3143 The argument @var{parms} specifies parameters for the key in an XML
3144 string. The details about the format of @var{parms} are specific to
3145 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
3149 <GnupgKeyParms format="internal">
3154 Name-Real: Joe Tester
3155 Name-Comment: with stupid passphrase
3156 Name-Email: joe@@foo.bar
3162 Here is an example for GpgSM as the crypto engine:
3165 <GnupgKeyParms format="internal">
3168 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3169 Name-Email: joe@@foo.bar
3173 Strings should be given in UTF-8 encoding. The only format supported
3174 for now is ``internal''. The content of the @code{GnupgKeyParms}
3175 container is passed verbatim to the crypto backend. Control
3176 statements are not allowed.
3178 After the operation completed successfully, the result can be
3179 retrieved with @code{gpgme_op_genkey_result}.
3181 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3182 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3183 @var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if
3184 @var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL}
3185 if no key was created by the backend.
3188 @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}})
3189 The function @code{gpgme_op_genkey_start} initiates a
3190 @code{gpgme_op_genkey} operation. It can be completed by calling
3191 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3193 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3194 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3195 @var{parms} is not a valid XML string, and
3196 @code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not
3200 @deftp {Data type} {gpgme_genkey_result_t}
3201 This is a pointer to a structure used to store the result of a
3202 @code{gpgme_op_genkey} operation. After successfully generating a
3203 key, you can retrieve the pointer to the result with
3204 @code{gpgme_op_genkey_result}. The structure contains the following
3208 @item unsigned int primary : 1
3209 This is a flag that is set to 1 if a primary key was created and to 0
3212 @item unsigned int sub : 1
3213 This is a flag that is set to 1 if a subkey was created and to 0
3217 This is the fingerprint of the key that was created. If both a
3218 primary and a sub key were generated, the fingerprint of the primary
3219 key will be returned. If the crypto engine does not provide the
3220 fingerprint, @code{fpr} will be a null pointer.
3224 @deftypefun gpgme_genkey_result_t gpgme_op_genkey_result (@w{gpgme_ctx_t @var{ctx}})
3225 The function @code{gpgme_op_genkey_result} returns a
3226 @code{gpgme_genkey_result_t} pointer to a structure holding the result of
3227 a @code{gpgme_op_genkey} operation. The pointer is only valid if the
3228 last operation on the context was a @code{gpgme_op_genkey} or
3229 @code{gpgme_op_genkey_start} operation, and if this operation finished
3230 successfully. The returned pointer is only valid until the next
3231 operation is started on the context.
3235 @node Exporting Keys
3236 @subsection Exporting Keys
3238 @cindex key ring, export from
3240 @deftypefun gpgme_error_t gpgme_op_export (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}})
3241 The function @code{gpgme_op_export} extracts public keys and returns
3242 them in the data buffer @var{keydata}. The output format of the key
3243 data returned is determined by the @acronym{ASCII} armor attribute set
3244 for the context @var{ctx}.
3246 If @var{pattern} is @code{NULL}, all available keys are returned.
3247 Otherwise, @var{pattern} contains an engine specific expression that
3248 is used to limit the list to all keys matching the pattern.
3250 @var{reserved} is reserved for future use and must be @code{0}.
3252 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3253 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3254 @var{keydata} is not a valid empty data buffer, and passes through any
3255 errors that are reported by the crypto engine support routines.
3258 @deftypefun gpgme_error_t gpgme_op_export_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}})
3259 The function @code{gpgme_op_export_start} initiates a
3260 @code{gpgme_op_export} operation. It can be completed by calling
3261 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3263 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3264 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3265 if @var{keydata} is not a valid empty data buffer.
3268 @deftypefun gpgme_error_t gpgme_op_export_ext (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}})
3269 The function @code{gpgme_op_export} extracts public keys and returns
3270 them in the data buffer @var{keydata}. The output format of the key
3271 data returned is determined by the @acronym{ASCII} armor attribute set
3272 for the context @var{ctx}.
3274 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3275 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3276 array of strings that are used to limit the list to all keys matching
3277 at least one of the patterns verbatim.
3279 @var{reserved} is reserved for future use and must be @code{0}.
3281 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3282 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3283 @var{keydata} is not a valid empty data buffer, and passes through any
3284 errors that are reported by the crypto engine support routines.
3287 @deftypefun gpgme_error_t gpgme_op_export_ext_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}})
3288 The function @code{gpgme_op_export_ext_start} initiates a
3289 @code{gpgme_op_export_ext} operation. It can be completed by calling
3290 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3292 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3293 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3294 if @var{keydata} is not a valid empty data buffer.
3298 @node Importing Keys
3299 @subsection Importing Keys
3301 @cindex key ring, import to
3303 @deftypefun gpgme_error_t gpgme_op_import (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3304 The function @code{gpgme_op_import} adds the keys in the data buffer
3305 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
3306 The format of @var{keydata} can be @acronym{ASCII} armored, for example,
3307 but the details are specific to the crypto engine.
3309 After the operation completed successfully, the result can be
3310 retrieved with @code{gpgme_op_import_result}.
3312 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3313 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3314 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3315 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3318 @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3319 The function @code{gpgme_op_import_start} initiates a
3320 @code{gpgme_op_import} operation. It can be completed by calling
3321 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3323 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3324 import could be started successfully, @code{GPG_ERR_INV_VALUE} if
3325 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3326 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3329 @deftp {Data type} {gpgme_import_status_t}
3330 This is a pointer to a structure used to store a part of the result of
3331 a @code{gpgme_op_import} operation. For each considered key one
3332 status is added that contains information about the result of the
3333 import. The structure contains the following members:
3336 @item gpgme_import_status_t next
3337 This is a pointer to the next status structure in the linked list, or
3338 @code{NULL} if this is the last element.
3341 This is the fingerprint of the key that was considered.
3343 @item gpgme_error_t result
3344 If the import was not successful, this is the error value that caused
3345 the import to fail. Otherwise the error code is
3346 @code{GPG_ERR_NO_ERROR}.
3348 @item unsigned int status
3349 This is a bit-wise OR of the following flags that give more
3350 information about what part of the key was imported. If the key was
3351 already known, this might be 0.
3354 @item GPGME_IMPORT_NEW
3357 @item GPGME_IMPORT_UID
3358 The key contained new user IDs.
3360 @item GPGME_IMPORT_SIG
3361 The key contained new signatures.
3363 @item GPGME_IMPORT_SUBKEY
3364 The key contained new sub keys.
3366 @item GPGME_IMPORT_SECRET
3367 The key contained a secret key.
3372 @deftp {Data type} {gpgme_import_result_t}
3373 This is a pointer to a structure used to store the result of a
3374 @code{gpgme_op_import} operation. After a successful import
3375 operation, you can retrieve the pointer to the result with
3376 @code{gpgme_op_import_result}. The structure contains the following
3380 @item int considered
3381 The total number of considered keys.
3383 @item int no_user_id
3384 The number of keys without user ID.
3387 The total number of imported keys.
3390 The number of imported RSA keys.
3393 The number of unchanged keys.
3396 The number of new user IDs.
3399 The number of new sub keys.
3401 @item new_signatures
3402 The number of new signatures.
3404 @item new_revocations
3405 The number of new revocations.
3408 The total number of secret keys read.
3410 @item secret_imported
3411 The number of imported secret keys.
3413 @item secret_unchanged
3414 The number of unchanged secret keys.
3417 The number of keys not imported.
3419 @item gpgme_import_status_t imports
3420 A list of gpgme_import_status_t objects which contain more information
3421 about the keys for which an import was attempted.
3425 @deftypefun gpgme_import_result_t gpgme_op_import_result (@w{gpgme_ctx_t @var{ctx}})
3426 The function @code{gpgme_op_import_result} returns a
3427 @code{gpgme_import_result_t} pointer to a structure holding the result
3428 of a @code{gpgme_op_import} operation. The pointer is only valid if
3429 the last operation on the context was a @code{gpgme_op_import} or
3430 @code{gpgme_op_import_start} operation, and if this operation finished
3431 successfully. The returned pointer is only valid until the next
3432 operation is started on the context.
3435 The following interface is deprecated and only provided for backward
3436 compatibility. Don't use it. It will be removed in a future version
3439 @deftypefun gpgme_error_t gpgme_op_import_ext (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}}, @w{int *@var{nr}})
3440 The function @code{gpgme_op_import_ext} is equivalent to:
3443 gpgme_error_t err = gpgme_op_import (ctx, keydata);
3446 gpgme_import_result_t result = gpgme_op_import_result (ctx);
3447 *nr = result->considered;
3454 @subsection Deleting Keys
3456 @cindex key ring, delete from
3458 @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}})
3459 The function @code{gpgme_op_delete} deletes the key @var{key} from the
3460 key ring of the crypto engine used by @var{ctx}. If
3461 @var{allow_secret} is @code{0}, only public keys are deleted,
3462 otherwise secret keys are deleted as well, if that is supported.
3464 The function returns the error code @code{GPG_ERR_NO_ERROR} if the key
3465 was deleted successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3466 @var{key} is not a valid pointer, @code{GPG_ERR_NO_PUBKEY} if
3467 @var{key} could not be found in the keyring,
3468 @code{GPG_ERR_AMBIGUOUS_NAME} if the key was not specified
3469 unambiguously, and @code{GPG_ERR_CONFLICT} if the secret key for
3470 @var{key} is available, but @var{allow_secret} is zero.
3473 @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}})
3474 The function @code{gpgme_op_delete_start} initiates a
3475 @code{gpgme_op_delete} operation. It can be completed by calling
3476 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3478 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3479 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3480 @var{ctx} or @var{key} is not a valid pointer.
3484 @node Trust Item Management
3485 @section Trust Item Management
3488 @strong{Caution:} The trust items interface is experimental.
3490 @deftp {Data type} gpgme_trust_item_t
3491 The @code{gpgme_trust_item_t} type is a pointer to a trust item object.
3492 It has the following members:
3496 This is a string describing the key to which this trust items belongs.
3499 This is the type of the trust item. A value of 1 refers to a key, a
3500 value of 2 refers to a user ID.
3503 This is the trust level.
3505 @item char *owner_trust
3506 The owner trust if @code{type} is 1.
3508 @item char *validity
3509 The calculated validity.
3512 The user name if @code{type} is 2.
3517 * Listing Trust Items:: Browsing the list of available trust items.
3518 * Information About Trust Items:: Requesting information about trust items.
3519 * Manipulating Trust Items:: Operations on trust items.
3523 @node Listing Trust Items
3524 @subsection Listing Trust Items
3525 @cindex trust item list
3527 @deftypefun gpgme_error_t gpgme_op_trustlist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}})
3528 The function @code{gpgme_op_trustlist_start} initiates a trust item
3529 listing operation inside the context @var{ctx}. It sets everything up
3530 so that subsequent invocations of @code{gpgme_op_trustlist_next} return
3531 the trust items in the list.
3533 The string @var{pattern} contains an engine specific expression that
3534 is used to limit the list to all trust items matching the pattern. It
3535 can not be the empty string.
3537 The argument @var{max_level} is currently ignored.
3539 The context will be busy until either all trust items are received
3540 (and @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}), or
3541 @code{gpgme_op_trustlist_end} is called to finish the operation.
3543 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3544 @var{ctx} is not a valid pointer, and passes through any errors that
3545 are reported by the crypto engine support routines.
3548 @deftypefun gpgme_error_t gpgme_op_trustlist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_trust_item_t *@var{r_item}})
3549 The function @code{gpgme_op_trustlist_next} returns the next trust
3550 item in the list created by a previous @code{gpgme_op_trustlist_start}
3551 operation in the context @var{ctx}. The trust item can be destroyed
3552 with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}.
3554 This is the only way to get at @code{gpgme_trust_item_t} objects in
3557 If the last trust item in the list has already been returned,
3558 @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}.
3560 The function returns the error code @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3561 @var{r_item} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if
3562 there is not enough memory for the operation.
3565 @deftypefun gpgme_error_t gpgme_op_trustlist_end (@w{gpgme_ctx_t @var{ctx}})
3566 The function @code{gpgme_op_trustlist_next} ends a pending key list
3567 operation in the context @var{ctx}.
3569 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3570 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
3571 time during the operation there was not enough memory available.
3575 @node Information About Trust Items
3576 @subsection Information About Trust Items
3577 @cindex trust item, information about
3578 @cindex trust item, attributes
3579 @cindex attributes, of a trust item
3581 The following interfaces are deprecated and only provided for backward
3582 compatibility. Don't use them. They will be removed in a future
3583 version of @acronym{GPGME}.
3585 Trust items have attributes which can be queried using the interfaces
3586 below. The attribute identifiers are shared with those for key
3587 attributes. @xref{Information About Keys}.
3589 @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}})
3590 The function @code{gpgme_trust_item_get_string_attr} returns the value
3591 of the string-representable attribute @var{what} of trust item
3592 @var{item}. The arguments @var{idx} and @var{reserved} are reserved
3593 for later use and should be @code{0} and @code{NULL} respectively.
3595 The string returned is only valid as long as the key is valid.
3597 The function returns @code{0} if an attribute can't be returned as a
3598 string, @var{key} is not a valid pointer, @var{idx} out of range,
3599 or @var{reserved} not @code{NULL}.
3602 @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}})
3603 The function @code{gpgme_trust_item_get_int_attr} returns the value of
3604 the number-representable attribute @var{what} of trust item
3605 @var{item}. If the attribute occurs more than once in the trust item,
3606 the index is specified by @var{idx}. However, currently no such
3607 attribute exists, so @var{idx} should be @code{0}. The argument
3608 @var{reserved} is reserved for later use and should be @code{NULL}.
3610 The function returns @code{0} if the attribute can't be returned as a
3611 number, @var{key} is not a valid pointer, @var{idx} out of range,
3612 or @var{reserved} not @code{NULL}.
3616 @node Manipulating Trust Items
3617 @subsection Manipulating Trust Items
3618 @cindex trust item, manipulation
3620 @deftypefun void gpgme_trust_item_ref (@w{gpgme_trust_item_t @var{item}})
3621 The function @code{gpgme_trust_item_ref} acquires an additional
3622 reference for the trust item @var{item}.
3625 @deftypefun void gpgme_trust_item_unref (@w{gpgme_trust_item_t @var{item}})
3626 The function @code{gpgme_trust_item_unref} releases a reference for
3627 the trust item @var{item}. If this was the last reference, the trust
3628 item will be destroyed and all resources associated to it will be
3633 The following interface is deprecated and only provided for backward
3634 compatibility. Don't use it. It will be removed in a future version
3637 @deftypefun void gpgme_trust_item_release (@w{gpgme_trust_item_t @var{item}})
3638 The function @code{gpgme_trust_item_release} is an alias for
3639 @code{gpgme_trust_item_unref}.
3643 @node Crypto Operations
3644 @section Crypto Operations
3645 @cindex cryptographic operation
3647 Sometimes, the result of a crypto operation returns a list of invalid
3648 keys encountered in processing the request. The following structure
3649 is used to hold information about such a key.
3651 @deftp {Data type} {gpgme_invalid_key_t}
3652 This is a pointer to a structure used to store a part of the result of
3653 a crypto operation which takes user IDs as one input parameter. The
3654 structure contains the following members:
3657 @item gpgme_invalid_key_t next
3658 This is a pointer to the next invalid key structure in the linked
3659 list, or @code{NULL} if this is the last element.
3662 The fingerprint or key ID of the invalid key encountered.
3664 @item gpgme_error_t reason
3665 An error code describing the reason why the key was found invalid.
3671 * Decrypt:: Decrypting a ciphertext.
3672 * Verify:: Verifying a signature.
3673 * Decrypt and Verify:: Decrypting a signed ciphertext.
3674 * Sign:: Creating a signature.
3675 * Encrypt:: Encrypting a plaintext.
3682 @cindex cryptographic operation, decryption
3684 @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}})
3685 The function @code{gpgme_op_decrypt} decrypts the ciphertext in the
3686 data object @var{cipher} and stores it into the data object
3689 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3690 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
3691 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
3692 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
3693 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
3694 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
3695 secret key could not be retrieved, and passes through any errors that
3696 are reported by the crypto engine support routines.
3699 @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}})
3700 The function @code{gpgme_op_decrypt_start} initiates a
3701 @code{gpgme_op_decrypt} operation. It can be completed by calling
3702 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3704 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3705 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3706 if @var{cipher} or @var{plain} is not a valid pointer.
3709 @deftp {Data type} {gpgme_recipient_t}
3710 This is a pointer to a structure used to store information about the
3711 recipient of an encrypted text which is decrypted in a
3712 @code{gpgme_op_decrypt} operation. This information (except for the
3713 status field) is even available before the operation finished
3714 successfully, for example in a passphrase callback. The structure
3715 contains the following members:
3718 @item gpgme_recipient_t next
3719 This is a pointer to the next recipient structure in the linked list,
3720 or @code{NULL} if this is the last element.
3722 @item gpgme_pubkey_algo_t
3723 The public key algorithm used in the encryption.
3725 @item unsigned int wrong_key_usage : 1
3726 This is true if the key was not used according to its policy.
3729 This is the key ID of the key (in hexadecimal digits) used as
3732 @item gpgme_error_t status
3733 This is an error number with the error code GPG_ERR_NO_SECKEY if the
3734 secret key for this recipient is not available, and 0 otherwise.
3738 @deftp {Data type} {gpgme_decrypt_result_t}
3739 This is a pointer to a structure used to store the result of a
3740 @code{gpgme_op_decrypt} operation. After successfully decrypting
3741 data, you can retrieve the pointer to the result with
3742 @code{gpgme_op_decrypt_result}. The structure contains the following
3746 @item char *unsupported_algorithm
3747 If an unsupported algorithm was encountered, this string describes the
3748 algorithm that is not supported.
3750 @item unsigned int wrong_key_usage : 1
3751 This is true if the key was not used according to its policy.
3753 @item gpgme_recipient_t recipient
3754 This is a linked list of recipients to which this message was encrypted.
3756 @item char *file_name
3757 This is the filename of the original plaintext message file if it is
3758 known, otherwise this is a null pointer.
3762 @deftypefun gpgme_decrypt_result_t gpgme_op_decrypt_result (@w{gpgme_ctx_t @var{ctx}})
3763 The function @code{gpgme_op_decrypt_result} returns a
3764 @code{gpgme_decrypt_result_t} pointer to a structure holding the
3765 result of a @code{gpgme_op_decrypt} operation. The pointer is only
3766 valid if the last operation on the context was a
3767 @code{gpgme_op_decrypt} or @code{gpgme_op_decrypt_start} operation.
3768 If the operation failed this might be a @code{NULL} pointer. The
3769 returned pointer is only valid until the next operation is started on
3776 @cindex verification
3777 @cindex signature, verification
3778 @cindex cryptographic operation, verification
3779 @cindex cryptographic operation, signature check
3780 @cindex signature notation data
3781 @cindex notation data
3783 @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}})
3784 The function @code{gpgme_op_verify} verifies that the signature in the
3785 data object @var{sig} is a valid signature. If @var{sig} is a
3786 detached signature, then the signed text should be provided in
3787 @var{signed_text} and @var{plain} should be a null pointer.
3788 Otherwise, if @var{sig} is a normal (or cleartext) signature,
3789 @var{signed_text} should be a null pointer and @var{plain} should be a
3790 writable data object that will contain the plaintext after successful
3793 The results of the individual signature verifications can be retrieved
3794 with @code{gpgme_op_verify_result}.
3796 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3797 operation could be completed successfully, @code{GPG_ERR_INV_VALUE} if
3798 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer,
3799 @code{GPG_ERR_NO_DATA} if @var{sig} does not contain any data to
3800 verify, and passes through any errors that are reported by the crypto
3801 engine support routines.
3804 @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}})
3805 The function @code{gpgme_op_verify_start} initiates a
3806 @code{gpgme_op_verify} operation. It can be completed by calling
3807 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3809 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3810 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3811 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer, and
3812 @code{GPG_ERR_NO_DATA} if @var{sig} or @var{plain} does not contain
3816 @deftp {Data type} {gpgme_sig_notation_t}
3817 This is a pointer to a structure used to store a part of the result of
3818 a @code{gpgme_op_verify} operation. The structure contains the
3822 @item gpgme_sig_notation_t next
3823 This is a pointer to the next new signature notation structure in the
3824 linked list, or @code{NULL} if this is the last element.
3827 The name of the notation field. If this is @code{NULL}, then the
3828 member @code{value} will contain a policy URL.
3831 The length of the @code{name} field. For strings the length is
3832 counted without the trailing binary zero.
3835 The value of the notation field. If @code{name} is @code{NULL}, then
3836 this is a policy URL.
3839 The length of the @code{value} field. For strings the length is
3840 counted without the trailing binary zero.
3842 @item gpgme_sig_notation_flags_t flags
3843 The accumulated flags field. This field contains the flags associated
3844 with the notation data in an accumulated form which can be used as an
3845 argument to the function @code{gpgme_sig_notation_add}. The value
3846 @code{flags} is a bitwise-or combination of one or multiple of the
3847 following bit values:
3850 @item GPGME_SIG_NOTATION_HUMAN_READABLE
3851 The @code{GPGME_SIG_NOTATION_HUMAN_READABLE} symbol specifies that the
3852 notation data is in human readable form
3854 @item GPGME_SIG_NOTATION_CRITICAL
3855 The @code{GPGME_SIG_NOTATION_CRITICAL} symbol specifies that the
3856 notation data is critical.
3860 @item unsigned int human_readable : 1
3861 This is true if the @code{GPGME_SIG_NOTATION_HUMAN_READABLE} flag is
3862 set and false otherwise. This flag is only valid for notation data,
3863 not for policy URLs.
3865 @item unsigned int critical : 1
3866 This is true if the @code{GPGME_SIG_NOTATION_CRITICAL} flag is set and
3867 false otherwise. This flag is valid for notation data and policy URLs.
3872 @deftp {Data type} {gpgme_signature_t}
3873 This is a pointer to a structure used to store a part of the result of
3874 a @code{gpgme_op_verify} operation. The structure contains the
3878 @item gpgme_signature_t next
3879 This is a pointer to the next new signature structure in the linked
3880 list, or @code{NULL} if this is the last element.
3882 @item gpgme_sigsum_t summary
3883 This is a bit vector giving a summary of the signature status. It
3884 provides an easy interface to a defined semantic of the signature
3885 status. Checking just one bit is sufficient to see whether a
3886 signature is valid without any restrictions.
3888 The defined bits are:
3890 @item GPGME_SIGSUM_VALID
3891 The signature is fully valid.
3893 @item GPGME_SIGSUM_GREEN
3894 The signature is good but one might want to display some extra
3895 information. Check the other bits.
3897 @item GPGME_SIGSUM_RED
3898 The signature is bad. It might be useful to check other bits and
3899 display more information, i.e. a revoked certificate might not render a
3900 signature invalid when the message was received prior to the cause for
3903 @item GPGME_SIGSUM_KEY_REVOKED
3904 The key or at least one certificate has been revoked.
3906 @item GPGME_SIGSUM_KEY_EXPIRED
3907 The key or one of the certificates has expired. It is probably a good
3908 idea to display the date of the expiration.
3910 @item GPGME_SIGSUM_SIG_EXPIRED
3911 The signature has expired.
3913 @item GPGME_SIGSUM_KEY_MISSING
3914 Can't verify due to a missing key or certificate.
3916 @item GPGME_SIGSUM_CRL_MISSING
3917 The CRL (or an equivalent mechanism) is not available.
3919 @item GPGME_SIGSUM_CRL_TOO_OLD
3920 Available CRL is too old.
3922 @item GPGME_SIGSUM_BAD_POLICY
3923 A policy requirement was not met.
3925 @item GPGME_SIGSUM_SYS_ERROR
3926 A system error occured.
3930 This is the fingerprint or key ID of the signature.
3932 @item gpgme_error_t status
3933 This is the status of the signature. In particular, the following
3934 status codes are of interest:
3937 @item GPG_ERR_NO_ERROR
3938 This status indicates that the signature is valid. For the combined
3939 result this status means that all signatures are valid.
3941 @item GPG_ERR_SIG_EXPIRED
3942 This status indicates that the signature is valid but expired. For
3943 the combined result this status means that all signatures are valid
3946 @item GPG_ERR_KEY_EXPIRED
3947 This status indicates that the signature is valid but the key used to
3948 verify the signature has expired. For the combined result this status
3949 means that all signatures are valid and all keys are expired.
3951 @item GPG_ERR_CERT_REVOKED
3952 This status indicates that the signature is valid but the key used
3953 to verify the signature has been revoked. For the combined result
3954 this status means that all signatures are valid and all keys are
3957 @item GPG_ERR_BAD_SIGNATURE
3958 This status indicates that the signature is invalid. For the combined
3959 result this status means that all signatures are invalid.
3961 @item GPG_ERR_NO_PUBKEY
3962 This status indicates that the signature could not be verified due to
3963 a missing key. For the combined result this status means that all
3964 signatures could not be checked due to missing keys.
3966 @item GPG_ERR_GENERAL
3967 This status indicates that there was some other error which prevented
3968 the signature verification.
3971 @item gpgme_sig_notation_t notations
3972 This is a linked list with the notation data and policy URLs.
3974 @item unsigned long timestamp
3975 The creation timestamp of this signature.
3977 @item unsigned long exp_timestamp
3978 The expiration timestamp of this signature, or 0 if the signature does
3981 @item unsigned int wrong_key_usage : 1
3982 This is true if the key was not used according to its policy.
3984 @item gpgme_validity_t validity
3985 The validity of the signature.
3987 @item gpgme_error_t validity_reason
3988 If a signature is not valid, this provides a reason why.
3990 @item gpgme_pubkey_algo_t
3991 The public key algorithm used to create this signature.
3993 @item gpgme_hash_algo_t
3994 The hash algorithm used to create this signature.
3998 @deftp {Data type} {gpgme_verify_result_t}
3999 This is a pointer to a structure used to store the result of a
4000 @code{gpgme_op_verify} operation. After verifying a signature, you
4001 can retrieve the pointer to the result with
4002 @code{gpgme_op_verify_result}. If the operation failed this might be
4003 a @code{NULL} pointer. The structure contains the following member:
4006 @item gpgme_signature_t signatures
4007 A linked list with information about all signatures for which a
4008 verification was attempted.
4010 @item char *file_name
4011 This is the filename of the original plaintext message file if it is
4012 known, otherwise this is a null pointer.
4016 @deftypefun gpgme_verify_result_t gpgme_op_verify_result (@w{gpgme_ctx_t @var{ctx}})
4017 The function @code{gpgme_op_verify_result} returns a
4018 @code{gpgme_verify_result_t} pointer to a structure holding the result
4019 of a @code{gpgme_op_verify} operation. The pointer is only valid if
4020 the last operation on the context was a @code{gpgme_op_verify},
4021 @code{gpgme_op_verify_start}, @code{gpgme_op_decrypt_verify} or
4022 @code{gpgme_op_decrypt_verify_start} operation, and if this operation
4023 finished successfully (for @code{gpgme_op_decrypt_verify} and
4024 @code{gpgme_op_decrypt_verify_start}, the error code
4025 @code{GPG_ERR_NO_DATA} counts as successful in this context). The
4026 returned pointer is only valid until the next operation is started on
4031 The following interfaces are deprecated and only provided for backward
4032 compatibility. Don't use them. They will be removed in a future
4033 version of @acronym{GPGME}.
4035 @deftp {Data type} {enum gpgme_sig_stat_t}
4036 @tindex gpgme_sig_stat_t
4037 The @code{gpgme_sig_stat_t} type holds the result of a signature check, or
4038 the combined result of all signatures. The following results are
4042 @item GPGME_SIG_STAT_NONE
4043 This status should not occur in normal operation.
4045 @item GPGME_SIG_STAT_GOOD
4046 This status indicates that the signature is valid. For the combined
4047 result this status means that all signatures are valid.
4049 @item GPGME_SIG_STAT_GOOD_EXP
4050 This status indicates that the signature is valid but expired. For
4051 the combined result this status means that all signatures are valid
4054 @item GPGME_SIG_STAT_GOOD_EXPKEY
4055 This status indicates that the signature is valid but the key used to
4056 verify the signature has expired. For the combined result this status
4057 means that all signatures are valid and all keys are expired.
4059 @item GPGME_SIG_STAT_BAD
4060 This status indicates that the signature is invalid. For the combined
4061 result this status means that all signatures are invalid.
4063 @item GPGME_SIG_STAT_NOKEY
4064 This status indicates that the signature could not be verified due to
4065 a missing key. For the combined result this status means that all
4066 signatures could not be checked due to missing keys.
4068 @item GPGME_SIG_STAT_NOSIG
4069 This status indicates that the signature data provided was not a real
4072 @item GPGME_SIG_STAT_ERROR
4073 This status indicates that there was some other error which prevented
4074 the signature verification.
4076 @item GPGME_SIG_STAT_DIFF
4077 For the combined result this status means that at least two signatures
4078 have a different status. You can get each key's status with
4079 @code{gpgme_get_sig_status}.
4083 @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}})
4084 The function @code{gpgme_get_sig_status} is equivalent to:
4087 gpgme_verify_result_t result;
4088 gpgme_signature_t sig;
4090 result = gpgme_op_verify_result (ctx);
4091 sig = result->signatures;
4103 switch (gpg_err_code (sig->status))
4105 case GPG_ERR_NO_ERROR:
4106 *r_stat = GPGME_SIG_STAT_GOOD;
4109 case GPG_ERR_BAD_SIGNATURE:
4110 *r_stat = GPGME_SIG_STAT_BAD;
4113 case GPG_ERR_NO_PUBKEY:
4114 *r_stat = GPGME_SIG_STAT_NOKEY;
4117 case GPG_ERR_NO_DATA:
4118 *r_stat = GPGME_SIG_STAT_NOSIG;
4121 case GPG_ERR_SIG_EXPIRED:
4122 *r_stat = GPGME_SIG_STAT_GOOD_EXP;
4125 case GPG_ERR_KEY_EXPIRED:
4126 *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY;
4130 *r_stat = GPGME_SIG_STAT_ERROR;
4135 *r_created = sig->timestamp;
4140 @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}})
4141 The function @code{gpgme_get_sig_string_attr} is equivalent to:
4144 gpgme_verify_result_t result;
4145 gpgme_signature_t sig;
4147 result = gpgme_op_verify_result (ctx);
4148 sig = result->signatures;
4160 case GPGME_ATTR_FPR:
4163 case GPGME_ATTR_ERRTOK:
4165 return sig->wrong_key_usage ? "Wrong_Key_Usage" : "";
4176 @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}})
4177 The function @code{gpgme_get_sig_ulong_attr} is equivalent to:
4180 gpgme_verify_result_t result;
4181 gpgme_signature_t sig;
4183 result = gpgme_op_verify_result (ctx);
4184 sig = result->signatures;
4196 case GPGME_ATTR_CREATED:
4197 return sig->timestamp;
4199 case GPGME_ATTR_EXPIRE:
4200 return sig->exp_timestamp;
4202 case GPGME_ATTR_VALIDITY:
4203 return (unsigned long) sig->validity;
4205 case GPGME_ATTR_SIG_STATUS:
4206 switch (sig->status)
4208 case GPG_ERR_NO_ERROR:
4209 return GPGME_SIG_STAT_GOOD;
4211 case GPG_ERR_BAD_SIGNATURE:
4212 return GPGME_SIG_STAT_BAD;
4214 case GPG_ERR_NO_PUBKEY:
4215 return GPGME_SIG_STAT_NOKEY;
4217 case GPG_ERR_NO_DATA:
4218 return GPGME_SIG_STAT_NOSIG;
4220 case GPG_ERR_SIG_EXPIRED:
4221 return GPGME_SIG_STAT_GOOD_EXP;
4223 case GPG_ERR_KEY_EXPIRED:
4224 return GPGME_SIG_STAT_GOOD_EXPKEY;
4227 return GPGME_SIG_STAT_ERROR;
4230 case GPGME_ATTR_SIG_SUMMARY:
4231 return sig->summary;
4240 @deftypefun {const char *} gpgme_get_sig_key (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_key_t *@var{r_key}})
4241 The function @code{gpgme_get_sig_key} is equivalent to:
4244 gpgme_verify_result_t result;
4245 gpgme_signature_t sig;
4247 result = gpgme_op_verify_result (ctx);
4248 sig = result->signatures;
4256 return gpg_error (GPG_ERR_EOF);
4258 return gpgme_get_key (ctx, sig->fpr, r_key, 0);
4263 @node Decrypt and Verify
4264 @subsection Decrypt and Verify
4265 @cindex decryption and verification
4266 @cindex verification and decryption
4267 @cindex signature check
4268 @cindex cryptographic operation, decryption and verification
4270 @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}})
4271 The function @code{gpgme_op_decrypt_verify} decrypts the ciphertext in
4272 the data object @var{cipher} and stores it into the data object
4273 @var{plain}. If @var{cipher} contains signatures, they will be
4276 After the operation completed, @code{gpgme_op_decrypt_result} and
4277 @code{gpgme_op_verify_result} can be used to retrieve more information
4278 about the signatures.
4280 If the error code @code{GPG_ERR_NO_DATA} is returned, @var{cipher}
4281 does not contain any data to decrypt. However, it might still be
4282 signed. The information about detected signatures is available with
4283 @code{gpgme_op_verify_result} in this case.
4285 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4286 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
4287 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
4288 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
4289 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
4290 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
4291 secret key could not be retrieved, and passes through any errors that
4292 are reported by the crypto engine support routines.
4295 @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}})
4296 The function @code{gpgme_op_decrypt_verify_start} initiates a
4297 @code{gpgme_op_decrypt_verify} operation. It can be completed by
4298 calling @code{gpgme_wait} on the context. @xref{Waiting For
4301 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4302 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
4303 @var{ctx}, @var{cipher}, @var{plain} or @var{r_stat} is not a valid
4304 pointer, and @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain
4305 any data to decrypt.
4311 @cindex signature, creation
4313 @cindex cryptographic operation, signing
4315 A signature can contain signatures by one or more keys. The set of
4316 keys used to create a signatures is contained in a context, and is
4317 applied to all following signing operations in this context (until the
4321 * Selecting Signers:: How to choose the keys to sign with.
4322 * Creating a Signature:: How to create a signature.
4323 * Signature Notation Data:: How to add notation data to a signature.
4327 @node Selecting Signers
4328 @subsubsection Selecting Signers
4329 @cindex signature, selecting signers
4330 @cindex signers, selecting
4332 @deftypefun void gpgme_signers_clear (@w{gpgme_ctx_t @var{ctx}})
4333 The function @code{gpgme_signers_clear} releases a reference for each
4334 key on the signers list and removes the list of signers from the
4337 Every context starts with an empty list.
4340 @deftypefun gpgme_error_t gpgme_signers_add (@w{gpgme_ctx_t @var{ctx}}, @w{const gpgme_key_t @var{key}})
4341 The function @code{gpgme_signers_add} adds the key @var{key} to the
4342 list of signers in the context @var{ctx}.
4344 Calling this function acquires an additional reference for the key.
4347 @deftypefun gpgme_key_t gpgme_signers_enum (@w{const gpgme_ctx_t @var{ctx}}, @w{int @var{seq}})
4348 The function @code{gpgme_signers_enum} returns the @var{seq}th key in
4349 the list of signers in the context @var{ctx}. An additional reference
4350 is acquired for the user.
4352 If @var{seq} is out of range, @code{NULL} is returned.
4356 @node Creating a Signature
4357 @subsubsection Creating a Signature
4359 @deftp {Data type} {enum gpgme_sig_mode_t}
4360 @tindex gpgme_sig_mode_t
4361 The @code{gpgme_sig_mode_t} type is used to specify the desired type of a
4362 signature. The following modes are available:
4365 @item GPGME_SIG_MODE_NORMAL
4366 A normal signature is made, the output includes the plaintext and the
4369 @item GPGME_SIG_MODE_DETACH
4370 A detached signature is made.
4372 @item GPGME_SIG_MODE_CLEAR
4373 A clear text signature is made. The @acronym{ASCII} armor and text
4374 mode settings of the context are ignored.
4378 @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}})
4379 The function @code{gpgme_op_sign} creates a signature for the text in
4380 the data object @var{plain} and returns it in the data object
4381 @var{sig}. The type of the signature created is determined by the
4382 @acronym{ASCII} armor and text mode attributes set for the context
4383 @var{ctx} and the requested signature mode @var{mode}.
4385 After the operation completed successfully, the result can be
4386 retrieved with @code{gpgme_op_sign_result}.
4388 If an S/MIME signed message is created using the CMS crypto engine,
4389 the number of certificates to include in the message can be specified
4390 with @code{gpgme_set_include_certs}. @xref{Included Certificates}.