1 \input texinfo @c -*- mode: texinfo; coding: utf-8; -*-
2 @documentencoding UTF-8
3 @setfilename gpgme.info
4 @settitle The `GnuPG Made Easy' Reference Manual
6 @dircategory GNU Libraries
8 * @acronym{GPGME}: (gpgme). Adding support for cryptography to your program.
11 @c Unify some of the indices.
16 Copyright @copyright{} 2002, 2003, 2004, 2005, 2006, 2007,
17 2008, 2010, 2012, 2013, 2014 g10 Code GmbH.
20 Permission is granted to copy, distribute and/or modify this document
21 under the terms of the GNU General Public License as published by the
22 Free Software Foundation; either version 3 of the License, or (at your
23 option) any later version. The text of the license can be found in the
24 section entitled ``Copying''.
27 This document is distributed in the hope that it will be useful, but
28 WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 General Public License for more details.
35 @c Macros used by the description of the UI server protocol
48 This file documents the @acronym{GPGME} library.
50 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
51 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
54 @c NOTE: Don't forget to update the year for the TeX version, too.
59 @c We do not want that bastard short titlepage.
61 @c @shorttitlepage The `GnuPG Made Easy' Reference Manual
64 @center @titlefont{The `GnuPG Made Easy'}
66 @center @titlefont{Reference Manual}
68 @center Edition @value{EDITION}
70 @center last updated @value{UPDATED}
72 @center for version @value{VERSION}
74 @vskip 0pt plus 1filll
75 Published by g10 Code GmbH@* Hüttenstr. 61@* 40699 Erkrath, Germany
87 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
88 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
89 @value{VERSION} of the @acronym{GPGME} library.
93 * Introduction:: How to use this manual.
94 * Preparation:: What you should do before using the library.
95 * Protocols and Engines:: Supported crypto protocols.
96 * Algorithms:: Supported algorithms.
97 * Error Handling:: Error numbers and their meanings.
98 * Exchanging Data:: Passing data to and from @acronym{GPGME}.
99 * Contexts:: Handling @acronym{GPGME} contexts.
103 * UI Server Protocol:: The GnuPG UI Server Protocol.
104 * Debugging:: How to solve problems.
106 * Library Copying:: The GNU Lesser General Public License says
107 how you can copy and share `GnuPG Made Easy'.
108 * Copying:: The GNU General Public License says how you
109 can copy and share this manual.
113 * Concept Index:: Index of concepts and programs.
114 * Function and Data Index:: Index of functions, variables and data types.
118 --- The Detailed Node Listing ---
122 * Getting Started:: Purpose of the manual, and how to use it.
123 * Features:: Reasons to install and use @acronym{GPGME}.
124 * Overview:: Basic architecture of the @acronym{GPGME} library.
128 * Header:: What header file you need to include.
129 * Building the Source:: Compiler options to be used.
130 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
131 * Using Automake:: Compiler options to be used the easy way.
132 * Using Libtool:: Avoiding compiler options entirely.
133 * Library Version Check:: Getting and verifying the library version.
134 * Signal Handling:: How @acronym{GPGME} affects signal handling.
135 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
137 Protocols and Engines
139 * Engine Version Check:: Verifying the engine version.
140 * Engine Information:: Obtaining more information about the engines.
141 * Engine Configuration:: Changing the engine configuration.
142 * OpenPGP:: Support for the OpenPGP protocol.
143 * Cryptographic Message Syntax:: Support for the CMS.
147 * Public Key Algorithms:: A list of all public key algorithms.
148 * Hash Algorithms:: A list of all hash algorithms.
152 * Error Values:: The error value and what it means.
153 * Error Codes:: A list of important error codes.
154 * Error Sources:: A list of important error sources.
155 * Error Strings:: How to get a descriptive string from a value.
159 * Creating Data Buffers:: Creating new data buffers.
160 * Destroying Data Buffers:: Releasing data buffers.
161 * Manipulating Data Buffers:: Operations on data buffers.
163 Creating Data Buffers
165 * Memory Based Data Buffers:: Creating memory based data buffers.
166 * File Based Data Buffers:: Creating file based data buffers.
167 * Callback Based Data Buffers:: Creating callback based data buffers.
169 Manipulating Data Buffers
171 * Data Buffer I/O Operations:: I/O operations on data buffers.
172 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
176 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
177 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
178 * Result Management:: Managing the result of crypto operations.
179 * Context Attributes:: Setting properties of a context.
180 * Key Management:: Managing keys with @acronym{GPGME}.
181 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
182 * Crypto Operations:: Using a context for cryptography.
183 * Run Control:: Controlling how operations are run.
187 * Protocol Selection:: Selecting the protocol used by a context.
188 * Crypto Engine:: Configuring the crypto engine.
189 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
190 * Text Mode:: Choosing canonical text mode.
191 * Included Certificates:: Including a number of certificates.
192 * Key Listing Mode:: Selecting key listing mode.
193 * Passphrase Callback:: Getting the passphrase from the user.
194 * Progress Meter Callback:: Being informed about the progress.
195 * Locale:: Setting the locale of a context.
199 * Listing Keys:: Browsing the list of available keys.
200 * Information About Keys:: Requesting detailed information about keys.
201 * Key Signatures:: Listing the signatures on a key.
202 * Manipulating Keys:: Operations on keys.
203 * Generating Keys:: Creating new key pairs.
204 * Exporting Keys:: Retrieving key data from the key ring.
205 * Importing Keys:: Adding keys to the key ring.
206 * Deleting Keys:: Removing keys from the key ring.
207 * Advanced Key Editing:: Advanced key edit operation.
209 Trust Item Management
211 * Listing Trust Items:: Browsing the list of available trust items.
212 * Information About Trust Items:: Requesting information about trust items.
213 * Manipulating Trust Items:: Operations on trust items.
217 * Decrypt:: Decrypting a ciphertext.
218 * Verify:: Verifying a signature.
219 * Decrypt and Verify:: Decrypting a signed ciphertext.
220 * Sign:: Creating a signature.
221 * Encrypt:: Encrypting a plaintext.
225 * Selecting Signers:: How to choose the keys to sign with.
226 * Creating a Signature:: How to create a signature.
227 * Signature Notation Data:: How to add notation data to a signature.
231 * Encrypting a Plaintext:: How to encrypt a plaintext.
235 * Waiting For Completion:: Waiting until an operation is completed.
236 * Using External Event Loops:: Advanced control over what happens when.
237 * Cancellation:: How to end pending operations prematurely.
239 Using External Event Loops
241 * I/O Callback Interface:: How I/O callbacks are registered.
242 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
243 * I/O Callback Example:: An example how to use I/O callbacks.
244 * I/O Callback Example GTK+:: How to integrate @acronym{GPGME} in GTK+.
245 * I/O Callback Example GDK:: How to integrate @acronym{GPGME} in GDK.
246 * I/O Callback Example Qt:: How to integrate @acronym{GPGME} in Qt.
252 @chapter Introduction
254 `GnuPG Made Easy' (@acronym{GPGME}) is a C language library that
255 allows to add support for cryptography to a program. It is designed
256 to make access to public key crypto engines like GnuPG or GpgSM easier
257 for applications. @acronym{GPGME} provides a high-level crypto API
258 for encryption, decryption, signing, signature verification and key
261 @acronym{GPGME} uses GnuPG and GpgSM as its backends to support
262 OpenPGP and the Cryptographic Message Syntax (CMS).
265 * Getting Started:: Purpose of the manual, and how to use it.
266 * Features:: Reasons to install and use @acronym{GPGME}.
267 * Overview:: Basic architecture of the @acronym{GPGME} library.
271 @node Getting Started
272 @section Getting Started
274 This manual documents the @acronym{GPGME} library programming
275 interface. All functions and data types provided by the library are
278 The reader is assumed to possess basic knowledge about cryptography in
279 general, and public key cryptography in particular. The underlying
280 cryptographic engines that are used by the library are not explained,
281 but where necessary, special features or requirements by an engine are
282 mentioned as far as they are relevant to @acronym{GPGME} or its users.
284 This manual can be used in several ways. If read from the beginning
285 to the end, it gives a good introduction into the library and how it
286 can be used in an application. Forward references are included where
287 necessary. Later on, the manual can be used as a reference manual to
288 get just the information needed about any particular interface of the
289 library. Experienced programmers might want to start looking at the
290 examples at the end of the manual, and then only read up those parts
291 of the interface which are unclear.
297 @acronym{GPGME} has a couple of advantages over other libraries doing
298 a similar job, and over implementing support for GnuPG or other crypto
299 engines into your application directly.
302 @item it's free software
303 Anybody can use, modify, and redistribute it under the terms of the GNU
304 Lesser General Public License (@pxref{Library Copying}).
307 @acronym{GPGME} provides transparent support for several cryptographic
308 protocols by different engines. Currently, @acronym{GPGME} supports
309 the OpenPGP protocol using GnuPG as the backend, and the Cryptographic
310 Message Syntax using GpgSM as the backend.
313 @acronym{GPGME} hides the differences between the protocols and
314 engines from the programmer behind an easy-to-use interface. This way
315 the programmer can focus on the other parts of the program, and still
316 integrate strong cryptography in his application. Once support for
317 @acronym{GPGME} has been added to a program, it is easy to add support
318 for other crypto protocols once @acronym{GPGME} backends provide them.
325 @acronym{GPGME} provides a data abstraction that is used to pass data
326 to the crypto engine, and receive returned data from it. Data can be
327 read from memory or from files, but it can also be provided by a
330 The actual cryptographic operations are always set within a context.
331 A context provides configuration parameters that define the behaviour
332 of all operations performed within it. Only one operation per context
333 is allowed at any time, but when one operation is finished, you can
334 run the next operation in the same context. There can be more than
335 one context, and all can run different operations at the same time.
337 Furthermore, @acronym{GPGME} has rich key management facilities
338 including listing keys, querying their attributes, generating,
339 importing, exporting and deleting keys, and acquiring information
340 about the trust path.
342 With some precautions, @acronym{GPGME} can be used in a multi-threaded
343 environment, although it is not completely thread safe and thus needs
344 the support of the application.
350 To use @acronym{GPGME}, you have to perform some changes to your
351 sources and the build system. The necessary changes are small and
352 explained in the following sections. At the end of this chapter, it
353 is described how the library is initialized, and how the requirements
354 of the library are verified.
357 * Header:: What header file you need to include.
358 * Building the Source:: Compiler options to be used.
359 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
360 * Using Automake:: Compiler options to be used the easy way.
361 * Using Libtool:: Avoiding compiler options entirely.
362 * Library Version Check:: Getting and verifying the library version.
363 * Signal Handling:: How @acronym{GPGME} affects signal handling.
364 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
373 All interfaces (data types and functions) of the library are defined
374 in the header file `gpgme.h'. You must include this in all programs
375 using the library, either directly or through some other header file,
382 The name space of @acronym{GPGME} is @code{gpgme_*} for function names
383 and data types and @code{GPGME_*} for other symbols. Symbols internal
384 to @acronym{GPGME} take the form @code{_gpgme_*} and @code{_GPGME_*}.
386 Because @acronym{GPGME} makes use of the GPG Error library, using
387 @acronym{GPGME} will also use the @code{GPG_ERR_*} name space
388 directly, and the @code{gpg_err*} and @code{gpg_str*} name space
392 @node Building the Source
393 @section Building the Source
394 @cindex compiler options
395 @cindex compiler flags
397 If you want to compile a source file including the `gpgme.h' header
398 file, you must make sure that the compiler can find it in the
399 directory hierarchy. This is accomplished by adding the path to the
400 directory in which the header file is located to the compilers include
401 file search path (via the @option{-I} option).
403 However, the path to the include file is determined at the time the
404 source is configured. To solve this problem, gpgme ships with a small
405 helper program @command{gpgme-config} that knows about the path to the
406 include file and other configuration options. The options that need
407 to be added to the compiler invocation at compile time are output by
408 the @option{--cflags} option to @command{gpgme-config}. The following
409 example shows how it can be used at the command line:
412 gcc -c foo.c `gpgme-config --cflags`
415 Adding the output of @samp{gpgme-config --cflags} to the compiler
416 command line will ensure that the compiler can find the
417 @acronym{GPGME} header file.
419 A similar problem occurs when linking the program with the library.
420 Again, the compiler has to find the library files. For this to work,
421 the path to the library files has to be added to the library search
422 path (via the @option{-L} option). For this, the option
423 @option{--libs} to @command{gpgme-config} can be used. For
424 convenience, this option also outputs all other options that are
425 required to link the program with @acronym{GPGME} (in particular, the
426 @samp{-lgpgme} option). The example shows how to link @file{foo.o}
427 with the @acronym{GPGME} library to a program @command{foo}.
430 gcc -o foo foo.o `gpgme-config --libs`
433 Of course you can also combine both examples to a single command by
434 specifying both options to @command{gpgme-config}:
437 gcc -o foo foo.c `gpgme-config --cflags --libs`
440 If you want to link to one of the thread-safe versions of
441 @acronym{GPGME}, you must specify the @option{--thread} option before
442 any other option to select the thread package you want to link with.
443 Supported thread packages are @option{--thread=pth} and
444 @option{--thread=pthread}.
447 @node Largefile Support (LFS)
448 @section Largefile Support (LFS)
449 @cindex largefile support
452 @acronym{GPGME} is compiled with largefile support by default, if it
453 is available on the system. This means that GPGME supports files
454 larger than two gigabyte in size, if the underlying operating system
455 can. On some systems, largefile support is already the default. On
456 such systems, nothing special is required. However, some systems
457 provide only support for files up to two gigabyte in size by default.
458 Support for larger file sizes has to be specifically enabled.
460 To make a difficult situation even more complex, such systems provide
461 two different types of largefile support. You can either get all
462 relevant functions replaced with alternatives that are largefile
463 capable, or you can get new functions and data types for largefile
464 support added. Those new functions have the same name as their
465 smallfile counterparts, but with a suffix of 64.
467 An example: The data type @code{off_t} is 32 bit wide on GNU/Linux PC
468 systems. To address offsets in large files, you can either enable
469 largefile support add-on. Then a new data type @code{off64_t} is
470 provided, which is 64 bit wide. Or you can replace the existing
471 @code{off_t} data type with its 64 bit wide counterpart. All
472 occurences of @code{off_t} are then automagically replaced.
474 As if matters were not complex enough, there are also two different
475 types of file descriptors in such systems. This is important because
476 if file descriptors are exchanged between programs that use a
477 different maximum file size, certain errors must be produced on some
478 file descriptors to prevent subtle overflow bugs from occuring.
480 As you can see, supporting two different maximum file sizes at the
481 same time is not at all an easy task. However, the maximum file size
482 does matter for @acronym{GPGME}, because some data types it uses in
483 its interfaces are affected by that. For example, the @code{off_t}
484 data type is used in the @code{gpgme_data_seek} function, to match its
485 @acronym{POSIX} counterpart. This affects the call-frame of the
486 function, and thus the ABI of the library. Furthermore, file
487 descriptors can be exchanged between GPGME and the application.
489 For you as the user of the library, this means that your program must
490 be compiled in the same file size mode as the library. Luckily, there
491 is absolutely no valid reason for new programs to not enable largefile
492 support by default and just use that. The compatibility modes (small
493 file sizes or dual mode) can be considered an historic artefact, only
494 useful to allow for a transitional period.
496 On POSIX platforms @acronym{GPGME} is compiled using largefile support
497 by default. This means that your application must do the same, at
498 least as far as it is relevant for using the @file{gpgme.h} header
499 file. All types in this header files refer to their largefile
500 counterparts, if they are different from any default types on the
503 On 32 and 64 bit Windows platforms @code{off_t} is declared as 32 bit
504 signed integer. There is no specific support for LFS in the C
505 library. The recommendation from Microsoft is to use the native
506 interface (@code{CreateFile} et al.) for large files. Released binary
507 versions of @acronym{GPGME} (libgpgme-11.dll) have always been build
508 with a 32 bit @code{off_t}. To avoid an ABI break we stick to this
509 convention for 32 bit Windows by using @code{long} there.
510 @acronym{GPGME} versions for 64 bit Windows have never been released
511 and thus we are able to use @code{int64_t} instead of @code{off_t}
512 there. For easier migration the typedef @code{gpgme_off_t} has been
513 defined. The reason we cannot use @code{off_t} directly is that some
514 toolchains (e.g. mingw64) introduce a POSIX compatible hack for
515 @code{off_t}. Some widely used toolkits make use of this hack and in
516 turn @acronym{GPGME} would need to use it also. However, this would
517 introduce an ABI break and existing software making use of libgpgme
518 might suffer from a severe break. Thus with version 1.4.2 we
519 redefined all functions using @code{off_t} to use @code{gpgme_off_t}
520 which is defined as explained above. This way we keep the ABI well
521 defined and independent of any toolchain hacks. The bottom line is
522 that LFS support in @acronym{GPGME} is only available on 64 bit
525 On POSIX platforms you can enable largefile support, if it is
526 different from the default on the system the application is compiled
527 on, by using the Autoconf macro @code{AC_SYS_LARGEFILE}. If you do
528 this, then you don't need to worry about anything else: It will just
529 work. In this case you might also want to use @code{AC_FUNC_FSEEKO}
530 to take advantage of some new interfaces, and @code{AC_TYPE_OFF_T}
533 If you do not use Autoconf, you can define the preprocessor symbol
534 @code{_FILE_OFFSET_BITS} to 64 @emph{before} including any header
535 files, for example by specifying the option
536 @code{-D_FILE_OFFSET_BITS=64} on the compiler command line. You will
537 also want to define the preprocessor symbol @code{LARGEFILE_SOURCE} to
538 1 in this case, to take advantage of some new interfaces.
540 If you do not want to do either of the above, you probably know enough
541 about the issue to invent your own solution. Just keep in mind that
542 the @acronym{GPGME} header file expects that largefile support is
543 enabled, if it is available. In particular, we do not support dual
544 mode (@code{_LARGEFILE64_SOURCE}).
548 @section Using Automake
552 It is much easier if you use GNU Automake instead of writing your own
553 Makefiles. If you do that you do not have to worry about finding and
554 invoking the @command{gpgme-config} script at all. @acronym{GPGME}
555 provides an extension to Automake that does all the work for you.
557 @c A simple macro for optional variables.
559 @r{[}@var{\varname\}@r{]}
561 @defmac AM_PATH_GPGME (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
562 @defmacx AM_PATH_GPGME_PTH (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
563 @defmacx AM_PATH_GPGME_PTHREAD (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
564 Check whether @acronym{GPGME} (at least version @var{minimum-version},
565 if given) exists on the host system. If it is found, execute
566 @var{action-if-found}, otherwise do @var{action-if-not-found}, if
569 Additionally, the function defines @code{GPGME_CFLAGS} to the flags
570 needed for compilation of the program to find the @file{gpgme.h}
571 header file, and @code{GPGME_LIBS} to the linker flags needed to link
572 the program to the @acronym{GPGME} library.
574 @code{AM_PATH_GPGME_PTH} checks for the version of @acronym{GPGME}
575 that can be used with GNU Pth, and defines @code{GPGME_PTH_CFLAGS} and
576 @code{GPGME_PTH_LIBS}.
578 @code{AM_PATH_GPGME_PTHREAD} checks for the version of @acronym{GPGME}
579 that can be used with the native pthread implementation, and defines
580 @code{GPGME_PTHREAD_CFLAGS} and @code{GPGME_PTHREAD_LIBS}.
583 You can use the defined Autoconf variables like this in your
587 AM_CPPFLAGS = $(GPGME_CFLAGS)
588 LDADD = $(GPGME_LIBS)
593 @section Using Libtool
596 The easiest way is to just use GNU Libtool. If you use libtool, and
597 link to @code{libgpgme.la}, @code{libgpgme-pth.la} or
598 @code{libgpgme-pthread.la} respectively, everything will be done
599 automatically by Libtool.
602 @node Library Version Check
603 @section Library Version Check
604 @cindex version check, of the library
606 @deftypefun {const char *} gpgme_check_version (@w{const char *@var{required_version}})
607 The function @code{gpgme_check_version} has four purposes. It can be
608 used to retrieve the version number of the library. In addition it
609 can verify that the version number is higher than a certain required
610 version number. In either case, the function initializes some
611 sub-systems, and for this reason alone it must be invoked early in
612 your program, before you make use of the other functions in
613 @acronym{GPGME}. The last purpose is to run selftests.
615 As a side effect for W32 based systems, the socket layer will get
619 If @var{required_version} is @code{NULL}, the function returns a
620 pointer to a statically allocated string containing the version number
623 If @var{required_version} is not @code{NULL}, it should point to a
624 string containing a version number, and the function checks that the
625 version of the library is at least as high as the version number
626 provided. In this case, the function returns a pointer to a
627 statically allocated string containing the version number of the
628 library. If @var{REQUIRED_VERSION} is not a valid version number, or
629 if the version requirement is not met, the function returns
632 If you use a version of a library that is backwards compatible with
633 older releases, but contains additional interfaces which your program
634 uses, this function provides a run-time check if the necessary
635 features are provided by the installed version of the library.
637 If a selftest fails, the function may still succeed. Selftest errors
638 are returned later when invoking @code{gpgme_new}, so that a detailed
639 error code can be returned (historically, @code{gpgme_check_version}
640 does not return a detailed error code).
644 @deftypefun {int} gpgme_set_global_flag @
645 (@w{const char *@var{name}}, @
646 @w{const char *@var{value}})
648 On some systems it is not easy to set environment variables and thus
649 hard to use @acronym{GPGME}'s internal trace facility for debugging.
650 This function has been introduced as an alternative way to enable
651 debugging and for a couple of other rarely used tweaks. It is
652 important to assure that only one thread accesses @acronym{GPGME}
653 functions between a call to this function and after the return from
654 the call to @code{gpgme_check_version}.
656 All currently supported features require that this function is called
657 as early as possible --- even before @code{gpgme_check_version}. The
658 features are identified by the following values for @var{name}:
662 To enable debugging use the string ``debug'' for @var{name} and
663 @var{value} identical to the value used with the environment variable
666 @item "disable-gpgconf"
667 Using this feature with any @var{value} disables the detection of the
668 gpgconf program and thus forces GPGME to fallback into the simple
669 OpenPGP only mode. It may be used to force the use of GnuPG-1 on
670 systems which have both GPG versions installed. Note that in general
671 the use of @code{gpgme_set_engine_info} is a better way to select a
672 specific engine version.
676 Set the name of the gpgconf respective gpg binary. The defaults are
677 @code{GNU/GnuPG/gpgconf} and @code{GNU/GnuPG/gpg}. Under Unix the
678 leading directory part is ignored. Under Windows the leading
679 directory part is used as the default installation directory; the
680 @code{.exe} suffix is added by GPGME. Use forward slashed even under
685 This function returns @code{0} on success. In contrast to other
686 functions the non-zero return value on failure does not convey any
687 error code. For setting ``debug'' the only possible error cause is an
688 out of memory condition; which would exhibit itself later anyway.
689 Thus the return value may be ignored.
693 After initializing @acronym{GPGME}, you should set the locale
694 information to the locale required for your output terminal. This
695 locale information is needed for example for the curses and Gtk
696 pinentry. Here is an example of a complete initialization:
705 /* Initialize the locale environment. */
706 setlocale (LC_ALL, "");
707 gpgme_check_version (NULL);
708 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
710 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
715 Note that you are highly recommended to initialize the locale settings
716 like this. @acronym{GPGME} can not do this for you because it would
717 not be thread safe. The conditional on LC_MESSAGES is only necessary
718 for portability to W32 systems.
721 @node Signal Handling
722 @section Signal Handling
724 @cindex signal handling
726 The @acronym{GPGME} library communicates with child processes (the
727 crypto engines). If a child process dies unexpectedly, for example
728 due to a bug, or system problem, a @code{SIGPIPE} signal will be
729 delivered to the application. The default action is to abort the
730 program. To protect against this, @code{gpgme_check_version} sets the
731 @code{SIGPIPE} signal action to @code{SIG_IGN}, which means that the
732 signal will be ignored.
734 @acronym{GPGME} will only do that if the signal action for
735 @code{SIGPIPE} is @code{SIG_DEF} at the time
736 @code{gpgme_check_version} is called. If it is something different,
737 @code{GPGME} will take no action.
739 This means that if your application does not install any signal
740 handler for @code{SIGPIPE}, you don't need to take any precautions.
741 If you do install a signal handler for @code{SIGPIPE}, you must be
742 prepared to handle any @code{SIGPIPE} events that occur due to
743 @acronym{GPGME} writing to a defunct pipe. Furthermore, if your
744 application is multi-threaded, and you install a signal action for
745 @code{SIGPIPE}, you must make sure you do this either before
746 @code{gpgme_check_version} is called or afterwards.
749 @node Multi Threading
750 @section Multi Threading
751 @cindex thread-safeness
752 @cindex multi-threading
754 The @acronym{GPGME} library is not entirely thread-safe, but it can
755 still be used in a multi-threaded environment if some care is taken.
756 If the following requirements are met, there should be no race
757 conditions to worry about:
761 @acronym{GPGME} supports the thread libraries pthread and GNU Pth.
762 The support for this has to be enabled at compile time.
763 @acronym{GPGME} will automatically detect the location in which the
764 thread libraries are installed and activate the support for them at
767 Support for other thread libraries is very easy to add. Please
768 contact us if you have the need.
771 If you want to use @acronym{GPGME} with threads, you must link to the
772 right version of the library. The name of the right library is
773 @code{libgpgme-} followed by the name of the thread package you use.
774 For example, if you use GNU Pth, the right name is
775 @code{libgpgme-pth}. Use the Automake macros or
776 @command{gpgme-config} program for simplicity.
780 The function @code{gpgme_check_version} must be called before any
781 other function in the library, because it initializes the thread
782 support subsystem in @acronym{GPGME}. To achieve this in
783 multi-threaded programs, you must synchronize the memory with respect
784 to other threads that also want to use @acronym{GPGME}. For this, it
785 is sufficient to call @code{gpgme_check_version} before creating the
786 other threads using @acronym{GPGME}@footnote{At least this is true for
787 POSIX threads, as @code{pthread_create} is a function that
788 synchronizes memory with respects to other threads. There are many
789 functions which have this property, a complete list can be found in
790 POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the
791 definition of the term ``Memory Synchronization''. For other thread
792 packages other, more relaxed or more strict rules may apply.}.
795 Any @code{gpgme_data_t} and @code{gpgme_ctx_t} object must only be
796 accessed by one thread at a time. If multiple threads want to deal
797 with the same object, the caller has to make sure that operations on
798 that object are fully synchronized.
801 Only one thread at any time is allowed to call @code{gpgme_wait}. If
802 multiple threads call this function, the caller must make sure that
803 all invocations are fully synchronized. It is safe to start
804 asynchronous operations while a thread is running in gpgme_wait.
807 The function @code{gpgme_strerror} is not thread safe. You have to
808 use @code{gpgme_strerror_r} instead.
812 @node Protocols and Engines
813 @chapter Protocols and Engines
816 @cindex crypto engine
818 @cindex crypto backend
820 @acronym{GPGME} supports several cryptographic protocols, however, it
821 does not implement them. Rather it uses backends (also called
822 engines) which implement the protocol. @acronym{GPGME} uses
823 inter-process communication to pass data back and forth between the
824 application and the backend, but the details of the communication
825 protocol and invocation of the backend is completely hidden by the
826 interface. All complexity is handled by @acronym{GPGME}. Where an
827 exchange of information between the application and the backend is
828 necessary, @acronym{GPGME} provides the necessary callback function
829 hooks and further interfaces.
831 @deftp {Data type} {enum gpgme_protocol_t}
832 @tindex gpgme_protocol_t
833 The @code{gpgme_protocol_t} type specifies the set of possible protocol
834 values that are supported by @acronym{GPGME}. The following protocols
838 @item GPGME_PROTOCOL_OpenPGP
839 This specifies the OpenPGP protocol.
841 @item GPGME_PROTOCOL_CMS
842 This specifies the Cryptographic Message Syntax.
844 @item GPGME_PROTOCOL_ASSUAN
845 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
847 @item GPGME_PROTOCOL_G13
848 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
850 @item GPGME_PROTOCOL_UISERVER
851 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
853 @item GPGME_PROTOCOL_UNKNOWN
854 Reserved for future extension. You may use this to indicate that the
855 used protocol is not known to the application. Currently,
856 @acronym{GPGME} does not accept this value in any operation, though,
857 except for @code{gpgme_get_protocol_name}.
862 @deftypefun {const char *} gpgme_get_protocol_name (@w{gpgme_protocol_t @var{protocol}})
863 The function @code{gpgme_get_protocol_name} returns a statically
864 allocated string describing the protocol @var{protocol}, or
865 @code{NULL} if the protocol number is not valid.
869 * Engine Version Check:: Verifying the engine version.
870 * Engine Information:: Obtaining more information about the engines.
871 * Engine Configuration:: Changing the engine configuration.
872 * OpenPGP:: Support for the OpenPGP protocol.
873 * Cryptographic Message Syntax:: Support for the CMS.
877 @node Engine Version Check
878 @section Engine Version Check
879 @cindex version check, of the engines
881 @deftypefun gpgme_error_t gpgme_engine_check_version (@w{gpgme_protocol_t @var{protocol}})
882 The function @code{gpgme_engine_check_version} verifies that the
883 engine implementing the protocol @var{PROTOCOL} is installed in the
884 expected path and meets the version requirement of @acronym{GPGME}.
886 This function returns the error code @code{GPG_ERR_NO_ERROR} if the
887 engine is available and @code{GPG_ERR_INV_ENGINE} if it is not.
891 @node Engine Information
892 @section Engine Information
893 @cindex engine, information about
895 @deftp {Data type} {gpgme_engine_info_t}
896 @tindex gpgme_protocol_t
897 The @code{gpgme_engine_info_t} type specifies a pointer to a structure
898 describing a crypto engine. The structure contains the following
902 @item gpgme_engine_info_t next
903 This is a pointer to the next engine info structure in the linked
904 list, or @code{NULL} if this is the last element.
906 @item gpgme_protocol_t protocol
907 This is the protocol for which the crypto engine is used. You can
908 convert this to a string with @code{gpgme_get_protocol_name} for
911 @item const char *file_name
912 This is a string holding the file name of the executable of the crypto
913 engine. Currently, it is never @code{NULL}, but using @code{NULL} is
914 reserved for future use, so always check before you use it.
916 @item const char *home_dir
917 This is a string holding the directory name of the crypto engine's
918 configuration directory. If it is @code{NULL}, then the default
921 @item const char *version
922 This is a string containing the version number of the crypto engine.
923 It might be @code{NULL} if the version number can not be determined,
924 for example because the executable doesn't exist or is invalid.
926 @item const char *req_version
927 This is a string containing the minimum required version number of the
928 crypto engine for @acronym{GPGME} to work correctly. This is the
929 version number that @code{gpgme_engine_check_version} verifies
930 against. Currently, it is never @code{NULL}, but using @code{NULL} is
931 reserved for future use, so always check before you use it.
935 @deftypefun gpgme_error_t gpgme_get_engine_info (@w{gpgme_engine_info_t *@var{info}})
936 The function @code{gpgme_get_engine_info} returns a linked list of
937 engine info structures in @var{info}. Each info structure describes
938 the defaults of one configured backend.
940 The memory for the info structures is allocated the first time this
941 function is invoked, and must not be freed by the caller.
943 This function returns the error code @code{GPG_ERR_NO_ERROR} if
944 successful, and a system error if the memory could not be allocated.
947 Here is an example how you can provide more diagnostics if you receive
948 an error message which indicates that the crypto engine is invalid.
956 if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
958 gpgme_engine_info_t info;
959 err = gpgme_get_engine_info (&info);
962 while (info && info->protocol != gpgme_get_protocol (ctx))
965 fprintf (stderr, "GPGME compiled without support for protocol %s",
966 gpgme_get_protocol_name (info->protocol));
967 else if (info->file_name && !info->version)
968 fprintf (stderr, "Engine %s not installed properly",
970 else if (info->file_name && info->version && info->req_version)
971 fprintf (stderr, "Engine %s version %s installed, "
972 "but at least version %s required", info->file_name,
973 info->version, info->req_version);
975 fprintf (stderr, "Unknown problem with engine for protocol %s",
976 gpgme_get_protocol_name (info->protocol));
982 @node Engine Configuration
983 @section Engine Configuration
984 @cindex engine, configuration of
985 @cindex configuration of crypto backend
987 You can change the configuration of a backend engine, and thus change
988 the executable program and configuration directory to be used. You
989 can make these changes the default or set them for some contexts
992 @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}})
993 The function @code{gpgme_set_engine_info} changes the default
994 configuration of the crypto engine implementing the protocol
997 @var{file_name} is the file name of the executable program
998 implementing this protocol, and @var{home_dir} is the directory name
999 of the configuration directory for this crypto engine. If
1000 @var{home_dir} is @code{NULL}, the engine's default will be used.
1002 The new defaults are not applied to already created GPGME contexts.
1004 This function returns the error code @code{GPG_ERR_NO_ERROR} if
1005 successful, or an eror code on failure.
1008 The functions @code{gpgme_ctx_get_engine_info} and
1009 @code{gpgme_ctx_set_engine_info} can be used to change the engine
1010 configuration per context. @xref{Crypto Engine}.
1017 @cindex protocol, GnuPG
1018 @cindex engine, GnuPG
1020 OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard.
1021 This is the first protocol that was supported by @acronym{GPGME}.
1023 The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}.
1026 @node Cryptographic Message Syntax
1027 @section Cryptographic Message Syntax
1029 @cindex cryptographic message syntax
1031 @cindex protocol, CMS
1032 @cindex engine, GpgSM
1034 @cindex protocol, S/MIME
1036 @acronym{CMS} is implemented by GpgSM, the S/MIME implementation for
1039 The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}.
1046 The crypto backends support a variety of algorithms used in public key
1047 cryptography.@footnote{Some engines also provide symmetric only
1048 encryption; see the description of the encryption function on how to use
1049 this.} The following sections list the identifiers used to denote such
1053 * Public Key Algorithms:: A list of all public key algorithms.
1054 * Hash Algorithms:: A list of all hash algorithms.
1058 @node Public Key Algorithms
1059 @section Public Key Algorithms
1060 @cindex algorithms, public key
1061 @cindex public key algorithms
1063 Public key algorithms are used for encryption, decryption, signing and
1064 verification of signatures.
1066 @deftp {Data type} {enum gpgme_pubkey_algo_t}
1067 @tindex gpgme_pubkey_algo_t
1068 The @code{gpgme_pubkey_algo_t} type specifies the set of all public key
1069 algorithms that are supported by @acronym{GPGME}. Possible values
1074 This value indicates the RSA (Rivest, Shamir, Adleman) algorithm.
1076 @item GPGME_PK_RSA_E
1077 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
1078 algorithm for encryption and decryption only.
1080 @item GPGME_PK_RSA_S
1081 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
1082 algorithm for signing and verification only.
1085 This value indicates DSA, the Digital Signature Algorithm.
1088 This value indicates ElGamal.
1090 @item GPGME_PK_ELG_E
1091 This value also indicates ElGamal and is used specifically in GnuPG.
1093 @item GPGME_PK_ELG_E
1094 This value also indicates ElGamal and is used specifically in GnuPG.
1096 @item GPGME_PK_ECDSA
1097 This value indicates ECDSA, the Elliptic Curve Digital Signature
1098 Algorithm as defined by FIPS 186-2.
1101 This value indicates ECDH, the Eliptic Curve Diffie-Hellmann encryption
1102 algorithm as defined by the ECC in OpenPGP draft.
1107 @deftypefun {const char *} gpgme_pubkey_algo_name (@w{gpgme_pubkey_algo_t @var{algo}})
1108 The function @code{gpgme_pubkey_algo_name} returns a pointer to a
1109 statically allocated string containing a description of the public key
1110 algorithm @var{algo}. This string can be used to output the name of
1111 the public key algorithm to the user.
1113 If @var{algo} is not a valid public key algorithm, @code{NULL} is
1118 @node Hash Algorithms
1119 @section Hash Algorithms
1120 @cindex algorithms, hash
1121 @cindex algorithms, message digest
1122 @cindex hash algorithms
1123 @cindex message digest algorithms
1125 Hash (message digest) algorithms are used to compress a long message
1126 to make it suitable for public key cryptography.
1128 @deftp {Data type} {enum gpgme_hash_algo_t}
1129 @tindex gpgme_hash_algo_t
1130 The @code{gpgme_hash_algo_t} type specifies the set of all hash algorithms
1131 that are supported by @acronym{GPGME}. Possible values are:
1136 @item GPGME_MD_RMD160
1138 @item GPGME_MD_TIGER
1139 @item GPGME_MD_HAVAL
1140 @item GPGME_MD_SHA256
1141 @item GPGME_MD_SHA384
1142 @item GPGME_MD_SHA512
1144 @item GPGME_MD_CRC32
1145 @item GPGME_MD_CRC32_RFC1510
1146 @item GPGME_MD_CRC24_RFC2440
1150 @deftypefun {const char *} gpgme_hash_algo_name (@w{gpgme_hash_algo_t @var{algo}})
1151 The function @code{gpgme_hash_algo_name} returns a pointer to a
1152 statically allocated string containing a description of the hash
1153 algorithm @var{algo}. This string can be used to output the name of
1154 the hash algorithm to the user.
1156 If @var{algo} is not a valid hash algorithm, @code{NULL} is returned.
1160 @node Error Handling
1161 @chapter Error Handling
1162 @cindex error handling
1164 Many functions in @acronym{GPGME} can return an error if they fail.
1165 For this reason, the application should always catch the error
1166 condition and take appropriate measures, for example by releasing the
1167 resources and passing the error up to the caller, or by displaying a
1168 descriptive message to the user and cancelling the operation.
1170 Some error values do not indicate a system error or an error in the
1171 operation, but the result of an operation that failed properly. For
1172 example, if you try to decrypt a tempered message, the decryption will
1173 fail. Another error value actually means that the end of a data
1174 buffer or list has been reached. The following descriptions explain
1175 for many error codes what they mean usually. Some error values have
1176 specific meanings if returned by a certain functions. Such cases are
1177 described in the documentation of those functions.
1179 @acronym{GPGME} uses the @code{libgpg-error} library. This allows to
1180 share the error codes with other components of the GnuPG system, and
1181 thus pass error values transparently from the crypto engine, or some
1182 helper application of the crypto engine, to the user. This way no
1183 information is lost. As a consequence, @acronym{GPGME} does not use
1184 its own identifiers for error codes, but uses those provided by
1185 @code{libgpg-error}. They usually start with @code{GPG_ERR_}.
1187 However, @acronym{GPGME} does provide aliases for the functions
1188 defined in libgpg-error, which might be preferred for name space
1192 * Error Values:: The error value and what it means.
1193 * Error Sources:: A list of important error sources.
1194 * Error Codes:: A list of important error codes.
1195 * Error Strings:: How to get a descriptive string from a value.
1200 @section Error Values
1201 @cindex error values
1203 @cindex error sources
1205 @deftp {Data type} {gpgme_err_code_t}
1206 The @code{gpgme_err_code_t} type is an alias for the @code{libgpg-error}
1207 type @code{gpg_err_code_t}. The error code indicates the type of an
1208 error, or the reason why an operation failed.
1210 A list of important error codes can be found in the next section.
1213 @deftp {Data type} {gpgme_err_source_t}
1214 The @code{gpgme_err_source_t} type is an alias for the
1215 @code{libgpg-error} type @code{gpg_err_source_t}. The error source
1216 has not a precisely defined meaning. Sometimes it is the place where
1217 the error happened, sometimes it is the place where an error was
1218 encoded into an error value. Usually the error source will give an
1219 indication to where to look for the problem. This is not always true,
1220 but it is attempted to achieve this goal.
1222 A list of important error sources can be found in the next section.
1225 @deftp {Data type} {gpgme_error_t}
1226 The @code{gpgme_error_t} type is an alias for the @code{libgpg-error}
1227 type @code{gpg_error_t}. An error value like this has always two
1228 components, an error code and an error source. Both together form the
1231 Thus, the error value can not be directly compared against an error
1232 code, but the accessor functions described below must be used.
1233 However, it is guaranteed that only 0 is used to indicate success
1234 (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of
1235 the error value are set to 0, too.
1237 Note that in @acronym{GPGME}, the error source is used purely for
1238 diagnostical purposes. Only the error code should be checked to test
1239 for a certain outcome of a function. The manual only documents the
1240 error code part of an error value. The error source is left
1241 unspecified and might be anything.
1244 @deftypefun {static inline gpgme_err_code_t} gpgme_err_code (@w{gpgme_error_t @var{err}})
1245 The static inline function @code{gpgme_err_code} returns the
1246 @code{gpgme_err_code_t} component of the error value @var{err}. This
1247 function must be used to extract the error code from an error value in
1248 order to compare it with the @code{GPG_ERR_*} error code macros.
1251 @deftypefun {static inline gpgme_err_source_t} gpgme_err_source (@w{gpgme_error_t @var{err}})
1252 The static inline function @code{gpgme_err_source} returns the
1253 @code{gpgme_err_source_t} component of the error value @var{err}. This
1254 function must be used to extract the error source from an error value in
1255 order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros.
1258 @deftypefun {static inline gpgme_error_t} gpgme_err_make (@w{gpgme_err_source_t @var{source}}, @w{gpgme_err_code_t @var{code}})
1259 The static inline function @code{gpgme_err_make} returns the error
1260 value consisting of the error source @var{source} and the error code
1263 This function can be used in callback functions to construct an error
1264 value to return it to the library.
1267 @deftypefun {static inline gpgme_error_t} gpgme_error (@w{gpgme_err_code_t @var{code}})
1268 The static inline function @code{gpgme_error} returns the error value
1269 consisting of the default error source and the error code @var{code}.
1271 For @acronym{GPGME} applications, the default error source is
1272 @code{GPG_ERR_SOURCE_USER_1}. You can define
1273 @code{GPGME_ERR_SOURCE_DEFAULT} before including @file{gpgme.h} to
1274 change this default.
1276 This function can be used in callback functions to construct an error
1277 value to return it to the library.
1280 The @code{libgpg-error} library provides error codes for all system
1281 error numbers it knows about. If @var{err} is an unknown error
1282 number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The
1283 following functions can be used to construct error values from system
1286 @deftypefun {gpgme_error_t} gpgme_err_make_from_errno (@w{gpgme_err_source_t @var{source}}, @w{int @var{err}})
1287 The function @code{gpgme_err_make_from_errno} is like
1288 @code{gpgme_err_make}, but it takes a system error like @code{errno}
1289 instead of a @code{gpgme_err_code_t} error code.
1292 @deftypefun {gpgme_error_t} gpgme_error_from_errno (@w{int @var{err}})
1293 The function @code{gpgme_error_from_errno} is like @code{gpgme_error},
1294 but it takes a system error like @code{errno} instead of a
1295 @code{gpgme_err_code_t} error code.
1298 Sometimes you might want to map system error numbers to error codes
1299 directly, or map an error code representing a system error back to the
1300 system error number. The following functions can be used to do that.
1302 @deftypefun {gpgme_err_code_t} gpgme_err_code_from_errno (@w{int @var{err}})
1303 The function @code{gpgme_err_code_from_errno} returns the error code
1304 for the system error @var{err}. If @var{err} is not a known system
1305 error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}.
1308 @deftypefun {int} gpgme_err_code_to_errno (@w{gpgme_err_code_t @var{err}})
1309 The function @code{gpgme_err_code_to_errno} returns the system error
1310 for the error code @var{err}. If @var{err} is not an error code
1311 representing a system error, or if this system error is not defined on
1312 this system, the function returns @code{0}.
1317 @section Error Sources
1318 @cindex error codes, list of
1320 The library @code{libgpg-error} defines an error source for every
1321 component of the GnuPG system. The error source part of an error
1322 value is not well defined. As such it is mainly useful to improve the
1323 diagnostic error message for the user.
1325 If the error code part of an error value is @code{0}, the whole error
1326 value will be @code{0}. In this case the error source part is of
1327 course @code{GPG_ERR_SOURCE_UNKNOWN}.
1329 The list of error sources that might occur in applications using
1333 @item GPG_ERR_SOURCE_UNKNOWN
1334 The error source is not known. The value of this error source is
1337 @item GPG_ERR_SOURCE_GPGME
1338 The error source is @acronym{GPGME} itself. This is the default for
1339 errors that occur in the @acronym{GPGME} library.
1341 @item GPG_ERR_SOURCE_GPG
1342 The error source is GnuPG, which is the crypto engine used for the
1345 @item GPG_ERR_SOURCE_GPGSM
1346 The error source is GPGSM, which is the crypto engine used for the
1349 @item GPG_ERR_SOURCE_GCRYPT
1350 The error source is @code{libgcrypt}, which is used by crypto engines
1351 to perform cryptographic operations.
1353 @item GPG_ERR_SOURCE_GPGAGENT
1354 The error source is @command{gpg-agent}, which is used by crypto
1355 engines to perform operations with the secret key.
1357 @item GPG_ERR_SOURCE_PINENTRY
1358 The error source is @command{pinentry}, which is used by
1359 @command{gpg-agent} to query the passphrase to unlock a secret key.
1361 @item GPG_ERR_SOURCE_SCD
1362 The error source is the SmartCard Daemon, which is used by
1363 @command{gpg-agent} to delegate operations with the secret key to a
1366 @item GPG_ERR_SOURCE_KEYBOX
1367 The error source is @code{libkbx}, a library used by the crypto
1368 engines to manage local keyrings.
1370 @item GPG_ERR_SOURCE_USER_1
1371 @item GPG_ERR_SOURCE_USER_2
1372 @item GPG_ERR_SOURCE_USER_3
1373 @item GPG_ERR_SOURCE_USER_4
1374 These error sources are not used by any GnuPG component and can be
1375 used by other software. For example, applications using
1376 @acronym{GPGME} can use them to mark error values coming from callback
1377 handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors
1378 created with @code{gpgme_error} and @code{gpgme_error_from_errno},
1379 unless you define @code{GPGME_ERR_SOURCE_DEFAULT} before including
1385 @section Error Codes
1386 @cindex error codes, list of
1388 The library @code{libgpg-error} defines many error values. Most of
1389 them are not used by @code{GPGME} directly, but might be returned by
1390 @acronym{GPGME} because it received them from the crypto engine. The
1391 below list only includes such error codes that have a specific meaning
1392 in @code{GPGME}, or which are so common that you should know about
1397 This value indicates the end of a list, buffer or file.
1399 @item GPG_ERR_NO_ERROR
1400 This value indicates success. The value of this error code is
1401 @code{0}. Also, it is guaranteed that an error value made from the
1402 error code @code{0} will be @code{0} itself (as a whole). This means
1403 that the error source information is lost for this error code,
1404 however, as this error code indicates that no error occured, this is
1405 generally not a problem.
1407 @item GPG_ERR_GENERAL
1408 This value means that something went wrong, but either there is not
1409 enough information about the problem to return a more useful error
1410 value, or there is no separate error value for this type of problem.
1412 @item GPG_ERR_ENOMEM
1413 This value means that an out-of-memory condition occurred.
1416 System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
1419 @item GPG_ERR_INV_VALUE
1420 This value means that some user provided data was out of range. This
1421 can also refer to objects. For example, if an empty
1422 @code{gpgme_data_t} object was expected, but one containing data was
1423 provided, this error value is returned.
1425 @item GPG_ERR_UNUSABLE_PUBKEY
1426 This value means that some recipients for a message were invalid.
1428 @item GPG_ERR_UNUSABLE_SECKEY
1429 This value means that some signers were invalid.
1431 @item GPG_ERR_NO_DATA
1432 This value means that a @code{gpgme_data_t} object which was expected
1433 to have content was found empty.
1435 @item GPG_ERR_CONFLICT
1436 This value means that a conflict of some sort occurred.
1438 @item GPG_ERR_NOT_IMPLEMENTED
1439 This value indicates that the specific function (or operation) is not
1440 implemented. This error should never happen. It can only occur if
1441 you use certain values or configuration options which do not work,
1442 but for which we think that they should work at some later time.
1444 @item GPG_ERR_DECRYPT_FAILED
1445 This value indicates that a decryption operation was unsuccessful.
1447 @item GPG_ERR_BAD_PASSPHRASE
1448 This value means that the user did not provide a correct passphrase
1451 @item GPG_ERR_CANCELED
1452 This value means that the operation was canceled.
1454 @item GPG_ERR_INV_ENGINE
1455 This value means that the engine that implements the desired protocol
1456 is currently not available. This can either be because the sources
1457 were configured to exclude support for this engine, or because the
1458 engine is not installed properly.
1460 @item GPG_ERR_AMBIGUOUS_NAME
1461 This value indicates that a user ID or other specifier did not specify
1464 @item GPG_ERR_WRONG_KEY_USAGE
1465 This value indicates that a key is not used appropriately.
1467 @item GPG_ERR_CERT_REVOKED
1468 This value indicates that a key signature was revoced.
1470 @item GPG_ERR_CERT_EXPIRED
1471 This value indicates that a key signature expired.
1473 @item GPG_ERR_NO_CRL_KNOWN
1474 This value indicates that no certificate revocation list is known for
1477 @item GPG_ERR_NO_POLICY_MATCH
1478 This value indicates that a policy issue occured.
1480 @item GPG_ERR_NO_SECKEY
1481 This value indicates that no secret key for the user ID is available.
1483 @item GPG_ERR_MISSING_CERT
1484 This value indicates that a key could not be imported because the
1485 issuer certificate is missing.
1487 @item GPG_ERR_BAD_CERT_CHAIN
1488 This value indicates that a key could not be imported because its
1489 certificate chain is not good, for example it could be too long.
1491 @item GPG_ERR_UNSUPPORTED_ALGORITHM
1492 This value means a verification failed because the cryptographic
1493 algorithm is not supported by the crypto backend.
1495 @item GPG_ERR_BAD_SIGNATURE
1496 This value means a verification failed because the signature is bad.
1498 @item GPG_ERR_NO_PUBKEY
1499 This value means a verification failed because the public key is not
1502 @item GPG_ERR_USER_1
1503 @item GPG_ERR_USER_2
1505 @item GPG_ERR_USER_16
1506 These error codes are not used by any GnuPG component and can be
1507 freely used by other software. Applications using @acronym{GPGME}
1508 might use them to mark specific errors returned by callback handlers
1509 if no suitable error codes (including the system errors) for
1510 these errors exist already.
1515 @section Error Strings
1516 @cindex error values, printing of
1517 @cindex error codes, printing of
1518 @cindex error sources, printing of
1519 @cindex error strings
1521 @deftypefun {const char *} gpgme_strerror (@w{gpgme_error_t @var{err}})
1522 The function @code{gpgme_strerror} returns a pointer to a statically
1523 allocated string containing a description of the error code contained
1524 in the error value @var{err}. This string can be used to output a
1525 diagnostic message to the user.
1527 This function is not thread safe. Use @code{gpgme_strerror_r} in
1528 multi-threaded programs.
1532 @deftypefun {int} gpgme_strerror_r (@w{gpgme_error_t @var{err}}, @w{char *@var{buf}}, @w{size_t @var{buflen}})
1533 The function @code{gpgme_strerror_r} returns the error string for
1534 @var{err} in the user-supplied buffer @var{buf} of size @var{buflen}.
1535 This function is, in contrast to @code{gpgme_strerror}, thread-safe if
1536 a thread-safe @code{strerror_r} function is provided by the system.
1537 If the function succeeds, 0 is returned and @var{buf} contains the
1538 string describing the error. If the buffer was not large enough,
1539 ERANGE is returned and @var{buf} contains as much of the beginning of
1540 the error string as fits into the buffer.
1544 @deftypefun {const char *} gpgme_strsource (@w{gpgme_error_t @var{err}})
1545 The function @code{gpgme_strerror} returns a pointer to a statically
1546 allocated string containing a description of the error source
1547 contained in the error value @var{err}. This string can be used to
1548 output a diagnostic message to the user.
1551 The following example illustrates the use of @code{gpgme_strerror}:
1555 gpgme_error_t err = gpgme_new (&ctx);
1558 fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
1559 argv[0], gpgme_strsource (err), gpgme_strerror (err));
1565 @node Exchanging Data
1566 @chapter Exchanging Data
1567 @cindex data, exchanging
1569 A lot of data has to be exchanged between the user and the crypto
1570 engine, like plaintext messages, ciphertext, signatures and
1571 information about the keys. The technical details about exchanging
1572 the data information are completely abstracted by @acronym{GPGME}.
1573 The user provides and receives the data via @code{gpgme_data_t} objects,
1574 regardless of the communication protocol between @acronym{GPGME} and
1575 the crypto engine in use.
1577 @deftp {Data type} {gpgme_data_t}
1578 The @code{gpgme_data_t} type is a handle for a container for generic
1579 data, which is used by @acronym{GPGME} to exchange data with the user.
1582 @code{gpgme_data_t} objects do not provide notifications on events.
1583 It is assumed that read and write operations are blocking until data
1584 is available. If this is undesirable, the application must ensure
1585 that all GPGME data operations always have data available, for example
1586 by using memory buffers or files rather than pipes or sockets. This
1587 might be relevant, for example, if the external event loop mechanism
1590 @deftp {Data type} {gpgme_off_t}
1591 On POSIX platforms the @code{gpgme_off_t} type is an alias for
1592 @code{off_t}; it may be used interchangeable. On Windows platforms
1593 @code{gpgme_off_t} is defined as a long (i.e. 32 bit) for 32 bit
1594 Windows and as a 64 bit signed integer for 64 bit Windows.
1597 @deftp {Data type} {gpgme_ssize_t}
1598 The @code{gpgme_ssize_t} type is an alias for @code{ssize_t}. It has
1599 only been introduced to overcome portability problems pertaining to
1600 the declaration of @code{ssize_t} by different toolchains.
1605 * Creating Data Buffers:: Creating new data buffers.
1606 * Destroying Data Buffers:: Releasing data buffers.
1607 * Manipulating Data Buffers:: Operations on data buffers.
1611 @node Creating Data Buffers
1612 @section Creating Data Buffers
1613 @cindex data buffer, creation
1615 Data objects can be based on memory, files, or callback functions
1616 provided by the user. Not all operations are supported by all
1621 * Memory Based Data Buffers:: Creating memory based data buffers.
1622 * File Based Data Buffers:: Creating file based data buffers.
1623 * Callback Based Data Buffers:: Creating callback based data buffers.
1627 @node Memory Based Data Buffers
1628 @subsection Memory Based Data Buffers
1630 Memory based data objects store all data in allocated memory. This is
1631 convenient, but only practical for an amount of data that is a
1632 fraction of the available physical memory. The data has to be copied
1633 from its source and to its destination, which can often be avoided by
1634 using one of the other data object
1636 @deftypefun gpgme_error_t gpgme_data_new (@w{gpgme_data_t *@var{dh}})
1637 The function @code{gpgme_data_new} creates a new @code{gpgme_data_t}
1638 object and returns a handle for it in @var{dh}. The data object is
1639 memory based and initially empty.
1641 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1642 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1643 @var{dh} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1644 enough memory is available.
1647 @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}})
1648 The function @code{gpgme_data_new_from_mem} creates a new
1649 @code{gpgme_data_t} object and fills it with @var{size} bytes starting
1652 If @var{copy} is not zero, a private copy of the data is made. If
1653 @var{copy} is zero, the data is taken from the specified buffer as
1654 needed, and the user has to ensure that the buffer remains valid for
1655 the whole life span of the data object.
1657 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1658 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1659 @var{dh} or @var{buffer} is not a valid pointer, and
1660 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1663 @deftypefun gpgme_error_t gpgme_data_new_from_file (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}})
1664 The function @code{gpgme_data_new_from_file} creates a new
1665 @code{gpgme_data_t} object and fills it with the content of the file
1668 If @var{copy} is not zero, the whole file is read in at initialization
1669 time and the file is not used anymore after that. This is the only
1670 mode supported currently. Later, a value of zero for @var{copy} might
1671 cause all reads to be delayed until the data is needed, but this is
1672 not yet implemented.
1674 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1675 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1676 @var{dh} or @var{filename} is not a valid pointer,
1677 @code{GPG_ERR_NOT_IMPLEMENTED} if @var{code} is zero, and
1678 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1681 @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}})
1682 The function @code{gpgme_data_new_from_filepart} creates a new
1683 @code{gpgme_data_t} object and fills it with a part of the file specified
1684 by @var{filename} or @var{fp}.
1686 Exactly one of @var{filename} and @var{fp} must be non-zero, the other
1687 must be zero. The argument that is not zero specifies the file from
1688 which @var{length} bytes are read into the data object, starting from
1691 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1692 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1693 @var{dh} and exactly one of @var{filename} and @var{fp} is not a valid
1694 pointer, and @code{GPG_ERR_ENOMEM} if not enough memory is available.
1698 @node File Based Data Buffers
1699 @subsection File Based Data Buffers
1701 File based data objects operate directly on file descriptors or
1702 streams. Only a small amount of data is stored in core at any time,
1703 so the size of the data objects is not limited by @acronym{GPGME}.
1705 @deftypefun gpgme_error_t gpgme_data_new_from_fd (@w{gpgme_data_t *@var{dh}}, @w{int @var{fd}})
1706 The function @code{gpgme_data_new_from_fd} creates a new
1707 @code{gpgme_data_t} object and uses the file descriptor @var{fd} to read
1708 from (if used as an input data object) and write to (if used as an
1709 output data object).
1711 When using the data object as an input buffer, the function might read
1712 a bit more from the file descriptor than is actually needed by the
1713 crypto engine in the desired operation because of internal buffering.
1715 Note that GPGME assumes that the file descriptor is set to blocking
1716 mode. Errors during I/O operations, except for EINTR, are usually
1717 fatal for crypto operations.
1719 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1720 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1721 enough memory is available.
1724 @deftypefun gpgme_error_t gpgme_data_new_from_stream (@w{gpgme_data_t *@var{dh}}, @w{FILE *@var{stream}})
1725 The function @code{gpgme_data_new_from_stream} creates a new
1726 @code{gpgme_data_t} object and uses the I/O stream @var{stream} to read
1727 from (if used as an input data object) and write to (if used as an
1728 output data object).
1730 When using the data object as an input buffer, the function might read
1731 a bit more from the stream than is actually needed by the crypto
1732 engine in the desired operation because of internal buffering.
1734 Note that GPGME assumes that the stream is in blocking mode. Errors
1735 during I/O operations, except for EINTR, are usually fatal for crypto
1738 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1739 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1740 enough memory is available.
1744 @node Callback Based Data Buffers
1745 @subsection Callback Based Data Buffers
1747 If neither memory nor file based data objects are a good fit for your
1748 application, you can implement the functions a data object provides
1749 yourself and create a data object from these callback functions.
1751 @deftp {Data type} {ssize_t (*gpgme_data_read_cb_t) (@w{void *@var{handle}}, @w{void @var{*buffer}}, @w{size_t @var{size}})}
1752 @tindex gpgme_data_read_cb_t
1753 The @code{gpgme_data_read_cb_t} type is the type of functions which
1754 @acronym{GPGME} calls if it wants to read data from a user-implemented
1755 data object. The function should read up to @var{size} bytes from the
1756 current read position into the space starting at @var{buffer}. The
1757 @var{handle} is provided by the user at data object creation time.
1759 Note that GPGME assumes that the read blocks until data is available.
1760 Errors during I/O operations, except for EINTR, are usually fatal for
1763 The function should return the number of bytes read, 0 on EOF, and -1
1764 on error. If an error occurs, @var{errno} should be set to describe
1765 the type of the error.
1768 @deftp {Data type} {ssize_t (*gpgme_data_write_cb_t) (@w{void *@var{handle}}, @w{const void @var{*buffer}}, @w{size_t @var{size}})}
1769 @tindex gpgme_data_write_cb_t
1770 The @code{gpgme_data_write_cb_t} type is the type of functions which
1771 @acronym{GPGME} calls if it wants to write data to a user-implemented
1772 data object. The function should write up to @var{size} bytes to the
1773 current write position from the space starting at @var{buffer}. The
1774 @var{handle} is provided by the user at data object creation time.
1776 Note that GPGME assumes that the write blocks until data is available.
1777 Errors during I/O operations, except for EINTR, are usually fatal for
1780 The function should return the number of bytes written, and -1 on
1781 error. If an error occurs, @var{errno} should be set to describe the
1785 @deftp {Data type} {off_t (*gpgme_data_seek_cb_t) (@w{void *@var{handle}}, @w{off_t @var{offset}}, @w{int @var{whence}})}
1786 @tindex gpgme_data_seek_cb_t
1787 The @code{gpgme_data_seek_cb_t} type is the type of functions which
1788 @acronym{GPGME} calls if it wants to change the current read/write
1789 position in a user-implemented data object, just like the @code{lseek}
1792 The function should return the new read/write position, and -1 on
1793 error. If an error occurs, @var{errno} should be set to describe the
1797 @deftp {Data type} {void (*gpgme_data_release_cb_t) (@w{void *@var{handle}})}
1798 @tindex gpgme_data_release_cb_t
1799 The @code{gpgme_data_release_cb_t} type is the type of functions which
1800 @acronym{GPGME} calls if it wants to destroy a user-implemented data
1801 object. The @var{handle} is provided by the user at data object
1805 @deftp {Data type} {struct gpgme_data_cbs}
1806 This structure is used to store the data callback interface functions
1807 described above. It has the following members:
1810 @item gpgme_data_read_cb_t read
1811 This is the function called by @acronym{GPGME} to read data from the
1812 data object. It is only required for input data object.
1814 @item gpgme_data_write_cb_t write
1815 This is the function called by @acronym{GPGME} to write data to the
1816 data object. It is only required for output data object.
1818 @item gpgme_data_seek_cb_t seek
1819 This is the function called by @acronym{GPGME} to change the current
1820 read/write pointer in the data object (if available). It is optional.
1822 @item gpgme_data_release_cb_t release
1823 This is the function called by @acronym{GPGME} to release a data
1824 object. It is optional.
1828 @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}})
1829 The function @code{gpgme_data_new_from_cbs} creates a new
1830 @code{gpgme_data_t} object and uses the user-provided callback functions
1831 to operate on the data object.
1833 The handle @var{handle} is passed as first argument to the callback
1834 functions. This can be used to identify this data object.
1836 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1837 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1838 enough memory is available.
1841 The following interface is deprecated and only provided for backward
1842 compatibility. Don't use it. It will be removed in a future version
1845 @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}})
1846 The function @code{gpgme_data_new_with_read_cb} creates a new
1847 @code{gpgme_data_t} object and uses the callback function @var{readfunc}
1848 to retrieve the data on demand. As the callback function can supply
1849 the data in any way it wants, this is the most flexible data type
1850 @acronym{GPGME} provides. However, it can not be used to write data.
1852 The callback function receives @var{hook_value} as its first argument
1853 whenever it is invoked. It should return up to @var{count} bytes in
1854 @var{buffer}, and return the number of bytes actually read in
1855 @var{nread}. It may return @code{0} in @var{nread} if no data is
1856 currently available. To indicate @code{EOF} the function should
1857 return with an error code of @code{-1} and set @var{nread} to
1858 @code{0}. The callback function may support to reset its internal
1859 read pointer if it is invoked with @var{buffer} and @var{nread} being
1860 @code{NULL} and @var{count} being @code{0}.
1862 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1863 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1864 @var{dh} or @var{readfunc} is not a valid pointer, and
1865 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1869 @node Destroying Data Buffers
1870 @section Destroying Data Buffers
1871 @cindex data buffer, destruction
1873 @deftypefun void gpgme_data_release (@w{gpgme_data_t @var{dh}})
1874 The function @code{gpgme_data_release} destroys the data object with
1875 the handle @var{dh}. It releases all associated resources that were
1876 not provided by the user in the first place.
1879 @deftypefun {char *} gpgme_data_release_and_get_mem (@w{gpgme_data_t @var{dh}}, @w{size_t *@var{length}})
1880 The function @code{gpgme_data_release_and_get_mem} is like
1881 @code{gpgme_data_release}, except that it returns the data buffer and
1882 its length that was provided by the object.
1884 The user has to release the buffer with @code{gpgme_free}. In case
1885 the user provided the data buffer in non-copy mode, a copy will be
1886 made for this purpose.
1888 In case an error returns, or there is no suitable data buffer that can
1889 be returned to the user, the function will return @code{NULL}. In any
1890 case, the data object @var{dh} is destroyed.
1894 @deftypefun void gpgme_free (@w{void *@var{buffer}})
1895 The function @code{gpgme_free} releases the memory returned by
1896 @code{gpgme_data_release_and_get_mem}. It should be used instead of
1897 the system libraries @code{free} function in case different allocators
1898 are used in a single program.
1902 @node Manipulating Data Buffers
1903 @section Manipulating Data Buffers
1904 @cindex data buffer, manipulation
1906 Data buffers contain data and meta-data. The following operations can
1907 be used to manipulate both.
1911 * Data Buffer I/O Operations:: I/O operations on data buffers.
1912 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
1913 * Data Buffer Convenience:: Convenience fucntion for data buffers.
1917 @node Data Buffer I/O Operations
1918 @subsection Data Buffer I/O Operations
1919 @cindex data buffer, I/O operations
1920 @cindex data buffer, read
1921 @cindex data buffer, write
1922 @cindex data buffer, seek
1924 @deftypefun ssize_t gpgme_data_read (@w{gpgme_data_t @var{dh}}, @w{void *@var{buffer}}, @w{size_t @var{length}})
1925 The function @code{gpgme_data_read} reads up to @var{length} bytes
1926 from the data object with the handle @var{dh} into the space starting
1929 If no error occurs, the actual amount read is returned. If the end of
1930 the data object is reached, the function returns 0.
1932 In all other cases, the function returns -1 and sets @var{errno}.
1935 @deftypefun ssize_t gpgme_data_write (@w{gpgme_data_t @var{dh}}, @w{const void *@var{buffer}}, @w{size_t @var{size}})
1936 The function @code{gpgme_data_write} writes up to @var{size} bytes
1937 starting from @var{buffer} into the data object with the handle
1938 @var{dh} at the current write position.
1940 The function returns the number of bytes actually written, or -1 if an
1941 error occurs. If an error occurs, @var{errno} is set.
1944 @deftypefun off_t gpgme_data_seek (@w{gpgme_data_t @var{dh}}, @w{off_t @var{offset}}, @w{int @var{whence}})
1945 The function @code{gpgme_data_seek} changes the current read/write
1948 The @var{whence} argument specifies how the @var{offset} should be
1949 interpreted. It must be one of the following symbolic constants:
1953 Specifies that @var{offset} is a count of characters from the
1954 beginning of the data object.
1957 Specifies that @var{offset} is a count of characters from the current
1958 file position. This count may be positive or negative.
1961 Specifies that @var{offset} is a count of characters from the end of
1962 the data object. A negative count specifies a position within the
1963 current extent of the data object; a positive count specifies a
1964 position past the current end. If you set the position past the
1965 current end, and actually write data, you will extend the data object
1966 with zeros up to that position.
1969 If successful, the function returns the resulting file position,
1970 measured in bytes from the beginning of the data object. You can use
1971 this feature together with @code{SEEK_CUR} to read the current
1972 read/write position.
1974 If the function fails, -1 is returned and @var{errno} is set.
1977 The following function is deprecated and should not be used. It will
1978 be removed in a future version of @acronym{GPGME}.
1980 @deftypefun gpgme_error_t gpgme_data_rewind (@w{gpgme_data_t @var{dh}})
1981 The function @code{gpgme_data_rewind} is equivalent to:
1984 return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
1985 ? gpgme_error_from_errno (errno) : 0;
1992 @node Data Buffer Meta-Data
1993 @subsection Data Buffer Meta-Data
1994 @cindex data buffer, meta-data
1995 @cindex data buffer, file name
1996 @cindex data buffer, encoding
1998 @deftypefun {char *} gpgme_data_get_file_name (@w{gpgme_data_t @var{dh}})
1999 The function @code{gpgme_data_get_file_name} returns a pointer to a
2000 string containing the file name associated with the data object. The
2001 file name will be stored in the output when encrypting or signing the
2002 data and will be returned to the user when decrypting or verifying the
2005 If no error occurs, the string containing the file name is returned.
2006 Otherwise, @code{NULL} will be returned.
2010 @deftypefun gpgme_error_t gpgme_data_set_file_name (@w{gpgme_data_t @var{dh}}, @w{const char *@var{file_name}})
2011 The function @code{gpgme_data_set_file_name} sets the file name
2012 associated with the data object. The file name will be stored in the
2013 output when encrypting or signing the data and will be returned to the
2014 user when decrypting or verifying the output data.
2016 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2017 @var{dh} is not a valid pointer and @code{GPG_ERR_ENOMEM} if not
2018 enough memory is available.
2022 @deftp {Data type} {enum gpgme_data_encoding_t}
2023 @tindex gpgme_data_encoding_t
2024 The @code{gpgme_data_encoding_t} type specifies the encoding of a
2025 @code{gpgme_data_t} object. For input data objects, the encoding is
2026 useful to give the backend a hint on the type of data. For output
2027 data objects, the encoding can specify the output data format on
2028 certain operations. Please note that not all backends support all
2029 encodings on all operations. The following data types are available:
2032 @item GPGME_DATA_ENCODING_NONE
2033 This specifies that the encoding is not known. This is the default
2034 for a new data object. The backend will try its best to detect the
2035 encoding automatically.
2037 @item GPGME_DATA_ENCODING_BINARY
2038 This specifies that the data is encoding in binary form; i.e. there is
2039 no special encoding.
2041 @item GPGME_DATA_ENCODING_BASE64
2042 This specifies that the data is encoded using the Base-64 encoding
2043 scheme as used by @acronym{MIME} and other protocols.
2045 @item GPGME_DATA_ENCODING_ARMOR
2046 This specifies that the data is encoded in an armored form as used by
2049 @item GPGME_DATA_ENCODING_URL
2050 The data is a list of linefeed delimited URLs. This is only useful with
2051 @code{gpgme_op_import}.
2053 @item GPGME_DATA_ENCODING_URL0
2054 The data is a list of binary zero delimited URLs. This is only useful
2055 with @code{gpgme_op_import}.
2057 @item GPGME_DATA_ENCODING_URLESC
2058 The data is a list of linefeed delimited URLs with all control and space
2059 characters percent escaped. This mode is is not yet implemented.
2064 @deftypefun gpgme_data_encoding_t gpgme_data_get_encoding (@w{gpgme_data_t @var{dh}})
2065 The function @code{gpgme_data_get_encoding} returns the encoding of
2066 the data object with the handle @var{dh}. If @var{dh} is not a valid
2067 pointer (e.g. @code{NULL}) @code{GPGME_DATA_ENCODING_NONE} is
2071 @deftypefun gpgme_error_t gpgme_data_set_encoding (@w{gpgme_data_t @var{dh}, gpgme_data_encoding_t @var{enc}})
2072 The function @code{gpgme_data_set_encoding} changes the encoding of
2073 the data object with the handle @var{dh} to @var{enc}.
2076 @node Data Buffer Convenience
2077 @subsection Data Buffer Convenience Functions
2078 @cindex data buffer, convenience
2079 @cindex type of data
2082 @deftp {Data type} {enum gpgme_data_type_t}
2083 @tindex gpgme_data_type_t
2084 The @code{gpgme_data_type_t} type is used to return the detected type
2085 of the content of a data buffer.
2089 @item GPGME_DATA_TYPE_INVALID
2090 This is returned by @code{gpgme_data_identify} if it was not possible
2091 to identify the data. Reasons for this might be a non-seekable stream
2092 or a memory problem. The value is 0.
2093 @item GPGME_DATA_TYPE_UNKNOWN
2094 The type of the data is not known.
2095 @item GPGME_DATA_TYPE_PGP_SIGNED
2096 The data is an OpenPGP signed message. This may be a binary
2097 signature, a detached one or a cleartext signature.
2098 @item GPGME_DATA_TYPE_PGP_OTHER
2099 This is a generic OpenPGP message. In most cases this will be
2101 @item GPGME_DATA_TYPE_PGP_KEY
2102 This is an OpenPGP key (private or public).
2103 @item GPGME_DATA_TYPE_CMS_SIGNED
2104 This is a CMS signed message.
2105 @item GPGME_DATA_TYPE_CMS_ENCRYPTED
2106 This is a CMS encrypted (enveloped data) message.
2107 @item GPGME_DATA_TYPE_CMS_OTHER
2108 This is used for other CMS message types.
2109 @item GPGME_DATA_TYPE_X509_CERT
2110 The data is a X.509 certificate
2111 @item GPGME_DATA_TYPE_PKCS12
2112 The data is a PKCS#12 message. This is commonly used to exchange
2113 private keys for X.509.
2116 @deftypefun gpgme_data_type_t gpgme_data_identify (@w{gpgme_data_t @var{dh}})
2117 The function @code{gpgme_data_identify} returns the type of the data
2118 with the handle @var{dh}. If it is not possible to perform the
2119 identification, the function returns zero
2120 (@code{GPGME_DATA_TYPE_INVALID}). Note that depending on how the data
2121 object has been created the identification may not be possible or the
2122 data object may change its internal state (file pointer moved). For
2123 file or memory based data object, the state should not change.
2134 All cryptographic operations in @acronym{GPGME} are performed within a
2135 context, which contains the internal state of the operation as well as
2136 configuration parameters. By using several contexts you can run
2137 several cryptographic operations in parallel, with different
2140 @deftp {Data type} {gpgme_ctx_t}
2141 The @code{gpgme_ctx_t} type is a handle for a @acronym{GPGME} context,
2142 which is used to hold the configuration, status and result of
2143 cryptographic operations.
2147 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
2148 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
2149 * Result Management:: Managing the result of crypto operations.
2150 * Context Attributes:: Setting properties of a context.
2151 * Key Management:: Managing keys with @acronym{GPGME}.
2152 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
2153 * Crypto Operations:: Using a context for cryptography.
2154 * Run Control:: Controlling how operations are run.
2158 @node Creating Contexts
2159 @section Creating Contexts
2160 @cindex context, creation
2162 @deftypefun gpgme_error_t gpgme_new (@w{gpgme_ctx_t *@var{ctx}})
2163 The function @code{gpgme_new} creates a new @code{gpgme_ctx_t} object
2164 and returns a handle for it in @var{ctx}.
2166 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2167 context was successfully created, @code{GPG_ERR_INV_VALUE} if
2168 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
2169 enough memory is available. Also, it returns
2170 @code{GPG_ERR_NOT_OPERATIONAL} if @code{gpgme_check_version} was not
2171 called to initialize GPGME, and @code{GPG_ERR_SELFTEST_FAILED} if a
2172 selftest failed. Currently, the only selftest is for Windows MingW32
2173 targets to see if @code{-mms-bitfields} was used (as required).
2177 @node Destroying Contexts
2178 @section Destroying Contexts
2179 @cindex context, destruction
2181 @deftypefun void gpgme_release (@w{gpgme_ctx_t @var{ctx}})
2182 The function @code{gpgme_release} destroys the context with the handle
2183 @var{ctx} and releases all associated resources.
2187 @node Result Management
2188 @section Result Management
2189 @cindex context, result of operation
2191 The detailed result of an operation is returned in operation-specific
2192 structures such as @code{gpgme_decrypt_result_t}. The corresponding
2193 retrieval functions such as @code{gpgme_op_decrypt_result} provide
2194 static access to the results after an operation completes. The
2195 following interfaces make it possible to detach a result structure
2196 from its associated context and give it a lifetime beyond that of the
2197 current operation or context.
2199 @deftypefun void gpgme_result_ref (@w{void *@var{result}})
2200 The function @code{gpgme_result_ref} acquires an additional reference
2201 for the result @var{result}, which may be of any type
2202 @code{gpgme_*_result_t}. As long as the user holds a reference, the
2203 result structure is guaranteed to be valid and unmodified.
2206 @deftypefun void gpgme_result_unref (@w{void *@var{result}})
2207 The function @code{gpgme_result_unref} releases a reference for the
2208 result @var{result}. If this was the last reference, the result
2209 structure will be destroyed and all resources associated to it will be
2213 Note that a context may hold its own references to result structures,
2214 typically until the context is destroyed or the next operation is
2215 started. In fact, these references are accessed through the
2216 @code{gpgme_op_*_result} functions.
2219 @node Context Attributes
2220 @section Context Attributes
2221 @cindex context, attributes
2224 * Protocol Selection:: Selecting the protocol used by a context.
2225 * Crypto Engine:: Configuring the crypto engine.
2226 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
2227 * Text Mode:: Choosing canonical text mode.
2228 * Included Certificates:: Including a number of certificates.
2229 * Key Listing Mode:: Selecting key listing mode.
2230 * Passphrase Callback:: Getting the passphrase from the user.
2231 * Progress Meter Callback:: Being informed about the progress.
2232 * Locale:: Setting the locale of a context.
2236 @node Protocol Selection
2237 @subsection Protocol Selection
2238 @cindex context, selecting protocol
2239 @cindex protocol, selecting
2241 @deftypefun gpgme_error_t gpgme_set_protocol (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}})
2242 The function @code{gpgme_set_protocol} sets the protocol used within
2243 the context @var{ctx} to @var{proto}. All crypto operations will be
2244 performed by the crypto engine configured for that protocol.
2245 @xref{Protocols and Engines}.
2247 Setting the protocol with @code{gpgme_set_protocol} does not check if
2248 the crypto engine for that protocol is available and installed
2249 correctly. @xref{Engine Version Check}.
2251 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2252 protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if
2253 @var{protocol} is not a valid protocol.
2256 @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}})
2257 The function @code{gpgme_get_protocol} retrieves the protocol currently
2258 use with the context @var{ctx}.
2263 @subsection Crypto Engine
2264 @cindex context, configuring engine
2265 @cindex engine, configuration per context
2267 The following functions can be used to set and retrieve the
2268 configuration of the crypto engines of a specific context. The
2269 default can also be retrieved without any particular context.
2270 @xref{Engine Information}. The default can also be changed globally.
2271 @xref{Engine Configuration}.
2273 @deftypefun gpgme_engine_info_t gpgme_ctx_get_engine_info (@w{gpgme_ctx_t @var{ctx}})
2274 The function @code{gpgme_ctx_get_engine_info} returns a linked list of
2275 engine info structures. Each info structure describes the
2276 configuration of one configured backend, as used by the context
2279 The result is valid until the next invocation of
2280 @code{gpgme_ctx_set_engine_info} for this particular context.
2282 This function can not fail.
2285 @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}})
2286 The function @code{gpgme_ctx_set_engine_info} changes the
2287 configuration of the crypto engine implementing the protocol
2288 @var{proto} for the context @var{ctx}.
2290 @var{file_name} is the file name of the executable program
2291 implementing this protocol, and @var{home_dir} is the directory name
2292 of the configuration directory for this crypto engine. If
2293 @var{home_dir} is @code{NULL}, the engine's default will be used.
2295 Currently this function must be used before starting the first crypto
2296 operation. It is unspecified if and when the changes will take effect
2297 if the function is called after starting the first operation on the
2300 This function returns the error code @code{GPG_ERR_NO_ERROR} if
2301 successful, or an eror code on failure.
2305 @c FIXME: Unfortunately, using @acronym here breaks texi2dvi.
2307 @subsection @acronym{ASCII} Armor
2308 @cindex context, armor mode
2309 @cindex @acronym{ASCII} armor
2312 @deftypefun void gpgme_set_armor (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2313 The function @code{gpgme_set_armor} specifies if the output should be
2314 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
2317 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
2321 @deftypefun int gpgme_get_armor (@w{gpgme_ctx_t @var{ctx}})
2322 The function @code{gpgme_get_armor} returns 1 if the output is
2323 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
2324 not a valid pointer.
2329 @subsection Text Mode
2330 @cindex context, text mode
2332 @cindex canonical text mode
2334 @deftypefun void gpgme_set_textmode (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2335 The function @code{gpgme_set_textmode} specifies if canonical text mode
2336 should be used. By default, text mode is not used.
2338 Text mode is for example used for the RFC2015 signatures; note that
2339 the updated RFC 3156 mandates that the mail user agent does some
2340 preparations so that text mode is not needed anymore.
2342 This option is only relevant to the OpenPGP crypto engine, and ignored
2343 by all other engines.
2345 Canonical text mode is disabled if @var{yes} is zero, and enabled
2349 @deftypefun int gpgme_get_textmode (@w{gpgme_ctx_t @var{ctx}})
2350 The function @code{gpgme_get_textmode} returns 1 if canonical text
2351 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2356 @node Included Certificates
2357 @subsection Included Certificates
2358 @cindex certificates, included
2360 @deftypefun void gpgme_set_include_certs (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{nr_of_certs}})
2361 The function @code{gpgme_set_include_certs} specifies how many
2362 certificates should be included in an S/MIME signed message. By
2363 default, only the sender's certificate is included. The possible
2364 values of @var{nr_of_certs} are:
2367 @item GPGME_INCLUDE_CERTS_DEFAULT
2368 Fall back to the default of the crypto backend. This is the default
2371 Include all certificates except the root certificate.
2373 Include all certificates.
2375 Include no certificates.
2377 Include the sender's certificate only.
2379 Include the first n certificates of the certificates path, starting
2380 from the sender's certificate. The number @code{n} must be positive.
2383 Values of @var{nr_of_certs} smaller than -2 are undefined.
2385 This option is only relevant to the CMS crypto engine, and ignored by
2389 @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}})
2390 The function @code{gpgme_get_include_certs} returns the number of
2391 certificates to include into an S/MIME signed message.
2395 @node Key Listing Mode
2396 @subsection Key Listing Mode
2397 @cindex key listing mode
2398 @cindex key listing, mode of
2400 @deftypefun gpgme_error_t gpgme_set_keylist_mode (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_keylist_mode_t @var{mode}})
2401 The function @code{gpgme_set_keylist_mode} changes the default
2402 behaviour of the key listing functions. The value in @var{mode} is a
2403 bitwise-or combination of one or multiple of the following bit values:
2406 @item GPGME_KEYLIST_MODE_LOCAL
2407 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
2408 keyring should be searched for keys in the keylisting operation. This
2411 @item GPGME_KEYLIST_MODE_EXTERN
2412 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
2413 source should be searched for keys in the keylisting operation. The
2414 type of external source is dependant on the crypto engine used and
2415 whether it is combined with @code{GPGME_KEYLIST_MODE_LOCAL}. For
2416 example, it can be a remote keyserver or LDAP certificate server.
2418 @item GPGME_KEYLIST_MODE_SIGS
2419 The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key
2420 signatures should be included in the listed keys.
2422 @item GPGME_KEYLIST_MODE_SIG_NOTATIONS
2423 The @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} symbol specifies that the
2424 signature notations on key signatures should be included in the listed
2425 keys. This only works if @code{GPGME_KEYLIST_MODE_SIGS} is also
2428 @item GPGME_KEYLIST_MODE_EPHEMERAL
2429 The @code{GPGME_KEYLIST_MODE_EPHEMERAL} symbol specifies that keys
2430 flagged as ephemeral are included in the listing.
2432 @item GPGME_KEYLIST_MODE_VALIDATE
2433 The @code{GPGME_KEYLIST_MODE_VALIDATE} symbol specifies that the
2434 backend should do key or certificate validation and not just get the
2435 validity information from an internal cache. This might be an
2436 expensive operation and is in general not useful. Currently only
2437 implemented for the S/MIME backend and ignored for other backends.
2441 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
2442 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
2443 compatibility, you should get the current mode with
2444 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
2445 appropriate bits, and then using that calculated value in the
2446 @code{gpgme_set_keylisting_mode} operation. This will leave all other
2447 bits in the mode value intact (in particular those that are not used
2448 in the current version of the library).
2450 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2451 mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx}
2452 is not a valid pointer or @var{mode} is not a valid mode.
2456 @deftypefun gpgme_keylist_mode_t gpgme_get_keylist_mode (@w{gpgme_ctx_t @var{ctx}})
2457 The function @code{gpgme_get_keylist_mode} returns the current key
2458 listing mode of the context @var{ctx}. This value can then be
2459 modified and used in a subsequent @code{gpgme_set_keylist_mode}
2460 operation to only affect the desired bits (and leave all others
2463 The function returns 0 if @var{ctx} is not a valid pointer, and the
2464 current mode otherwise. Note that 0 is not a valid mode value.
2468 @node Passphrase Callback
2469 @subsection Passphrase Callback
2470 @cindex callback, passphrase
2471 @cindex passphrase callback
2473 @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}})}
2474 @tindex gpgme_passphrase_cb_t
2475 The @code{gpgme_passphrase_cb_t} type is the type of functions usable as
2476 passphrase callback function.
2478 The argument @var{uid_hint} might contain a string that gives an
2479 indication for which user ID the passphrase is required. If this is
2480 not available, or not applicable (in the case of symmetric encryption,
2481 for example), @var{uid_hint} will be @code{NULL}.
2483 The argument @var{passphrase_info}, if not @code{NULL}, will give
2484 further information about the context in which the passphrase is
2485 required. This information is engine and operation specific.
2487 If this is the repeated attempt to get the passphrase, because
2488 previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
2491 The user must write the passphrase, followed by a newline character,
2492 to the file descriptor @var{fd}. The function @code{gpgme_io_writen}
2493 should be used for the write operation. Note that if the user returns
2494 0 to indicate success, the user must at least write a newline
2495 character before returning from the callback.
2497 If an error occurs, return the corresponding @code{gpgme_error_t}
2498 value. You can use the error code @code{GPG_ERR_CANCELED} to abort
2499 the operation. Otherwise, return @code{0}.
2502 @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}})
2503 The function @code{gpgme_set_passphrase_cb} sets the function that is
2504 used when a passphrase needs to be provided by the user to
2505 @var{passfunc}. The function @var{passfunc} needs to implemented by
2506 the user, and whenever it is called, it is called with its first
2507 argument being @var{hook_value}. By default, no passphrase callback
2510 Not all crypto engines require this callback to retrieve the
2511 passphrase. It is better if the engine retrieves the passphrase from
2512 a trusted agent (a daemon process), rather than having each user to
2513 implement their own passphrase query. Some engines do not even
2514 support an external passphrase callback at all, in this case the error
2515 code @code{GPG_ERR_NOT_SUPPORTED} is returned.
2517 The user can disable the use of a passphrase callback function by
2518 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
2522 @deftypefun void gpgme_get_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t *@var{passfunc}}, @w{void **@var{hook_value}})
2523 The function @code{gpgme_get_passphrase_cb} returns the function that
2524 is used when a passphrase needs to be provided by the user in
2525 @var{*passfunc}, and the first argument for this function in
2526 @var{*hook_value}. If no passphrase callback is set, or @var{ctx} is
2527 not a valid pointer, @code{NULL} is returned in both variables.
2529 @var{passfunc} or @var{hook_value} can be @code{NULL}. In this case,
2530 the corresponding value will not be returned.
2534 @node Progress Meter Callback
2535 @subsection Progress Meter Callback
2536 @cindex callback, progress meter
2537 @cindex progress meter callback
2539 @deftp {Data type} {void (*gpgme_progress_cb_t)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
2540 @tindex gpgme_progress_cb_t
2541 The @code{gpgme_progress_cb_t} type is the type of functions usable as
2542 progress callback function.
2544 The arguments are specific to the crypto engine. More information
2545 about the progress information returned from the GnuPG engine can be
2546 found in the GnuPG source code in the file @file{doc/DETAILS} in the
2550 @deftypefun void gpgme_set_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t @var{progfunc}}, @w{void *@var{hook_value}})
2551 The function @code{gpgme_set_progress_cb} sets the function that is
2552 used when progress information about a cryptographic operation is
2553 available. The function @var{progfunc} needs to implemented by the
2554 user, and whenever it is called, it is called with its first argument
2555 being @var{hook_value}. By default, no progress callback function
2558 Setting a callback function allows an interactive program to display
2559 progress information about a long operation to the user.
2561 The user can disable the use of a progress callback function by
2562 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
2566 @deftypefun void gpgme_get_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t *@var{progfunc}}, @w{void **@var{hook_value}})
2567 The function @code{gpgme_get_progress_cb} returns the function that is
2568 used to inform the user about the progress made in @var{*progfunc},
2569 and the first argument for this function in @var{*hook_value}. If no
2570 progress callback is set, or @var{ctx} is not a valid pointer,
2571 @code{NULL} is returned in both variables.
2573 @var{progfunc} or @var{hook_value} can be @code{NULL}. In this case,
2574 the corresponding value will not be returned.
2580 @cindex locale, default
2581 @cindex locale, of a context
2583 A locale setting can be associated with a context. This locale is
2584 passed to the crypto engine, and used for applications like the PIN
2585 entry, which is displayed to the user when entering a passphrase is
2588 The default locale is used to initialize the locale setting of all
2589 contexts created afterwards.
2591 @deftypefun gpgme_error_t gpgme_set_locale (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{category}}, @w{const char *@var{value}})
2592 The function @code{gpgme_set_locale} sets the locale of the context
2593 @var{ctx}, or the default locale if @var{ctx} is a null pointer.
2595 The locale settings that should be changed are specified by
2596 @var{category}. Supported categories are @code{LC_CTYPE},
2597 @code{LC_MESSAGES}, and @code{LC_ALL}, which is a wildcard you can use
2598 if you want to change all the categories at once.
2600 The value to be used for the locale setting is @var{value}, which will
2601 be copied to @acronym{GPGME}'s internal data structures. @var{value}
2602 can be a null pointer, which disables setting the locale, and will
2603 make PIN entry and other applications use their default setting, which
2604 is usually not what you want.
2606 Note that the settings are only used if the application runs on a text
2607 terminal, and that the settings should fit the configuration of the
2608 output terminal. Normally, it is sufficient to initialize the default
2611 The function returns an error if not enough memory is available.
2615 @node Key Management
2616 @section Key Management
2617 @cindex key management
2619 Some of the cryptographic operations require that recipients or
2620 signers are specified. This is always done by specifying the
2621 respective keys that should be used for the operation. The following
2622 section describes how such keys can be selected and manipulated.
2624 @deftp {Data type} gpgme_subkey_t
2625 The @code{gpgme_subkey_t} type is a pointer to a subkey structure.
2626 Sub keys are one component of a @code{gpgme_key_t} object. In fact,
2627 subkeys are those parts that contains the real information about the
2628 individual cryptographic keys that belong to the same key object. One
2629 @code{gpgme_key_t} can contain several subkeys. The first subkey in
2630 the linked list is also called the primary key.
2632 The subkey structure has the following members:
2635 @item gpgme_subkey_t next
2636 This is a pointer to the next subkey structure in the linked list, or
2637 @code{NULL} if this is the last element.
2639 @item unsigned int revoked : 1
2640 This is true if the subkey is revoked.
2642 @item unsigned int expired : 1
2643 This is true if the subkey is expired.
2645 @item unsigned int disabled : 1
2646 This is true if the subkey is disabled.
2648 @item unsigned int invalid : 1
2649 This is true if the subkey is invalid.
2651 @item unsigned int can_encrypt : 1
2652 This is true if the subkey can be used for encryption.
2654 @item unsigned int can_sign : 1
2655 This is true if the subkey can be used to create data signatures.
2657 @item unsigned int can_certify : 1
2658 This is true if the subkey can be used to create key certificates.
2660 @item unsigned int can_authenticate : 1
2661 This is true if the subkey can be used for authentication.
2663 @item unsigned int is_qualified : 1
2664 This is true if the subkey can be used for qualified signatures
2665 according to local government regulations.
2667 @item unsigned int secret : 1
2668 This is true if the subkey is a secret key. Note that it will be false
2669 if the key is actually a stub key; i.e. a secret key operation is
2670 currently not possible (offline-key).
2672 @item gpgme_pubkey_algo_t pubkey_algo
2673 This is the public key algorithm supported by this subkey.
2675 @item unsigned int length
2676 This is the length of the subkey (in bits).
2679 This is the key ID of the subkey in hexadecimal digits.
2682 This is the fingerprint of the subkey in hexadecimal digits, if
2685 @item long int timestamp
2686 This is the creation timestamp of the subkey. This is -1 if the
2687 timestamp is invalid, and 0 if it is not available.
2689 @item long int expires
2690 This is the expiration timestamp of the subkey, or 0 if the subkey
2695 @deftp {Data type} gpgme_key_sig_t
2696 The @code{gpgme_key_sig_t} type is a pointer to a key signature structure.
2697 Key signatures are one component of a @code{gpgme_key_t} object, and
2698 validate user IDs on the key.
2700 The signatures on a key are only available if the key was retrieved
2701 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
2702 enabled, because it can be expensive to retrieve all signatures of a
2705 The signature notations on a key signature are only available if the
2706 key was retrieved via a listing operation with the
2707 @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} mode enabled, because it can
2708 be expensive to retrieve all signature notations.
2710 The key signature structure has the following members:
2713 @item gpgme_key_sig_t next
2714 This is a pointer to the next key signature structure in the linked
2715 list, or @code{NULL} if this is the last element.
2717 @item unsigned int revoked : 1
2718 This is true if the key signature is a revocation signature.
2720 @item unsigned int expired : 1
2721 This is true if the key signature is expired.
2723 @item unsigned int invalid : 1
2724 This is true if the key signature is invalid.
2726 @item unsigned int exportable : 1
2727 This is true if the key signature is exportable.
2729 @item gpgme_pubkey_algo_t pubkey_algo
2730 This is the public key algorithm used to create the signature.
2733 This is the key ID of the key (in hexadecimal digits) used to create
2736 @item long int timestamp
2737 This is the creation timestamp of the key signature. This is -1 if
2738 the timestamp is invalid, and 0 if it is not available.
2740 @item long int expires
2741 This is the expiration timestamp of the key signature, or 0 if the key
2742 signature does not expire.
2744 @item gpgme_error_t status
2745 This is the status of the signature and has the same meaning as the
2746 member of the same name in a @code{gpgme_signature_t} object.
2748 @item unsigned int sig_class
2749 This specifies the signature class of the key signature. The meaning
2750 is specific to the crypto engine.
2753 This is the main user ID of the key used to create the signature.
2756 This is the name component of @code{uid}, if available.
2759 This is the comment component of @code{uid}, if available.
2762 This is the email component of @code{uid}, if available.
2764 @item gpgme_sig_notation_t notations
2765 This is a linked list with the notation data and policy URLs.
2769 @deftp {Data type} gpgme_user_id_t
2770 A user ID is a component of a @code{gpgme_key_t} object. One key can
2771 have many user IDs. The first one in the list is the main (or
2774 The user ID structure has the following members.
2777 @item gpgme_user_id_t next
2778 This is a pointer to the next user ID structure in the linked list, or
2779 @code{NULL} if this is the last element.
2781 @item unsigned int revoked : 1
2782 This is true if the user ID is revoked.
2784 @item unsigned int invalid : 1
2785 This is true if the user ID is invalid.
2787 @item gpgme_validity_t validity
2788 This specifies the validity of the user ID.
2791 This is the user ID string.
2794 This is the name component of @code{uid}, if available.
2797 This is the comment component of @code{uid}, if available.
2800 This is the email component of @code{uid}, if available.
2802 @item gpgme_key_sig_t signatures
2803 This is a linked list with the signatures on this user ID.
2807 @deftp {Data type} gpgme_key_t
2808 The @code{gpgme_key_t} type is a pointer to a key object. It has the
2812 @item gpgme_keylist_mode_t keylist_mode
2813 The keylist mode that was active when the key was retrieved.
2815 @item unsigned int revoked : 1
2816 This is true if the key is revoked.
2818 @item unsigned int expired : 1
2819 This is true if the key is expired.
2821 @item unsigned int disabled : 1
2822 This is true if the key is disabled.
2824 @item unsigned int invalid : 1
2825 This is true if the key is invalid. This might have several reasons,
2826 for a example for the S/MIME backend, it will be set in during key
2827 listsing if the key could not be validated due to a missing
2828 certificates or unmatched policies.
2830 @item unsigned int can_encrypt : 1
2831 This is true if the key (ie one of its subkeys) can be used for
2834 @item unsigned int can_sign : 1
2835 This is true if the key (ie one of its subkeys) can be used to create
2838 @item unsigned int can_certify : 1
2839 This is true if the key (ie one of its subkeys) can be used to create
2842 @item unsigned int can_authenticate : 1
2843 This is true if the key (ie one of its subkeys) can be used for
2846 @item unsigned int is_qualified : 1
2847 This is true if the key can be used for qualified signatures according
2848 to local government regulations.
2850 @item unsigned int secret : 1
2851 This is true if the key is a secret key. Note, that this will always be
2852 true even if the corresponding subkey flag may be false (offline/stub
2855 @item gpgme_protocol_t protocol
2856 This is the protocol supported by this key.
2858 @item char *issuer_serial
2859 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2862 @item char *issuer_name
2863 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2866 @item char *chain_id
2867 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2868 chain ID, which can be used to built the certificate chain.
2870 @item gpgme_validity_t owner_trust
2871 If @code{protocol} is @code{GPGME_PROTOCOL_OpenPGP}, then this is the
2874 @item gpgme_subkey_t subkeys
2875 This is a linked list with the subkeys of the key. The first subkey
2876 in the list is the primary key and usually available.
2878 @item gpgme_user_id_t uids
2879 This is a linked list with the user IDs of the key. The first user ID
2880 in the list is the main (or primary) user ID.
2885 * Listing Keys:: Browsing the list of available keys.
2886 * Information About Keys:: Requesting detailed information about keys.
2887 * Key Signatures:: Listing the signatures on a key.
2888 * Manipulating Keys:: Operations on keys.
2889 * Generating Keys:: Creating new key pairs.
2890 * Exporting Keys:: Retrieving key data from the key ring.
2891 * Importing Keys:: Adding keys to the key ring.
2892 * Deleting Keys:: Removing keys from the key ring.
2893 * Changing Passphrases:: Change the passphrase of a key.
2894 * Advanced Key Editing:: Advanced key edit operation.
2899 @subsection Listing Keys
2900 @cindex listing keys
2902 @cindex key listing, start
2903 @cindex key ring, list
2904 @cindex key ring, search
2906 @deftypefun gpgme_error_t gpgme_op_keylist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
2907 The function @code{gpgme_op_keylist_start} initiates a key listing
2908 operation inside the context @var{ctx}. It sets everything up so that
2909 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
2912 If @var{pattern} is @code{NULL}, all available keys are returned.
2913 Otherwise, @var{pattern} contains an engine specific expression that
2914 is used to limit the list to all keys matching the pattern. Note that
2915 the total length of the pattern is restricted to an engine-specific
2916 maximum (a couple of hundred characters are usually accepted). The
2917 pattern should be used to restrict the search to a certain common name
2918 or user, not to list many specific keys at once by listing their
2919 fingerprints or key IDs.
2921 If @var{secret_only} is not @code{0}, the list is restricted to secret
2924 The context will be busy until either all keys are received (and
2925 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2926 @code{gpgme_op_keylist_end} is called to finish the operation.
2928 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2929 @var{ctx} is not a valid pointer, and passes through any errors that
2930 are reported by the crypto engine support routines.
2933 @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}})
2934 The function @code{gpgme_op_keylist_ext_start} initiates an extended
2935 key listing operation inside the context @var{ctx}. It sets
2936 everything up so that subsequent invocations of
2937 @code{gpgme_op_keylist_next} return the keys in the list.
2939 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
2940 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
2941 array of strings that are used to limit the list to all keys matching
2942 at least one of the patterns verbatim. Note that the total length of
2943 all patterns is restricted to an engine-specific maximum (the exact
2944 limit also depends on the number of patterns and amount of quoting
2945 required, but a couple of hundred characters are usually accepted).
2946 Patterns should be used to restrict the search to a certain common
2947 name or user, not to list many specific keys at once by listing their
2948 fingerprints or key IDs.
2950 If @var{secret_only} is not @code{0}, the list is restricted to secret
2953 The value of @var{reserved} must be @code{0}.
2955 The context will be busy until either all keys are received (and
2956 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2957 @code{gpgme_op_keylist_end} is called to finish the operation.
2959 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2960 @var{ctx} is not a valid pointer, and passes through any errors that
2961 are reported by the crypto engine support routines.
2964 @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}})
2965 The function @code{gpgme_op_keylist_next} returns the next key in the
2966 list created by a previous @code{gpgme_op_keylist_start} operation in
2967 the context @var{ctx}. The key will have one reference for the user.
2968 @xref{Manipulating Keys}.
2970 This is the only way to get at @code{gpgme_key_t} objects in
2973 If the last key in the list has already been returned,
2974 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}.
2976 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2977 @var{ctx} or @var{r_key} is not a valid pointer, and
2978 @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation.
2981 @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}})
2982 The function @code{gpgme_op_keylist_end} ends a pending key list
2983 operation in the context @var{ctx}.
2985 After the operation completed successfully, the result of the key
2986 listing operation can be retrieved with
2987 @code{gpgme_op_keylist_result}.
2989 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2990 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
2991 time during the operation there was not enough memory available.
2994 The following example illustrates how all keys containing a certain
2995 string (@code{g10code}) can be listed with their key ID and the name
2996 and e-mail address of the main user ID:
3001 gpgme_error_t err = gpgme_new (&ctx);
3005 err = gpgme_op_keylist_start (ctx, "g10code", 0);
3008 err = gpgme_op_keylist_next (ctx, &key);
3011 printf ("%s:", key->subkeys->keyid);
3012 if (key->uids && key->uids->name)
3013 printf (" %s", key->uids->name);
3014 if (key->uids && key->uids->email)
3015 printf (" <%s>", key->uids->email);
3017 gpgme_key_release (key);
3019 gpgme_release (ctx);
3021 if (gpg_err_code (err) != GPG_ERR_EOF)
3023 fprintf (stderr, "can not list keys: %s\n", gpgme_strerror (err));
3028 @deftp {Data type} {gpgme_keylist_result_t}
3029 This is a pointer to a structure used to store the result of a
3030 @code{gpgme_op_keylist_*} operation. After successfully ending a key
3031 listing operation, you can retrieve the pointer to the result with
3032 @code{gpgme_op_keylist_result}. The structure contains the following
3036 @item unsigned int truncated : 1
3037 This is true if the crypto backend had to truncate the result, and
3038 less than the desired keys could be listed.
3042 @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}})
3043 The function @code{gpgme_op_keylist_result} returns a
3044 @code{gpgme_keylist_result_t} pointer to a structure holding the
3045 result of a @code{gpgme_op_keylist_*} operation. The pointer is only
3046 valid if the last operation on the context was a key listing
3047 operation, and if this operation finished successfully. The returned
3048 pointer is only valid until the next operation is started on the
3052 In a simple program, for which a blocking operation is acceptable, the
3053 following function can be used to retrieve a single key.
3055 @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}})
3056 The function @code{gpgme_get_key} gets the key with the fingerprint
3057 (or key ID) @var{fpr} from the crypto backend and return it in
3058 @var{r_key}. If @var{secret} is true, get the secret key. The
3059 currently active keylist mode is used to retrieve the key. The key
3060 will have one reference for the user.
3062 If the key is not found in the keyring, @code{gpgme_get_key} returns
3063 the error code @code{GPG_ERR_EOF} and *@var{r_key} will be set to
3066 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3067 @var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a
3068 fingerprint or key ID, @code{GPG_ERR_AMBIGUOUS_NAME} if the key ID was
3069 not a unique specifier for a key, and @code{GPG_ERR_ENOMEM} if at some
3070 time during the operation there was not enough memory available.
3074 @node Information About Keys
3075 @subsection Information About Keys
3076 @cindex key, information about
3077 @cindex key, attributes
3078 @cindex attributes, of a key
3080 Please see the beginning of this section for more information about
3081 @code{gpgme_key_t} objects.
3083 @deftp {Data type} gpgme_validity_t
3084 The @code{gpgme_validity_t} type is used to specify the validity of a user ID
3085 in a key. The following validities are defined:
3088 @item GPGME_VALIDITY_UNKNOWN
3089 The user ID is of unknown validity. The string representation of this
3092 @item GPGME_VALIDITY_UNDEFINED
3093 The validity of the user ID is undefined. The string representation of this
3096 @item GPGME_VALIDITY_NEVER
3097 The user ID is never valid. The string representation of this
3100 @item GPGME_VALIDITY_MARGINAL
3101 The user ID is marginally valid. The string representation of this
3104 @item GPGME_VALIDITY_FULL
3105 The user ID is fully valid. The string representation of this
3108 @item GPGME_VALIDITY_ULTIMATE
3109 The user ID is ultimately valid. The string representation of this
3115 The following interfaces are deprecated and only provided for backward
3116 compatibility. Don't use them. They will be removed in a future
3117 version of @acronym{GPGME}.
3119 @deftp {Data type} gpgme_attr_t
3120 The @code{gpgme_attr_t} type is used to specify a key or trust item
3121 attribute. The following attributes are defined:
3124 @item GPGME_ATTR_KEYID
3125 This is the key ID of a sub key. It is representable as a string.
3127 For trust items, the trust item refers to the key with this ID.
3129 @item GPGME_ATTR_FPR
3130 This is the fingerprint of a sub key. It is representable as a
3133 @item GPGME_ATTR_ALGO
3134 This is the crypto algorithm for which the sub key can be used. It
3135 is representable as a string and as a number. The numbers correspond
3136 to the @code{enum gcry_pk_algos} values in the gcrypt library.
3138 @item GPGME_ATTR_LEN
3139 This is the key length of a sub key. It is representable as a
3142 @item GPGME_ATTR_CREATED
3143 This is the timestamp at creation time of a sub key. It is
3144 representable as a number.
3146 @item GPGME_ATTR_EXPIRE
3147 This is the expiration time of a sub key. It is representable as a
3150 @item GPGME_ATTR_OTRUST
3151 XXX FIXME (also for trust items)
3153 @item GPGME_ATTR_USERID
3154 This is a user ID. There can be more than one user IDs in a
3155 @var{gpgme_key_t} object. The first one (with index 0) is the primary
3156 user ID. The user ID is representable as a number.
3158 For trust items, this is the user ID associated with this trust item.
3160 @item GPGME_ATTR_NAME
3161 This is the name belonging to a user ID. It is representable as a string.
3163 @item GPGME_ATTR_EMAIL
3164 This is the email address belonging to a user ID. It is representable
3167 @item GPGME_ATTR_COMMENT
3168 This is the comment belonging to a user ID. It is representable as a
3171 @item GPGME_ATTR_VALIDITY
3172 This is the validity belonging to a user ID. It is representable as a
3173 string and as a number. See below for a list of available validities.
3175 For trust items, this is the validity that is associated with this
3178 @item GPGME_ATTR_UID_REVOKED
3179 This specifies if a user ID is revoked. It is representable as a
3180 number, and is @code{1} if the user ID is revoked, and @code{0}
3183 @item GPGME_ATTR_UID_INVALID
3184 This specifies if a user ID is invalid. It is representable as a
3185 number, and is @code{1} if the user ID is invalid, and @code{0}
3188 @item GPGME_ATTR_LEVEL
3189 This is the trust level of a trust item.
3191 @item GPGME_ATTR_TYPE
3192 This returns information about the type of key. For the string function
3193 this will eother be "PGP" or "X.509". The integer function returns 0
3194 for PGP and 1 for X.509. It is also used for the type of a trust item.
3196 @item GPGME_ATTR_IS_SECRET
3197 This specifies if the key is a secret key. It is representable as a
3198 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
3200 @item GPGME_ATTR_KEY_REVOKED
3201 This specifies if a sub key is revoked. It is representable as a
3202 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
3204 @item GPGME_ATTR_KEY_INVALID
3205 This specifies if a sub key is invalid. It is representable as a
3206 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
3208 @item GPGME_ATTR_KEY_EXPIRED
3209 This specifies if a sub key is expired. It is representable as a
3210 number, and is @code{1} if the key is expired, and @code{0} otherwise.
3212 @item GPGME_ATTR_KEY_DISABLED
3213 This specifies if a sub key is disabled. It is representable as a
3214 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
3216 @item GPGME_ATTR_KEY_CAPS
3217 This is a description of the capabilities of a sub key. It is
3218 representable as a string. The string contains the letter ``e'' if
3219 the key can be used for encryption, ``s'' if the key can be used for
3220 signatures, and ``c'' if the key can be used for certifications.
3222 @item GPGME_ATTR_CAN_ENCRYPT
3223 This specifies if a sub key can be used for encryption. It is
3224 representable as a number, and is @code{1} if the sub key can be used
3225 for encryption, and @code{0} otherwise.
3227 @item GPGME_ATTR_CAN_SIGN
3228 This specifies if a sub key can be used to create data signatures. It
3229 is representable as a number, and is @code{1} if the sub key can be
3230 used for signatures, and @code{0} otherwise.
3232 @item GPGME_ATTR_CAN_CERTIFY
3233 This specifies if a sub key can be used to create key certificates.
3234 It is representable as a number, and is @code{1} if the sub key can be
3235 used for certifications, and @code{0} otherwise.
3237 @item GPGME_ATTR_SERIAL
3238 The X.509 issuer serial attribute of the key. It is representable as
3241 @item GPGME_ATTR_ISSUE
3242 The X.509 issuer name attribute of the key. It is representable as a
3245 @item GPGME_ATTR_CHAINID
3246 The X.509 chain ID can be used to build the certification chain. It
3247 is representable as a string.
3251 @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}})
3252 The function @code{gpgme_key_get_string_attr} returns the value of the
3253 string-representable attribute @var{what} of key @var{key}. If the
3254 attribute is an attribute of a sub key or an user ID, @var{idx}
3255 specifies the sub key or user ID of which the attribute value is
3256 returned. The argument @var{reserved} is reserved for later use and
3257 should be @code{NULL}.
3259 The string returned is only valid as long as the key is valid.
3261 The function returns @code{0} if an attribute can't be returned as a
3262 string, @var{key} is not a valid pointer, @var{idx} out of range,
3263 or @var{reserved} not @code{NULL}.
3266 @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}})
3267 The function @code{gpgme_key_get_ulong_attr} returns the value of the
3268 number-representable attribute @var{what} of key @var{key}. If the
3269 attribute is an attribute of a sub key or an user ID, @var{idx}
3270 specifies the sub key or user ID of which the attribute value is
3271 returned. The argument @var{reserved} is reserved for later use and
3272 should be @code{NULL}.
3274 The function returns @code{0} if the attribute can't be returned as a
3275 number, @var{key} is not a valid pointer, @var{idx} out of range, or
3276 @var{reserved} not @code{NULL}.
3280 @node Key Signatures
3281 @subsection Key Signatures
3282 @cindex key, signatures
3283 @cindex signatures, on a key
3285 The following interfaces are deprecated and only provided for backward
3286 compatibility. Don't use them. They will be removed in a future
3287 version of @acronym{GPGME}.
3289 The signatures on a key are only available if the key was retrieved
3290 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
3291 enabled, because it is expensive to retrieve all signatures of a key.
3293 So, before using the below interfaces to retrieve the signatures on a
3294 key, you have to make sure that the key was listed with signatures
3295 enabled. One convenient, but blocking, way to do this is to use the
3296 function @code{gpgme_get_key}.
3298 @deftp {Data type} gpgme_attr_t
3299 The @code{gpgme_attr_t} type is used to specify a key signature
3300 attribute. The following attributes are defined:
3303 @item GPGME_ATTR_KEYID
3304 This is the key ID of the key which was used for the signature. It is
3305 representable as a string.
3307 @item GPGME_ATTR_ALGO
3308 This is the crypto algorithm used to create the signature. It is
3309 representable as a string and as a number. The numbers correspond to
3310 the @code{enum gcry_pk_algos} values in the gcrypt library.
3312 @item GPGME_ATTR_CREATED
3313 This is the timestamp at creation time of the signature. It is
3314 representable as a number.
3316 @item GPGME_ATTR_EXPIRE
3317 This is the expiration time of the signature. It is representable as
3320 @item GPGME_ATTR_USERID
3321 This is the user ID associated with the signing key. The user ID is
3322 representable as a number.
3324 @item GPGME_ATTR_NAME
3325 This is the name belonging to a user ID. It is representable as a string.
3327 @item GPGME_ATTR_EMAIL
3328 This is the email address belonging to a user ID. It is representable
3331 @item GPGME_ATTR_COMMENT
3332 This is the comment belonging to a user ID. It is representable as a
3335 @item GPGME_ATTR_KEY_REVOKED
3336 This specifies if a key signature is a revocation signature. It is
3337 representable as a number, and is @code{1} if the key is revoked, and
3340 @c @item GPGME_ATTR_KEY_EXPIRED
3341 @c This specifies if a key signature is expired. It is representable as
3342 @c a number, and is @code{1} if the key is revoked, and @code{0}
3345 @item GPGME_ATTR_SIG_CLASS
3346 This specifies the signature class of a key signature. It is
3347 representable as a number. The meaning is specific to the crypto
3350 @item GPGME_ATTR_SIG_CLASS
3351 This specifies the signature class of a key signature. It is
3352 representable as a number. The meaning is specific to the crypto
3355 @item GPGME_ATTR_SIG_STATUS
3356 This is the same value as returned by @code{gpgme_get_sig_status}.
3360 @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}})
3361 The function @code{gpgme_key_sig_get_string_attr} returns the value of
3362 the string-representable attribute @var{what} of the signature
3363 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3364 argument @var{reserved} is reserved for later use and should be
3367 The string returned is only valid as long as the key is valid.
3369 The function returns @code{0} if an attribute can't be returned as a
3370 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3371 out of range, or @var{reserved} not @code{NULL}.
3374 @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}})
3375 The function @code{gpgme_key_sig_get_ulong_attr} returns the value of
3376 the number-representable attribute @var{what} of the signature
3377 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3378 argument @var{reserved} is reserved for later use and should be
3381 The function returns @code{0} if an attribute can't be returned as a
3382 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3383 out of range, or @var{reserved} not @code{NULL}.
3387 @node Manipulating Keys
3388 @subsection Manipulating Keys
3389 @cindex key, manipulation
3391 @deftypefun void gpgme_key_ref (@w{gpgme_key_t @var{key}})
3392 The function @code{gpgme_key_ref} acquires an additional reference for
3396 @deftypefun void gpgme_key_unref (@w{gpgme_key_t @var{key}})
3397 The function @code{gpgme_key_unref} releases a reference for the key
3398 @var{key}. If this was the last reference, the key will be destroyed
3399 and all resources associated to it will be released.
3403 The following interface is deprecated and only provided for backward
3404 compatibility. Don't use it. It will be removed in a future version
3407 @deftypefun void gpgme_key_release (@w{gpgme_key_t @var{key}})
3408 The function @code{gpgme_key_release} is equivalent to
3409 @code{gpgme_key_unref}.
3413 @node Generating Keys
3414 @subsection Generating Keys
3415 @cindex key, creation
3416 @cindex key ring, add
3418 @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}})
3419 The function @code{gpgme_op_genkey} generates a new key pair in the
3420 context @var{ctx}. The meaning of @var{public} and @var{secret}
3421 depends on the crypto backend.
3423 GnuPG does not support @var{public} and @var{secret}, they should be
3424 @code{NULL}. GnuPG will generate a key pair and add it to the
3425 standard key ring. The fingerprint of the generated key is available
3426 with @code{gpgme_op_genkey_result}.
3428 GpgSM requires @var{public} to be a writable data object. GpgSM will
3429 generate a secret key (which will be stored by @command{gpg-agent},
3430 and return a certificate request in @var{public}, which then needs to
3431 be signed by the certification authority and imported before it can be
3432 used. GpgSM does not make the fingerprint available.
3434 The argument @var{parms} specifies parameters for the key in an XML
3435 string. The details about the format of @var{parms} are specific to
3436 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
3437 the crypto engine (all parameters of OpenPGP key generation are
3438 documented in the GPG manual):
3441 <GnupgKeyParms format="internal">
3443 Subkey-Type: default
3444 Name-Real: Joe Tester
3445 Name-Comment: with stupid passphrase
3446 Name-Email: joe@@foo.bar
3452 Here is an example for GpgSM as the crypto engine (all parameters of
3453 OpenPGP key generation are documented in the GPGSM manual):
3456 <GnupgKeyParms format="internal">
3459 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3460 Name-Email: joe@@foo.bar
3464 Strings should be given in UTF-8 encoding. The only format supported
3465 for now is ``internal''. The content of the @code{GnupgKeyParms}
3466 container is passed verbatim to the crypto backend. Control
3467 statements are not allowed.
3469 After the operation completed successfully, the result can be
3470 retrieved with @code{gpgme_op_genkey_result}.
3472 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3473 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3474 @var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if
3475 @var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL}
3476 if no key was created by the backend.
3479 @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}})
3480 The function @code{gpgme_op_genkey_start} initiates a
3481 @code{gpgme_op_genkey} operation. It can be completed by calling
3482 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3484 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3485 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3486 @var{parms} is not a valid XML string, and
3487 @code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not
3491 @deftp {Data type} {gpgme_genkey_result_t}
3492 This is a pointer to a structure used to store the result of a
3493 @code{gpgme_op_genkey} operation. After successfully generating a
3494 key, you can retrieve the pointer to the result with
3495 @code{gpgme_op_genkey_result}. The structure contains the following
3499 @item unsigned int primary : 1
3500 This is a flag that is set to 1 if a primary key was created and to 0
3503 @item unsigned int sub : 1
3504 This is a flag that is set to 1 if a subkey was created and to 0
3508 This is the fingerprint of the key that was created. If both a
3509 primary and a sub key were generated, the fingerprint of the primary
3510 key will be returned. If the crypto engine does not provide the
3511 fingerprint, @code{fpr} will be a null pointer.
3515 @deftypefun gpgme_genkey_result_t gpgme_op_genkey_result (@w{gpgme_ctx_t @var{ctx}})
3516 The function @code{gpgme_op_genkey_result} returns a
3517 @code{gpgme_genkey_result_t} pointer to a structure holding the result of
3518 a @code{gpgme_op_genkey} operation. The pointer is only valid if the
3519 last operation on the context was a @code{gpgme_op_genkey} or
3520 @code{gpgme_op_genkey_start} operation, and if this operation finished
3521 successfully. The returned pointer is only valid until the next
3522 operation is started on the context.
3526 @node Exporting Keys
3527 @subsection Exporting Keys
3529 @cindex key ring, export from
3531 Exporting keys means the same as running @command{gpg} with the command
3532 @option{--export}. However, a mode flag can be used to change the way
3533 the export works. The available mode flags are described below, they
3534 may be or-ed together.
3538 @item GPGME_EXPORT_MODE_EXTERN
3539 If this bit is set, the output is send directly to the default
3540 keyserver. This is currently only allowed for OpenPGP keys. It is good
3541 practise to not send more than a few dozens key to a keyserver at one
3542 time. Using this flag requires that the @var{keydata} argument of the
3543 export function is set to @code{NULL}.
3545 @item GPGME_EXPORT_MODE_MINIMAL
3546 If this bit is set, the smallest possible key is exported. For OpenPGP
3547 keys it removes all signatures except for the latest self-signatures.
3548 For X.509 keys it has no effect.
3555 @deftypefun gpgme_error_t gpgme_op_export (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3556 The function @code{gpgme_op_export} extracts public keys and returns
3557 them in the data buffer @var{keydata}. The output format of the key
3558 data returned is determined by the @acronym{ASCII} armor attribute set
3559 for the context @var{ctx}, or, if that is not set, by the encoding
3560 specified for @var{keydata}.
3562 If @var{pattern} is @code{NULL}, all available keys are returned.
3563 Otherwise, @var{pattern} contains an engine specific expression that
3564 is used to limit the list to all keys matching the pattern.
3566 @var{mode} is usually 0; other values are described above.
3568 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3569 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3570 @var{keydata} is not a valid empty data buffer, and passes through any
3571 errors that are reported by the crypto engine support routines.
3574 @deftypefun gpgme_error_t gpgme_op_export_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3575 The function @code{gpgme_op_export_start} initiates a
3576 @code{gpgme_op_export} operation. It can be completed by calling
3577 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3579 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3580 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3581 if @var{keydata} is not a valid empty data buffer.
3584 @deftypefun gpgme_error_t gpgme_op_export_ext (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3585 The function @code{gpgme_op_export} extracts public keys and returns
3586 them in the data buffer @var{keydata}. The output format of the key
3587 data returned is determined by the @acronym{ASCII} armor attribute set
3588 for the context @var{ctx}, or, if that is not set, by the encoding
3589 specified for @var{keydata}.
3591 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3592 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3593 array of strings that are used to limit the list to all keys matching
3594 at least one of the patterns verbatim.
3596 @var{mode} is usually 0; other values are described above.
3598 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3599 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3600 @var{keydata} is not a valid empty data buffer, and passes through any
3601 errors that are reported by the crypto engine support routines.
3604 @deftypefun gpgme_error_t gpgme_op_export_ext_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3605 The function @code{gpgme_op_export_ext_start} initiates a
3606 @code{gpgme_op_export_ext} operation. It can be completed by calling
3607 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3609 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3610 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3611 if @var{keydata} is not a valid empty data buffer.
3615 @deftypefun gpgme_error_t gpgme_op_export_keys (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t keys[]}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3616 The function @code{gpgme_op_export_keys} extracts public keys and returns
3617 them in the data buffer @var{keydata}. The output format of the key
3618 data returned is determined by the @acronym{ASCII} armor attribute set
3619 for the context @var{ctx}, or, if that is not set, by the encoding
3620 specified for @var{keydata}.
3622 The keys to export are taken form the @code{NULL} terminated array
3623 @var{keys}. Only keys of the the currently selected protocol of
3624 @var{ctx} which do have a fingerprint set are considered for export.
3625 Other keys specified by the @var{keys} are ignored. In particular
3626 OpenPGP keys retrieved via an external key listing are not included.
3628 @var{mode} is usually 0; other values are described above.
3630 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3631 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3632 @var{keydata} is not a valid empty data buffer, @code{GPG_ERR_NO_DATA}
3633 if no useful keys are in @var{keys} and passes through any errors that
3634 are reported by the crypto engine support routines.
3637 @deftypefun gpgme_error_t gpgme_op_export_keys_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{keys}[]}, @w{gpgme_export_mode_t @var{mode}}, @w{gpgme_data_t @var{keydata}})
3638 The function @code{gpgme_op_export_keys_start} initiates a
3639 @code{gpgme_op_export_ext} operation. It can be completed by calling
3640 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3642 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3643 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3644 if @var{keydata} is not a valid empty data buffer, @code{GPG_ERR_NO_DATA}
3645 if no useful keys are in @var{keys} and passes through any errors that
3646 are reported by the crypto engine support routines.
3650 @node Importing Keys
3651 @subsection Importing Keys
3653 @cindex key ring, import to
3655 Importing keys means the same as running @command{gpg} with the command
3659 @deftypefun gpgme_error_t gpgme_op_import (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3660 The function @code{gpgme_op_import} adds the keys in the data buffer
3661 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
3662 The format of @var{keydata} can be @acronym{ASCII} armored, for example,
3663 but the details are specific to the crypto engine.
3665 After the operation completed successfully, the result can be
3666 retrieved with @code{gpgme_op_import_result}.
3668 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3669 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3670 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3671 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3674 @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3675 The function @code{gpgme_op_import_start} initiates a
3676 @code{gpgme_op_import} operation. It can be completed by calling
3677 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3679 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3680 import could be started successfully, @code{GPG_ERR_INV_VALUE} if
3681 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3682 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3685 @deftypefun gpgme_error_t gpgme_op_import_keys (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{keys}})
3686 The function @code{gpgme_op_import_keys} adds the keys described by the
3687 @code{NULL} terminated array @var{keys} to the key ring of the crypto