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. This encoding is useful to give the backend
1872 a hint on the type of data. The following data types are available:
1875 @item GPGME_DATA_ENCODING_NONE
1876 This specifies that the encoding is not known. This is the default
1877 for a new data object. The backend will try its best to detect the
1878 encoding automatically.
1880 @item GPGME_DATA_ENCODING_BINARY
1881 This specifies that the data is encoding in binary form; i.e. there is
1882 no special encoding.
1884 @item GPGME_DATA_ENCODING_BASE64
1885 This specifies that the data is encoded using the Base-64 encoding
1886 scheme as used by @acronym{MIME} and other protocols.
1888 @item GPGME_DATA_ENCODING_ARMOR
1889 This specifies that the data is encoded in an armored form as used by
1894 @deftypefun gpgme_data_encoding_t gpgme_data_get_encoding (@w{gpgme_data_t @var{dh}})
1895 The function @code{gpgme_data_get_encoding} returns the encoding of
1896 the data object with the handle @var{dh}. If @var{dh} is not a valid
1897 pointer (e.g. @code{NULL}) @code{GPGME_DATA_ENCODING_NONE} is
1901 @deftypefun gpgme_error_t gpgme_data_set_encoding (@w{gpgme_data_t @var{dh}, gpgme_data_encoding_t @var{enc}})
1902 The function @code{gpgme_data_set_encoding} changes the encoding of
1903 the data object with the handle @var{dh} to @var{enc}.
1914 All cryptographic operations in @acronym{GPGME} are performed within a
1915 context, which contains the internal state of the operation as well as
1916 configuration parameters. By using several contexts you can run
1917 several cryptographic operations in parallel, with different
1920 @deftp {Data type} {gpgme_ctx_t}
1921 The @code{gpgme_ctx_t} type is a handle for a @acronym{GPGME} context,
1922 which is used to hold the configuration, status and result of
1923 cryptographic operations.
1927 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
1928 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
1929 * Context Attributes:: Setting properties of a context.
1930 * Key Management:: Managing keys with @acronym{GPGME}.
1931 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
1932 * Crypto Operations:: Using a context for cryptography.
1933 * Run Control:: Controlling how operations are run.
1937 @node Creating Contexts
1938 @section Creating Contexts
1939 @cindex context, creation
1941 @deftypefun gpgme_error_t gpgme_new (@w{gpgme_ctx_t *@var{ctx}})
1942 The function @code{gpgme_new} creates a new @code{gpgme_ctx_t} object
1943 and returns a handle for it in @var{ctx}.
1945 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1946 context was successfully created, @code{GPG_ERR_INV_VALUE} if
1947 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1948 enough memory is available.
1952 @node Destroying Contexts
1953 @section Destroying Contexts
1954 @cindex context, destruction
1956 @deftypefun void gpgme_release (@w{gpgme_ctx_t @var{ctx}})
1957 The function @code{gpgme_release} destroys the context with the handle
1958 @var{ctx} and releases all associated resources.
1962 @node Context Attributes
1963 @section Context Attributes
1964 @cindex context, attributes
1967 * Protocol Selection:: Selecting the protocol used by a context.
1968 * Crypto Engine:: Configuring the crypto engine.
1969 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
1970 * Text Mode:: Choosing canonical text mode.
1971 * Included Certificates:: Including a number of certificates.
1972 * Key Listing Mode:: Selecting key listing mode.
1973 * Passphrase Callback:: Getting the passphrase from the user.
1974 * Progress Meter Callback:: Being informed about the progress.
1975 * Locale:: Setting the locale of a context.
1979 @node Protocol Selection
1980 @subsection Protocol Selection
1981 @cindex context, selecting protocol
1982 @cindex protocol, selecting
1984 @deftypefun gpgme_error_t gpgme_set_protocol (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}})
1985 The function @code{gpgme_set_protocol} sets the protocol used within
1986 the context @var{ctx} to @var{proto}. All crypto operations will be
1987 performed by the crypto engine configured for that protocol.
1988 @xref{Protocols and Engines}.
1990 Setting the protocol with @code{gpgme_set_protocol} does not check if
1991 the crypto engine for that protocol is available and installed
1992 correctly. @xref{Engine Version Check}.
1994 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1995 protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if
1996 @var{protocol} is not a valid protocol.
1999 @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}})
2000 The function @code{gpgme_get_protocol} retrieves the protocol currently
2001 use with the context @var{ctx}.
2006 @subsection Crypto Engine
2007 @cindex context, configuring engine
2008 @cindex engine, configuration per context
2010 The following functions can be used to set and retrieve the
2011 configuration of the crypto engines of a specific context. The
2012 default can also be retrieved without any particular context.
2013 @xref{Engine Information}. The default can also be changed globally.
2014 @xref{Engine Configuration}.
2016 @deftypefun gpgme_engine_info_t gpgme_ctx_get_engine_info (@w{gpgme_ctx_t @var{ctx}})
2017 The function @code{gpgme_ctx_get_engine_info} returns a linked list of
2018 engine info structures. Each info structure describes the
2019 configuration of one configured backend, as used by the context
2022 The result is valid until the next invocation of
2023 @code{gpgme_ctx_set_engine_info} for this particular context.
2025 This function can not fail.
2028 @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}})
2029 The function @code{gpgme_ctx_set_engine_info} changes the
2030 configuration of the crypto engine implementing the protocol
2031 @var{proto} for the context @var{ctx}.
2033 @var{file_name} is the file name of the executable program
2034 implementing this protocol, and @var{home_dir} is the directory name
2035 of the configuration directory for this crypto engine. If
2036 @var{home_dir} is @code{NULL}, the engine's default will be used.
2038 Currently this function must be used before starting the first crypto
2039 operation. It is unspecified if and when the changes will take effect
2040 if the function is called after starting the first operation on the
2043 This function returns the error code @code{GPG_ERR_NO_ERROR} if
2044 successful, or an eror code on failure.
2048 @c FIXME: Unfortunately, using @acronym here breaks texi2dvi.
2050 @subsection @acronym{ASCII} Armor
2051 @cindex context, armor mode
2052 @cindex @acronym{ASCII} armor
2055 @deftypefun void gpgme_set_armor (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2056 The function @code{gpgme_set_armor} specifies if the output should be
2057 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
2060 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
2064 @deftypefun int gpgme_get_armor (@w{gpgme_ctx_t @var{ctx}})
2065 The function @code{gpgme_get_armor} returns 1 if the output is
2066 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
2067 not a valid pointer.
2072 @subsection Text Mode
2073 @cindex context, text mode
2075 @cindex canonical text mode
2077 @deftypefun void gpgme_set_textmode (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2078 The function @code{gpgme_set_textmode} specifies if canonical text mode
2079 should be used. By default, text mode is not used.
2081 Text mode is for example used for the RFC2015 signatures; note that
2082 the updated RFC 3156 mandates that the mail user agent does some
2083 preparations so that text mode is not needed anymore.
2085 This option is only relevant to the OpenPGP crypto engine, and ignored
2086 by all other engines.
2088 Canonical text mode is disabled if @var{yes} is zero, and enabled
2092 @deftypefun int gpgme_get_textmode (@w{gpgme_ctx_t @var{ctx}})
2093 The function @code{gpgme_get_textmode} returns 1 if canonical text
2094 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2099 @node Included Certificates
2100 @subsection Included Certificates
2101 @cindex certificates, included
2103 @deftypefun void gpgme_set_include_certs (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{nr_of_certs}})
2104 The function @code{gpgme_set_include_certs} specifies how many
2105 certificates should be included in an S/MIME signed message. By
2106 default, only the sender's certificate is included. The possible
2107 values of @var{nr_of_certs} are:
2110 @item GPGME_INCLUDE_CERTS_DEFAULT
2111 Fall back to the default of the crypto backend. This is the default
2114 Include all certificates except the root certificate.
2116 Include all certificates.
2118 Include no certificates.
2120 Include the sender's certificate only.
2122 Include the first n certificates of the certificates path, starting
2123 from the sender's certificate. The number @code{n} must be positive.
2126 Values of @var{nr_of_certs} smaller than -2 are undefined.
2128 This option is only relevant to the CMS crypto engine, and ignored by
2132 @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}})
2133 The function @code{gpgme_get_include_certs} returns the number of
2134 certificates to include into an S/MIME signed message.
2138 @node Key Listing Mode
2139 @subsection Key Listing Mode
2140 @cindex key listing mode
2141 @cindex key listing, mode of
2143 @deftypefun gpgme_error_t gpgme_set_keylist_mode (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_keylist_mode_t @var{mode}})
2144 The function @code{gpgme_set_keylist_mode} changes the default
2145 behaviour of the key listing functions. The value in @var{mode} is a
2146 bitwise-or combination of one or multiple of the following bit values:
2149 @item GPGME_KEYLIST_MODE_LOCAL
2150 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
2151 keyring should be searched for keys in the keylisting operation. This
2154 @item GPGME_KEYLIST_MODE_EXTERN
2155 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
2156 source should be searched for keys in the keylisting
2157 operation. The type of external source is dependant on the crypto
2158 engine used. For example, it can be a remote keyserver or LDAP
2161 @item GPGME_KEYLIST_MODE_SIGS
2162 The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key
2163 signatures should be included in the listed keys.
2165 @item GPGME_KEYLIST_MODE_SIG_NOTATIONS
2166 The @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} symbol specifies that the
2167 signature notations on key signatures should be included in the listed
2168 keys. This only works if @code{GPGME_KEYLIST_MODE_SIGS} is also
2171 @item GPGME_KEYLIST_MODE_VALIDATE
2172 The @code{GPGME_KEYLIST_MODE_VALIDATE} symbol specifies that the
2173 backend should do key or certificate validation and not just get the
2174 validity information from an internal cache. This might be an
2175 expensive operation and is in general not useful. Currently only
2176 implemented for the S/MIME backend and ignored for other backends.
2180 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
2181 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
2182 compatibility, you should get the current mode with
2183 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
2184 appropriate bits, and then using that calulcated value in the
2185 @code{gpgme_set_keylisting_mode} operation. This will leave all other
2186 bits in the mode value intact (in particular those that are not used
2187 in the current version of the library).
2189 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2190 mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx}
2191 is not a valid pointer or @var{mode} is not a valid mode.
2195 @deftypefun gpgme_keylist_mode_t gpgme_get_keylist_mode (@w{gpgme_ctx_t @var{ctx}})
2196 The function @code{gpgme_get_keylist_mode} returns the current key
2197 listing mode of the context @var{ctx}. This value can then be
2198 modified and used in a subsequent @code{gpgme_set_keylist_mode}
2199 operation to only affect the desired bits (and leave all others
2202 The function returns 0 if @var{ctx} is not a valid pointer, and the
2203 current mode otherwise. Note that 0 is not a valid mode value.
2207 @node Passphrase Callback
2208 @subsection Passphrase Callback
2209 @cindex callback, passphrase
2210 @cindex passphrase callback
2212 @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}})}
2213 @tindex gpgme_passphrase_cb_t
2214 The @code{gpgme_passphrase_cb_t} type is the type of functions usable as
2215 passphrase callback function.
2217 The argument @var{uid_hint} might contain a string that gives an
2218 indication for which user ID the passphrase is required. If this is
2219 not available, or not applicable (in the case of symmetric encryption,
2220 for example), @var{uid_hint} will be @code{NULL}.
2222 The argument @var{passphrase_info}, if not @code{NULL}, will give
2223 further information about the context in which the passphrase is
2224 required. This information is engine and operation specific.
2226 If this is the repeated attempt to get the passphrase, because
2227 previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
2230 The user must write the passphrase, followed by a newline character,
2231 to the file descriptor @var{fd}. If the user returns 0 indicating
2232 success, the user must at least write a newline character before
2233 returning from the callback.
2235 If an error occurs, return the corresponding @code{gpgme_error_t}
2236 value. You can use the error code @code{GPG_ERR_CANCELED} to abort
2237 the operation. Otherwise, return @code{0}.
2240 @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}})
2241 The function @code{gpgme_set_passphrase_cb} sets the function that is
2242 used when a passphrase needs to be provided by the user to
2243 @var{passfunc}. The function @var{passfunc} needs to implemented by
2244 the user, and whenever it is called, it is called with its first
2245 argument being @var{hook_value}. By default, no passphrase callback
2248 Not all crypto engines require this callback to retrieve the
2249 passphrase. It is better if the engine retrieves the passphrase from
2250 a trusted agent (a daemon process), rather than having each user to
2251 implement their own passphrase query. Some engines do not even
2252 support an external passphrase callback at all, in this case the error
2253 code @code{GPG_ERR_NOT_SUPPORTED} is returned.
2255 The user can disable the use of a passphrase callback function by
2256 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
2260 @deftypefun void gpgme_get_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t *@var{passfunc}}, @w{void **@var{hook_value}})
2261 The function @code{gpgme_get_passphrase_cb} returns the function that
2262 is used when a passphrase needs to be provided by the user in
2263 @var{*passfunc}, and the first argument for this function in
2264 @var{*hook_value}. If no passphrase callback is set, or @var{ctx} is
2265 not a valid pointer, @code{NULL} is returned in both variables.
2267 @var{passfunc} or @var{hook_value} can be @code{NULL}. In this case,
2268 the corresponding value will not be returned.
2272 @node Progress Meter Callback
2273 @subsection Progress Meter Callback
2274 @cindex callback, progress meter
2275 @cindex progress meter callback
2277 @deftp {Data type} {void (*gpgme_progress_cb_t)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
2278 @tindex gpgme_progress_cb_t
2279 The @code{gpgme_progress_cb_t} type is the type of functions usable as
2280 progress callback function.
2282 The arguments are specific to the crypto engine. More information
2283 about the progress information returned from the GnuPG engine can be
2284 found in the GnuPG source code in the file @file{doc/DETAILS} in the
2288 @deftypefun void gpgme_set_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t @var{progfunc}}, @w{void *@var{hook_value}})
2289 The function @code{gpgme_set_progress_cb} sets the function that is
2290 used when progress information about a cryptographic operation is
2291 available. The function @var{progfunc} needs to implemented by the
2292 user, and whenever it is called, it is called with its first argument
2293 being @var{hook_value}. By default, no progress callback function
2296 Setting a callback function allows an interactive program to display
2297 progress information about a long operation to the user.
2299 The user can disable the use of a progress callback function by
2300 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
2304 @deftypefun void gpgme_get_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t *@var{progfunc}}, @w{void **@var{hook_value}})
2305 The function @code{gpgme_get_progress_cb} returns the function that is
2306 used to inform the user about the progress made in @var{*progfunc},
2307 and the first argument for this function in @var{*hook_value}. If no
2308 progress callback is set, or @var{ctx} is not a valid pointer,
2309 @code{NULL} is returned in both variables.
2311 @var{progfunc} or @var{hook_value} can be @code{NULL}. In this case,
2312 the corresponding value will not be returned.
2318 @cindex locale, default
2319 @cindex locale, of a context
2321 A locale setting can be associated with a context. This locale is
2322 passed to the crypto engine, and used for applications like the PIN
2323 entry, which is displayed to the user when entering a passphrase is
2326 The default locale is used to initialize the locale setting of all
2327 contexts created afterwards.
2329 @deftypefun gpgme_error_t gpgme_set_locale (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{category}}, @w{const char *@var{value}})
2330 The function @code{gpgme_set_locale} sets the locale of the context
2331 @var{ctx}, or the default locale if @var{ctx} is a null pointer.
2333 The locale settings that should be changed are specified by
2334 @var{category}. Supported categories are @code{LC_CTYPE},
2335 @code{LC_MESSAGES}, and @code{LC_ALL}, which is a wildcard you can use
2336 if you want to change all the categories at once.
2338 The value to be used for the locale setting is @var{value}, which will
2339 be copied to @acronym{GPGME}'s internal data structures. @var{value}
2340 can be a null pointer, which disables setting the locale, and will
2341 make PIN entry and other applications use their default setting, which
2342 is usually not what you want.
2344 Note that the settings are only used if the application runs on a text
2345 terminal, and that the settings should fit the configuration of the
2346 output terminal. Normally, it is sufficient to initialize the default
2349 The function returns an error if not enough memory is available.
2353 @node Key Management
2354 @section Key Management
2355 @cindex key management
2357 Some of the cryptographic operations require that recipients or
2358 signers are specified. This is always done by specifying the
2359 respective keys that should be used for the operation. The following
2360 section describes how such keys can be selected and manipulated.
2362 @deftp {Data type} gpgme_sub_key_t
2363 The @code{gpgme_sub_key_t} type is a pointer to a subkey structure.
2364 Sub keys are one component of a @code{gpgme_key_t} object. In fact,
2365 subkeys are those parts that contains the real information about the
2366 individual cryptographic keys that belong to the same key object. One
2367 @code{gpgme_key_t} can contain several subkeys. The first subkey in
2368 the linked list is also called the primary key.
2370 The subkey structure has the following members:
2373 @item gpgme_sub_key_t next
2374 This is a pointer to the next subkey structure in the linked list, or
2375 @code{NULL} if this is the last element.
2377 @item unsigned int revoked : 1
2378 This is true if the subkey is revoked.
2380 @item unsigned int expired : 1
2381 This is true if the subkey is expired.
2383 @item unsigned int disabled : 1
2384 This is true if the subkey is disabled.
2386 @item unsigned int invalid : 1
2387 This is true if the subkey is invalid.
2389 @item unsigned int can_encrypt : 1
2390 This is true if the subkey can be used for encryption.
2392 @item unsigned int can_sign : 1
2393 This is true if the subkey can be used to create data signatures.
2395 @item unsigned int can_certify : 1
2396 This is true if the subkey can be used to create key certificates.
2398 @item unsigned int can_authenticate : 1
2399 This is true if the subkey can be used for authentication.
2401 @item unsigned int is_qualified : 1
2402 This is true if the subkey can be used for qualified signatures
2403 according to local government regulations.
2405 @item unsigned int secret : 1
2406 This is true if the subkey is a secret key. Note that it will be false
2407 if the key is actually a stub key; i.e. a secret key operation is
2408 currently not possible (offline-key).
2410 @item gpgme_pubkey_algo_t pubkey_algo
2411 This is the public key algorithm supported by this subkey.
2413 @item unsigned int length
2414 This is the length of the subkey (in bits).
2417 This is the key ID of the subkey in hexadecimal digits.
2420 This is the fingerprint of the subkey in hexadecimal digits, if
2423 @item long int timestamp
2424 This is the creation timestamp of the subkey. This is -1 if the
2425 timestamp is invalid, and 0 if it is not available.
2427 @item long int expires
2428 This is the expiration timestamp of the subkey, or 0 if the subkey
2433 @deftp {Data type} gpgme_key_sig_t
2434 The @code{gpgme_key_sig_t} type is a pointer to a key signature structure.
2435 Key signatures are one component of a @code{gpgme_key_t} object, and
2436 validate user IDs on the key.
2438 The signatures on a key are only available if the key was retrieved
2439 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
2440 enabled, because it can be expensive to retrieve all signatures of a
2443 The signature notations on a key signature are only available if the
2444 key was retrieved via a listing operation with the
2445 @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} mode enabled, because it can
2446 be expensive to retrieve all signature notations.
2448 The key signature structure has the following members:
2451 @item gpgme_key_sig_t next
2452 This is a pointer to the next key signature structure in the linked
2453 list, or @code{NULL} if this is the last element.
2455 @item unsigned int revoked : 1
2456 This is true if the key signature is a revocation signature.
2458 @item unsigned int expired : 1
2459 This is true if the key signature is expired.
2461 @item unsigned int invalid : 1
2462 This is true if the key signature is invalid.
2464 @item unsigned int exportable : 1
2465 This is true if the key signature is exportable.
2467 @item gpgme_pubkey_algo_t pubkey_algo
2468 This is the public key algorithm used to create the signature.
2471 This is the key ID of the key (in hexadecimal digits) used to create
2474 @item long int timestamp
2475 This is the creation timestamp of the key signature. This is -1 if
2476 the timestamp is invalid, and 0 if it is not available.
2478 @item long int expires
2479 This is the expiration timestamp of the key signature, or 0 if the key
2480 signature does not expire.
2482 @item gpgme_error_t status
2483 This is the status of the signature and has the same meaning as the
2484 member of the same name in a @code{gpgme_signature_t} object.
2486 @item unsigned int sig_class
2487 This specifies the signature class of the key signature. The meaning
2488 is specific to the crypto engine.
2491 This is the main user ID of the key used to create the signature.
2494 This is the name component of @code{uid}, if available.
2497 This is the comment component of @code{uid}, if available.
2500 This is the email component of @code{uid}, if available.
2502 @item gpgme_sig_notation_t notations
2503 This is a linked list with the notation data and policy URLs.
2507 @deftp {Data type} gpgme_user_id_t
2508 A user ID is a component of a @code{gpgme_key_t} object. One key can
2509 have many user IDs. The first one in the list is the main (or
2512 The user ID structure has the following members.
2515 @item gpgme_user_id_t next
2516 This is a pointer to the next user ID structure in the linked list, or
2517 @code{NULL} if this is the last element.
2519 @item unsigned int revoked : 1
2520 This is true if the user ID is revoked.
2522 @item unsigned int invalid : 1
2523 This is true if the user ID is invalid.
2525 @item gpgme_validity_t validity
2526 This specifies the validity of the user ID.
2529 This is the user ID string.
2532 This is the name component of @code{uid}, if available.
2535 This is the comment component of @code{uid}, if available.
2538 This is the email component of @code{uid}, if available.
2540 @item gpgme_key_sig_t signatures
2541 This is a linked list with the signatures on this user ID.
2545 @deftp {Data type} gpgme_key_t
2546 The @code{gpgme_key_t} type is a pointer to a key object. It has the
2550 @item gpgme_keylist_mode_t keylist_mode
2551 The keylist mode that was active when the key was retrieved.
2553 @item unsigned int revoked : 1
2554 This is true if the key is revoked.
2556 @item unsigned int expired : 1
2557 This is true if the key is expired.
2559 @item unsigned int disabled : 1
2560 This is true if the key is disabled.
2562 @item unsigned int invalid : 1
2563 This is true if the key is invalid. This might have several reasons,
2564 for a example for the S/MIME backend, it will be set in during key
2565 listsing if the key could not be validated due to a missing
2566 certificates or unmatched policies.
2568 @item unsigned int can_encrypt : 1
2569 This is true if the key (ie one of its subkeys) can be used for
2572 @item unsigned int can_sign : 1
2573 This is true if the key (ie one of its subkeys) can be used to create
2576 @item unsigned int can_certify : 1
2577 This is true if the key (ie one of its subkeys) can be used to create
2580 @item unsigned int can_authenticate : 1
2581 This is true if the key (ie one of its subkeys) can be used for
2584 @item unsigned int is_qualified : 1
2585 This is true if the key can be used for qualified signatures according
2586 to local government regulations.
2588 @item unsigned int secret : 1
2589 This is true if the key is a secret key. Note, that this will always be
2590 true even if the corresponding subkey flag may be false (offline/stub
2593 @item gpgme_protocol_t protocol
2594 This is the protocol supported by this key.
2596 @item char *issuer_serial
2597 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2600 @item char *issuer_name
2601 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2604 @item char *chain_id
2605 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2606 chain ID, which can be used to built the certificate chain.
2608 @item gpgme_validity_t owner_trust
2609 If @code{protocol} is @code{GPGME_PROTOCOL_OpenPGP}, then this is the
2612 @item gpgme_sub_key_t subkeys
2613 This is a linked list with the subkeys of the key. The first subkey
2614 in the list is the primary key and usually available.
2616 @item gpgme_user_id_t uids
2617 This is a linked list with the user IDs of the key. The first user ID
2618 in the list is the main (or primary) user ID.
2623 * Listing Keys:: Browsing the list of available keys.
2624 * Information About Keys:: Requesting detailed information about keys.
2625 * Key Signatures:: Listing the signatures on a key.
2626 * Manipulating Keys:: Operations on keys.
2627 * Generating Keys:: Creating new key pairs.
2628 * Exporting Keys:: Retrieving key data from the key ring.
2629 * Importing Keys:: Adding keys to the key ring.
2630 * Deleting Keys:: Removing keys from the key ring.
2631 * Advanced Key Editing:: Advanced key edit operation.
2636 @subsection Listing Keys
2637 @cindex listing keys
2639 @cindex key listing, start
2640 @cindex key ring, list
2641 @cindex key ring, search
2643 @deftypefun gpgme_error_t gpgme_op_keylist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
2644 The function @code{gpgme_op_keylist_start} initiates a key listing
2645 operation inside the context @var{ctx}. It sets everything up so that
2646 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
2649 If @var{pattern} is @code{NULL}, all available keys are returned.
2650 Otherwise, @var{pattern} contains an engine specific expression that
2651 is used to limit the list to all keys matching the pattern. Note that
2652 the total length of the pattern is restricted to an engine-specific
2653 maximum (a couple of hundred characters are usually accepted). The
2654 pattern should be used to restrict the search to a certain common name
2655 or user, not to list many specific keys at once by listing their
2656 fingerprints or key IDs.
2658 If @var{secret_only} is not @code{0}, the list is restricted to secret
2661 The context will be busy until either all keys are received (and
2662 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2663 @code{gpgme_op_keylist_end} is called to finish the operation.
2665 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2666 @var{ctx} is not a valid pointer, and passes through any errors that
2667 are reported by the crypto engine support routines.
2670 @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}})
2671 The function @code{gpgme_op_keylist_ext_start} initiates an extended
2672 key listing operation inside the context @var{ctx}. It sets
2673 everything up so that subsequent invocations of
2674 @code{gpgme_op_keylist_next} return the keys in the list.
2676 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
2677 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
2678 array of strings that are used to limit the list to all keys matching
2679 at least one of the patterns verbatim. Note that the total length of
2680 all patterns is restricted to an engine-specific maximum (the exact
2681 limit also depends on the number of patterns and amount of quoting
2682 required, but a couple of hundred characters are usually accepted).
2683 Patterns should be used to restrict the search to a certain common
2684 name or user, not to list many specific keys at once by listing their
2685 fingerprints or key IDs.
2687 If @var{secret_only} is not @code{0}, the list is restricted to secret
2690 The value of @var{reserved} must be @code{0}.
2692 The context will be busy until either all keys are received (and
2693 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2694 @code{gpgme_op_keylist_end} is called to finish the operation.
2696 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2697 @var{ctx} is not a valid pointer, and passes through any errors that
2698 are reported by the crypto engine support routines.
2701 @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}})
2702 The function @code{gpgme_op_keylist_next} returns the next key in the
2703 list created by a previous @code{gpgme_op_keylist_start} operation in
2704 the context @var{ctx}. The key will have one reference for the user.
2705 @xref{Manipulating Keys}.
2707 This is the only way to get at @code{gpgme_key_t} objects in
2710 If the last key in the list has already been returned,
2711 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}.
2713 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2714 @var{ctx} or @var{r_key} is not a valid pointer, and
2715 @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation.
2718 @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}})
2719 The function @code{gpgme_op_keylist_next} ends a pending key list
2720 operation in the context @var{ctx}.
2722 After the operation completed successfully, the result of the key
2723 listing operation can be retrieved with
2724 @code{gpgme_op_keylist_result}.
2726 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2727 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
2728 time during the operation there was not enough memory available.
2731 The following example illustrates how all keys containing a certain
2732 string (@code{g10code}) can be listed with their key ID and the name
2733 and e-mail address of the main user ID:
2737 gpgme_error_t err = gpgme_new (&ctx);
2741 err = gpgme_op_keylist_start (ctx, "g10code", 0);
2744 err = gpgme_op_keylist_next (ctx, &key);
2747 printf ("%s: %s <%s>\n", key->keyid, key->name, key->email);
2748 gpgme_key_release (key);
2750 gpgme_release (ctx);
2752 if (gpg_err_code (err) != GPG_ERR_EOF)
2754 fprintf (stderr, "%s: can not list keys: %s\n",
2755 argv[0], gpgme_strerror (err));
2760 @deftp {Data type} {gpgme_keylist_result_t}
2761 This is a pointer to a structure used to store the result of a
2762 @code{gpgme_op_keylist_*} operation. After successfully ending a key
2763 listing operation, you can retrieve the pointer to the result with
2764 @code{gpgme_op_keylist_result}. The structure contains the following
2768 @item unsigned int truncated : 1
2769 This is true if the crypto backend had to truncate the result, and
2770 less than the desired keys could be listed.
2774 @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}})
2775 The function @code{gpgme_op_keylist_result} returns a
2776 @code{gpgme_keylist_result_t} pointer to a structure holding the
2777 result of a @code{gpgme_op_keylist_*} operation. The pointer is only
2778 valid if the last operation on the context was a key listing
2779 operation, and if this operation finished successfully. The returned
2780 pointer is only valid until the next operation is started on the
2784 In a simple program, for which a blocking operation is acceptable, the
2785 following function can be used to retrieve a single key.
2787 @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}})
2788 The function @code{gpgme_get_key} gets the key with the fingerprint
2789 (or key ID) @var{fpr} from the crypto backend and return it in
2790 @var{r_key}. If @var{secret} is true, get the secret key. The
2791 currently active keylist mode is used to retrieve the key. The key
2792 will have one reference for the user.
2794 If the key is not found in the keyring, @code{gpgme_get_key} returns
2795 the error code @code{GPG_ERR_NO_ERROR} and *@var{r_key} will be set to
2798 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2799 @var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a
2800 fingerprint or key ID, @code{GPG_ERR_AMBIGUOUS_NAME} if the key ID was
2801 not a unique specifier for a key, and @code{GPG_ERR_ENOMEM} if at some
2802 time during the operation there was not enough memory available.
2806 @node Information About Keys
2807 @subsection Information About Keys
2808 @cindex key, information about
2809 @cindex key, attributes
2810 @cindex attributes, of a key
2812 Please see the beginning of this section for more information about
2813 @code{gpgme_key_t} objects.
2815 @deftp {Data type} gpgme_validity_t
2816 The @code{gpgme_validity_t} type is used to specify the validity of a user ID
2817 in a key. The following validities are defined:
2820 @item GPGME_VALIDITY_UNKNOWN
2821 The user ID is of unknown validity. The string representation of this
2824 @item GPGME_VALIDITY_UNDEFINED
2825 The validity of the user ID is undefined. The string representation of this
2828 @item GPGME_VALIDITY_NEVER
2829 The user ID is never valid. The string representation of this
2832 @item GPGME_VALIDITY_MARGINAL
2833 The user ID is marginally valid. The string representation of this
2836 @item GPGME_VALIDITY_FULL
2837 The user ID is fully valid. The string representation of this
2840 @item GPGME_VALIDITY_ULTIMATE
2841 The user ID is ultimately valid. The string representation of this
2847 The following interfaces are deprecated and only provided for backward
2848 compatibility. Don't use them. They will be removed in a future
2849 version of @acronym{GPGME}.
2851 @deftp {Data type} gpgme_attr_t
2852 The @code{gpgme_attr_t} type is used to specify a key or trust item
2853 attribute. The following attributes are defined:
2856 @item GPGME_ATTR_KEYID
2857 This is the key ID of a sub key. It is representable as a string.
2859 For trust items, the trust item refers to the key with this ID.
2861 @item GPGME_ATTR_FPR
2862 This is the fingerprint of a sub key. It is representable as a
2865 @item GPGME_ATTR_ALGO
2866 This is the crypto algorithm for which the sub key can be used. It
2867 is representable as a string and as a number. The numbers correspond
2868 to the @code{enum gcry_pk_algos} values in the gcrypt library.
2870 @item GPGME_ATTR_LEN
2871 This is the key length of a sub key. It is representable as a
2874 @item GPGME_ATTR_CREATED
2875 This is the timestamp at creation time of a sub key. It is
2876 representable as a number.
2878 @item GPGME_ATTR_EXPIRE
2879 This is the expiration time of a sub key. It is representable as a
2882 @item GPGME_ATTR_OTRUST
2883 XXX FIXME (also for trust items)
2885 @item GPGME_ATTR_USERID
2886 This is a user ID. There can be more than one user IDs in a
2887 @var{gpgme_key_t} object. The first one (with index 0) is the primary
2888 user ID. The user ID is representable as a number.
2890 For trust items, this is the user ID associated with this trust item.
2892 @item GPGME_ATTR_NAME
2893 This is the name belonging to a user ID. It is representable as a string.
2895 @item GPGME_ATTR_EMAIL
2896 This is the email address belonging to a user ID. It is representable
2899 @item GPGME_ATTR_COMMENT
2900 This is the comment belonging to a user ID. It is representable as a
2903 @item GPGME_ATTR_VALIDITY
2904 This is the validity belonging to a user ID. It is representable as a
2905 string and as a number. See below for a list of available validities.
2907 For trust items, this is the validity that is associated with this
2910 @item GPGME_ATTR_UID_REVOKED
2911 This specifies if a user ID is revoked. It is representable as a
2912 number, and is @code{1} if the user ID is revoked, and @code{0}
2915 @item GPGME_ATTR_UID_INVALID
2916 This specifies if a user ID is invalid. It is representable as a
2917 number, and is @code{1} if the user ID is invalid, and @code{0}
2920 @item GPGME_ATTR_LEVEL
2921 This is the trust level of a trust item.
2923 @item GPGME_ATTR_TYPE
2924 This returns information about the type of key. For the string function
2925 this will eother be "PGP" or "X.509". The integer function returns 0
2926 for PGP and 1 for X.509. It is also used for the type of a trust item.
2928 @item GPGME_ATTR_IS_SECRET
2929 This specifies if the key is a secret key. It is representable as a
2930 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
2932 @item GPGME_ATTR_KEY_REVOKED
2933 This specifies if a sub key is revoked. It is representable as a
2934 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
2936 @item GPGME_ATTR_KEY_INVALID
2937 This specifies if a sub key is invalid. It is representable as a
2938 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
2940 @item GPGME_ATTR_KEY_EXPIRED
2941 This specifies if a sub key is expired. It is representable as a
2942 number, and is @code{1} if the key is expired, and @code{0} otherwise.
2944 @item GPGME_ATTR_KEY_DISABLED
2945 This specifies if a sub key is disabled. It is representable as a
2946 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
2948 @item GPGME_ATTR_KEY_CAPS
2949 This is a description of the capabilities of a sub key. It is
2950 representable as a string. The string contains the letter ``e'' if
2951 the key can be used for encryption, ``s'' if the key can be used for
2952 signatures, and ``c'' if the key can be used for certifications.
2954 @item GPGME_ATTR_CAN_ENCRYPT
2955 This specifies if a sub key can be used for encryption. It is
2956 representable as a number, and is @code{1} if the sub key can be used
2957 for encryption, and @code{0} otherwise.
2959 @item GPGME_ATTR_CAN_SIGN
2960 This specifies if a sub key can be used to create data signatures. It
2961 is representable as a number, and is @code{1} if the sub key can be
2962 used for signatures, and @code{0} otherwise.
2964 @item GPGME_ATTR_CAN_CERTIFY
2965 This specifies if a sub key can be used to create key certificates.
2966 It is representable as a number, and is @code{1} if the sub key can be
2967 used for certifications, and @code{0} otherwise.
2969 @item GPGME_ATTR_SERIAL
2970 The X.509 issuer serial attribute of the key. It is representable as
2973 @item GPGME_ATTR_ISSUE
2974 The X.509 issuer name attribute of the key. It is representable as a
2977 @item GPGME_ATTR_CHAINID
2978 The X.509 chain ID can be used to build the certification chain. It
2979 is representable as a string.
2983 @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}})
2984 The function @code{gpgme_key_get_string_attr} returns the value of the
2985 string-representable attribute @var{what} of key @var{key}. If the
2986 attribute is an attribute of a sub key or an user ID, @var{idx}
2987 specifies the sub key or user ID of which the attribute value is
2988 returned. The argument @var{reserved} is reserved for later use and
2989 should be @code{NULL}.
2991 The string returned is only valid as long as the key is valid.
2993 The function returns @code{0} if an attribute can't be returned as a
2994 string, @var{key} is not a valid pointer, @var{idx} out of range,
2995 or @var{reserved} not @code{NULL}.
2998 @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}})
2999 The function @code{gpgme_key_get_ulong_attr} returns the value of the
3000 number-representable attribute @var{what} of key @var{key}. If the
3001 attribute is an attribute of a sub key or an user ID, @var{idx}
3002 specifies the sub key or user ID of which the attribute value is
3003 returned. The argument @var{reserved} is reserved for later use and
3004 should be @code{NULL}.
3006 The function returns @code{0} if the attribute can't be returned as a
3007 number, @var{key} is not a valid pointer, @var{idx} out of range, or
3008 @var{reserved} not @code{NULL}.
3012 @node Key Signatures
3013 @subsection Key Signatures
3014 @cindex key, signatures
3015 @cindex signatures, on a key
3017 The following interfaces are deprecated and only provided for backward
3018 compatibility. Don't use them. They will be removed in a future
3019 version of @acronym{GPGME}.
3021 The signatures on a key are only available if the key was retrieved
3022 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
3023 enabled, because it is expensive to retrieve all signatures of a key.
3025 So, before using the below interfaces to retrieve the signatures on a
3026 key, you have to make sure that the key was listed with signatures
3027 enabled. One convenient, but blocking, way to do this is to use the
3028 function @code{gpgme_get_key}.
3030 @deftp {Data type} gpgme_attr_t
3031 The @code{gpgme_attr_t} type is used to specify a key signature
3032 attribute. The following attributes are defined:
3035 @item GPGME_ATTR_KEYID
3036 This is the key ID of the key which was used for the signature. It is
3037 representable as a string.
3039 @item GPGME_ATTR_ALGO
3040 This is the crypto algorithm used to create the signature. It is
3041 representable as a string and as a number. The numbers correspond to
3042 the @code{enum gcry_pk_algos} values in the gcrypt library.
3044 @item GPGME_ATTR_CREATED
3045 This is the timestamp at creation time of the signature. It is
3046 representable as a number.
3048 @item GPGME_ATTR_EXPIRE
3049 This is the expiration time of the signature. It is representable as
3052 @item GPGME_ATTR_USERID
3053 This is the user ID associated with the signing key. The user ID is
3054 representable as a number.
3056 @item GPGME_ATTR_NAME
3057 This is the name belonging to a user ID. It is representable as a string.
3059 @item GPGME_ATTR_EMAIL
3060 This is the email address belonging to a user ID. It is representable
3063 @item GPGME_ATTR_COMMENT
3064 This is the comment belonging to a user ID. It is representable as a
3067 @item GPGME_ATTR_KEY_REVOKED
3068 This specifies if a key signature is a revocation signature. It is
3069 representable as a number, and is @code{1} if the key is revoked, and
3072 @c @item GPGME_ATTR_KEY_EXPIRED
3073 @c This specifies if a key signature is expired. It is representable as
3074 @c a number, and is @code{1} if the key is revoked, and @code{0}
3077 @item GPGME_ATTR_SIG_CLASS
3078 This specifies the signature class of a key signature. It is
3079 representable as a number. The meaning is specific to the crypto
3082 @item GPGME_ATTR_SIG_CLASS
3083 This specifies the signature class of a key signature. It is
3084 representable as a number. The meaning is specific to the crypto
3087 @item GPGME_ATTR_SIG_STATUS
3088 This is the same value as returned by @code{gpgme_get_sig_status}.
3092 @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}})
3093 The function @code{gpgme_key_sig_get_string_attr} returns the value of
3094 the string-representable attribute @var{what} of the signature
3095 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3096 argument @var{reserved} is reserved for later use and should be
3099 The string returned is only valid as long as the key is valid.
3101 The function returns @code{0} if an attribute can't be returned as a
3102 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3103 out of range, or @var{reserved} not @code{NULL}.
3106 @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}})
3107 The function @code{gpgme_key_sig_get_ulong_attr} returns the value of
3108 the number-representable attribute @var{what} of the signature
3109 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3110 argument @var{reserved} is reserved for later use and should be
3113 The function returns @code{0} if an attribute can't be returned as a
3114 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3115 out of range, or @var{reserved} not @code{NULL}.
3119 @node Manipulating Keys
3120 @subsection Manipulating Keys
3121 @cindex key, manipulation
3123 @deftypefun void gpgme_key_ref (@w{gpgme_key_t @var{key}})
3124 The function @code{gpgme_key_ref} acquires an additional reference for
3128 @deftypefun void gpgme_key_unref (@w{gpgme_key_t @var{key}})
3129 The function @code{gpgme_key_unref} releases a reference for the key
3130 @var{key}. If this was the last reference, the key will be destroyed
3131 and all resources associated to it will be released.
3135 The following interface is deprecated and only provided for backward
3136 compatibility. Don't use it. It will be removed in a future version
3139 @deftypefun void gpgme_key_release (@w{gpgme_key_t @var{key}})
3140 The function @code{gpgme_key_release} is equivalent to
3141 @code{gpgme_key_unref}.
3145 @node Generating Keys
3146 @subsection Generating Keys
3147 @cindex key, creation
3148 @cindex key ring, add
3150 @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}})
3151 The function @code{gpgme_op_genkey} generates a new key pair in the
3152 context @var{ctx}. The meaning of @var{public} and @var{secret}
3153 depends on the crypto backend.
3155 GnuPG does not support @var{public} and @var{secret}, they should be
3156 @code{NULL}. GnuPG will generate a key pair and add it to the
3157 standard key ring. The fingerprint of the generated key is available
3158 with @code{gpgme_op_genkey_result}.
3160 GpgSM requires @var{public} to be a writable data object. GpgSM will
3161 generate a secret key (which will be stored by @command{gpg-agent},
3162 and return a certificate request in @var{public}, which then needs to
3163 be signed by the certification authority and imported before it can be
3164 used. GpgSM does not make the fingerprint available.
3166 The argument @var{parms} specifies parameters for the key in an XML
3167 string. The details about the format of @var{parms} are specific to
3168 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
3172 <GnupgKeyParms format="internal">
3177 Name-Real: Joe Tester
3178 Name-Comment: with stupid passphrase
3179 Name-Email: joe@@foo.bar
3185 Here is an example for GpgSM as the crypto engine:
3188 <GnupgKeyParms format="internal">
3191 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3192 Name-Email: joe@@foo.bar
3196 Strings should be given in UTF-8 encoding. The only format supported
3197 for now is ``internal''. The content of the @code{GnupgKeyParms}
3198 container is passed verbatim to the crypto backend. Control
3199 statements are not allowed.
3201 After the operation completed successfully, the result can be
3202 retrieved with @code{gpgme_op_genkey_result}.
3204 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3205 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3206 @var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if
3207 @var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL}
3208 if no key was created by the backend.
3211 @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}})
3212 The function @code{gpgme_op_genkey_start} initiates a
3213 @code{gpgme_op_genkey} operation. It can be completed by calling
3214 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3216 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3217 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3218 @var{parms} is not a valid XML string, and
3219 @code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not
3223 @deftp {Data type} {gpgme_genkey_result_t}
3224 This is a pointer to a structure used to store the result of a
3225 @code{gpgme_op_genkey} operation. After successfully generating a
3226 key, you can retrieve the pointer to the result with
3227 @code{gpgme_op_genkey_result}. The structure contains the following
3231 @item unsigned int primary : 1
3232 This is a flag that is set to 1 if a primary key was created and to 0
3235 @item unsigned int sub : 1
3236 This is a flag that is set to 1 if a subkey was created and to 0
3240 This is the fingerprint of the key that was created. If both a
3241 primary and a sub key were generated, the fingerprint of the primary
3242 key will be returned. If the crypto engine does not provide the
3243 fingerprint, @code{fpr} will be a null pointer.
3247 @deftypefun gpgme_genkey_result_t gpgme_op_genkey_result (@w{gpgme_ctx_t @var{ctx}})
3248 The function @code{gpgme_op_genkey_result} returns a
3249 @code{gpgme_genkey_result_t} pointer to a structure holding the result of
3250 a @code{gpgme_op_genkey} operation. The pointer is only valid if the
3251 last operation on the context was a @code{gpgme_op_genkey} or
3252 @code{gpgme_op_genkey_start} operation, and if this operation finished
3253 successfully. The returned pointer is only valid until the next
3254 operation is started on the context.
3258 @node Exporting Keys
3259 @subsection Exporting Keys
3261 @cindex key ring, export from
3263 @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}})
3264 The function @code{gpgme_op_export} extracts public keys and returns
3265 them in the data buffer @var{keydata}. The output format of the key
3266 data returned is determined by the @acronym{ASCII} armor attribute set
3267 for the context @var{ctx}.
3269 If @var{pattern} is @code{NULL}, all available keys are returned.
3270 Otherwise, @var{pattern} contains an engine specific expression that
3271 is used to limit the list to all keys matching the pattern.
3273 @var{reserved} is reserved for future use and must be @code{0}.
3275 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3276 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3277 @var{keydata} is not a valid empty data buffer, and passes through any
3278 errors that are reported by the crypto engine support routines.
3281 @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}})
3282 The function @code{gpgme_op_export_start} initiates a
3283 @code{gpgme_op_export} operation. It can be completed by calling
3284 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3286 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3287 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3288 if @var{keydata} is not a valid empty data buffer.
3291 @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}})
3292 The function @code{gpgme_op_export} extracts public keys and returns
3293 them in the data buffer @var{keydata}. The output format of the key
3294 data returned is determined by the @acronym{ASCII} armor attribute set
3295 for the context @var{ctx}.
3297 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3298 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3299 array of strings that are used to limit the list to all keys matching
3300 at least one of the patterns verbatim.
3302 @var{reserved} is reserved for future use and must be @code{0}.
3304 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3305 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3306 @var{keydata} is not a valid empty data buffer, and passes through any
3307 errors that are reported by the crypto engine support routines.
3310 @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}})
3311 The function @code{gpgme_op_export_ext_start} initiates a
3312 @code{gpgme_op_export_ext} operation. It can be completed by calling
3313 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3315 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3316 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3317 if @var{keydata} is not a valid empty data buffer.
3321 @node Importing Keys
3322 @subsection Importing Keys
3324 @cindex key ring, import to
3326 @deftypefun gpgme_error_t gpgme_op_import (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3327 The function @code{gpgme_op_import} adds the keys in the data buffer
3328 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
3329 The format of @var{keydata} can be @acronym{ASCII} armored, for example,
3330 but the details are specific to the crypto engine.
3332 After the operation completed successfully, the result can be
3333 retrieved with @code{gpgme_op_import_result}.
3335 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3336 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3337 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3338 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3341 @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3342 The function @code{gpgme_op_import_start} initiates a
3343 @code{gpgme_op_import} operation. It can be completed by calling
3344 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3346 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3347 import could be started successfully, @code{GPG_ERR_INV_VALUE} if
3348 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3349 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3352 @deftp {Data type} {gpgme_import_status_t}
3353 This is a pointer to a structure used to store a part of the result of
3354 a @code{gpgme_op_import} operation. For each considered key one
3355 status is added that contains information about the result of the
3356 import. The structure contains the following members:
3359 @item gpgme_import_status_t next
3360 This is a pointer to the next status structure in the linked list, or
3361 @code{NULL} if this is the last element.
3364 This is the fingerprint of the key that was considered.
3366 @item gpgme_error_t result
3367 If the import was not successful, this is the error value that caused
3368 the import to fail. Otherwise the error code is
3369 @code{GPG_ERR_NO_ERROR}.
3371 @item unsigned int status
3372 This is a bit-wise OR of the following flags that give more
3373 information about what part of the key was imported. If the key was
3374 already known, this might be 0.
3377 @item GPGME_IMPORT_NEW
3380 @item GPGME_IMPORT_UID
3381 The key contained new user IDs.
3383 @item GPGME_IMPORT_SIG
3384 The key contained new signatures.
3386 @item GPGME_IMPORT_SUBKEY
3387 The key contained new sub keys.
3389 @item GPGME_IMPORT_SECRET
3390 The key contained a secret key.
3395 @deftp {Data type} {gpgme_import_result_t}
3396 This is a pointer to a structure used to store the result of a
3397 @code{gpgme_op_import} operation. After a successful import
3398 operation, you can retrieve the pointer to the result with
3399 @code{gpgme_op_import_result}. The structure contains the following
3403 @item int considered
3404 The total number of considered keys.
3406 @item int no_user_id
3407 The number of keys without user ID.
3410 The total number of imported keys.
3413 The number of imported RSA keys.
3416 The number of unchanged keys.
3419 The number of new user IDs.
3422 The number of new sub keys.
3424 @item new_signatures
3425 The number of new signatures.
3427 @item new_revocations
3428 The number of new revocations.
3431 The total number of secret keys read.
3433 @item secret_imported
3434 The number of imported secret keys.
3436 @item secret_unchanged
3437 The number of unchanged secret keys.
3440 The number of keys not imported.
3442 @item gpgme_import_status_t imports
3443 A list of gpgme_import_status_t objects which contain more information
3444 about the keys for which an import was attempted.
3448 @deftypefun gpgme_import_result_t gpgme_op_import_result (@w{gpgme_ctx_t @var{ctx}})
3449 The function @code{gpgme_op_import_result} returns a
3450 @code{gpgme_import_result_t} pointer to a structure holding the result
3451 of a @code{gpgme_op_import} operation. The pointer is only valid if
3452 the last operation on the context was a @code{gpgme_op_import} or
3453 @code{gpgme_op_import_start} operation, and if this operation finished
3454 successfully. The returned pointer is only valid until the next
3455 operation is started on the context.
3458 The following interface is deprecated and only provided for backward
3459 compatibility. Don't use it. It will be removed in a future version
3462 @deftypefun gpgme_error_t gpgme_op_import_ext (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}}, @w{int *@var{nr}})
3463 The function @code{gpgme_op_import_ext} is equivalent to:
3466 gpgme_error_t err = gpgme_op_import (ctx, keydata);
3469 gpgme_import_result_t result = gpgme_op_import_result (ctx);
3470 *nr = result->considered;
3477 @subsection Deleting Keys
3479 @cindex key ring, delete from
3481 @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}})
3482 The function @code{gpgme_op_delete} deletes the key @var{key} from the
3483 key ring of the crypto engine used by @var{ctx}. If
3484 @var{allow_secret} is @code{0}, only public keys are deleted,
3485 otherwise secret keys are deleted as well, if that is supported.
3487 The function returns the error code @code{GPG_ERR_NO_ERROR} if the key
3488 was deleted successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3489 @var{key} is not a valid pointer, @code{GPG_ERR_NO_PUBKEY} if
3490 @var{key} could not be found in the keyring,
3491 @code{GPG_ERR_AMBIGUOUS_NAME} if the key was not specified
3492 unambiguously, and @code{GPG_ERR_CONFLICT} if the secret key for
3493 @var{key} is available, but @var{allow_secret} is zero.
3496 @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}})
3497 The function @code{gpgme_op_delete_start} initiates a
3498 @code{gpgme_op_delete} operation. It can be completed by calling
3499 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3501 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3502 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3503 @var{ctx} or @var{key} is not a valid pointer.
3507 @node Advanced Key Editing
3508 @subsection Advanced Key Editing
3511 @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}})}
3512 @tindex gpgme_edit_cb_t
3513 The @code{gpgme_edit_cb_t} type is the type of functions which
3514 @acronym{GPGME} calls if it a key edit operation is on-going. The
3515 status code @var{status} and the argument line @var{args} are passed
3516 through by @acronym{GPGME} from the crypto engine. The file
3517 descriptor @var{fd} is -1 for normal status messages. If @var{status}
3518 indicates a command rather than a status message, the response to the
3519 command should be written to @var{fd}. The @var{handle} is provided
3520 by the user at start of operation.
3522 The function should return @code{GPG_ERR_NO_ERROR} or an error value.
3525 @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}})
3526 The function @code{gpgme_op_edit} processes the key @var{KEY}
3527 interactively, using the edit callback function @var{FNC} with the
3528 handle @var{HANDLE}. The callback is invoked for every status and
3529 command request from the crypto engine. The output of the crypto
3530 engine is written to the data object @var{out}.
3532 Note that the protocol between the callback function and the crypto
3533 engine is specific to the crypto engine and no further support in
3534 implementing this protocol correctly is provided by @acronym{GPGME}.
3536 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3537 edit operation completes successfully, @code{GPG_ERR_INV_VALUE} if
3538 @var{ctx} or @var{key} is not a valid pointer, and any error returned
3539 by the crypto engine or the edit callback handler.
3542 @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}})
3543 The function @code{gpgme_op_edit_start} initiates a
3544 @code{gpgme_op_edit} operation. It can be completed by calling
3545 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3547 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3548 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3549 @var{ctx} or @var{key} is not a valid pointer.
3553 @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}})
3554 The function @code{gpgme_op_card_edit} is analogous to
3555 @code{gpgme_op_edit}, but should be used to process the smart card corresponding to the key @var{key}.
3558 @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}})
3559 The function @code{gpgme_op_card_edit_start} initiates a
3560 @code{gpgme_op_card_edit} operation. It can be completed by calling
3561 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3563 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3564 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3565 @var{ctx} or @var{key} is not a valid pointer.
3569 @node Trust Item Management
3570 @section Trust Item Management
3573 @strong{Caution:} The trust items interface is experimental.
3575 @deftp {Data type} gpgme_trust_item_t
3576 The @code{gpgme_trust_item_t} type is a pointer to a trust item object.
3577 It has the following members:
3581 This is a string describing the key to which this trust items belongs.
3584 This is the type of the trust item. A value of 1 refers to a key, a
3585 value of 2 refers to a user ID.
3588 This is the trust level.
3590 @item char *owner_trust
3591 The owner trust if @code{type} is 1.
3593 @item char *validity
3594 The calculated validity.
3597 The user name if @code{type} is 2.
3602 * Listing Trust Items:: Browsing the list of available trust items.
3603 * Information About Trust Items:: Requesting information about trust items.
3604 * Manipulating Trust Items:: Operations on trust items.
3608 @node Listing Trust Items
3609 @subsection Listing Trust Items
3610 @cindex trust item list
3612 @deftypefun gpgme_error_t gpgme_op_trustlist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}})
3613 The function @code{gpgme_op_trustlist_start} initiates a trust item
3614 listing operation inside the context @var{ctx}. It sets everything up
3615 so that subsequent invocations of @code{gpgme_op_trustlist_next} return
3616 the trust items in the list.
3618 The string @var{pattern} contains an engine specific expression that
3619 is used to limit the list to all trust items matching the pattern. It
3620 can not be the empty string.
3622 The argument @var{max_level} is currently ignored.
3624 The context will be busy until either all trust items are received
3625 (and @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}), or
3626 @code{gpgme_op_trustlist_end} is called to finish the operation.
3628 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3629 @var{ctx} is not a valid pointer, and passes through any errors that
3630 are reported by the crypto engine support routines.
3633 @deftypefun gpgme_error_t gpgme_op_trustlist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_trust_item_t *@var{r_item}})
3634 The function @code{gpgme_op_trustlist_next} returns the next trust
3635 item in the list created by a previous @code{gpgme_op_trustlist_start}
3636 operation in the context @var{ctx}. The trust item can be destroyed
3637 with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}.
3639 This is the only way to get at @code{gpgme_trust_item_t} objects in
3642 If the last trust item in the list has already been returned,
3643 @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}.
3645 The function returns the error code @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3646 @var{r_item} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if
3647 there is not enough memory for the operation.
3650 @deftypefun gpgme_error_t gpgme_op_trustlist_end (@w{gpgme_ctx_t @var{ctx}})
3651 The function @code{gpgme_op_trustlist_next} ends a pending key list
3652 operation in the context @var{ctx}.
3654 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3655 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
3656 time during the operation there was not enough memory available.
3660 @node Information About Trust Items
3661 @subsection Information About Trust Items
3662 @cindex trust item, information about
3663 @cindex trust item, attributes
3664 @cindex attributes, of a trust item
3666 The following interfaces are deprecated and only provided for backward
3667 compatibility. Don't use them. They will be removed in a future
3668 version of @acronym{GPGME}.
3670 Trust items have attributes which can be queried using the interfaces
3671 below. The attribute identifiers are shared with those for key
3672 attributes. @xref{Information About Keys}.
3674 @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}})
3675 The function @code{gpgme_trust_item_get_string_attr} returns the value
3676 of the string-representable attribute @var{what} of trust item
3677 @var{item}. The arguments @var{idx} and @var{reserved} are reserved
3678 for later use and should be @code{0} and @code{NULL} respectively.
3680 The string returned is only valid as long as the key is valid.
3682 The function returns @code{0} if an attribute can't be returned as a
3683 string, @var{key} is not a valid pointer, @var{idx} out of range,
3684 or @var{reserved} not @code{NULL}.
3687 @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}})
3688 The function @code{gpgme_trust_item_get_int_attr} returns the value of
3689 the number-representable attribute @var{what} of trust item
3690 @var{item}. If the attribute occurs more than once in the trust item,
3691 the index is specified by @var{idx}. However, currently no such
3692 attribute exists, so @var{idx} should be @code{0}. The argument
3693 @var{reserved} is reserved for later use and should be @code{NULL}.
3695 The function returns @code{0} if the attribute can't be returned as a
3696 number, @var{key} is not a valid pointer, @var{idx} out of range,
3697 or @var{reserved} not @code{NULL}.
3701 @node Manipulating Trust Items
3702 @subsection Manipulating Trust Items
3703 @cindex trust item, manipulation
3705 @deftypefun void gpgme_trust_item_ref (@w{gpgme_trust_item_t @var{item}})
3706 The function @code{gpgme_trust_item_ref} acquires an additional
3707 reference for the trust item @var{item}.
3710 @deftypefun void gpgme_trust_item_unref (@w{gpgme_trust_item_t @var{item}})
3711 The function @code{gpgme_trust_item_unref} releases a reference for
3712 the trust item @var{item}. If this was the last reference, the trust
3713 item will be destroyed and all resources associated to it will be
3718 The following interface is deprecated and only provided for backward
3719 compatibility. Don't use it. It will be removed in a future version
3722 @deftypefun void gpgme_trust_item_release (@w{gpgme_trust_item_t @var{item}})
3723 The function @code{gpgme_trust_item_release} is an alias for
3724 @code{gpgme_trust_item_unref}.
3728 @node Crypto Operations
3729 @section Crypto Operations
3730 @cindex cryptographic operation
3732 Sometimes, the result of a crypto operation returns a list of invalid
3733 keys encountered in processing the request. The following structure
3734 is used to hold information about such a key.
3736 @deftp {Data type} {gpgme_invalid_key_t}
3737 This is a pointer to a structure used to store a part of the result of
3738 a crypto operation which takes user IDs as one input parameter. The
3739 structure contains the following members:
3742 @item gpgme_invalid_key_t next
3743 This is a pointer to the next invalid key structure in the linked
3744 list, or @code{NULL} if this is the last element.
3747 The fingerprint or key ID of the invalid key encountered.
3749 @item gpgme_error_t reason
3750 An error code describing the reason why the key was found invalid.
3756 * Decrypt:: Decrypting a ciphertext.
3757 * Verify:: Verifying a signature.
3758 * Decrypt and Verify:: Decrypting a signed ciphertext.
3759 * Sign:: Creating a signature.
3760 * Encrypt:: Encrypting a plaintext.
3767 @cindex cryptographic operation, decryption
3769 @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}})
3770 The function @code{gpgme_op_decrypt} decrypts the ciphertext in the
3771 data object @var{cipher} and stores it into the data object
3774 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3775 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
3776 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
3777 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
3778 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
3779 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
3780 secret key could not be retrieved, and passes through any errors that
3781 are reported by the crypto engine support routines.
3784 @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}})
3785 The function @code{gpgme_op_decrypt_start} initiates a
3786 @code{gpgme_op_decrypt} operation. It can be completed by calling
3787 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3789 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3790 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3791 if @var{cipher} or @var{plain} is not a valid pointer.
3794 @deftp {Data type} {gpgme_recipient_t}
3795 This is a pointer to a structure used to store information about the
3796 recipient of an encrypted text which is decrypted in a
3797 @code{gpgme_op_decrypt} operation. This information (except for the
3798 status field) is even available before the operation finished
3799 successfully, for example in a passphrase callback. The structure
3800 contains the following members:
3803 @item gpgme_recipient_t next
3804 This is a pointer to the next recipient structure in the linked list,
3805 or @code{NULL} if this is the last element.
3807 @item gpgme_pubkey_algo_t
3808 The public key algorithm used in the encryption.
3810 @item unsigned int wrong_key_usage : 1
3811 This is true if the key was not used according to its policy.
3814 This is the key ID of the key (in hexadecimal digits) used as
3817 @item gpgme_error_t status
3818 This is an error number with the error code GPG_ERR_NO_SECKEY if the
3819 secret key for this recipient is not available, and 0 otherwise.
3823 @deftp {Data type} {gpgme_decrypt_result_t}
3824 This is a pointer to a structure used to store the result of a
3825 @code{gpgme_op_decrypt} operation. After successfully decrypting
3826 data, you can retrieve the pointer to the result with
3827 @code{gpgme_op_decrypt_result}. The structure contains the following
3831 @item char *unsupported_algorithm
3832 If an unsupported algorithm was encountered, this string describes the
3833 algorithm that is not supported.
3835 @item unsigned int wrong_key_usage : 1
3836 This is true if the key was not used according to its policy.
3838 @item gpgme_recipient_t recipient
3839 This is a linked list of recipients to which this message was encrypted.
3841 @item char *file_name
3842 This is the filename of the original plaintext message file if it is
3843 known, otherwise this is a null pointer.
3847 @deftypefun gpgme_decrypt_result_t gpgme_op_decrypt_result (@w{gpgme_ctx_t @var{ctx}})
3848 The function @code{gpgme_op_decrypt_result} returns a
3849 @code{gpgme_decrypt_result_t} pointer to a structure holding the
3850 result of a @code{gpgme_op_decrypt} operation. The pointer is only
3851 valid if the last operation on the context was a
3852 @code{gpgme_op_decrypt} or @code{gpgme_op_decrypt_start} operation.
3853 If the operation failed this might be a @code{NULL} pointer. The
3854 returned pointer is only valid until the next operation is started on
3861 @cindex verification
3862 @cindex signature, verification
3863 @cindex cryptographic operation, verification
3864 @cindex cryptographic operation, signature check
3865 @cindex signature notation data
3866 @cindex notation data
3868 @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}})
3869 The function @code{gpgme_op_verify} verifies that the signature in the
3870 data object @var{sig} is a valid signature. If @var{sig} is a
3871 detached signature, then the signed text should be provided in
3872 @var{signed_text} and @var{plain} should be a null pointer.
3873 Otherwise, if @var{sig} is a normal (or cleartext) signature,
3874 @var{signed_text} should be a null pointer and @var{plain} should be a
3875 writable data object that will contain the plaintext after successful
3878 The results of the individual signature verifications can be retrieved
3879 with @code{gpgme_op_verify_result}.
3881 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3882 operation could be completed successfully, @code{GPG_ERR_INV_VALUE} if
3883 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer,
3884 @code{GPG_ERR_NO_DATA} if @var{sig} does not contain any data to
3885 verify, and passes through any errors that are reported by the crypto
3886 engine support routines.
3889 @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}})
3890 The function @code{gpgme_op_verify_start} initiates a
3891 @code{gpgme_op_verify} operation. It can be completed by calling
3892 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3894 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3895 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3896 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer, and
3897 @code{GPG_ERR_NO_DATA} if @var{sig} or @var{plain} does not contain
3901 @deftp {Data type} {gpgme_sig_notation_t}
3902 This is a pointer to a structure used to store a part of the result of
3903 a @code{gpgme_op_verify} operation. The structure contains the
3907 @item gpgme_sig_notation_t next
3908 This is a pointer to the next new signature notation structure in the
3909 linked list, or @code{NULL} if this is the last element.
3912 The name of the notation field. If this is @code{NULL}, then the
3913 member @code{value} will contain a policy URL.
3916 The length of the @code{name} field. For strings the length is
3917 counted without the trailing binary zero.
3920 The value of the notation field. If @code{name} is @code{NULL}, then
3921 this is a policy URL.
3924 The length of the @code{value} field. For strings the length is
3925 counted without the trailing binary zero.
3927 @item gpgme_sig_notation_flags_t flags
3928 The accumulated flags field. This field contains the flags associated
3929 with the notation data in an accumulated form which can be used as an
3930 argument to the function @code{gpgme_sig_notation_add}. The value
3931 @code{flags} is a bitwise-or combination of one or multiple of the
3932 following bit values:
3935 @item GPGME_SIG_NOTATION_HUMAN_READABLE
3936 The @code{GPGME_SIG_NOTATION_HUMAN_READABLE} symbol specifies that the
3937 notation data is in human readable form
3939 @item GPGME_SIG_NOTATION_CRITICAL
3940 The @code{GPGME_SIG_NOTATION_CRITICAL} symbol specifies that the
3941 notation data is critical.
3945 @item unsigned int human_readable : 1
3946 This is true if the @code{GPGME_SIG_NOTATION_HUMAN_READABLE} flag is
3947 set and false otherwise. This flag is only valid for notation data,
3948 not for policy URLs.
3950 @item unsigned int critical : 1
3951 This is true if the @code{GPGME_SIG_NOTATION_CRITICAL} flag is set and
3952 false otherwise. This flag is valid for notation data and policy URLs.
3957 @deftp {Data type} {gpgme_signature_t}
3958 This is a pointer to a structure used to store a part of the result of
3959 a @code{gpgme_op_verify} operation. The structure contains the
3963 @item gpgme_signature_t next
3964 This is a pointer to the next new signature structure in the linked
3965 list, or @code{NULL} if this is the last element.
3967 @item gpgme_sigsum_t summary
3968 This is a bit vector giving a summary of the signature status. It
3969 provides an easy interface to a defined semantic of the signature
3970 status. Checking just one bit is sufficient to see whether a
3971 signature is valid without any restrictions.
3973 The defined bits are:
3975 @item GPGME_SIGSUM_VALID
3976 The signature is fully valid.
3978 @item GPGME_SIGSUM_GREEN
3979 The signature is good but one might want to display some extra
3980 information. Check the other bits.
3982 @item GPGME_SIGSUM_RED
3983 The signature is bad. It might be useful to check other bits and
3984 display more information, i.e. a revoked certificate might not render a
3985 signature invalid when the message was received prior to the cause for
3988 @item GPGME_SIGSUM_KEY_REVOKED
3989 The key or at least one certificate has been revoked.
3991 @item GPGME_SIGSUM_KEY_EXPIRED
3992 The key or one of the certificates has expired. It is probably a good
3993 idea to display the date of the expiration.
3995 @item GPGME_SIGSUM_SIG_EXPIRED
3996 The signature has expired.
3998 @item GPGME_SIGSUM_KEY_MISSING
3999 Can't verify due to a missing key or certificate.
4001 @item GPGME_SIGSUM_CRL_MISSING
4002 The CRL (or an equivalent mechanism) is not available.
4004 @item GPGME_SIGSUM_CRL_TOO_OLD
4005 Available CRL is too old.
4007 @item GPGME_SIGSUM_BAD_POLICY
4008 A policy requirement was not met.
4010 @item GPGME_SIGSUM_SYS_ERROR
4011 A system error occured.
4015 This is the fingerprint or key ID of the signature.
4017 @item gpgme_error_t status
4018 This is the status of the signature. In particular, the following
4019 status codes are of interest:
4022 @item GPG_ERR_NO_ERROR
4023 This status indicates that the signature is valid. For the combined
4024 result this status means that all signatures are valid.
4026 @item GPG_ERR_SIG_EXPIRED
4027 This status indicates that the signature is valid but expired. For
4028 the combined result this status means that all signatures are valid
4031 @item GPG_ERR_KEY_EXPIRED
4032 This status indicates that the signature is valid but the key used to
4033 verify the signature has expired. For the combined result this status
4034 means that all signatures are valid and all keys are expired.
4036 @item GPG_ERR_CERT_REVOKED
4037 This status indicates that the signature is valid but the key used
4038 to verify the signature has been revoked. For the combined result
4039 this status means that all signatures are valid and all keys are
4042 @item GPG_ERR_BAD_SIGNATURE
4043 This status indicates that the signature is invalid. For the combined
4044 result this status means that all signatures are invalid.
4046 @item GPG_ERR_NO_PUBKEY
4047 This status indicates that the signature could not be verified due to
4048 a missing key. For the combined result this status means that all
4049 signatures could not be checked due to missing keys.
4051 @item GPG_ERR_GENERAL
4052 This status indicates that there was some other error which prevented
4053 the signature verification.
4056 @item gpgme_sig_notation_t notations
4057 This is a linked list with the notation data and policy URLs.
4059 @item unsigned long timestamp
4060 The creation timestamp of this signature.
4062 @item unsigned long exp_timestamp
4063 The expiration timestamp of this signature, or 0 if the signature does
4066 @item unsigned int wrong_key_usage : 1
4067 This is true if the key was not used according to its policy.
4069 @item unsigned int pka_trust : 2
4070 This is set to the trust information gained by means of the PKA system.
4074 No PKA information available or verification not possible.
4076 PKA verification failed.
4078 PKA verification succeeded.
4080 Reserved for future use.
4082 Depending on the configuration of the engine, this metric may also be
4083 reflected by the validity of the signature.
4085 @item unsigned int chain_model : 1
4086 This is true if the validity of the signature has been checked using the
4087 chain model. In the chain model the time the signature has been created
4088 must be within the validity period of the certificate and the time the
4089 certificate itself has been created must be within the validity period
4090 of the issuing certificate. In contrast the default validation model
4091 checks the validity of signature as well at the entire certificate chain
4092 at the current time.
4095 @item gpgme_validity_t validity
4096 The validity of the signature.
4098 @item gpgme_error_t validity_reason
4099 If a signature is not valid, this provides a reason why.
4101 @item gpgme_pubkey_algo_t
4102 The public key algorithm used to create this signature.
4104 @item gpgme_hash_algo_t
4105 The hash algorithm used to create this signature.
4109 @deftp {Data type} {gpgme_verify_result_t}
4110 This is a pointer to a structure used to store the result of a
4111 @code{gpgme_op_verify} operation. After verifying a signature, you
4112 can retrieve the pointer to the result with
4113 @code{gpgme_op_verify_result}. If the operation failed this might be
4114 a @code{NULL} pointer. The structure contains the following member:
4117 @item gpgme_signature_t signatures
4118 A linked list with information about all signatures for which a
4119 verification was attempted.
4121 @item char *file_name
4122 This is the filename of the original plaintext message file if it is
4123 known, otherwise this is a null pointer.
4127 @deftypefun gpgme_verify_result_t gpgme_op_verify_result (@w{gpgme_ctx_t @var{ctx}})
4128 The function @code{gpgme_op_verify_result} returns a
4129 @code{gpgme_verify_result_t} pointer to a structure holding the result
4130 of a @code{gpgme_op_verify} operation. The pointer is only valid if
4131 the last operation on the context was a @code{gpgme_op_verify},
4132 @code{gpgme_op_verify_start}, @code{gpgme_op_decrypt_verify} or
4133 @code{gpgme_op_decrypt_verify_start} operation, and if this operation
4134 finished successfully (for @code{gpgme_op_decrypt_verify} and
4135 @code{gpgme_op_decrypt_verify_start}, the error code
4136 @code{GPG_ERR_NO_DATA} counts as successful in this context). The
4137 returned pointer is only valid until the next operation is started on
4142 The following interfaces are deprecated and only provided for backward
4143 compatibility. Don't use them. They will be removed in a future
4144 version of @acronym{GPGME}.
4146 @deftp {Data type} {enum gpgme_sig_stat_t}
4147 @tindex gpgme_sig_stat_t
4148 The @code{gpgme_sig_stat_t} type holds the result of a signature check, or
4149 the combined result of all signatures. The following results are
4153 @item GPGME_SIG_STAT_NONE
4154 This status should not occur in normal operation.
4156 @item GPGME_SIG_STAT_GOOD
4157 This status indicates that the signature is valid. For the combined
4158 result this status means that all signatures are valid.
4160 @item GPGME_SIG_STAT_GOOD_EXP
4161 This status indicates that the signature is valid but expired. For
4162 the combined result this status means that all signatures are valid
4165 @item GPGME_SIG_STAT_GOOD_EXPKEY
4166 This status indicates that the signature is valid but the key used to
4167 verify the signature has expired. For the combined result this status
4168 means that all signatures are valid and all keys are expired.
4170 @item GPGME_SIG_STAT_BAD
4171 This status indicates that the signature is invalid. For the combined
4172 result this status means that all signatures are invalid.
4174 @item GPGME_SIG_STAT_NOKEY
4175 This status indicates that the signature could not be verified due to
4176 a missing key. For the combined result this status means that all
4177 signatures could not be checked due to missing keys.
4179 @item GPGME_SIG_STAT_NOSIG
4180 This status indicates that the signature data provided was not a real
4183 @item GPGME_SIG_STAT_ERROR
4184 This status indicates that there was some other error which prevented
4185 the signature verification.
4187 @item GPGME_SIG_STAT_DIFF
4188 For the combined result this status means that at least two signatures
4189 have a different status. You can get each key's status with
4190 @code{gpgme_get_sig_status}.
4194 @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}})
4195 The function @code{gpgme_get_sig_status} is equivalent to:
4198 gpgme_verify_result_t result;
4199 gpgme_signature_t sig;
4201 result = gpgme_op_verify_result (ctx);
4202 sig = result->signatures;
4214 switch (gpg_err_code (sig->status))
4216 case GPG_ERR_NO_ERROR:
4217 *r_stat = GPGME_SIG_STAT_GOOD;
4220 case GPG_ERR_BAD_SIGNATURE:
4221 *r_stat = GPGME_SIG_STAT_BAD;
4224 case GPG_ERR_NO_PUBKEY:
4225 *r_stat = GPGME_SIG_STAT_NOKEY;
4228 case GPG_ERR_NO_DATA:
4229 *r_stat = GPGME_SIG_STAT_NOSIG;
4232 case GPG_ERR_SIG_EXPIRED:
4233 *r_stat = GPGME_SIG_STAT_GOOD_EXP;
4236 case GPG_ERR_KEY_EXPIRED:
4237 *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY;
4241 *r_stat = GPGME_SIG_STAT_ERROR;
4246 *r_created = sig->timestamp;
4251 @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}})
4252 The function @code{gpgme_get_sig_string_attr} is equivalent to:
4255 gpgme_verify_result_t result;
4256 gpgme_signature_t sig;
4258 result = gpgme_op_verify_result (ctx);
4259 sig = result->signatures;
4271 case GPGME_ATTR_FPR:
4274 case GPGME_ATTR_ERRTOK:
4276 return sig->wrong_key_usage ? "Wrong_Key_Usage" : "";
4287 @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}})
4288 The function @code{gpgme_get_sig_ulong_attr} is equivalent to:
4291 gpgme_verify_result_t result;
4292 gpgme_signature_t sig;
4294 result = gpgme_op_verify_result (ctx);
4295 sig = result->signatures;
4307 case GPGME_ATTR_CREATED:
4308 return sig->timestamp;
4310 case GPGME_ATTR_EXPIRE:
4311 return sig->exp_timestamp;
4313 case GPGME_ATTR_VALIDITY:
4314 return (unsigned long) sig->validity;
4316 case GPGME_ATTR_SIG_STATUS:
4317 switch (sig->status)
4319 case GPG_ERR_NO_ERROR:
4320 return GPGME_SIG_STAT_GOOD;
4322 case GPG_ERR_BAD_SIGNATURE:
4323 return GPGME_SIG_STAT_BAD;
4325 case GPG_ERR_NO_PUBKEY:
4326 return GPGME_SIG_STAT_NOKEY;
4328 case GPG_ERR_NO_DATA:
4329 return GPGME_SIG_STAT_NOSIG;
4331 case GPG_ERR_SIG_EXPIRED:
4332 return GPGME_SIG_STAT_GOOD_EXP;
4334 case GPG_ERR_KEY_EXPIRED:
4335 return GPGME_SIG_STAT_GOOD_EXPKEY;
4338 return GPGME_SIG_STAT_ERROR;
4341 case GPGME_ATTR_SIG_SUMMARY:
4342 return sig->summary;
4351 @deftypefun {const char *} gpgme_get_sig_key (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_key_t *@var{r_key}})
4352 The function @code{gpgme_get_sig_key} is equivalent to:
4355 gpgme_verify_result_t result;
4356 gpgme_signature_t sig;
4358 result = gpgme_op_verify_result (ctx);
4359 sig = result->signatures;
4367 return gpg_error (GPG_ERR_EOF);
4369 return gpgme_get_key (ctx, sig->fpr, r_key, 0);
4374 @node Decrypt and Verify
4375 @subsection Decrypt and Verify
4376 @cindex decryption and verification
4377 @cindex verification and decryption
4378 @cindex signature check
4379 @cindex cryptographic operation, decryption and verification
4381 @deftypefun gpgme_error_t gpgme_op_decrypt_verify (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{cipher}}, @w{gpgme_data_t @var{plain}})
4382 The function @code{gpgme_op_decrypt_verify} decrypts the ciphertext in
4383 the data object @var{cipher} and stores it into the data object