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, 2006, 2007 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, 2006, 2007 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.
193 * Advanced Key Editing:: Advanced key edit operation.
195 Trust Item Management
197 * Listing Trust Items:: Browsing the list of available trust items.
198 * Information About Trust Items:: Requesting information about trust items.
199 * Manipulating Trust Items:: Operations on trust items.
203 * Decrypt:: Decrypting a ciphertext.
204 * Verify:: Verifying a signature.
205 * Decrypt and Verify:: Decrypting a signed ciphertext.
206 * Sign:: Creating a signature.
207 * Encrypt:: Encrypting a plaintext.
211 * Selecting Signers:: How to choose the keys to sign with.
212 * Creating a Signature:: How to create a signature.
213 * Signature Notation Data:: How to add notation data to a signature.
217 * Encrypting a Plaintext:: How to encrypt a plaintext.
221 * Waiting For Completion:: Waiting until an operation is completed.
222 * Using External Event Loops:: Advanced control over what happens when.
223 * Cancellation:: How to end pending operations prematurely.
225 Using External Event Loops
227 * I/O Callback Interface:: How I/O callbacks are registered.
228 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
229 * I/O Callback Example:: An example how to use I/O callbacks.
230 * I/O Callback Example GTK+:: How to integrate @acronym{GPGME} in GTK+.
231 * I/O Callback Example GDK:: How to integrate @acronym{GPGME} in GDK.
232 * I/O Callback Example Qt:: How to integrate @acronym{GPGME} in Qt.
238 @chapter Introduction
240 `GnuPG Made Easy' (@acronym{GPGME}) is a C language library that
241 allows to add support for cryptography to a program. It is designed
242 to make access to public key crypto engines like GnuPG or GpgSM easier
243 for applications. @acronym{GPGME} provides a high-level crypto API
244 for encryption, decryption, signing, signature verification and key
247 @acronym{GPGME} uses GnuPG and GpgSM as its backends to support
248 OpenPGP and the Cryptographic Message Syntax (CMS).
251 * Getting Started:: Purpose of the manual, and how to use it.
252 * Features:: Reasons to install and use @acronym{GPGME}.
253 * Overview:: Basic architecture of the @acronym{GPGME} library.
257 @node Getting Started
258 @section Getting Started
260 This manual documents the @acronym{GPGME} library programming
261 interface. All functions and data types provided by the library are
264 The reader is assumed to possess basic knowledge about cryptography in
265 general, and public key cryptography in particular. The underlying
266 cryptographic engines that are used by the library are not explained,
267 but where necessary, special features or requirements by an engine are
268 mentioned as far as they are relevant to @acronym{GPGME} or its users.
270 This manual can be used in several ways. If read from the beginning
271 to the end, it gives a good introduction into the library and how it
272 can be used in an application. Forward references are included where
273 necessary. Later on, the manual can be used as a reference manual to
274 get just the information needed about any particular interface of the
275 library. Experienced programmers might want to start looking at the
276 examples at the end of the manual, and then only read up those parts
277 of the interface which are unclear.
283 @acronym{GPGME} has a couple of advantages over other libraries doing
284 a similar job, and over implementing support for GnuPG or other crypto
285 engines into your application directly.
288 @item it's free software
289 Anybody can use, modify, and redistribute it under the terms of the GNU
290 Lesser General Public License (@pxref{Library Copying}).
293 @acronym{GPGME} provides transparent support for several cryptographic
294 protocols by different engines. Currently, @acronym{GPGME} supports
295 the OpenPGP protocol using GnuPG as the backend, and the Cryptographic
296 Message Syntax using GpgSM as the backend.
299 @acronym{GPGME} hides the differences between the protocols and
300 engines from the programmer behind an easy-to-use interface. This way
301 the programmer can focus on the other parts of the program, and still
302 integrate strong cryptography in his application. Once support for
303 @acronym{GPGME} has been added to a program, it is easy to add support
304 for other crypto protocols once @acronym{GPGME} backends provide them.
311 @acronym{GPGME} provides a data abstraction that is used to pass data
312 to the crypto engine, and receive returned data from it. Data can be
313 read from memory or from files, but it can also be provided by a
316 The actual cryptographic operations are always set within a context.
317 A context provides configuration parameters that define the behaviour
318 of all operations performed within it. Only one operation per context
319 is allowed at any time, but when one operation is finished, you can
320 run the next operation in the same context. There can be more than
321 one context, and all can run different operations at the same time.
323 Furthermore, @acronym{GPGME} has rich key management facilities
324 including listing keys, querying their attributes, generating,
325 importing, exporting and deleting keys, and acquiring information
326 about the trust path.
328 With some precautions, @acronym{GPGME} can be used in a multi-threaded
329 environment, although it is not completely thread safe and thus needs
330 the support of the application.
336 To use @acronym{GPGME}, you have to perform some changes to your
337 sources and the build system. The necessary changes are small and
338 explained in the following sections. At the end of this chapter, it
339 is described how the library is initialized, and how the requirements
340 of the library are verified.
343 * Header:: What header file you need to include.
344 * Building the Source:: Compiler options to be used.
345 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
346 * Using Automake:: Compiler options to be used the easy way.
347 * Using Libtool:: Avoiding compiler options entirely.
348 * Library Version Check:: Getting and verifying the library version.
349 * Signal Handling:: How @acronym{GPGME} affects signal handling.
350 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
359 All interfaces (data types and functions) of the library are defined
360 in the header file `gpgme.h'. You must include this in all programs
361 using the library, either directly or through some other header file,
368 The name space of @acronym{GPGME} is @code{gpgme_*} for function names
369 and data types and @code{GPGME_*} for other symbols. Symbols internal
370 to @acronym{GPGME} take the form @code{_gpgme_*} and @code{_GPGME_*}.
372 Because @acronym{GPGME} makes use of the GPG Error library, using
373 @acronym{GPGME} will also use the @code{GPG_ERR_*} name space
374 directly, and the @code{gpg_err*} and @code{gpg_str*} name space
378 @node Building the Source
379 @section Building the Source
380 @cindex compiler options
381 @cindex compiler flags
383 If you want to compile a source file including the `gpgme.h' header
384 file, you must make sure that the compiler can find it in the
385 directory hierarchy. This is accomplished by adding the path to the
386 directory in which the header file is located to the compilers include
387 file search path (via the @option{-I} option).
389 However, the path to the include file is determined at the time the
390 source is configured. To solve this problem, gpgme ships with a small
391 helper program @command{gpgme-config} that knows about the path to the
392 include file and other configuration options. The options that need
393 to be added to the compiler invocation at compile time are output by
394 the @option{--cflags} option to @command{gpgme-config}. The following
395 example shows how it can be used at the command line:
398 gcc -c foo.c `gpgme-config --cflags`
401 Adding the output of @samp{gpgme-config --cflags} to the compiler
402 command line will ensure that the compiler can find the
403 @acronym{GPGME} header file.
405 A similar problem occurs when linking the program with the library.
406 Again, the compiler has to find the library files. For this to work,
407 the path to the library files has to be added to the library search
408 path (via the @option{-L} option). For this, the option
409 @option{--libs} to @command{gpgme-config} can be used. For
410 convenience, this option also outputs all other options that are
411 required to link the program with @acronym{GPGME} (in particular, the
412 @samp{-lgpgme} option). The example shows how to link @file{foo.o}
413 with the @acronym{GPGME} library to a program @command{foo}.
416 gcc -o foo foo.o `gpgme-config --libs`
419 Of course you can also combine both examples to a single command by
420 specifying both options to @command{gpgme-config}:
423 gcc -o foo foo.c `gpgme-config --cflags --libs`
426 If you want to link to one of the thread-safe versions of
427 @acronym{GPGME}, you must specify the @option{--thread} option before
428 any other option to select the thread package you want to link with.
429 Supported thread packages are @option{--thread=pth} and
430 @option{--thread=pthread}.
433 @node Largefile Support (LFS)
434 @section Largefile Support (LFS)
435 @cindex largefile support
438 @acronym{GPGME} is compiled with largefile support by default, if it
439 is available on the system. This means that GPGME supports files
440 larger than two gigabyte in size, if the underlying operating system
441 can. On some systems, largefile support is already the default. On
442 such systems, nothing special is required. However, some systems
443 provide only support for files up to two gigabyte in size by default.
444 Support for larger file sizes has to be specifically enabled.
446 To make a difficult situation even more complex, such systems provide
447 two different types of largefile support. You can either get all
448 relevant functions replaced with alternatives that are largefile
449 capable, or you can get new functions and data types for largefile
450 support added. Those new functions have the same name as their
451 smallfile counterparts, but with a suffix of 64.
453 An example: The data type @code{off_t} is 32 bit wide on GNU/Linux PC
454 systems. To address offsets in large files, you can either enable
455 largefile support add-on. Then a new data type @code{off64_t} is
456 provided, which is 64 bit wide. Or you can replace the existing
457 @code{off_t} data type with its 64 bit wide counterpart. All
458 occurences of @code{off_t} are then automagically replaced.
460 As if matters were not complex enough, there are also two different
461 types of file descriptors in such systems. This is important because
462 if file descriptors are exchanged between programs that use a
463 different maximum file size, certain errors must be produced on some
464 file descriptors to prevent subtle overflow bugs from occuring.
466 As you can see, supporting two different maximum file sizes at the
467 same time is not at all an easy task. However, the maximum file size
468 does matter for @acronym{GPGME}, because some data types it uses in
469 its interfaces are affected by that. For example, the @code{off_t}
470 data type is used in the @code{gpgme_data_seek} function, to match its
471 @acronym{POSIX} counterpart. This affects the call-frame of the
472 function, and thus the ABI of the library. Furthermore, file
473 descriptors can be exchanged between GPGME and the application.
475 For you as the user of the library, this means that your program must
476 be compiled in the same file size mode as the library. Luckily, there
477 is absolutely no valid reason for new programs to not enable largefile
478 support by default and just use that. The compatibility modes (small
479 file sizes or dual mode) can be considered an historic artefact, only
480 useful to allow for a transitional period.
482 @acronym{GPGME} is compiled using largefile support by default. This
483 means that your application must do the same, at least as far as it is
484 relevant for using the @file{gpgme.h} header file. All types in this
485 header files refer to their largefile counterparts, if they are
486 different from any default types on the system.
488 You can enable largefile support, if it is different from the default
489 on the system the application is compiled on, by using the Autoconf
490 macro @code{AC_SYS_LARGEFILE}. If you do this, then you don't need to
491 worry about anything else: It will just work. In this case you might
492 also want to use @code{AC_FUNC_FSEEKO} to take advantage of some new
493 interfaces, and @code{AC_TYPE_OFF_T} (just in case).
495 If you do not use Autoconf, you can define the preprocessor symbol
496 @code{_FILE_OFFSET_BITS} to 64 @emph{before} including any header
497 files, for example by specifying the option
498 @code{-D_FILE_OFFSET_BITS=64} on the compiler command line. You will
499 also want to define the preprocessor symbol @code{LARGEFILE_SOURCE} to
500 1 in this case, to take advantage of some new interfaces.
502 If you do not want to do either of the above, you probably know enough
503 about the issue to invent your own solution. Just keep in mind that
504 the @acronym{GPGME} header file expects that largefile support is
505 enabled, if it is available. In particular, we do not support dual
506 mode (@code{_LARGEFILE64_SOURCE}).
510 @section Using Automake
514 It is much easier if you use GNU Automake instead of writing your own
515 Makefiles. If you do that you do not have to worry about finding and
516 invoking the @command{gpgme-config} script at all. @acronym{GPGME}
517 provides an extension to Automake that does all the work for you.
519 @c A simple macro for optional variables.
521 @r{[}@var{\varname\}@r{]}
523 @defmac AM_PATH_GPGME (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
524 @defmacx AM_PATH_GPGME_PTH (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
525 @defmacx AM_PATH_GPGME_PTHREAD (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
526 Check whether @acronym{GPGME} (at least version @var{minimum-version},
527 if given) exists on the host system. If it is found, execute
528 @var{action-if-found}, otherwise do @var{action-if-not-found}, if
531 Additionally, the function defines @code{GPGME_CFLAGS} to the flags
532 needed for compilation of the program to find the @file{gpgme.h}
533 header file, and @code{GPGME_LIBS} to the linker flags needed to link
534 the program to the @acronym{GPGME} library.
536 @code{AM_PATH_GPGME_PTH} checks for the version of @acronym{GPGME}
537 that can be used with GNU Pth, and defines @code{GPGME_PTH_CFLAGS} and
538 @code{GPGME_PTH_LIBS}.
540 @code{AM_PATH_GPGME_PTHREAD} checks for the version of @acronym{GPGME}
541 that can be used with the native pthread implementation, and defines
542 @code{GPGME_PTHREAD_CFLAGS} and @code{GPGME_PTHREAD_LIBS}.
545 You can use the defined Autoconf variables like this in your
549 AM_CPPFLAGS = $(GPGME_CFLAGS)
550 LDADD = $(GPGME_LIBS)
555 @section Using Libtool
558 The easiest way is to just use GNU Libtool. If you use libtool, and
559 link to @code{libgpgme.la}, @code{libgpgme-pth.la} or
560 @code{libgpgme-pthread.la} respectively, everything will be done
561 automatically by Libtool.
564 @node Library Version Check
565 @section Library Version Check
566 @cindex version check, of the library
568 @deftypefun {const char *} gpgme_check_version (@w{const char *@var{required_version}})
569 The function @code{gpgme_check_version} has three purposes. It can be
570 used to retrieve the version number of the library. In addition it
571 can verify that the version number is higher than a certain required
572 version number. In either case, the function initializes some
573 sub-systems, and for this reason alone it must be invoked early in
574 your program, before you make use of the other functions in
577 As a side effect for W32 based systems, the socket layer will get
581 If @var{required_version} is @code{NULL}, the function returns a
582 pointer to a statically allocated string containing the version number
585 If @var{required_version} is not @code{NULL}, it should point to a
586 string containing a version number, and the function checks that the
587 version of the library is at least as high as the version number
588 provided. In this case, the function returns a pointer to a
589 statically allocated string containing the version number of the
590 library. If @var{REQUIRED_VERSION} is not a valid version number, or
591 if the version requirement is not met, the function returns
594 If you use a version of a library that is backwards compatible with
595 older releases, but contains additional interfaces which your program
596 uses, this function provides a run-time check if the necessary
597 features are provided by the installed version of the library.
601 After initializing @acronym{GPGME}, you should set the locale
602 information to the locale required for your output terminal. This
603 locale information is needed for example for the curses and Gtk
604 pinentry. Here is an example of a complete initialization:
613 /* Initialize the locale environment. */
614 setlocale (LC_ALL, "");
615 gpgme_check_version (NULL);
616 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
618 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
623 Note that you are highly recommended to initialize the locale settings
624 like this. @acronym{GPGME} can not do this for you because it would
625 not be thread safe. The conditional on LC_MESSAGES is only necessary
626 for portability to W32 systems.
629 @node Signal Handling
630 @section Signal Handling
632 @cindex signal handling
634 The @acronym{GPGME} library communicates with child processes (the
635 crypto engines). If a child process dies unexpectedly, for example
636 due to a bug, or system problem, a @code{SIGPIPE} signal will be
637 delivered to the application. The default action is to abort the
638 program. To protect against this, @code{gpgme_check_version} sets the
639 @code{SIGPIPE} signal action to @code{SIG_IGN}, which means that the
640 signal will be ignored.
642 @acronym{GPGME} will only do that if the signal action for
643 @code{SIGPIPE} is @code{SIG_DEF} at the time
644 @code{gpgme_check_version} is called. If it is something different,
645 @code{GPGME} will take no action.
647 This means that if your application does not install any signal
648 handler for @code{SIGPIPE}, you don't need to take any precautions.
649 If you do install a signal handler for @code{SIGPIPE}, you must be
650 prepared to handle any @code{SIGPIPE} events that occur due to
651 @acronym{GPGME} writing to a defunct pipe. Furthermore, if your
652 application is multi-threaded, and you install a signal action for
653 @code{SIGPIPE}, you must make sure you do this either before
654 @code{gpgme_check_version} is called or afterwards.
657 @node Multi Threading
658 @section Multi Threading
659 @cindex thread-safeness
660 @cindex multi-threading
662 The @acronym{GPGME} library is not entirely thread-safe, but it can
663 still be used in a multi-threaded environment if some care is taken.
664 If the following requirements are met, there should be no race
665 conditions to worry about:
669 @acronym{GPGME} supports the thread libraries pthread and GNU Pth.
670 The support for this has to be enabled at compile time.
671 @acronym{GPGME} will automatically detect the location in which the
672 thread libraries are installed and activate the support for them at
675 Support for other thread libraries is very easy to add. Please
676 contact us if you have the need.
679 If you want to use @acronym{GPGME} with threads, you must link to the
680 right version of the library. The name of the right library is
681 @code{libgpgme-} followed by the name of the thread package you use.
682 For example, if you use GNU Pth, the right name is
683 @code{libgpgme-pth}. Use the Automake macros or
684 @command{gpgme-config} program for simplicity.
688 The function @code{gpgme_check_version} must be called before any
689 other function in the library, because it initializes the thread
690 support subsystem in @acronym{GPGME}. To achieve this in
691 multi-threaded programs, you must synchronize the memory with respect
692 to other threads that also want to use @acronym{GPGME}. For this, it
693 is sufficient to call @code{gpgme_check_version} before creating the
694 other threads using @acronym{GPGME}@footnote{At least this is true for
695 POSIX threads, as @code{pthread_create} is a function that
696 synchronizes memory with respects to other threads. There are many
697 functions which have this property, a complete list can be found in
698 POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the
699 definition of the term ``Memory Synchronization''. For other thread
700 packages other, more relaxed or more strict rules may apply.}.
703 Any @code{gpgme_data_t} and @code{gpgme_ctx_t} object must only be
704 accessed by one thread at a time. If multiple threads want to deal
705 with the same object, the caller has to make sure that operations on
706 that object are fully synchronized.
709 Only one thread at any time is allowed to call @code{gpgme_wait}. If
710 multiple threads call this function, the caller must make sure that
711 all invocations are fully synchronized. It is safe to start
712 asynchronous operations while a thread is running in gpgme_wait.
715 The function @code{gpgme_strerror} is not thread safe. You have to
716 use @code{gpgme_strerror_r} instead.
720 @node Protocols and Engines
721 @chapter Protocols and Engines
724 @cindex crypto engine
726 @cindex crypto backend
728 @acronym{GPGME} supports several cryptographic protocols, however, it
729 does not implement them. Rather it uses backends (also called
730 engines) which implement the protocol. @acronym{GPGME} uses
731 inter-process communication to pass data back and forth between the
732 application and the backend, but the details of the communication
733 protocol and invocation of the backend is completely hidden by the
734 interface. All complexity is handled by @acronym{GPGME}. Where an
735 exchange of information between the application and the backend is
736 necessary, @acronym{GPGME} provides the necessary callback function
737 hooks and further interfaces.
739 @deftp {Data type} {enum gpgme_protocol_t}
740 @tindex gpgme_protocol_t
741 The @code{gpgme_protocol_t} type specifies the set of possible protocol
742 values that are supported by @acronym{GPGME}. The following protocols
746 @item GPGME_PROTOCOL_OpenPGP
747 This specifies the OpenPGP protocol.
749 @item GPGME_PROTOCOL_CMS
750 This specifies the Cryptographic Message Syntax.
752 @item GPGME_PROTOCOL_UNKNOWN
753 Reserved for future extension. You may use this to indicate that the
754 used protocol is not known to the application. Currently,
755 @acronym{GPGME} does not accept this value in any operation, though,
756 except for @code{gpgme_get_protocol_name}.
761 @deftypefun {const char *} gpgme_get_protocol_name (@w{gpgme_protocol_t @var{protocol}})
762 The function @code{gpgme_get_protocol_name} returns a statically
763 allocated string describing the protocol @var{protocol}, or
764 @code{NULL} if the protocol number is not valid.
768 * Engine Version Check:: Verifying the engine version.
769 * Engine Information:: Obtaining more information about the engines.
770 * Engine Configuration:: Changing the engine configuration.
771 * OpenPGP:: Support for the OpenPGP protocol.
772 * Cryptographic Message Syntax:: Support for the CMS.
776 @node Engine Version Check
777 @section Engine Version Check
778 @cindex version check, of the engines
780 @deftypefun gpgme_error_t gpgme_engine_check_version (@w{gpgme_protocol_t @var{protocol}})
781 The function @code{gpgme_engine_check_version} verifies that the
782 engine implementing the protocol @var{PROTOCOL} is installed in the
783 expected path and meets the version requirement of @acronym{GPGME}.
785 This function returns the error code @code{GPG_ERR_NO_ERROR} if the
786 engine is available and @code{GPG_ERR_INV_ENGINE} if it is not.
790 @node Engine Information
791 @section Engine Information
792 @cindex engine, information about
794 @deftp {Data type} {gpgme_engine_info_t}
795 @tindex gpgme_protocol_t
796 The @code{gpgme_engine_info_t} type specifies a pointer to a structure
797 describing a crypto engine. The structure contains the following
801 @item gpgme_engine_info_t next
802 This is a pointer to the next engine info structure in the linked
803 list, or @code{NULL} if this is the last element.
805 @item gpgme_protocol_t protocol
806 This is the protocol for which the crypto engine is used. You can
807 convert this to a string with @code{gpgme_get_protocol_name} for
810 @item const char *file_name
811 This is a string holding the file name of the executable of the crypto
812 engine. Currently, it is never @code{NULL}, but using @code{NULL} is
813 reserved for future use, so always check before you use it.
815 @item const char *home_dir
816 This is a string holding the directory name of the crypto engine's
817 configuration directory. If it is @code{NULL}, then the default
820 @item const char *version
821 This is a string containing the version number of the crypto engine.
822 It might be @code{NULL} if the version number can not be determined,
823 for example because the executable doesn't exist or is invalid.
825 @item const char *req_version
826 This is a string containing the minimum required version number of the
827 crypto engine for @acronym{GPGME} to work correctly. This is the
828 version number that @code{gpgme_engine_check_version} verifies
829 against. Currently, it is never @code{NULL}, but using @code{NULL} is
830 reserved for future use, so always check before you use it.
834 @deftypefun gpgme_error_t gpgme_get_engine_info (@w{gpgme_engine_info_t *@var{info}})
835 The function @code{gpgme_get_engine_info} returns a linked list of
836 engine info structures in @var{info}. Each info structure describes
837 the defaults of one configured backend.
839 The memory for the info structures is allocated the first time this
840 function is invoked, and must not be freed by the caller.
842 This function returns the error code @code{GPG_ERR_NO_ERROR} if
843 successful, and a system error if the memory could not be allocated.
846 Here is an example how you can provide more diagnostics if you receive
847 an error message which indicates that the crypto engine is invalid.
855 if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
857 gpgme_engine_info_t info;
858 err = gpgme_get_engine_info (&info);
861 while (info && info->protocol != gpgme_get_protocol (ctx))
864 fprintf (stderr, "GPGME compiled without support for protocol %s",
865 gpgme_get_protocol_name (info->protocol));
866 else if (info->path && !info->version)
867 fprintf (stderr, "Engine %s not installed properly",
869 else if (info->path && info->version && info->req_version)
870 fprintf (stderr, "Engine %s version %s installed, "
871 "but at least version %s required", info->path,
872 info->version, info->req_version);
874 fprintf (stderr, "Unknown problem with engine for protocol %s",
875 gpgme_get_protocol_name (info->protocol));
881 @node Engine Configuration
882 @section Engine Configuration
883 @cindex engine, configuration of
884 @cindex configuration of crypto backend
886 You can change the configuration of a backend engine, and thus change
887 the executable program and configuration directory to be used. You
888 can make these changes the default or set them for some contexts
891 @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}})
892 The function @code{gpgme_set_engine_info} changes the default
893 configuration of the crypto engine implementing the protocol
896 @var{file_name} is the file name of the executable program
897 implementing this protocol, and @var{home_dir} is the directory name
898 of the configuration directory for this crypto engine. If
899 @var{home_dir} is @code{NULL}, the engine's default will be used.
901 The new defaults are not applied to already created GPGME contexts.
903 This function returns the error code @code{GPG_ERR_NO_ERROR} if
904 successful, or an eror code on failure.
907 The functions @code{gpgme_ctx_get_engine_info} and
908 @code{gpgme_ctx_set_engine_info} can be used to change the engine
909 configuration per context. @xref{Crypto Engine}.
916 @cindex protocol, GnuPG
917 @cindex engine, GnuPG
919 OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard.
920 This is the first protocol that was supported by @acronym{GPGME}.
922 The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}.
925 @node Cryptographic Message Syntax
926 @section Cryptographic Message Syntax
928 @cindex cryptographic message syntax
930 @cindex protocol, CMS
931 @cindex engine, GpgSM
933 @cindex protocol, S/MIME
935 @acronym{CMS} is implemented by GpgSM, the S/MIME implementation for
938 The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}.
945 The crypto backends support a variety of algorithms used in public key
946 cryptography. The following sections list the identifiers used to
947 denote such an algorithm.
950 * Public Key Algorithms:: A list of all public key algorithms.
951 * Hash Algorithms:: A list of all hash algorithms.
955 @node Public Key Algorithms
956 @section Public Key Algorithms
957 @cindex algorithms, public key
958 @cindex public key algorithms
960 Public key algorithms are used for encryption, decryption, signing and
961 verification of signatures.
963 @deftp {Data type} {enum gpgme_pubkey_algo_t}
964 @tindex gpgme_pubkey_algo_t
965 The @code{gpgme_pubkey_algo_t} type specifies the set of all public key
966 algorithms that are supported by @acronym{GPGME}. Possible values
971 This value indicates the RSA (Rivest, Shamir, Adleman) algorithm.
974 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
975 algorithm for encryption and decryption only.
978 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
979 algorithm for signing and verification only.
982 This value indicates DSA, the Digital Signature Algorithm.
985 This value indicates ElGamal.
988 This value also indicates ElGamal and is used specifically in GnuPG.
992 @deftypefun {const char *} gpgme_pubkey_algo_name (@w{gpgme_pubkey_algo_t @var{algo}})
993 The function @code{gpgme_pubkey_algo_name} returns a pointer to a
994 statically allocated string containing a description of the public key
995 algorithm @var{algo}. This string can be used to output the name of
996 the public key algorithm to the user.
998 If @var{algo} is not a valid public key algorithm, @code{NULL} is
1003 @node Hash Algorithms
1004 @section Hash Algorithms
1005 @cindex algorithms, hash
1006 @cindex algorithms, message digest
1007 @cindex hash algorithms
1008 @cindex message digest algorithms
1010 Hash (message digest) algorithms are used to compress a long message
1011 to make it suitable for public key cryptography.
1013 @deftp {Data type} {enum gpgme_hash_algo_t}
1014 @tindex gpgme_hash_algo_t
1015 The @code{gpgme_hash_algo_t} type specifies the set of all hash algorithms
1016 that are supported by @acronym{GPGME}. Possible values are:
1021 @item GPGME_MD_RMD160
1023 @item GPGME_MD_TIGER
1024 @item GPGME_MD_HAVAL
1025 @item GPGME_MD_SHA256
1026 @item GPGME_MD_SHA384
1027 @item GPGME_MD_SHA512
1029 @item GPGME_MD_CRC32
1030 @item GPGME_MD_CRC32_RFC1510
1031 @item GPGME_MD_CRC24_RFC2440
1035 @deftypefun {const char *} gpgme_hash_algo_name (@w{gpgme_hash_algo_t @var{algo}})
1036 The function @code{gpgme_hash_algo_name} returns a pointer to a
1037 statically allocated string containing a description of the hash
1038 algorithm @var{algo}. This string can be used to output the name of
1039 the hash algorithm to the user.
1041 If @var{algo} is not a valid hash algorithm, @code{NULL} is returned.
1045 @node Error Handling
1046 @chapter Error Handling
1047 @cindex error handling
1049 Many functions in @acronym{GPGME} can return an error if they fail.
1050 For this reason, the application should always catch the error
1051 condition and take appropriate measures, for example by releasing the
1052 resources and passing the error up to the caller, or by displaying a
1053 descriptive message to the user and cancelling the operation.
1055 Some error values do not indicate a system error or an error in the
1056 operation, but the result of an operation that failed properly. For
1057 example, if you try to decrypt a tempered message, the decryption will
1058 fail. Another error value actually means that the end of a data
1059 buffer or list has been reached. The following descriptions explain
1060 for many error codes what they mean usually. Some error values have
1061 specific meanings if returned by a certain functions. Such cases are
1062 described in the documentation of those functions.
1064 @acronym{GPGME} uses the @code{libgpg-error} library. This allows to
1065 share the error codes with other components of the GnuPG system, and
1066 thus pass error values transparently from the crypto engine, or some
1067 helper application of the crypto engine, to the user. This way no
1068 information is lost. As a consequence, @acronym{GPGME} does not use
1069 its own identifiers for error codes, but uses those provided by
1070 @code{libgpg-error}. They usually start with @code{GPG_ERR_}.
1072 However, @acronym{GPGME} does provide aliases for the functions
1073 defined in libgpg-error, which might be preferred for name space
1077 * Error Values:: The error value and what it means.
1078 * Error Sources:: A list of important error sources.
1079 * Error Codes:: A list of important error codes.
1080 * Error Strings:: How to get a descriptive string from a value.
1085 @section Error Values
1086 @cindex error values
1088 @cindex error sources
1090 @deftp {Data type} {gpgme_err_code_t}
1091 The @code{gpgme_err_code_t} type is an alias for the @code{libgpg-error}
1092 type @code{gpg_err_code_t}. The error code indicates the type of an
1093 error, or the reason why an operation failed.
1095 A list of important error codes can be found in the next section.
1098 @deftp {Data type} {gpgme_err_source_t}
1099 The @code{gpgme_err_source_t} type is an alias for the
1100 @code{libgpg-error} type @code{gpg_err_source_t}. The error source
1101 has not a precisely defined meaning. Sometimes it is the place where
1102 the error happened, sometimes it is the place where an error was
1103 encoded into an error value. Usually the error source will give an
1104 indication to where to look for the problem. This is not always true,
1105 but it is attempted to achieve this goal.
1107 A list of important error sources can be found in the next section.
1110 @deftp {Data type} {gpgme_error_t}
1111 The @code{gpgme_error_t} type is an alias for the @code{libgpg-error}
1112 type @code{gpg_error_t}. An error value like this has always two
1113 components, an error code and an error source. Both together form the
1116 Thus, the error value can not be directly compared against an error
1117 code, but the accessor functions described below must be used.
1118 However, it is guaranteed that only 0 is used to indicate success
1119 (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of
1120 the error value are set to 0, too.
1122 Note that in @acronym{GPGME}, the error source is used purely for
1123 diagnostical purposes. Only the error code should be checked to test
1124 for a certain outcome of a function. The manual only documents the
1125 error code part of an error value. The error source is left
1126 unspecified and might be anything.
1129 @deftypefun {static inline gpgme_err_code_t} gpgme_err_code (@w{gpgme_error_t @var{err}})
1130 The static inline function @code{gpgme_err_code} returns the
1131 @code{gpgme_err_code_t} component of the error value @var{err}. This
1132 function must be used to extract the error code from an error value in
1133 order to compare it with the @code{GPG_ERR_*} error code macros.
1136 @deftypefun {static inline gpgme_err_source_t} gpgme_err_source (@w{gpgme_error_t @var{err}})
1137 The static inline function @code{gpgme_err_source} returns the
1138 @code{gpgme_err_source_t} component of the error value @var{err}. This
1139 function must be used to extract the error source from an error value in
1140 order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros.
1143 @deftypefun {static inline gpgme_error_t} gpgme_err_make (@w{gpgme_err_source_t @var{source}}, @w{gpgme_err_code_t @var{code}})
1144 The static inline function @code{gpgme_err_make} returns the error
1145 value consisting of the error source @var{source} and the error code
1148 This function can be used in callback functions to construct an error
1149 value to return it to the library.
1152 @deftypefun {static inline gpgme_error_t} gpgme_error (@w{gpgme_err_code_t @var{code}})
1153 The static inline function @code{gpgme_error} returns the error value
1154 consisting of the default error source and the error code @var{code}.
1156 For @acronym{GPGME} applications, the default error source is
1157 @code{GPG_ERR_SOURCE_USER_1}. You can define
1158 @code{GPGME_ERR_SOURCE_DEFAULT} before including @file{gpgme.h} to
1159 change this default.
1161 This function can be used in callback functions to construct an error
1162 value to return it to the library.
1165 The @code{libgpg-error} library provides error codes for all system
1166 error numbers it knows about. If @var{err} is an unknown error
1167 number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The
1168 following functions can be used to construct error values from system
1171 @deftypefun {gpgme_error_t} gpgme_err_make_from_errno (@w{gpgme_err_source_t @var{source}}, @w{int @var{err}})
1172 The function @code{gpgme_err_make_from_errno} is like
1173 @code{gpgme_err_make}, but it takes a system error like @code{errno}
1174 instead of a @code{gpgme_err_code_t} error code.
1177 @deftypefun {gpgme_error_t} gpgme_error_from_errno (@w{int @var{err}})
1178 The function @code{gpgme_error_from_errno} is like @code{gpgme_error},
1179 but it takes a system error like @code{errno} instead of a
1180 @code{gpgme_err_code_t} error code.
1183 Sometimes you might want to map system error numbers to error codes
1184 directly, or map an error code representing a system error back to the
1185 system error number. The following functions can be used to do that.
1187 @deftypefun {gpgme_err_code_t} gpgme_err_code_from_errno (@w{int @var{err}})
1188 The function @code{gpgme_err_code_from_errno} returns the error code
1189 for the system error @var{err}. If @var{err} is not a known system
1190 error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}.
1193 @deftypefun {int} gpgme_err_code_to_errno (@w{gpgme_err_code_t @var{err}})
1194 The function @code{gpgme_err_code_to_errno} returns the system error
1195 for the error code @var{err}. If @var{err} is not an error code
1196 representing a system error, or if this system error is not defined on
1197 this system, the function returns @code{0}.
1202 @section Error Sources
1203 @cindex error codes, list of
1205 The library @code{libgpg-error} defines an error source for every
1206 component of the GnuPG system. The error source part of an error
1207 value is not well defined. As such it is mainly useful to improve the
1208 diagnostic error message for the user.
1210 If the error code part of an error value is @code{0}, the whole error
1211 value will be @code{0}. In this case the error source part is of
1212 course @code{GPG_ERR_SOURCE_UNKNOWN}.
1214 The list of error sources that might occur in applications using
1218 @item GPG_ERR_SOURCE_UNKNOWN
1219 The error source is not known. The value of this error source is
1222 @item GPG_ERR_SOURCE_GPGME
1223 The error source is @acronym{GPGME} itself. This is the default for
1224 errors that occur in the @acronym{GPGME} library.
1226 @item GPG_ERR_SOURCE_GPG
1227 The error source is GnuPG, which is the crypto engine used for the
1230 @item GPG_ERR_SOURCE_GPGSM
1231 The error source is GPGSM, which is the crypto engine used for the
1234 @item GPG_ERR_SOURCE_GCRYPT
1235 The error source is @code{libgcrypt}, which is used by crypto engines
1236 to perform cryptographic operations.
1238 @item GPG_ERR_SOURCE_GPGAGENT
1239 The error source is @command{gpg-agent}, which is used by crypto
1240 engines to perform operations with the secret key.
1242 @item GPG_ERR_SOURCE_PINENTRY
1243 The error source is @command{pinentry}, which is used by
1244 @command{gpg-agent} to query the passphrase to unlock a secret key.
1246 @item GPG_ERR_SOURCE_SCD
1247 The error source is the SmartCard Daemon, which is used by
1248 @command{gpg-agent} to delegate operations with the secret key to a
1251 @item GPG_ERR_SOURCE_KEYBOX
1252 The error source is @code{libkbx}, a library used by the crypto
1253 engines to manage local keyrings.
1255 @item GPG_ERR_SOURCE_USER_1
1256 @item GPG_ERR_SOURCE_USER_2
1257 @item GPG_ERR_SOURCE_USER_3
1258 @item GPG_ERR_SOURCE_USER_4
1259 These error sources are not used by any GnuPG component and can be
1260 used by other software. For example, applications using
1261 @acronym{GPGME} can use them to mark error values coming from callback
1262 handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors
1263 created with @code{gpgme_error} and @code{gpgme_error_from_errno},
1264 unless you define @code{GPGME_ERR_SOURCE_DEFAULT} before including
1270 @section Error Codes
1271 @cindex error codes, list of
1273 The library @code{libgpg-error} defines many error values. Most of
1274 them are not used by @code{GPGME} directly, but might be returned by
1275 @acronym{GPGME} because it received them from the crypto engine. The
1276 below list only includes such error codes that have a specific meaning
1277 in @code{GPGME}, or which are so common that you should know about
1282 This value indicates the end of a list, buffer or file.
1284 @item GPG_ERR_NO_ERROR
1285 This value indicates success. The value of this error code is
1286 @code{0}. Also, it is guaranteed that an error value made from the
1287 error code @code{0} will be @code{0} itself (as a whole). This means
1288 that the error source information is lost for this error code,
1289 however, as this error code indicates that no error occured, this is
1290 generally not a problem.
1292 @item GPG_ERR_GENERAL
1293 This value means that something went wrong, but either there is not
1294 enough information about the problem to return a more useful error
1295 value, or there is no separate error value for this type of problem.
1297 @item GPG_ERR_ENOMEM
1298 This value means that an out-of-memory condition occurred.
1301 System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
1304 @item GPG_ERR_INV_VALUE
1305 This value means that some user provided data was out of range. This
1306 can also refer to objects. For example, if an empty
1307 @code{gpgme_data_t} object was expected, but one containing data was
1308 provided, this error value is returned.
1310 @item GPG_ERR_UNUSABLE_PUBKEY
1311 This value means that some recipients for a message were invalid.
1313 @item GPG_ERR_UNUSABLE_SECKEY
1314 This value means that some signers were invalid.
1316 @item GPG_ERR_NO_DATA
1317 This value means that a @code{gpgme_data_t} object which was expected
1318 to have content was found empty.
1320 @item GPG_ERR_CONFLICT
1321 This value means that a conflict of some sort occurred.
1323 @item GPG_ERR_NOT_IMPLEMENTED
1324 This value indicates that the specific function (or operation) is not
1325 implemented. This error should never happen. It can only occur if
1326 you use certain values or configuration options which do not work,
1327 but for which we think that they should work at some later time.
1329 @item GPG_ERR_DECRYPT_FAILED
1330 This value indicates that a decryption operation was unsuccessful.
1332 @item GPG_ERR_BAD_PASSPHRASE
1333 This value means that the user did not provide a correct passphrase
1336 @item GPG_ERR_CANCELED
1337 This value means that the operation was canceled.
1339 @item GPG_ERR_INV_ENGINE
1340 This value means that the engine that implements the desired protocol
1341 is currently not available. This can either be because the sources
1342 were configured to exclude support for this engine, or because the
1343 engine is not installed properly.
1345 @item GPG_ERR_AMBIGUOUS_NAME
1346 This value indicates that a user ID or other specifier did not specify
1349 @item GPG_ERR_WRONG_KEY_USAGE
1350 This value indicates that a key is not used appropriately.
1352 @item GPG_ERR_CERT_REVOKED
1353 This value indicates that a key signature was revoced.
1355 @item GPG_ERR_CERT_EXPIRED
1356 This value indicates that a key signature expired.
1358 @item GPG_ERR_NO_CRL_KNOWN
1359 This value indicates that no certificate revocation list is known for
1362 @item GPG_ERR_NO_POLICY_MATCH
1363 This value indicates that a policy issue occured.
1365 @item GPG_ERR_NO_SECKEY
1366 This value indicates that no secret key for the user ID is available.
1368 @item GPG_ERR_MISSING_CERT
1369 This value indicates that a key could not be imported because the
1370 issuer certificate is missing.
1372 @item GPG_ERR_BAD_CERT_CHAIN
1373 This value indicates that a key could not be imported because its
1374 certificate chain is not good, for example it could be too long.
1376 @item GPG_ERR_UNSUPPORTED_ALGORITHM
1377 This value means a verification failed because the cryptographic
1378 algorithm is not supported by the crypto backend.
1380 @item GPG_ERR_BAD_SIGNATURE
1381 This value means a verification failed because the signature is bad.
1383 @item GPG_ERR_NO_PUBKEY
1384 This value means a verification failed because the public key is not
1387 @item GPG_ERR_USER_1
1388 @item GPG_ERR_USER_2
1390 @item GPG_ERR_USER_16
1391 These error codes are not used by any GnuPG component and can be
1392 freely used by other software. Applications using @acronym{GPGME}
1393 might use them to mark specific errors returned by callback handlers
1394 if no suitable error codes (including the system errors) for
1395 these errors exist already.
1400 @section Error Strings
1401 @cindex error values, printing of
1402 @cindex error codes, printing of
1403 @cindex error sources, printing of
1404 @cindex error strings
1406 @deftypefun {const char *} gpgme_strerror (@w{gpgme_error_t @var{err}})
1407 The function @code{gpgme_strerror} returns a pointer to a statically
1408 allocated string containing a description of the error code contained
1409 in the error value @var{err}. This string can be used to output a
1410 diagnostic message to the user.
1412 This function is not thread safe. Use @code{gpgme_strerror_r} in
1413 multi-threaded programs.
1417 @deftypefun {int} gpgme_strerror_r (@w{gpgme_error_t @var{err}}, @w{char *@var{buf}}, @w{size_t @var{buflen}})
1418 The function @code{gpgme_strerror_r} returns the error string for
1419 @var{err} in the user-supplied buffer @var{buf} of size @var{buflen}.
1420 This function is, in contrast to @code{gpgme_strerror}, thread-safe if
1421 a thread-safe @code{strerror_r} function is provided by the system.
1422 If the function succeeds, 0 is returned and @var{buf} contains the
1423 string describing the error. If the buffer was not large enough,
1424 ERANGE is returned and @var{buf} contains as much of the beginning of
1425 the error string as fits into the buffer.
1429 @deftypefun {const char *} gpgme_strsource (@w{gpgme_error_t @var{err}})
1430 The function @code{gpgme_strerror} returns a pointer to a statically
1431 allocated string containing a description of the error source
1432 contained in the error value @var{err}. This string can be used to
1433 output a diagnostic message to the user.
1436 The following example illustrates the use of @code{gpgme_strerror}:
1440 gpgme_error_t err = gpgme_new (&ctx);
1443 fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
1444 argv[0], gpgme_strsource (err), gpgme_strerror (err));
1450 @node Exchanging Data
1451 @chapter Exchanging Data
1452 @cindex data, exchanging
1454 A lot of data has to be exchanged between the user and the crypto
1455 engine, like plaintext messages, ciphertext, signatures and
1456 information about the keys. The technical details about exchanging
1457 the data information are completely abstracted by @acronym{GPGME}.
1458 The user provides and receives the data via @code{gpgme_data_t} objects,
1459 regardless of the communication protocol between @acronym{GPGME} and
1460 the crypto engine in use.
1462 @deftp {Data type} {gpgme_data_t}
1463 The @code{gpgme_data_t} type is a handle for a container for generic
1464 data, which is used by @acronym{GPGME} to exchange data with the user.
1468 * Creating Data Buffers:: Creating new data buffers.
1469 * Destroying Data Buffers:: Releasing data buffers.
1470 * Manipulating Data Buffers:: Operations on data buffers.
1474 @node Creating Data Buffers
1475 @section Creating Data Buffers
1476 @cindex data buffer, creation
1478 Data objects can be based on memory, files, or callback functions
1479 provided by the user. Not all operations are supported by all
1484 * Memory Based Data Buffers:: Creating memory based data buffers.
1485 * File Based Data Buffers:: Creating file based data buffers.
1486 * Callback Based Data Buffers:: Creating callback based data buffers.
1490 @node Memory Based Data Buffers
1491 @subsection Memory Based Data Buffers
1493 Memory based data objects store all data in allocated memory. This is
1494 convenient, but only practical for an amount of data that is a
1495 fraction of the available physical memory. The data has to be copied
1496 from its source and to its destination, which can often be avoided by
1497 using one of the other data object
1499 @deftypefun gpgme_error_t gpgme_data_new (@w{gpgme_data_t *@var{dh}})
1500 The function @code{gpgme_data_new} creates a new @code{gpgme_data_t}
1501 object and returns a handle for it in @var{dh}. The data object is
1502 memory based and initially empty.
1504 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1505 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1506 @var{dh} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1507 enough memory is available.
1510 @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}})
1511 The function @code{gpgme_data_new_from_mem} creates a new
1512 @code{gpgme_data_t} object and fills it with @var{size} bytes starting
1515 If @var{copy} is not zero, a private copy of the data is made. If
1516 @var{copy} is zero, the data is taken from the specified buffer as
1517 needed, and the user has to ensure that the buffer remains valid for
1518 the whole life span of the data object.
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{buffer} is not a valid pointer, and
1523 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1526 @deftypefun gpgme_error_t gpgme_data_new_from_file (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}})
1527 The function @code{gpgme_data_new_from_file} creates a new
1528 @code{gpgme_data_t} object and fills it with the content of the file
1531 If @var{copy} is not zero, the whole file is read in at initialization
1532 time and the file is not used anymore after that. This is the only
1533 mode supported currently. Later, a value of zero for @var{copy} might
1534 cause all reads to be delayed until the data is needed, but this is
1535 not yet implemented.
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} or @var{filename} is not a valid pointer,
1540 @code{GPG_ERR_NOT_IMPLEMENTED} if @var{code} is zero, and
1541 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1544 @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}})
1545 The function @code{gpgme_data_new_from_filepart} creates a new
1546 @code{gpgme_data_t} object and fills it with a part of the file specified
1547 by @var{filename} or @var{fp}.
1549 Exactly one of @var{filename} and @var{fp} must be non-zero, the other
1550 must be zero. The argument that is not zero specifies the file from
1551 which @var{length} bytes are read into the data object, starting from
1554 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1555 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1556 @var{dh} and exactly one of @var{filename} and @var{fp} is not a valid
1557 pointer, and @code{GPG_ERR_ENOMEM} if not enough memory is available.
1561 @node File Based Data Buffers
1562 @subsection File Based Data Buffers
1564 File based data objects operate directly on file descriptors or
1565 streams. Only a small amount of data is stored in core at any time,
1566 so the size of the data objects is not limited by @acronym{GPGME}.
1568 @deftypefun gpgme_error_t gpgme_data_new_from_fd (@w{gpgme_data_t *@var{dh}}, @w{int @var{fd}})
1569 The function @code{gpgme_data_new_from_fd} creates a new
1570 @code{gpgme_data_t} object and uses the file descriptor @var{fd} to read
1571 from (if used as an input data object) and write to (if used as an
1572 output data object).
1574 When using the data object as an input buffer, the function might read
1575 a bit more from the file descriptor than is actually needed by the
1576 crypto engine in the desired operation because of internal buffering.
1578 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1579 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1580 enough memory is available.
1583 @deftypefun gpgme_error_t gpgme_data_new_from_stream (@w{gpgme_data_t *@var{dh}}, @w{FILE *@var{stream}})
1584 The function @code{gpgme_data_new_from_stream} creates a new
1585 @code{gpgme_data_t} object and uses the I/O stream @var{stream} to read
1586 from (if used as an input data object) and write to (if used as an
1587 output data object).
1589 When using the data object as an input buffer, the function might read
1590 a bit more from the stream than is actually needed by the crypto
1591 engine in the desired operation because of internal buffering.
1593 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1594 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1595 enough memory is available.
1599 @node Callback Based Data Buffers
1600 @subsection Callback Based Data Buffers
1602 If neither memory nor file based data objects are a good fit for your
1603 application, you can implement the functions a data object provides
1604 yourself and create a data object from these callback functions.
1606 @deftp {Data type} {ssize_t (*gpgme_data_read_cb_t) (@w{void *@var{handle}}, @w{void @var{*buffer}}, @w{size_t @var{size}})}
1607 @tindex gpgme_data_read_cb_t
1608 The @code{gpgme_data_read_cb_t} type is the type of functions which
1609 @acronym{GPGME} calls if it wants to read data from a user-implemented
1610 data object. The function should read up to @var{size} bytes from the
1611 current read position into the space starting at @var{buffer}. The
1612 @var{handle} is provided by the user at data object creation time.
1614 The function should return the number of bytes read, 0 on EOF, and -1
1615 on error. If an error occurs, @var{errno} should be set to describe
1616 the type of the error.
1619 @deftp {Data type} {ssize_t (*gpgme_data_write_cb_t) (@w{void *@var{handle}}, @w{const void @var{*buffer}}, @w{size_t @var{size}})}
1620 @tindex gpgme_data_write_cb_t
1621 The @code{gpgme_data_write_cb_t} type is the type of functions which
1622 @acronym{GPGME} calls if it wants to write data to a user-implemented
1623 data object. The function should write up to @var{size} bytes to the
1624 current write position from the space starting at @var{buffer}. The
1625 @var{handle} is provided by the user at data object creation time.
1627 The function should return the number of bytes written, and -1 on
1628 error. If an error occurs, @var{errno} should be set to describe the
1632 @deftp {Data type} {off_t (*gpgme_data_seek_cb_t) (@w{void *@var{handle}}, @w{off_t @var{offset}}, @w{int @var{whence}})}
1633 @tindex gpgme_data_seek_cb_t
1634 The @code{gpgme_data_seek_cb_t} type is the type of functions which
1635 @acronym{GPGME} calls if it wants to change the current read/write
1636 position in a user-implemented data object, just like the @code{lseek}
1639 The function should return the new read/write position, and -1 on
1640 error. If an error occurs, @var{errno} should be set to describe the
1644 @deftp {Data type} {void (*gpgme_data_release_cb_t) (@w{void *@var{handle}})}
1645 @tindex gpgme_data_release_cb_t
1646 The @code{gpgme_data_release_cb_t} type is the type of functions which
1647 @acronym{GPGME} calls if it wants to destroy a user-implemented data
1648 object. The @var{handle} is provided by the user at data object
1652 @deftp {Data type} {struct gpgme_data_cbs}
1653 This structure is used to store the data callback interface functions
1654 described above. It has the following members:
1657 @item gpgme_data_read_cb_t read
1658 This is the function called by @acronym{GPGME} to read data from the
1659 data object. It is only required for input data object.
1661 @item gpgme_data_write_cb_t write
1662 This is the function called by @acronym{GPGME} to write data to the
1663 data object. It is only required for output data object.
1665 @item gpgme_data_seek_cb_t seek
1666 This is the function called by @acronym{GPGME} to change the current
1667 read/write pointer in the data object (if available). It is optional.
1669 @item gpgme_data_release_cb_t release
1670 This is the function called by @acronym{GPGME} to release a data
1671 object. It is optional.
1675 @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}})
1676 The function @code{gpgme_data_new_from_cbs} creates a new
1677 @code{gpgme_data_t} object and uses the user-provided callback functions
1678 to operate on the data object.
1680 The handle @var{handle} is passed as first argument to the callback
1681 functions. This can be used to identify this data object.
1683 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1684 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1685 enough memory is available.
1688 The following interface is deprecated and only provided for backward
1689 compatibility. Don't use it. It will be removed in a future version
1692 @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}})
1693 The function @code{gpgme_data_new_with_read_cb} creates a new
1694 @code{gpgme_data_t} object and uses the callback function @var{readfunc}
1695 to retrieve the data on demand. As the callback function can supply
1696 the data in any way it wants, this is the most flexible data type
1697 @acronym{GPGME} provides. However, it can not be used to write data.
1699 The callback function receives @var{hook_value} as its first argument
1700 whenever it is invoked. It should return up to @var{count} bytes in
1701 @var{buffer}, and return the number of bytes actually read in
1702 @var{nread}. It may return @code{0} in @var{nread} if no data is
1703 currently available. To indicate @code{EOF} the function should
1704 return with an error code of @code{-1} and set @var{nread} to
1705 @code{0}. The callback function may support to reset its internal
1706 read pointer if it is invoked with @var{buffer} and @var{nread} being
1707 @code{NULL} and @var{count} being @code{0}.
1709 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1710 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1711 @var{dh} or @var{readfunc} is not a valid pointer, and
1712 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1716 @node Destroying Data Buffers
1717 @section Destroying Data Buffers
1718 @cindex data buffer, destruction
1720 @deftypefun void gpgme_data_release (@w{gpgme_data_t @var{dh}})
1721 The function @code{gpgme_data_release} destroys the data object with
1722 the handle @var{dh}. It releases all associated resources that were
1723 not provided by the user in the first place.
1726 @deftypefun {char *} gpgme_data_release_and_get_mem (@w{gpgme_data_t @var{dh}}, @w{size_t *@var{length}})
1727 The function @code{gpgme_data_release_and_get_mem} is like
1728 @code{gpgme_data_release}, except that it returns the data buffer and
1729 its length that was provided by the object.
1731 The user has to release the buffer with @code{gpgme_free}. In case
1732 the user provided the data buffer in non-copy mode, a copy will be
1733 made for this purpose.
1735 In case an error returns, or there is no suitable data buffer that can
1736 be returned to the user, the function will return @code{NULL}. In any
1737 case, the data object @var{dh} is destroyed.
1741 @deftypefun void gpgme_free (@w{void *@var{buffer}})
1742 The function @code{gpgme_free} releases the memory returned by
1743 @code{gpgme_data_release_and_get_mem}. It should be used instead of
1744 the system libraries @code{free} function in case different allocators
1745 are used in a single program.
1749 @node Manipulating Data Buffers
1750 @section Manipulating Data Buffers
1751 @cindex data buffer, manipulation
1753 Data buffers contain data and meta-data. The following operations can
1754 be used to manipulate both.
1758 * Data Buffer I/O Operations:: I/O operations on data buffers.
1759 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
1763 @node Data Buffer I/O Operations
1764 @subsection Data Buffer I/O Operations
1765 @cindex data buffer, I/O operations
1766 @cindex data buffer, read
1767 @cindex data buffer, write
1768 @cindex data buffer, seek
1770 @deftypefun ssize_t gpgme_data_read (@w{gpgme_data_t @var{dh}}, @w{void *@var{buffer}}, @w{size_t @var{length}})
1771 The function @code{gpgme_data_read} reads up to @var{length} bytes
1772 from the data object with the handle @var{dh} into the space starting
1775 If no error occurs, the actual amount read is returned. If the end of
1776 the data object is reached, the function returns 0.
1778 In all other cases, the function returns -1 and sets @var{errno}.
1781 @deftypefun ssize_t gpgme_data_write (@w{gpgme_data_t @var{dh}}, @w{const void *@var{buffer}}, @w{size_t @var{size}})
1782 The function @code{gpgme_data_write} writes up to @var{size} bytes
1783 starting from @var{buffer} into the data object with the handle
1784 @var{dh} at the current write position.
1786 The function returns the number of bytes actually written, or -1 if an
1787 error occurs. If an error occurs, @var{errno} is set.
1790 @deftypefun off_t gpgme_data_seek (@w{gpgme_data_t @var{dh}}, @w{off_t @var{offset}}, @w{int @var{whence}})
1791 The function @code{gpgme_data_seek} changes the current read/write
1794 The @var{whence} argument specifies how the @var{offset} should be
1795 interpreted. It must be one of the following symbolic constants:
1799 Specifies that @var{offset} is a count of characters from the
1800 beginning of the data object.
1803 Specifies that @var{offset} is a count of characters from the current
1804 file position. This count may be positive or negative.
1807 Specifies that @var{offset} is a count of characters from the end of
1808 the data object. A negative count specifies a position within the
1809 current extent of the data object; a positive count specifies a
1810 position past the current end. If you set the position past the
1811 current end, and actually write data, you will extend the data object
1812 with zeros up to that position.
1815 If successful, the function returns the resulting file position,
1816 measured in bytes from the beginning of the data object. You can use
1817 this feature together with @code{SEEK_CUR} to read the current
1818 read/write position.
1820 If the function fails, -1 is returned and @var{errno} is set.
1823 The following function is deprecated and should not be used. It will
1824 be removed in a future version of @acronym{GPGME}.
1826 @deftypefun gpgme_error_t gpgme_data_rewind (@w{gpgme_data_t @var{dh}})
1827 The function @code{gpgme_data_rewind} is equivalent to:
1830 return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
1831 ? gpgme_error_from_errno (errno) : 0;
1838 @node Data Buffer Meta-Data
1839 @subsection Data Buffer Meta-Data
1840 @cindex data buffer, meta-data
1841 @cindex data buffer, file name
1842 @cindex data buffer, encoding
1844 @deftypefun {char *} gpgme_data_get_file_name (@w{gpgme_data_t @var{dh}})
1845 The function @code{gpgme_data_get_file_name} returns a pointer to a
1846 string containing the file name associated with the data object. The
1847 file name will be stored in the output when encrypting or signing the
1848 data and will be returned to the user when decrypting or verifying the
1851 If no error occurs, the string containing the file name is returned.
1852 Otherwise, @code{NULL} will be returned.
1856 @deftypefun gpgme_error_t gpgme_data_set_file_name (@w{gpgme_data_t @var{dh}}, @w{const char *@var{file_name}})
1857 The function @code{gpgme_data_set_file_name} sets the file name
1858 associated with the data object. The file name will be stored in the
1859 output when encrypting or signing the data and will be returned to the
1860 user when decrypting or verifying the output data.
1862 The function returns the error code @code{GPG_ERR_INV_VALUE} if
1863 @var{dh} is not a valid pointer and @code{GPG_ERR_ENOMEM} if not
1864 enough memory is available.
1868 @deftp {Data type} {enum gpgme_data_encoding_t}
1869 @tindex gpgme_data_encoding_t
1870 The @code{gpgme_data_encoding_t} type specifies the encoding of a
1871 @code{gpgme_data_t} object. For input data objects, the encoding is
1872 useful to give the backend a hint on the type of data. For output
1873 data objects, the encoding can specify the output data format on
1874 certain operations. Please note that not all backends support all
1875 encodings on all operations. The following data types are available:
1878 @item GPGME_DATA_ENCODING_NONE
1879 This specifies that the encoding is not known. This is the default
1880 for a new data object. The backend will try its best to detect the
1881 encoding automatically.
1883 @item GPGME_DATA_ENCODING_BINARY
1884 This specifies that the data is encoding in binary form; i.e. there is
1885 no special encoding.
1887 @item GPGME_DATA_ENCODING_BASE64
1888 This specifies that the data is encoded using the Base-64 encoding
1889 scheme as used by @acronym{MIME} and other protocols.
1891 @item GPGME_DATA_ENCODING_ARMOR
1892 This specifies that the data is encoded in an armored form as used by
1897 @deftypefun gpgme_data_encoding_t gpgme_data_get_encoding (@w{gpgme_data_t @var{dh}})
1898 The function @code{gpgme_data_get_encoding} returns the encoding of
1899 the data object with the handle @var{dh}. If @var{dh} is not a valid
1900 pointer (e.g. @code{NULL}) @code{GPGME_DATA_ENCODING_NONE} is
1904 @deftypefun gpgme_error_t gpgme_data_set_encoding (@w{gpgme_data_t @var{dh}, gpgme_data_encoding_t @var{enc}})
1905 The function @code{gpgme_data_set_encoding} changes the encoding of
1906 the data object with the handle @var{dh} to @var{enc}.
1917 All cryptographic operations in @acronym{GPGME} are performed within a
1918 context, which contains the internal state of the operation as well as
1919 configuration parameters. By using several contexts you can run
1920 several cryptographic operations in parallel, with different
1923 @deftp {Data type} {gpgme_ctx_t}
1924 The @code{gpgme_ctx_t} type is a handle for a @acronym{GPGME} context,
1925 which is used to hold the configuration, status and result of
1926 cryptographic operations.
1930 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
1931 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
1932 * Context Attributes:: Setting properties of a context.
1933 * Key Management:: Managing keys with @acronym{GPGME}.
1934 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
1935 * Crypto Operations:: Using a context for cryptography.
1936 * Run Control:: Controlling how operations are run.
1940 @node Creating Contexts
1941 @section Creating Contexts
1942 @cindex context, creation
1944 @deftypefun gpgme_error_t gpgme_new (@w{gpgme_ctx_t *@var{ctx}})
1945 The function @code{gpgme_new} creates a new @code{gpgme_ctx_t} object
1946 and returns a handle for it in @var{ctx}.
1948 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1949 context was successfully created, @code{GPG_ERR_INV_VALUE} if
1950 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1951 enough memory is available.
1955 @node Destroying Contexts
1956 @section Destroying Contexts
1957 @cindex context, destruction
1959 @deftypefun void gpgme_release (@w{gpgme_ctx_t @var{ctx}})
1960 The function @code{gpgme_release} destroys the context with the handle
1961 @var{ctx} and releases all associated resources.
1965 @node Context Attributes
1966 @section Context Attributes
1967 @cindex context, attributes
1970 * Protocol Selection:: Selecting the protocol used by a context.
1971 * Crypto Engine:: Configuring the crypto engine.
1972 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
1973 * Text Mode:: Choosing canonical text mode.
1974 * Included Certificates:: Including a number of certificates.
1975 * Key Listing Mode:: Selecting key listing mode.
1976 * Passphrase Callback:: Getting the passphrase from the user.
1977 * Progress Meter Callback:: Being informed about the progress.
1978 * Locale:: Setting the locale of a context.
1982 @node Protocol Selection
1983 @subsection Protocol Selection
1984 @cindex context, selecting protocol
1985 @cindex protocol, selecting
1987 @deftypefun gpgme_error_t gpgme_set_protocol (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}})
1988 The function @code{gpgme_set_protocol} sets the protocol used within
1989 the context @var{ctx} to @var{proto}. All crypto operations will be
1990 performed by the crypto engine configured for that protocol.
1991 @xref{Protocols and Engines}.
1993 Setting the protocol with @code{gpgme_set_protocol} does not check if
1994 the crypto engine for that protocol is available and installed
1995 correctly. @xref{Engine Version Check}.
1997 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1998 protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if
1999 @var{protocol} is not a valid protocol.
2002 @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}})
2003 The function @code{gpgme_get_protocol} retrieves the protocol currently
2004 use with the context @var{ctx}.
2009 @subsection Crypto Engine
2010 @cindex context, configuring engine
2011 @cindex engine, configuration per context
2013 The following functions can be used to set and retrieve the
2014 configuration of the crypto engines of a specific context. The
2015 default can also be retrieved without any particular context.
2016 @xref{Engine Information}. The default can also be changed globally.
2017 @xref{Engine Configuration}.
2019 @deftypefun gpgme_engine_info_t gpgme_ctx_get_engine_info (@w{gpgme_ctx_t @var{ctx}})
2020 The function @code{gpgme_ctx_get_engine_info} returns a linked list of
2021 engine info structures. Each info structure describes the
2022 configuration of one configured backend, as used by the context
2025 The result is valid until the next invocation of
2026 @code{gpgme_ctx_set_engine_info} for this particular context.
2028 This function can not fail.
2031 @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}})
2032 The function @code{gpgme_ctx_set_engine_info} changes the
2033 configuration of the crypto engine implementing the protocol
2034 @var{proto} for the context @var{ctx}.
2036 @var{file_name} is the file name of the executable program
2037 implementing this protocol, and @var{home_dir} is the directory name
2038 of the configuration directory for this crypto engine. If
2039 @var{home_dir} is @code{NULL}, the engine's default will be used.
2041 Currently this function must be used before starting the first crypto
2042 operation. It is unspecified if and when the changes will take effect
2043 if the function is called after starting the first operation on the
2046 This function returns the error code @code{GPG_ERR_NO_ERROR} if
2047 successful, or an eror code on failure.
2051 @c FIXME: Unfortunately, using @acronym here breaks texi2dvi.
2053 @subsection @acronym{ASCII} Armor
2054 @cindex context, armor mode
2055 @cindex @acronym{ASCII} armor
2058 @deftypefun void gpgme_set_armor (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2059 The function @code{gpgme_set_armor} specifies if the output should be
2060 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
2063 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
2067 @deftypefun int gpgme_get_armor (@w{gpgme_ctx_t @var{ctx}})
2068 The function @code{gpgme_get_armor} returns 1 if the output is
2069 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
2070 not a valid pointer.
2075 @subsection Text Mode
2076 @cindex context, text mode
2078 @cindex canonical text mode
2080 @deftypefun void gpgme_set_textmode (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2081 The function @code{gpgme_set_textmode} specifies if canonical text mode
2082 should be used. By default, text mode is not used.
2084 Text mode is for example used for the RFC2015 signatures; note that
2085 the updated RFC 3156 mandates that the mail user agent does some
2086 preparations so that text mode is not needed anymore.
2088 This option is only relevant to the OpenPGP crypto engine, and ignored
2089 by all other engines.
2091 Canonical text mode is disabled if @var{yes} is zero, and enabled
2095 @deftypefun int gpgme_get_textmode (@w{gpgme_ctx_t @var{ctx}})
2096 The function @code{gpgme_get_textmode} returns 1 if canonical text
2097 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2102 @node Included Certificates
2103 @subsection Included Certificates
2104 @cindex certificates, included
2106 @deftypefun void gpgme_set_include_certs (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{nr_of_certs}})
2107 The function @code{gpgme_set_include_certs} specifies how many
2108 certificates should be included in an S/MIME signed message. By
2109 default, only the sender's certificate is included. The possible
2110 values of @var{nr_of_certs} are:
2113 @item GPGME_INCLUDE_CERTS_DEFAULT
2114 Fall back to the default of the crypto backend. This is the default
2117 Include all certificates except the root certificate.
2119 Include all certificates.
2121 Include no certificates.
2123 Include the sender's certificate only.
2125 Include the first n certificates of the certificates path, starting
2126 from the sender's certificate. The number @code{n} must be positive.
2129 Values of @var{nr_of_certs} smaller than -2 are undefined.
2131 This option is only relevant to the CMS crypto engine, and ignored by
2135 @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}})
2136 The function @code{gpgme_get_include_certs} returns the number of
2137 certificates to include into an S/MIME signed message.
2141 @node Key Listing Mode
2142 @subsection Key Listing Mode
2143 @cindex key listing mode
2144 @cindex key listing, mode of
2146 @deftypefun gpgme_error_t gpgme_set_keylist_mode (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_keylist_mode_t @var{mode}})
2147 The function @code{gpgme_set_keylist_mode} changes the default
2148 behaviour of the key listing functions. The value in @var{mode} is a
2149 bitwise-or combination of one or multiple of the following bit values:
2152 @item GPGME_KEYLIST_MODE_LOCAL
2153 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
2154 keyring should be searched for keys in the keylisting operation. This
2157 @item GPGME_KEYLIST_MODE_EXTERN
2158 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
2159 source should be searched for keys in the keylisting
2160 operation. The type of external source is dependant on the crypto
2161 engine used. For example, it can be a remote keyserver or LDAP
2164 @item GPGME_KEYLIST_MODE_SIGS
2165 The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key
2166 signatures should be included in the listed keys.
2168 @item GPGME_KEYLIST_MODE_SIG_NOTATIONS
2169 The @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} symbol specifies that the
2170 signature notations on key signatures should be included in the listed
2171 keys. This only works if @code{GPGME_KEYLIST_MODE_SIGS} is also
2174 @item GPGME_KEYLIST_MODE_VALIDATE
2175 The @code{GPGME_KEYLIST_MODE_VALIDATE} symbol specifies that the
2176 backend should do key or certificate validation and not just get the
2177 validity information from an internal cache. This might be an
2178 expensive operation and is in general not useful. Currently only
2179 implemented for the S/MIME backend and ignored for other backends.
2183 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
2184 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
2185 compatibility, you should get the current mode with
2186 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
2187 appropriate bits, and then using that calulcated value in the
2188 @code{gpgme_set_keylisting_mode} operation. This will leave all other
2189 bits in the mode value intact (in particular those that are not used
2190 in the current version of the library).
2192 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2193 mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx}
2194 is not a valid pointer or @var{mode} is not a valid mode.
2198 @deftypefun gpgme_keylist_mode_t gpgme_get_keylist_mode (@w{gpgme_ctx_t @var{ctx}})
2199 The function @code{gpgme_get_keylist_mode} returns the current key
2200 listing mode of the context @var{ctx}. This value can then be
2201 modified and used in a subsequent @code{gpgme_set_keylist_mode}
2202 operation to only affect the desired bits (and leave all others
2205 The function returns 0 if @var{ctx} is not a valid pointer, and the
2206 current mode otherwise. Note that 0 is not a valid mode value.
2210 @node Passphrase Callback
2211 @subsection Passphrase Callback
2212 @cindex callback, passphrase
2213 @cindex passphrase callback
2215 @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}})}
2216 @tindex gpgme_passphrase_cb_t
2217 The @code{gpgme_passphrase_cb_t} type is the type of functions usable as
2218 passphrase callback function.
2220 The argument @var{uid_hint} might contain a string that gives an
2221 indication for which user ID the passphrase is required. If this is
2222 not available, or not applicable (in the case of symmetric encryption,
2223 for example), @var{uid_hint} will be @code{NULL}.
2225 The argument @var{passphrase_info}, if not @code{NULL}, will give
2226 further information about the context in which the passphrase is
2227 required. This information is engine and operation specific.
2229 If this is the repeated attempt to get the passphrase, because
2230 previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
2233 The user must write the passphrase, followed by a newline character,
2234 to the file descriptor @var{fd}. If the user returns 0 indicating
2235 success, the user must at least write a newline character before
2236 returning from the callback.
2238 If an error occurs, return the corresponding @code{gpgme_error_t}
2239 value. You can use the error code @code{GPG_ERR_CANCELED} to abort
2240 the operation. Otherwise, return @code{0}.
2243 @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}})
2244 The function @code{gpgme_set_passphrase_cb} sets the function that is
2245 used when a passphrase needs to be provided by the user to
2246 @var{passfunc}. The function @var{passfunc} needs to implemented by
2247 the user, and whenever it is called, it is called with its first
2248 argument being @var{hook_value}. By default, no passphrase callback
2251 Not all crypto engines require this callback to retrieve the
2252 passphrase. It is better if the engine retrieves the passphrase from
2253 a trusted agent (a daemon process), rather than having each user to
2254 implement their own passphrase query. Some engines do not even
2255 support an external passphrase callback at all, in this case the error
2256 code @code{GPG_ERR_NOT_SUPPORTED} is returned.
2258 The user can disable the use of a passphrase callback function by
2259 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
2263 @deftypefun void gpgme_get_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t *@var{passfunc}}, @w{void **@var{hook_value}})
2264 The function @code{gpgme_get_passphrase_cb} returns the function that
2265 is used when a passphrase needs to be provided by the user in
2266 @var{*passfunc}, and the first argument for this function in
2267 @var{*hook_value}. If no passphrase callback is set, or @var{ctx} is
2268 not a valid pointer, @code{NULL} is returned in both variables.
2270 @var{passfunc} or @var{hook_value} can be @code{NULL}. In this case,
2271 the corresponding value will not be returned.
2275 @node Progress Meter Callback
2276 @subsection Progress Meter Callback
2277 @cindex callback, progress meter
2278 @cindex progress meter callback
2280 @deftp {Data type} {void (*gpgme_progress_cb_t)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
2281 @tindex gpgme_progress_cb_t
2282 The @code{gpgme_progress_cb_t} type is the type of functions usable as
2283 progress callback function.
2285 The arguments are specific to the crypto engine. More information
2286 about the progress information returned from the GnuPG engine can be
2287 found in the GnuPG source code in the file @file{doc/DETAILS} in the
2291 @deftypefun void gpgme_set_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t @var{progfunc}}, @w{void *@var{hook_value}})
2292 The function @code{gpgme_set_progress_cb} sets the function that is
2293 used when progress information about a cryptographic operation is
2294 available. The function @var{progfunc} needs to implemented by the
2295 user, and whenever it is called, it is called with its first argument
2296 being @var{hook_value}. By default, no progress callback function
2299 Setting a callback function allows an interactive program to display
2300 progress information about a long operation to the user.
2302 The user can disable the use of a progress callback function by
2303 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
2307 @deftypefun void gpgme_get_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t *@var{progfunc}}, @w{void **@var{hook_value}})
2308 The function @code{gpgme_get_progress_cb} returns the function that is
2309 used to inform the user about the progress made in @var{*progfunc},
2310 and the first argument for this function in @var{*hook_value}. If no
2311 progress callback is set, or @var{ctx} is not a valid pointer,
2312 @code{NULL} is returned in both variables.
2314 @var{progfunc} or @var{hook_value} can be @code{NULL}. In this case,
2315 the corresponding value will not be returned.
2321 @cindex locale, default
2322 @cindex locale, of a context
2324 A locale setting can be associated with a context. This locale is
2325 passed to the crypto engine, and used for applications like the PIN
2326 entry, which is displayed to the user when entering a passphrase is
2329 The default locale is used to initialize the locale setting of all
2330 contexts created afterwards.
2332 @deftypefun gpgme_error_t gpgme_set_locale (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{category}}, @w{const char *@var{value}})
2333 The function @code{gpgme_set_locale} sets the locale of the context
2334 @var{ctx}, or the default locale if @var{ctx} is a null pointer.
2336 The locale settings that should be changed are specified by
2337 @var{category}. Supported categories are @code{LC_CTYPE},
2338 @code{LC_MESSAGES}, and @code{LC_ALL}, which is a wildcard you can use
2339 if you want to change all the categories at once.
2341 The value to be used for the locale setting is @var{value}, which will
2342 be copied to @acronym{GPGME}'s internal data structures. @var{value}
2343 can be a null pointer, which disables setting the locale, and will
2344 make PIN entry and other applications use their default setting, which
2345 is usually not what you want.
2347 Note that the settings are only used if the application runs on a text
2348 terminal, and that the settings should fit the configuration of the
2349 output terminal. Normally, it is sufficient to initialize the default
2352 The function returns an error if not enough memory is available.
2356 @node Key Management
2357 @section Key Management
2358 @cindex key management
2360 Some of the cryptographic operations require that recipients or
2361 signers are specified. This is always done by specifying the
2362 respective keys that should be used for the operation. The following
2363 section describes how such keys can be selected and manipulated.
2365 @deftp {Data type} gpgme_sub_key_t
2366 The @code{gpgme_sub_key_t} type is a pointer to a subkey structure.
2367 Sub keys are one component of a @code{gpgme_key_t} object. In fact,
2368 subkeys are those parts that contains the real information about the
2369 individual cryptographic keys that belong to the same key object. One
2370 @code{gpgme_key_t} can contain several subkeys. The first subkey in
2371 the linked list is also called the primary key.
2373 The subkey structure has the following members:
2376 @item gpgme_sub_key_t next
2377 This is a pointer to the next subkey structure in the linked list, or
2378 @code{NULL} if this is the last element.
2380 @item unsigned int revoked : 1
2381 This is true if the subkey is revoked.
2383 @item unsigned int expired : 1
2384 This is true if the subkey is expired.
2386 @item unsigned int disabled : 1
2387 This is true if the subkey is disabled.
2389 @item unsigned int invalid : 1
2390 This is true if the subkey is invalid.
2392 @item unsigned int can_encrypt : 1
2393 This is true if the subkey can be used for encryption.
2395 @item unsigned int can_sign : 1
2396 This is true if the subkey can be used to create data signatures.
2398 @item unsigned int can_certify : 1
2399 This is true if the subkey can be used to create key certificates.
2401 @item unsigned int can_authenticate : 1
2402 This is true if the subkey can be used for authentication.
2404 @item unsigned int is_qualified : 1
2405 This is true if the subkey can be used for qualified signatures
2406 according to local government regulations.
2408 @item unsigned int secret : 1
2409 This is true if the subkey is a secret key. Note that it will be false
2410 if the key is actually a stub key; i.e. a secret key operation is
2411 currently not possible (offline-key).
2413 @item gpgme_pubkey_algo_t pubkey_algo
2414 This is the public key algorithm supported by this subkey.
2416 @item unsigned int length
2417 This is the length of the subkey (in bits).
2420 This is the key ID of the subkey in hexadecimal digits.
2423 This is the fingerprint of the subkey in hexadecimal digits, if
2426 @item long int timestamp
2427 This is the creation timestamp of the subkey. This is -1 if the
2428 timestamp is invalid, and 0 if it is not available.
2430 @item long int expires
2431 This is the expiration timestamp of the subkey, or 0 if the subkey
2436 @deftp {Data type} gpgme_key_sig_t
2437 The @code{gpgme_key_sig_t} type is a pointer to a key signature structure.
2438 Key signatures are one component of a @code{gpgme_key_t} object, and
2439 validate user IDs on the key.
2441 The signatures on a key are only available if the key was retrieved
2442 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
2443 enabled, because it can be expensive to retrieve all signatures of a
2446 The signature notations on a key signature are only available if the
2447 key was retrieved via a listing operation with the
2448 @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} mode enabled, because it can
2449 be expensive to retrieve all signature notations.
2451 The key signature structure has the following members:
2454 @item gpgme_key_sig_t next
2455 This is a pointer to the next key signature structure in the linked
2456 list, or @code{NULL} if this is the last element.
2458 @item unsigned int revoked : 1
2459 This is true if the key signature is a revocation signature.
2461 @item unsigned int expired : 1
2462 This is true if the key signature is expired.
2464 @item unsigned int invalid : 1
2465 This is true if the key signature is invalid.
2467 @item unsigned int exportable : 1
2468 This is true if the key signature is exportable.
2470 @item gpgme_pubkey_algo_t pubkey_algo
2471 This is the public key algorithm used to create the signature.
2474 This is the key ID of the key (in hexadecimal digits) used to create
2477 @item long int timestamp
2478 This is the creation timestamp of the key signature. This is -1 if
2479 the timestamp is invalid, and 0 if it is not available.
2481 @item long int expires
2482 This is the expiration timestamp of the key signature, or 0 if the key
2483 signature does not expire.
2485 @item gpgme_error_t status
2486 This is the status of the signature and has the same meaning as the
2487 member of the same name in a @code{gpgme_signature_t} object.
2489 @item unsigned int sig_class
2490 This specifies the signature class of the key signature. The meaning
2491 is specific to the crypto engine.
2494 This is the main user ID of the key used to create the signature.
2497 This is the name component of @code{uid}, if available.
2500 This is the comment component of @code{uid}, if available.
2503 This is the email component of @code{uid}, if available.
2505 @item gpgme_sig_notation_t notations
2506 This is a linked list with the notation data and policy URLs.
2510 @deftp {Data type} gpgme_user_id_t
2511 A user ID is a component of a @code{gpgme_key_t} object. One key can
2512 have many user IDs. The first one in the list is the main (or
2515 The user ID structure has the following members.
2518 @item gpgme_user_id_t next
2519 This is a pointer to the next user ID structure in the linked list, or
2520 @code{NULL} if this is the last element.
2522 @item unsigned int revoked : 1
2523 This is true if the user ID is revoked.
2525 @item unsigned int invalid : 1
2526 This is true if the user ID is invalid.
2528 @item gpgme_validity_t validity
2529 This specifies the validity of the user ID.
2532 This is the user ID string.
2535 This is the name component of @code{uid}, if available.
2538 This is the comment component of @code{uid}, if available.
2541 This is the email component of @code{uid}, if available.
2543 @item gpgme_key_sig_t signatures
2544 This is a linked list with the signatures on this user ID.
2548 @deftp {Data type} gpgme_key_t
2549 The @code{gpgme_key_t} type is a pointer to a key object. It has the
2553 @item gpgme_keylist_mode_t keylist_mode
2554 The keylist mode that was active when the key was retrieved.
2556 @item unsigned int revoked : 1
2557 This is true if the key is revoked.
2559 @item unsigned int expired : 1
2560 This is true if the key is expired.
2562 @item unsigned int disabled : 1
2563 This is true if the key is disabled.
2565 @item unsigned int invalid : 1
2566 This is true if the key is invalid. This might have several reasons,
2567 for a example for the S/MIME backend, it will be set in during key
2568 listsing if the key could not be validated due to a missing
2569 certificates or unmatched policies.
2571 @item unsigned int can_encrypt : 1
2572 This is true if the key (ie one of its subkeys) can be used for
2575 @item unsigned int can_sign : 1
2576 This is true if the key (ie one of its subkeys) can be used to create
2579 @item unsigned int can_certify : 1
2580 This is true if the key (ie one of its subkeys) can be used to create
2583 @item unsigned int can_authenticate : 1
2584 This is true if the key (ie one of its subkeys) can be used for
2587 @item unsigned int is_qualified : 1
2588 This is true if the key can be used for qualified signatures according
2589 to local government regulations.
2591 @item unsigned int secret : 1
2592 This is true if the key is a secret key. Note, that this will always be
2593 true even if the corresponding subkey flag may be false (offline/stub
2596 @item gpgme_protocol_t protocol
2597 This is the protocol supported by this key.
2599 @item char *issuer_serial
2600 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2603 @item char *issuer_name
2604 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2607 @item char *chain_id
2608 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2609 chain ID, which can be used to built the certificate chain.
2611 @item gpgme_validity_t owner_trust
2612 If @code{protocol} is @code{GPGME_PROTOCOL_OpenPGP}, then this is the
2615 @item gpgme_sub_key_t subkeys
2616 This is a linked list with the subkeys of the key. The first subkey
2617 in the list is the primary key and usually available.
2619 @item gpgme_user_id_t uids
2620 This is a linked list with the user IDs of the key. The first user ID
2621 in the list is the main (or primary) user ID.
2626 * Listing Keys:: Browsing the list of available keys.
2627 * Information About Keys:: Requesting detailed information about keys.
2628 * Key Signatures:: Listing the signatures on a key.
2629 * Manipulating Keys:: Operations on keys.
2630 * Generating Keys:: Creating new key pairs.
2631 * Exporting Keys:: Retrieving key data from the key ring.
2632 * Importing Keys:: Adding keys to the key ring.
2633 * Deleting Keys:: Removing keys from the key ring.
2634 * Advanced Key Editing:: Advanced key edit operation.
2639 @subsection Listing Keys
2640 @cindex listing keys
2642 @cindex key listing, start
2643 @cindex key ring, list
2644 @cindex key ring, search
2646 @deftypefun gpgme_error_t gpgme_op_keylist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
2647 The function @code{gpgme_op_keylist_start} initiates a key listing
2648 operation inside the context @var{ctx}. It sets everything up so that
2649 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
2652 If @var{pattern} is @code{NULL}, all available keys are returned.
2653 Otherwise, @var{pattern} contains an engine specific expression that
2654 is used to limit the list to all keys matching the pattern. Note that
2655 the total length of the pattern is restricted to an engine-specific
2656 maximum (a couple of hundred characters are usually accepted). The
2657 pattern should be used to restrict the search to a certain common name
2658 or user, not to list many specific keys at once by listing their
2659 fingerprints or key IDs.
2661 If @var{secret_only} is not @code{0}, the list is restricted to secret
2664 The context will be busy until either all keys are received (and
2665 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2666 @code{gpgme_op_keylist_end} is called to finish the operation.
2668 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2669 @var{ctx} is not a valid pointer, and passes through any errors that
2670 are reported by the crypto engine support routines.
2673 @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}})
2674 The function @code{gpgme_op_keylist_ext_start} initiates an extended
2675 key listing operation inside the context @var{ctx}. It sets
2676 everything up so that subsequent invocations of
2677 @code{gpgme_op_keylist_next} return the keys in the list.
2679 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
2680 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
2681 array of strings that are used to limit the list to all keys matching
2682 at least one of the patterns verbatim. Note that the total length of
2683 all patterns is restricted to an engine-specific maximum (the exact
2684 limit also depends on the number of patterns and amount of quoting
2685 required, but a couple of hundred characters are usually accepted).
2686 Patterns should be used to restrict the search to a certain common
2687 name or user, not to list many specific keys at once by listing their
2688 fingerprints or key IDs.
2690 If @var{secret_only} is not @code{0}, the list is restricted to secret
2693 The value of @var{reserved} must be @code{0}.
2695 The context will be busy until either all keys are received (and
2696 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2697 @code{gpgme_op_keylist_end} is called to finish the operation.
2699 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2700 @var{ctx} is not a valid pointer, and passes through any errors that
2701 are reported by the crypto engine support routines.
2704 @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}})
2705 The function @code{gpgme_op_keylist_next} returns the next key in the
2706 list created by a previous @code{gpgme_op_keylist_start} operation in
2707 the context @var{ctx}. The key will have one reference for the user.
2708 @xref{Manipulating Keys}.
2710 This is the only way to get at @code{gpgme_key_t} objects in
2713 If the last key in the list has already been returned,
2714 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}.
2716 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2717 @var{ctx} or @var{r_key} is not a valid pointer, and
2718 @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation.
2721 @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}})
2722 The function @code{gpgme_op_keylist_next} ends a pending key list
2723 operation in the context @var{ctx}.
2725 After the operation completed successfully, the result of the key
2726 listing operation can be retrieved with
2727 @code{gpgme_op_keylist_result}.
2729 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2730 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
2731 time during the operation there was not enough memory available.
2734 The following example illustrates how all keys containing a certain
2735 string (@code{g10code}) can be listed with their key ID and the name
2736 and e-mail address of the main user ID:
2740 gpgme_error_t err = gpgme_new (&ctx);
2744 err = gpgme_op_keylist_start (ctx, "g10code", 0);
2747 err = gpgme_op_keylist_next (ctx, &key);
2750 printf ("%s: %s <%s>\n", key->keyid, key->name, key->email);
2751 gpgme_key_release (key);
2753 gpgme_release (ctx);
2755 if (gpg_err_code (err) != GPG_ERR_EOF)
2757 fprintf (stderr, "%s: can not list keys: %s\n",
2758 argv[0], gpgme_strerror (err));
2763 @deftp {Data type} {gpgme_keylist_result_t}
2764 This is a pointer to a structure used to store the result of a
2765 @code{gpgme_op_keylist_*} operation. After successfully ending a key
2766 listing operation, you can retrieve the pointer to the result with
2767 @code{gpgme_op_keylist_result}. The structure contains the following
2771 @item unsigned int truncated : 1
2772 This is true if the crypto backend had to truncate the result, and
2773 less than the desired keys could be listed.
2777 @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}})
2778 The function @code{gpgme_op_keylist_result} returns a
2779 @code{gpgme_keylist_result_t} pointer to a structure holding the
2780 result of a @code{gpgme_op_keylist_*} operation. The pointer is only
2781 valid if the last operation on the context was a key listing
2782 operation, and if this operation finished successfully. The returned
2783 pointer is only valid until the next operation is started on the
2787 In a simple program, for which a blocking operation is acceptable, the
2788 following function can be used to retrieve a single key.
2790 @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}})
2791 The function @code{gpgme_get_key} gets the key with the fingerprint
2792 (or key ID) @var{fpr} from the crypto backend and return it in
2793 @var{r_key}. If @var{secret} is true, get the secret key. The
2794 currently active keylist mode is used to retrieve the key. The key
2795 will have one reference for the user.
2797 If the key is not found in the keyring, @code{gpgme_get_key} returns
2798 the error code @code{GPG_ERR_NO_ERROR} and *@var{r_key} will be set to
2801 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2802 @var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a
2803 fingerprint or key ID, @code{GPG_ERR_AMBIGUOUS_NAME} if the key ID was
2804 not a unique specifier for a key, and @code{GPG_ERR_ENOMEM} if at some
2805 time during the operation there was not enough memory available.
2809 @node Information About Keys
2810 @subsection Information About Keys
2811 @cindex key, information about
2812 @cindex key, attributes
2813 @cindex attributes, of a key
2815 Please see the beginning of this section for more information about
2816 @code{gpgme_key_t} objects.
2818 @deftp {Data type} gpgme_validity_t
2819 The @code{gpgme_validity_t} type is used to specify the validity of a user ID
2820 in a key. The following validities are defined:
2823 @item GPGME_VALIDITY_UNKNOWN
2824 The user ID is of unknown validity. The string representation of this
2827 @item GPGME_VALIDITY_UNDEFINED
2828 The validity of the user ID is undefined. The string representation of this
2831 @item GPGME_VALIDITY_NEVER
2832 The user ID is never valid. The string representation of this
2835 @item GPGME_VALIDITY_MARGINAL
2836 The user ID is marginally valid. The string representation of this
2839 @item GPGME_VALIDITY_FULL
2840 The user ID is fully valid. The string representation of this
2843 @item GPGME_VALIDITY_ULTIMATE
2844 The user ID is ultimately valid. The string representation of this
2850 The following interfaces are deprecated and only provided for backward
2851 compatibility. Don't use them. They will be removed in a future
2852 version of @acronym{GPGME}.
2854 @deftp {Data type} gpgme_attr_t
2855 The @code{gpgme_attr_t} type is used to specify a key or trust item
2856 attribute. The following attributes are defined:
2859 @item GPGME_ATTR_KEYID
2860 This is the key ID of a sub key. It is representable as a string.
2862 For trust items, the trust item refers to the key with this ID.
2864 @item GPGME_ATTR_FPR
2865 This is the fingerprint of a sub key. It is representable as a
2868 @item GPGME_ATTR_ALGO
2869 This is the crypto algorithm for which the sub key can be used. It
2870 is representable as a string and as a number. The numbers correspond
2871 to the @code{enum gcry_pk_algos} values in the gcrypt library.
2873 @item GPGME_ATTR_LEN
2874 This is the key length of a sub key. It is representable as a
2877 @item GPGME_ATTR_CREATED
2878 This is the timestamp at creation time of a sub key. It is
2879 representable as a number.
2881 @item GPGME_ATTR_EXPIRE
2882 This is the expiration time of a sub key. It is representable as a
2885 @item GPGME_ATTR_OTRUST
2886 XXX FIXME (also for trust items)
2888 @item GPGME_ATTR_USERID
2889 This is a user ID. There can be more than one user IDs in a
2890 @var{gpgme_key_t} object. The first one (with index 0) is the primary
2891 user ID. The user ID is representable as a number.
2893 For trust items, this is the user ID associated with this trust item.
2895 @item GPGME_ATTR_NAME
2896 This is the name belonging to a user ID. It is representable as a string.
2898 @item GPGME_ATTR_EMAIL
2899 This is the email address belonging to a user ID. It is representable
2902 @item GPGME_ATTR_COMMENT
2903 This is the comment belonging to a user ID. It is representable as a
2906 @item GPGME_ATTR_VALIDITY
2907 This is the validity belonging to a user ID. It is representable as a
2908 string and as a number. See below for a list of available validities.
2910 For trust items, this is the validity that is associated with this
2913 @item GPGME_ATTR_UID_REVOKED
2914 This specifies if a user ID is revoked. It is representable as a
2915 number, and is @code{1} if the user ID is revoked, and @code{0}
2918 @item GPGME_ATTR_UID_INVALID
2919 This specifies if a user ID is invalid. It is representable as a
2920 number, and is @code{1} if the user ID is invalid, and @code{0}
2923 @item GPGME_ATTR_LEVEL
2924 This is the trust level of a trust item.
2926 @item GPGME_ATTR_TYPE
2927 This returns information about the type of key. For the string function
2928 this will eother be "PGP" or "X.509". The integer function returns 0
2929 for PGP and 1 for X.509. It is also used for the type of a trust item.
2931 @item GPGME_ATTR_IS_SECRET
2932 This specifies if the key is a secret key. It is representable as a
2933 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
2935 @item GPGME_ATTR_KEY_REVOKED
2936 This specifies if a sub key is revoked. It is representable as a
2937 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
2939 @item GPGME_ATTR_KEY_INVALID
2940 This specifies if a sub key is invalid. It is representable as a
2941 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
2943 @item GPGME_ATTR_KEY_EXPIRED
2944 This specifies if a sub key is expired. It is representable as a
2945 number, and is @code{1} if the key is expired, and @code{0} otherwise.
2947 @item GPGME_ATTR_KEY_DISABLED
2948 This specifies if a sub key is disabled. It is representable as a
2949 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
2951 @item GPGME_ATTR_KEY_CAPS
2952 This is a description of the capabilities of a sub key. It is
2953 representable as a string. The string contains the letter ``e'' if
2954 the key can be used for encryption, ``s'' if the key can be used for
2955 signatures, and ``c'' if the key can be used for certifications.
2957 @item GPGME_ATTR_CAN_ENCRYPT
2958 This specifies if a sub key can be used for encryption. It is
2959 representable as a number, and is @code{1} if the sub key can be used
2960 for encryption, and @code{0} otherwise.
2962 @item GPGME_ATTR_CAN_SIGN
2963 This specifies if a sub key can be used to create data signatures. It
2964 is representable as a number, and is @code{1} if the sub key can be
2965 used for signatures, and @code{0} otherwise.
2967 @item GPGME_ATTR_CAN_CERTIFY
2968 This specifies if a sub key can be used to create key certificates.
2969 It is representable as a number, and is @code{1} if the sub key can be
2970 used for certifications, and @code{0} otherwise.
2972 @item GPGME_ATTR_SERIAL
2973 The X.509 issuer serial attribute of the key. It is representable as
2976 @item GPGME_ATTR_ISSUE
2977 The X.509 issuer name attribute of the key. It is representable as a
2980 @item GPGME_ATTR_CHAINID
2981 The X.509 chain ID can be used to build the certification chain. It
2982 is representable as a string.
2986 @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}})
2987 The function @code{gpgme_key_get_string_attr} returns the value of the
2988 string-representable attribute @var{what} of key @var{key}. If the
2989 attribute is an attribute of a sub key or an user ID, @var{idx}
2990 specifies the sub key or user ID of which the attribute value is
2991 returned. The argument @var{reserved} is reserved for later use and
2992 should be @code{NULL}.
2994 The string returned is only valid as long as the key is valid.
2996 The function returns @code{0} if an attribute can't be returned as a
2997 string, @var{key} is not a valid pointer, @var{idx} out of range,
2998 or @var{reserved} not @code{NULL}.
3001 @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}})
3002 The function @code{gpgme_key_get_ulong_attr} returns the value of the
3003 number-representable attribute @var{what} of key @var{key}. If the
3004 attribute is an attribute of a sub key or an user ID, @var{idx}
3005 specifies the sub key or user ID of which the attribute value is
3006 returned. The argument @var{reserved} is reserved for later use and
3007 should be @code{NULL}.
3009 The function returns @code{0} if the attribute can't be returned as a
3010 number, @var{key} is not a valid pointer, @var{idx} out of range, or
3011 @var{reserved} not @code{NULL}.
3015 @node Key Signatures
3016 @subsection Key Signatures
3017 @cindex key, signatures
3018 @cindex signatures, on a key
3020 The following interfaces are deprecated and only provided for backward
3021 compatibility. Don't use them. They will be removed in a future
3022 version of @acronym{GPGME}.
3024 The signatures on a key are only available if the key was retrieved
3025 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
3026 enabled, because it is expensive to retrieve all signatures of a key.
3028 So, before using the below interfaces to retrieve the signatures on a
3029 key, you have to make sure that the key was listed with signatures
3030 enabled. One convenient, but blocking, way to do this is to use the
3031 function @code{gpgme_get_key}.
3033 @deftp {Data type} gpgme_attr_t
3034 The @code{gpgme_attr_t} type is used to specify a key signature
3035 attribute. The following attributes are defined:
3038 @item GPGME_ATTR_KEYID
3039 This is the key ID of the key which was used for the signature. It is
3040 representable as a string.
3042 @item GPGME_ATTR_ALGO
3043 This is the crypto algorithm used to create the signature. It is
3044 representable as a string and as a number. The numbers correspond to
3045 the @code{enum gcry_pk_algos} values in the gcrypt library.
3047 @item GPGME_ATTR_CREATED
3048 This is the timestamp at creation time of the signature. It is
3049 representable as a number.
3051 @item GPGME_ATTR_EXPIRE
3052 This is the expiration time of the signature. It is representable as
3055 @item GPGME_ATTR_USERID
3056 This is the user ID associated with the signing key. The user ID is
3057 representable as a number.
3059 @item GPGME_ATTR_NAME
3060 This is the name belonging to a user ID. It is representable as a string.
3062 @item GPGME_ATTR_EMAIL
3063 This is the email address belonging to a user ID. It is representable
3066 @item GPGME_ATTR_COMMENT
3067 This is the comment belonging to a user ID. It is representable as a
3070 @item GPGME_ATTR_KEY_REVOKED
3071 This specifies if a key signature is a revocation signature. It is
3072 representable as a number, and is @code{1} if the key is revoked, and
3075 @c @item GPGME_ATTR_KEY_EXPIRED
3076 @c This specifies if a key signature is expired. It is representable as
3077 @c a number, and is @code{1} if the key is revoked, and @code{0}
3080 @item GPGME_ATTR_SIG_CLASS
3081 This specifies the signature class of a key signature. It is
3082 representable as a number. The meaning is specific to the crypto
3085 @item GPGME_ATTR_SIG_CLASS
3086 This specifies the signature class of a key signature. It is
3087 representable as a number. The meaning is specific to the crypto
3090 @item GPGME_ATTR_SIG_STATUS
3091 This is the same value as returned by @code{gpgme_get_sig_status}.
3095 @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}})
3096 The function @code{gpgme_key_sig_get_string_attr} returns the value of
3097 the string-representable attribute @var{what} of the signature
3098 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3099 argument @var{reserved} is reserved for later use and should be
3102 The string returned is only valid as long as the key is valid.
3104 The function returns @code{0} if an attribute can't be returned as a
3105 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3106 out of range, or @var{reserved} not @code{NULL}.
3109 @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}})
3110 The function @code{gpgme_key_sig_get_ulong_attr} returns the value of
3111 the number-representable attribute @var{what} of the signature
3112 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3113 argument @var{reserved} is reserved for later use and should be
3116 The function returns @code{0} if an attribute can't be returned as a
3117 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3118 out of range, or @var{reserved} not @code{NULL}.
3122 @node Manipulating Keys
3123 @subsection Manipulating Keys
3124 @cindex key, manipulation
3126 @deftypefun void gpgme_key_ref (@w{gpgme_key_t @var{key}})
3127 The function @code{gpgme_key_ref} acquires an additional reference for
3131 @deftypefun void gpgme_key_unref (@w{gpgme_key_t @var{key}})
3132 The function @code{gpgme_key_unref} releases a reference for the key
3133 @var{key}. If this was the last reference, the key will be destroyed
3134 and all resources associated to it will be released.
3138 The following interface is deprecated and only provided for backward
3139 compatibility. Don't use it. It will be removed in a future version
3142 @deftypefun void gpgme_key_release (@w{gpgme_key_t @var{key}})
3143 The function @code{gpgme_key_release} is equivalent to
3144 @code{gpgme_key_unref}.
3148 @node Generating Keys
3149 @subsection Generating Keys
3150 @cindex key, creation
3151 @cindex key ring, add
3153 @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}})
3154 The function @code{gpgme_op_genkey} generates a new key pair in the
3155 context @var{ctx}. The meaning of @var{public} and @var{secret}
3156 depends on the crypto backend.
3158 GnuPG does not support @var{public} and @var{secret}, they should be
3159 @code{NULL}. GnuPG will generate a key pair and add it to the
3160 standard key ring. The fingerprint of the generated key is available
3161 with @code{gpgme_op_genkey_result}.
3163 GpgSM requires @var{public} to be a writable data object. GpgSM will
3164 generate a secret key (which will be stored by @command{gpg-agent},
3165 and return a certificate request in @var{public}, which then needs to
3166 be signed by the certification authority and imported before it can be
3167 used. GpgSM does not make the fingerprint available.
3169 The argument @var{parms} specifies parameters for the key in an XML
3170 string. The details about the format of @var{parms} are specific to
3171 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
3175 <GnupgKeyParms format="internal">
3180 Name-Real: Joe Tester
3181 Name-Comment: with stupid passphrase
3182 Name-Email: joe@@foo.bar
3188 Here is an example for GpgSM as the crypto engine:
3191 <GnupgKeyParms format="internal">
3194 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3195 Name-Email: joe@@foo.bar
3199 Strings should be given in UTF-8 encoding. The only format supported
3200 for now is ``internal''. The content of the @code{GnupgKeyParms}
3201 container is passed verbatim to the crypto backend. Control
3202 statements are not allowed.
3204 After the operation completed successfully, the result can be
3205 retrieved with @code{gpgme_op_genkey_result}.
3207 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3208 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3209 @var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if
3210 @var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL}
3211 if no key was created by the backend.
3214 @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}})
3215 The function @code{gpgme_op_genkey_start} initiates a
3216 @code{gpgme_op_genkey} operation. It can be completed by calling
3217 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3219 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3220 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3221 @var{parms} is not a valid XML string, and
3222 @code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not
3226 @deftp {Data type} {gpgme_genkey_result_t}
3227 This is a pointer to a structure used to store the result of a
3228 @code{gpgme_op_genkey} operation. After successfully generating a
3229 key, you can retrieve the pointer to the result with
3230 @code{gpgme_op_genkey_result}. The structure contains the following
3234 @item unsigned int primary : 1
3235 This is a flag that is set to 1 if a primary key was created and to 0
3238 @item unsigned int sub : 1
3239 This is a flag that is set to 1 if a subkey was created and to 0
3243 This is the fingerprint of the key that was created. If both a
3244 primary and a sub key were generated, the fingerprint of the primary
3245 key will be returned. If the crypto engine does not provide the
3246 fingerprint, @code{fpr} will be a null pointer.
3250 @deftypefun gpgme_genkey_result_t gpgme_op_genkey_result (@w{gpgme_ctx_t @var{ctx}})
3251 The function @code{gpgme_op_genkey_result} returns a
3252 @code{gpgme_genkey_result_t} pointer to a structure holding the result of
3253 a @code{gpgme_op_genkey} operation. The pointer is only valid if the
3254 last operation on the context was a @code{gpgme_op_genkey} or
3255 @code{gpgme_op_genkey_start} operation, and if this operation finished
3256 successfully. The returned pointer is only valid until the next
3257 operation is started on the context.
3261 @node Exporting Keys
3262 @subsection Exporting Keys
3264 @cindex key ring, export from
3266 @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}})
3267 The function @code{gpgme_op_export} extracts public keys and returns
3268 them in the data buffer @var{keydata}. The output format of the key
3269 data returned is determined by the @acronym{ASCII} armor attribute set
3270 for the context @var{ctx}, or, if that is not set, by the encoding
3271 specified for @var{keydata}.
3273 If @var{pattern} is @code{NULL}, all available keys are returned.
3274 Otherwise, @var{pattern} contains an engine specific expression that
3275 is used to limit the list to all keys matching the pattern.
3277 @var{reserved} is reserved for future use and must be @code{0}.
3279 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3280 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3281 @var{keydata} is not a valid empty data buffer, and passes through any
3282 errors that are reported by the crypto engine support routines.
3285 @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}})
3286 The function @code{gpgme_op_export_start} initiates a
3287 @code{gpgme_op_export} operation. It can be completed by calling
3288 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3290 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3291 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3292 if @var{keydata} is not a valid empty data buffer.
3295 @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}})
3296 The function @code{gpgme_op_export} extracts public keys and returns
3297 them in the data buffer @var{keydata}. The output format of the key
3298 data returned is determined by the @acronym{ASCII} armor attribute set
3299 for the context @var{ctx}, or, if that is not set, by the encoding
3300 specified for @var{keydata}.
3302 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3303 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3304 array of strings that are used to limit the list to all keys matching
3305 at least one of the patterns verbatim.
3307 @var{reserved} is reserved for future use and must be @code{0}.
3309 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3310 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3311 @var{keydata} is not a valid empty data buffer, and passes through any
3312 errors that are reported by the crypto engine support routines.
3315 @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}})
3316 The function @code{gpgme_op_export_ext_start} initiates a
3317 @code{gpgme_op_export_ext} operation. It can be completed by calling
3318 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3320 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3321 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3322 if @var{keydata} is not a valid empty data buffer.
3326 @node Importing Keys
3327 @subsection Importing Keys
3329 @cindex key ring, import to
3331 @deftypefun gpgme_error_t gpgme_op_import (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3332 The function @code{gpgme_op_import} adds the keys in the data buffer
3333 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
3334 The format of @var{keydata} can be @acronym{ASCII} armored, for example,
3335 but the details are specific to the crypto engine.
3337 After the operation completed successfully, the result can be
3338 retrieved with @code{gpgme_op_import_result}.
3340 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3341 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3342 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3343 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3346 @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3347 The function @code{gpgme_op_import_start} initiates a
3348 @code{gpgme_op_import} operation. It can be completed by calling
3349 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3351 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3352 import could be started successfully, @code{GPG_ERR_INV_VALUE} if
3353 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3354 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3357 @deftp {Data type} {gpgme_import_status_t}
3358 This is a pointer to a structure used to store a part of the result of
3359 a @code{gpgme_op_import} operation. For each considered key one
3360 status is added that contains information about the result of the
3361 import. The structure contains the following members:
3364 @item gpgme_import_status_t next
3365 This is a pointer to the next status structure in the linked list, or
3366 @code{NULL} if this is the last element.
3369 This is the fingerprint of the key that was considered.
3371 @item gpgme_error_t result
3372 If the import was not successful, this is the error value that caused
3373 the import to fail. Otherwise the error code is
3374 @code{GPG_ERR_NO_ERROR}.
3376 @item unsigned int status
3377 This is a bit-wise OR of the following flags that give more
3378 information about what part of the key was imported. If the key was
3379 already known, this might be 0.
3382 @item GPGME_IMPORT_NEW
3385 @item GPGME_IMPORT_UID
3386 The key contained new user IDs.
3388 @item GPGME_IMPORT_SIG
3389 The key contained new signatures.
3391 @item GPGME_IMPORT_SUBKEY
3392 The key contained new sub keys.
3394 @item GPGME_IMPORT_SECRET
3395 The key contained a secret key.
3400 @deftp {Data type} {gpgme_import_result_t}
3401 This is a pointer to a structure used to store the result of a
3402 @code{gpgme_op_import} operation. After a successful import
3403 operation, you can retrieve the pointer to the result with
3404 @code{gpgme_op_import_result}. The structure contains the following
3408 @item int considered
3409 The total number of considered keys.
3411 @item int no_user_id
3412 The number of keys without user ID.
3415 The total number of imported keys.
3418 The number of imported RSA keys.
3421 The number of unchanged keys.
3424 The number of new user IDs.
3427 The number of new sub keys.
3429 @item new_signatures
3430 The number of new signatures.
3432 @item new_revocations
3433 The number of new revocations.
3436 The total number of secret keys read.
3438 @item secret_imported
3439 The number of imported secret keys.
3441 @item secret_unchanged
3442 The number of unchanged secret keys.
3445 The number of keys not imported.
3447 @item gpgme_import_status_t imports
3448 A list of gpgme_import_status_t objects which contain more information
3449 about the keys for which an import was attempted.
3453 @deftypefun gpgme_import_result_t gpgme_op_import_result (@w{gpgme_ctx_t @var{ctx}})
3454 The function @code{gpgme_op_import_result} returns a
3455 @code{gpgme_import_result_t} pointer to a structure holding the result
3456 of a @code{gpgme_op_import} operation. The pointer is only valid if
3457 the last operation on the context was a @code{gpgme_op_import} or
3458 @code{gpgme_op_import_start} operation, and if this operation finished
3459 successfully. The returned pointer is only valid until the next
3460 operation is started on the context.
3463 The following interface is deprecated and only provided for backward
3464 compatibility. Don't use it. It will be removed in a future version
3467 @deftypefun gpgme_error_t gpgme_op_import_ext (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}}, @w{int *@var{nr}})
3468 The function @code{gpgme_op_import_ext} is equivalent to:
3471 gpgme_error_t err = gpgme_op_import (ctx, keydata);
3474 gpgme_import_result_t result = gpgme_op_import_result (ctx);
3475 *nr = result->considered;
3482 @subsection Deleting Keys
3484 @cindex key ring, delete from
3486 @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}})
3487 The function @code{gpgme_op_delete} deletes the key @var{key} from the
3488 key ring of the crypto engine used by @var{ctx}. If
3489 @var{allow_secret} is @code{0}, only public keys are deleted,
3490 otherwise secret keys are deleted as well, if that is supported.
3492 The function returns the error code @code{GPG_ERR_NO_ERROR} if the key
3493 was deleted successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3494 @var{key} is not a valid pointer, @code{GPG_ERR_NO_PUBKEY} if
3495 @var{key} could not be found in the keyring,
3496 @code{GPG_ERR_AMBIGUOUS_NAME} if the key was not specified
3497 unambiguously, and @code{GPG_ERR_CONFLICT} if the secret key for
3498 @var{key} is available, but @var{allow_secret} is zero.
3501 @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}})
3502 The function @code{gpgme_op_delete_start} initiates a
3503 @code{gpgme_op_delete} operation. It can be completed by calling
3504 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3506 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3507 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3508 @var{ctx} or @var{key} is not a valid pointer.
3512 @node Advanced Key Editing
3513 @subsection Advanced Key Editing
3516 @deftp {Data type} {gpgme_error_t (*gpgme_edit_cb_t) (@w{void *@var{handle}}, @w{gpgme_status_code_t @var{status}}, @w{const char *@var{args}}, @w{int @var{fd}})}
3517 @tindex gpgme_edit_cb_t
3518 The @code{gpgme_edit_cb_t} type is the type of functions which
3519 @acronym{GPGME} calls if it a key edit operation is on-going. The
3520 status code @var{status} and the argument line @var{args} are passed
3521 through by @acronym{GPGME} from the crypto engine. The file
3522 descriptor @var{fd} is -1 for normal status messages. If @var{status}
3523 indicates a command rather than a status message, the response to the
3524 command should be written to @var{fd}. The @var{handle} is provided
3525 by the user at start of operation.
3527 The function should return @code{GPG_ERR_NO_ERROR} or an error value.
3530 @deftypefun gpgme_error_t gpgme_op_edit (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3531 The function @code{gpgme_op_edit} processes the key @var{KEY}
3532 interactively, using the edit callback function @var{FNC} with the
3533 handle @var{HANDLE}. The callback is invoked for every status and
3534 command request from the crypto engine. The output of the crypto
3535 engine is written to the data object @var{out}.
3537 Note that the protocol between the callback function and the crypto
3538 engine is specific to the crypto engine and no further support in
3539 implementing this protocol correctly is provided by @acronym{GPGME}.
3541 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3542 edit operation completes successfully, @code{GPG_ERR_INV_VALUE} if
3543 @var{ctx} or @var{key} is not a valid pointer, and any error returned
3544 by the crypto engine or the edit callback handler.
3547 @deftypefun gpgme_error_t gpgme_op_edit_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3548 The function @code{gpgme_op_edit_start} initiates a
3549 @code{gpgme_op_edit} operation. It can be completed by calling
3550 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3552 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3553 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3554 @var{ctx} or @var{key} is not a valid pointer.
3558 @deftypefun gpgme_error_t gpgme_op_card_edit (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3559 The function @code{gpgme_op_card_edit} is analogous to
3560 @code{gpgme_op_edit}, but should be used to process the smart card corresponding to the key @var{key}.
3563 @deftypefun gpgme_error_t gpgme_op_card_edit_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3564 The function @code{gpgme_op_card_edit_start} initiates a
3565 @code{gpgme_op_card_edit} operation. It can be completed by calling
3566 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3568 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3569 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3570 @var{ctx} or @var{key} is not a valid pointer.
3574 @node Trust Item Management
3575 @section Trust Item Management
3578 @strong{Caution:} The trust items interface is experimental.
3580 @deftp {Data type} gpgme_trust_item_t
3581 The @code{gpgme_trust_item_t} type is a pointer to a trust item object.
3582 It has the following members:
3586 This is a string describing the key to which this trust items belongs.
3589 This is the type of the trust item. A value of 1 refers to a key, a
3590 value of 2 refers to a user ID.
3593 This is the trust level.
3595 @item char *owner_trust
3596 The owner trust if @code{type} is 1.
3598 @item char *validity
3599 The calculated validity.
3602 The user name if @code{type} is 2.
3607 * Listing Trust Items:: Browsing the list of available trust items.
3608 * Information About Trust Items:: Requesting information about trust items.
3609 * Manipulating Trust Items:: Operations on trust items.
3613 @node Listing Trust Items
3614 @subsection Listing Trust Items
3615 @cindex trust item list
3617 @deftypefun gpgme_error_t gpgme_op_trustlist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}})
3618 The function @code{gpgme_op_trustlist_start} initiates a trust item
3619 listing operation inside the context @var{ctx}. It sets everything up
3620 so that subsequent invocations of @code{gpgme_op_trustlist_next} return
3621 the trust items in the list.
3623 The string @var{pattern} contains an engine specific expression that
3624 is used to limit the list to all trust items matching the pattern. It
3625 can not be the empty string.
3627 The argument @var{max_level} is currently ignored.
3629 The context will be busy until either all trust items are received
3630 (and @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}), or
3631 @code{gpgme_op_trustlist_end} is called to finish the operation.
3633 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3634 @var{ctx} is not a valid pointer, and passes through any errors that
3635 are reported by the crypto engine support routines.
3638 @deftypefun gpgme_error_t gpgme_op_trustlist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_trust_item_t *@var{r_item}})
3639 The function @code{gpgme_op_trustlist_next} returns the next trust
3640 item in the list created by a previous @code{gpgme_op_trustlist_start}
3641 operation in the context @var{ctx}. The trust item can be destroyed
3642 with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}.
3644 This is the only way to get at @code{gpgme_trust_item_t} objects in
3647 If the last trust item in the list has already been returned,
3648 @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}.
3650 The function returns the error code @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3651 @var{r_item} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if
3652 there is not enough memory for the operation.
3655 @deftypefun gpgme_error_t gpgme_op_trustlist_end (@w{gpgme_ctx_t @var{ctx}})
3656 The function @code{gpgme_op_trustlist_next} ends a pending key list
3657 operation in the context @var{ctx}.
3659 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3660 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
3661 time during the operation there was not enough memory available.
3665 @node Information About Trust Items
3666 @subsection Information About Trust Items
3667 @cindex trust item, information about
3668 @cindex trust item, attributes
3669 @cindex attributes, of a trust item
3671 The following interfaces are deprecated and only provided for backward
3672 compatibility. Don't use them. They will be removed in a future
3673 version of @acronym{GPGME}.
3675 Trust items have attributes which can be queried using the interfaces
3676 below. The attribute identifiers are shared with those for key
3677 attributes. @xref{Information About Keys}.
3679 @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}})
3680 The function @code{gpgme_trust_item_get_string_attr} returns the value
3681 of the string-representable attribute @var{what} of trust item
3682 @var{item}. The arguments @var{idx} and @var{reserved} are reserved
3683 for later use and should be @code{0} and @code{NULL} respectively.
3685 The string returned is only valid as long as the key is valid.
3687 The function returns @code{0} if an attribute can't be returned as a
3688 string, @var{key} is not a valid pointer, @var{idx} out of range,
3689 or @var{reserved} not @code{NULL}.
3692 @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}})
3693 The function @code{gpgme_trust_item_get_int_attr} returns the value of
3694 the number-representable attribute @var{what} of trust item
3695 @var{item}. If the attribute occurs more than once in the trust item,
3696 the index is specified by @var{idx}. However, currently no such
3697 attribute exists, so @var{idx} should be @code{0}. The argument
3698 @var{reserved} is reserved for later use and should be @code{NULL}.
3700 The function returns @code{0} if the attribute can't be returned as a
3701 number, @var{key} is not a valid pointer, @var{idx} out of range,
3702 or @var{reserved} not @code{NULL}.
3706 @node Manipulating Trust Items
3707 @subsection Manipulating Trust Items
3708 @cindex trust item, manipulation
3710 @deftypefun void gpgme_trust_item_ref (@w{gpgme_trust_item_t @var{item}})
3711 The function @code{gpgme_trust_item_ref} acquires an additional
3712 reference for the trust item @var{item}.
3715 @deftypefun void gpgme_trust_item_unref (@w{gpgme_trust_item_t @var{item}})
3716 The function @code{gpgme_trust_item_unref} releases a reference for
3717 the trust item @var{item}. If this was the last reference, the trust
3718 item will be destroyed and all resources associated to it will be
3723 The following interface is deprecated and only provided for backward
3724 compatibility. Don't use it. It will be removed in a future version
3727 @deftypefun void gpgme_trust_item_release (@w{gpgme_trust_item_t @var{item}})
3728 The function @code{gpgme_trust_item_release} is an alias for
3729 @code{gpgme_trust_item_unref}.
3733 @node Crypto Operations
3734 @section Crypto Operations
3735 @cindex cryptographic operation
3737 Sometimes, the result of a crypto operation returns a list of invalid
3738 keys encountered in processing the request. The following structure
3739 is used to hold information about such a key.
3741 @deftp {Data type} {gpgme_invalid_key_t}
3742 This is a pointer to a structure used to store a part of the result of
3743 a crypto operation which takes user IDs as one input parameter. The
3744 structure contains the following members:
3747 @item gpgme_invalid_key_t next
3748 This is a pointer to the next invalid key structure in the linked
3749 list, or @code{NULL} if this is the last element.
3752 The fingerprint or key ID of the invalid key encountered.
3754 @item gpgme_error_t reason
3755 An error code describing the reason why the key was found invalid.
3761 * Decrypt:: Decrypting a ciphertext.
3762 * Verify:: Verifying a signature.
3763 * Decrypt and Verify:: Decrypting a signed ciphertext.
3764 * Sign:: Creating a signature.
3765 * Encrypt:: Encrypting a plaintext.
3772 @cindex cryptographic operation, decryption
3774 @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}})
3775 The function @code{gpgme_op_decrypt} decrypts the ciphertext in the
3776 data object @var{cipher} and stores it into the data object
3779 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3780 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
3781 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
3782 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
3783 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
3784 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
3785 secret key could not be retrieved, and passes through any errors that
3786 are reported by the crypto engine support routines.
3789 @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}})
3790 The function @code{gpgme_op_decrypt_start} initiates a
3791 @code{gpgme_op_decrypt} operation. It can be completed by calling
3792 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3794 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3795 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3796 if @var{cipher} or @var{plain} is not a valid pointer.
3799 @deftp {Data type} {gpgme_recipient_t}
3800 This is a pointer to a structure used to store information about the
3801 recipient of an encrypted text which is decrypted in a
3802 @code{gpgme_op_decrypt} operation. This information (except for the
3803 status field) is even available before the operation finished
3804 successfully, for example in a passphrase callback. The structure
3805 contains the following members:
3808 @item gpgme_recipient_t next
3809 This is a pointer to the next recipient structure in the linked list,
3810 or @code{NULL} if this is the last element.
3812 @item gpgme_pubkey_algo_t
3813 The public key algorithm used in the encryption.
3815 @item unsigned int wrong_key_usage : 1
3816 This is true if the key was not used according to its policy.
3819 This is the key ID of the key (in hexadecimal digits) used as
3822 @item gpgme_error_t status
3823 This is an error number with the error code GPG_ERR_NO_SECKEY if the
3824 secret key for this recipient is not available, and 0 otherwise.
3828 @deftp {Data type} {gpgme_decrypt_result_t}
3829 This is a pointer to a structure used to store the result of a
3830 @code{gpgme_op_decrypt} operation. After successfully decrypting
3831 data, you can retrieve the pointer to the result with
3832 @code{gpgme_op_decrypt_result}. The structure contains the following
3836 @item char *unsupported_algorithm
3837 If an unsupported algorithm was encountered, this string describes the
3838 algorithm that is not supported.
3840 @item unsigned int wrong_key_usage : 1
3841 This is true if the key was not used according to its policy.
3843 @item gpgme_recipient_t recipient
3844 This is a linked list of recipients to which this message was encrypted.
3846 @item char *file_name
3847 This is the filename of the original plaintext message file if it is
3848 known, otherwise this is a null pointer.
3852 @deftypefun gpgme_decrypt_result_t gpgme_op_decrypt_result (@w{gpgme_ctx_t @var{ctx}})
3853 The function @code{gpgme_op_decrypt_result} returns a
3854 @code{gpgme_decrypt_result_t} pointer to a structure holding the
3855 result of a @code{gpgme_op_decrypt} operation. The pointer is only
3856 valid if the last operation on the context was a
3857 @code{gpgme_op_decrypt} or @code{gpgme_op_decrypt_start} operation.
3858 If the operation failed this might be a @code{NULL} pointer. The
3859 returned pointer is only valid until the next operation is started on
3866 @cindex verification
3867 @cindex signature, verification
3868 @cindex cryptographic operation, verification
3869 @cindex cryptographic operation, signature check
3870 @cindex signature notation data
3871 @cindex notation data
3873 @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}})
3874 The function @code{gpgme_op_verify} verifies that the signature in the
3875 data object @var{sig} is a valid signature. If @var{sig} is a
3876 detached signature, then the signed text should be provided in
3877 @var{signed_text} and @var{plain} should be a null pointer.
3878 Otherwise, if @var{sig} is a normal (or cleartext) signature,
3879 @var{signed_text} should be a null pointer and @var{plain} should be a
3880 writable data object that will contain the plaintext after successful
3883 The results of the individual signature verifications can be retrieved
3884 with @code{gpgme_op_verify_result}.
3886 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3887 operation could be completed successfully, @code{GPG_ERR_INV_VALUE} if
3888 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer,
3889 @code{GPG_ERR_NO_DATA} if @var{sig} does not contain any data to
3890 verify, and passes through any errors that are reported by the crypto
3891 engine support routines.
3894 @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}})
3895 The function @code{gpgme_op_verify_start} initiates a
3896 @code{gpgme_op_verify} operation. It can be completed by calling
3897 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3899 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3900 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3901 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer, and
3902 @code{GPG_ERR_NO_DATA} if @var{sig} or @var{plain} does not contain
3906 @deftp {Data type} {gpgme_sig_notation_t}
3907 This is a pointer to a structure used to store a part of the result of
3908 a @code{gpgme_op_verify} operation. The structure contains the
3912 @item gpgme_sig_notation_t next
3913 This is a pointer to the next new signature notation structure in the
3914 linked list, or @code{NULL} if this is the last element.
3917 The name of the notation field. If this is @code{NULL}, then the
3918 member @code{value} will contain a policy URL.
3921 The length of the @code{name} field. For strings the length is
3922 counted without the trailing binary zero.
3925 The value of the notation field. If @code{name} is @code{NULL}, then
3926 this is a policy URL.
3929 The length of the @code{value} field. For strings the length is
3930 counted without the trailing binary zero.
3932 @item gpgme_sig_notation_flags_t flags
3933 The accumulated flags field. This field contains the flags associated
3934 with the notation data in an accumulated form which can be used as an
3935 argument to the function @code{gpgme_sig_notation_add}. The value
3936 @code{flags} is a bitwise-or combination of one or multiple of the
3937 following bit values:
3940 @item GPGME_SIG_NOTATION_HUMAN_READABLE
3941 The @code{GPGME_SIG_NOTATION_HUMAN_READABLE} symbol specifies that the
3942 notation data is in human readable form
3944 @item GPGME_SIG_NOTATION_CRITICAL
3945 The @code{GPGME_SIG_NOTATION_CRITICAL} symbol specifies that the
3946 notation data is critical.
3950 @item unsigned int human_readable : 1
3951 This is true if the @code{GPGME_SIG_NOTATION_HUMAN_READABLE} flag is
3952 set and false otherwise. This flag is only valid for notation data,
3953 not for policy URLs.
3955 @item unsigned int critical : 1
3956 This is true if the @code{GPGME_SIG_NOTATION_CRITICAL} flag is set and
3957 false otherwise. This flag is valid for notation data and policy URLs.
3962 @deftp {Data type} {gpgme_signature_t}
3963 This is a pointer to a structure used to store a part of the result of
3964 a @code{gpgme_op_verify} operation. The structure contains the
3968 @item gpgme_signature_t next
3969 This is a pointer to the next new signature structure in the linked
3970 list, or @code{NULL} if this is the last element.
3972 @item gpgme_sigsum_t summary
3973 This is a bit vector giving a summary of the signature status. It
3974 provides an easy interface to a defined semantic of the signature
3975 status. Checking just one bit is sufficient to see whether a
3976 signature is valid without any restrictions.
3978 The defined bits are:
3980 @item GPGME_SIGSUM_VALID
3981 The signature is fully valid.
3983 @item GPGME_SIGSUM_GREEN
3984 The signature is good but one might want to display some extra
3985 information. Check the other bits.
3987 @item GPGME_SIGSUM_RED
3988 The signature is bad. It might be useful to check other bits and
3989 display more information, i.e. a revoked certificate might not render a
3990 signature invalid when the message was received prior to the cause for
3993 @item GPGME_SIGSUM_KEY_REVOKED
3994 The key or at least one certificate has been revoked.
3996 @item GPGME_SIGSUM_KEY_EXPIRED
3997 The key or one of the certificates has expired. It is probably a good
3998 idea to display the date of the expiration.
4000 @item GPGME_SIGSUM_SIG_EXPIRED
4001 The signature has expired.
4003 @item GPGME_SIGSUM_KEY_MISSING
4004 Can't verify due to a missing key or certificate.
4006 @item GPGME_SIGSUM_CRL_MISSING
4007 The CRL (or an equivalent mechanism) is not available.
4009 @item GPGME_SIGSUM_CRL_TOO_OLD
4010 Available CRL is too old.
4012 @item GPGME_SIGSUM_BAD_POLICY
4013 A policy requirement was not met.
4015 @item GPGME_SIGSUM_SYS_ERROR
4016 A system error occured.
4020 This is the fingerprint or key ID of the signature.
4022 @item gpgme_error_t status
4023 This is the status of the signature. In particular, the following
4024 status codes are of interest:
4027 @item GPG_ERR_NO_ERROR
4028 This status indicates that the signature is valid. For the combined
4029 result this status means that all signatures are valid.
4031 @item GPG_ERR_SIG_EXPIRED
4032 This status indicates that the signature is valid but expired. For
4033 the combined result this status means that all signatures are valid
4036 @item GPG_ERR_KEY_EXPIRED
4037 This status indicates that the signature is valid but the key used to
4038 verify the signature has expired. For the combined result this status
4039 means that all signatures are valid and all keys are expired.
4041 @item GPG_ERR_CERT_REVOKED
4042 This status indicates that the signature is valid but the key used
4043 to verify the signature has been revoked. For the combined result
4044 this status means that all signatures are valid and all keys are
4047 @item GPG_ERR_BAD_SIGNATURE
4048 This status indicates that the signature is invalid. For the combined
4049 result this status means that all signatures are invalid.
4051 @item GPG_ERR_NO_PUBKEY
4052 This status indicates that the signature could not be verified due to
4053 a missing key. For the combined result this status means that all
4054 signatures could not be checked due to missing keys.
4056 @item GPG_ERR_GENERAL
4057 This status indicates that there was some other error which prevented
4058 the signature verification.
4061 @item gpgme_sig_notation_t notations
4062 This is a linked list with the notation data and policy URLs.
4064 @item unsigned long timestamp
4065 The creation timestamp of this signature.
4067 @item unsigned long exp_timestamp
4068 The expiration timestamp of this signature, or 0 if the signature does
4071 @item unsigned int wrong_key_usage : 1
4072 This is true if the key was not used according to its policy.
4074 @item unsigned int pka_trust : 2
4075 This is set to the trust information gained by means of the PKA system.
4079 No PKA information available or verification not possible.
4081 PKA verification failed.
4083 PKA verification succeeded.
4085 Reserved for future use.
4087 Depending on the configuration of the engine, this metric may also be
4088 reflected by the validity of the signature.
4090 @item unsigned int chain_model : 1
4091 This is true if the validity of the signature has been checked using the
4092 chain model. In the chain model the time the signature has been created
4093 must be within the validity period of the certificate and the time the
4094 certificate itself has been created must be within the validity period
4095 of the issuing certificate. In contrast the default validation model
4096 checks the validity of signature as well at the entire certificate chain
4097 at the current time.
4100 @item gpgme_validity_t validity
4101 The validity of the signature.
4103 @item gpgme_error_t validity_reason
4104 If a signature is not valid, this provides a reason why.
4106 @item gpgme_pubkey_algo_t
4107 The public key algorithm used to create this signature.
4109 @item gpgme_hash_algo_t
4110 The hash algorithm used to create this signature.
4114 @deftp {Data type} {gpgme_verify_result_t}
4115 This is a pointer to a structure used to store the result of a
4116 @code{gpgme_op_verify} operation. After verifying a signature, you
4117 can retrieve the pointer to the result with
4118 @code{gpgme_op_verify_result}. If the operation failed this might be
4119 a @code{NULL} pointer. The structure contains the following member:
4122 @item gpgme_signature_t signatures
4123 A linked list with information about all signatures for which a
4124 verification was attempted.
4126 @item char *file_name
4127 This is the filename of the original plaintext message file if it is
4128 known, otherwise this is a null pointer.
4132 @deftypefun gpgme_verify_result_t gpgme_op_verify_result (@w{gpgme_ctx_t @var{ctx}})
4133 The function @code{gpgme_op_verify_result} returns a
4134 @code{gpgme_verify_result_t} pointer to a structure holding the result
4135 of a @code{gpgme_op_verify} operation. The pointer is only valid if
4136 the last operation on the context was a @code{gpgme_op_verify},
4137 @code{gpgme_op_verify_start}, @code{gpgme_op_decrypt_verify} or
4138 @code{gpgme_op_decrypt_verify_start} operation, and if this operation
4139 finished successfully (for @code{gpgme_op_decrypt_verify} and
4140 @code{gpgme_op_decrypt_verify_start}, the error code
4141 @code{GPG_ERR_NO_DATA} counts as successful in this context). The
4142 returned pointer is only valid until the next operation is started on
4147 The following interfaces are deprecated and only provided for backward
4148 compatibility. Don't use them. They will be removed in a future
4149 version of @acronym{GPGME}.
4151 @deftp {Data type} {enum gpgme_sig_stat_t}
4152 @tindex gpgme_sig_stat_t
4153 The @code{gpgme_sig_stat_t} type holds the result of a signature check, or
4154 the combined result of all signatures. The following results are
4158 @item GPGME_SIG_STAT_NONE
4159 This status should not occur in normal operation.
4161 @item GPGME_SIG_STAT_GOOD
4162 This status indicates that the signature is valid. For the combined
4163 result this status means that all signatures are valid.
4165 @item GPGME_SIG_STAT_GOOD_EXP
4166 This status indicates that the signature is valid but expired. For
4167 the combined result this status means that all signatures are valid
4170 @item GPGME_SIG_STAT_GOOD_EXPKEY
4171 This status indicates that the signature is valid but the key used to
4172 verify the signature has expired. For the combined result this status
4173 means that all signatures are valid and all keys are expired.
4175 @item GPGME_SIG_STAT_BAD
4176 This status indicates that the signature is invalid. For the combined
4177 result this status means that all signatures are invalid.
4179 @item GPGME_SIG_STAT_NOKEY
4180 This status indicates that the signature could not be verified due to
4181 a missing key. For the combined result this status means that all
4182 signatures could not be checked due to missing keys.
4184 @item GPGME_SIG_STAT_NOSIG
4185 This status indicates that the signature data provided was not a real
4188 @item GPGME_SIG_STAT_ERROR
4189 This status indicates that there was some other error which prevented
4190 the signature verification.
4192 @item GPGME_SIG_STAT_DIFF
4193 For the combined result this status means that at least two signatures
4194 have a different status. You can get each key's status with
4195 @code{gpgme_get_sig_status}.
4199 @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}})
4200 The function @code{gpgme_get_sig_status} is equivalent to:
4203 gpgme_verify_result_t result;
4204 gpgme_signature_t sig;
4206 result = gpgme_op_verify_result (ctx);
4207 sig = result->signatures;
4219 switch (gpg_err_code (sig->status))
4221 case GPG_ERR_NO_ERROR:
4222 *r_stat = GPGME_SIG_STAT_GOOD;
4225 case GPG_ERR_BAD_SIGNATURE:
4226 *r_stat = GPGME_SIG_STAT_BAD;
4229 case GPG_ERR_NO_PUBKEY:
4230 *r_stat = GPGME_SIG_STAT_NOKEY;
4233 case GPG_ERR_NO_DATA:
4234 *r_stat = GPGME_SIG_STAT_NOSIG;
4237 case GPG_ERR_SIG_EXPIRED:
4238 *r_stat = GPGME_SIG_STAT_GOOD_EXP;
4241 case GPG_ERR_KEY_EXPIRED:
4242 *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY;
4246 *r_stat = GPGME_SIG_STAT_ERROR;
4251 *r_created = sig->timestamp;
4256 @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}})
4257 The function @code{gpgme_get_sig_string_attr} is equivalent to:
4260 gpgme_verify_result_t result;
4261 gpgme_signature_t sig;
4263 result = gpgme_op_verify_result (ctx);
4264 sig = result->signatures;
4276 case GPGME_ATTR_FPR:
4279 case GPGME_ATTR_ERRTOK:
4281 return sig->wrong_key_usage ? "Wrong_Key_Usage" : "";
4292 @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}})
4293 The function @code{gpgme_get_sig_ulong_attr} is equivalent to:
4296 gpgme_verify_result_t result;
4297 gpgme_signature_t sig;
4299 result = gpgme_op_verify_result (ctx);
4300 sig = result->signatures;
4312 case GPGME_ATTR_CREATED:
4313 return sig->timestamp;
4315 case GPGME_ATTR_EXPIRE:
4316 return sig->exp_timestamp;
4318 case GPGME_ATTR_VALIDITY:
4319 return (unsigned long) sig->validity;
4321 case GPGME_ATTR_SIG_STATUS:
4322 switch (sig->status)
4324 case GPG_ERR_NO_ERROR:
4325 return GPGME_SIG_STAT_GOOD;
4327 case GPG_ERR_BAD_SIGNATURE:
4328 return GPGME_SIG_STAT_BAD;
4330 case GPG_ERR_NO_PUBKEY:
4331 return GPGME_SIG_STAT_NOKEY;
4333 case GPG_ERR_NO_DATA:
4334 return GPGME_SIG_STAT_NOSIG;
4336 case GPG_ERR_SIG_EXPIRED:
4337 return GPGME_SIG_STAT_GOOD_EXP;
4339 case GPG_ERR_KEY_EXPIRED:
4340 return GPGME_SIG_STAT_GOOD_EXPKEY;
4343 return GPGME_SIG_STAT_ERROR;
4346 case GPGME_ATTR_SIG_SUMMARY:
4347 return sig->summary;
4356 @deftypefun {const char *} gpgme_get_sig_key (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_key_t *@var{r_key}})
4357 The function @code{gpgme_get_sig_key} is equivalent to:
4360 gpgme_verify_result_t result;
4361 gpgme_signature_t sig;
4363 result = gpgme_op_verify_result (ctx);
4364 sig = result->signatures;
4372 return gpg_error (GPG_ERR_EOF);
4374 return gpgme_get_key (ctx, sig->fpr, r_key, 0);
4379 @node Decrypt and Verify
4380 @subsection Decrypt and Verify
4381 @cindex decryption and verification
4382 @cindex verification and decryption
4383 @cindex signature check