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