1 \input texinfo @c -*- mode: texinfo; coding: latin-1; -*-
2 @documentencoding ISO-8859-1
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 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. It is important to assure that only one thread accesses
652 @acronym{GPGME} functions between a call to this function and after
653 the return from the call to @code{gpgme_check_version}.
655 To enable debugging, you need to call this function as early as
656 possible --- even before @code{gpgme_check_version} --- with the
657 string ``debug'' for @var{name} and @var{value} identical to the value
658 used with the environment variable @code{GPGME_DEBUG}.
660 This function returns @code{0} on success. In contrast to other
661 functions the non-zero return value on failure does not convey any
662 error code. For setting ``debug'' the only possible error cause is an
663 out of memory condition; which would exhibit itself later anyway.
664 Thus the return value may be ignored.
668 After initializing @acronym{GPGME}, you should set the locale
669 information to the locale required for your output terminal. This
670 locale information is needed for example for the curses and Gtk
671 pinentry. Here is an example of a complete initialization:
680 /* Initialize the locale environment. */
681 setlocale (LC_ALL, "");
682 gpgme_check_version (NULL);
683 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
685 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
690 Note that you are highly recommended to initialize the locale settings
691 like this. @acronym{GPGME} can not do this for you because it would
692 not be thread safe. The conditional on LC_MESSAGES is only necessary
693 for portability to W32 systems.
696 @node Signal Handling
697 @section Signal Handling
699 @cindex signal handling
701 The @acronym{GPGME} library communicates with child processes (the
702 crypto engines). If a child process dies unexpectedly, for example
703 due to a bug, or system problem, a @code{SIGPIPE} signal will be
704 delivered to the application. The default action is to abort the
705 program. To protect against this, @code{gpgme_check_version} sets the
706 @code{SIGPIPE} signal action to @code{SIG_IGN}, which means that the
707 signal will be ignored.
709 @acronym{GPGME} will only do that if the signal action for
710 @code{SIGPIPE} is @code{SIG_DEF} at the time
711 @code{gpgme_check_version} is called. If it is something different,
712 @code{GPGME} will take no action.
714 This means that if your application does not install any signal
715 handler for @code{SIGPIPE}, you don't need to take any precautions.
716 If you do install a signal handler for @code{SIGPIPE}, you must be
717 prepared to handle any @code{SIGPIPE} events that occur due to
718 @acronym{GPGME} writing to a defunct pipe. Furthermore, if your
719 application is multi-threaded, and you install a signal action for
720 @code{SIGPIPE}, you must make sure you do this either before
721 @code{gpgme_check_version} is called or afterwards.
724 @node Multi Threading
725 @section Multi Threading
726 @cindex thread-safeness
727 @cindex multi-threading
729 The @acronym{GPGME} library is not entirely thread-safe, but it can
730 still be used in a multi-threaded environment if some care is taken.
731 If the following requirements are met, there should be no race
732 conditions to worry about:
736 @acronym{GPGME} supports the thread libraries pthread and GNU Pth.
737 The support for this has to be enabled at compile time.
738 @acronym{GPGME} will automatically detect the location in which the
739 thread libraries are installed and activate the support for them at
742 Support for other thread libraries is very easy to add. Please
743 contact us if you have the need.
746 If you want to use @acronym{GPGME} with threads, you must link to the
747 right version of the library. The name of the right library is
748 @code{libgpgme-} followed by the name of the thread package you use.
749 For example, if you use GNU Pth, the right name is
750 @code{libgpgme-pth}. Use the Automake macros or
751 @command{gpgme-config} program for simplicity.
755 The function @code{gpgme_check_version} must be called before any
756 other function in the library, because it initializes the thread
757 support subsystem in @acronym{GPGME}. To achieve this in
758 multi-threaded programs, you must synchronize the memory with respect
759 to other threads that also want to use @acronym{GPGME}. For this, it
760 is sufficient to call @code{gpgme_check_version} before creating the
761 other threads using @acronym{GPGME}@footnote{At least this is true for
762 POSIX threads, as @code{pthread_create} is a function that
763 synchronizes memory with respects to other threads. There are many
764 functions which have this property, a complete list can be found in
765 POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the
766 definition of the term ``Memory Synchronization''. For other thread
767 packages other, more relaxed or more strict rules may apply.}.
770 Any @code{gpgme_data_t} and @code{gpgme_ctx_t} object must only be
771 accessed by one thread at a time. If multiple threads want to deal
772 with the same object, the caller has to make sure that operations on
773 that object are fully synchronized.
776 Only one thread at any time is allowed to call @code{gpgme_wait}. If
777 multiple threads call this function, the caller must make sure that
778 all invocations are fully synchronized. It is safe to start
779 asynchronous operations while a thread is running in gpgme_wait.
782 The function @code{gpgme_strerror} is not thread safe. You have to
783 use @code{gpgme_strerror_r} instead.
787 @node Protocols and Engines
788 @chapter Protocols and Engines
791 @cindex crypto engine
793 @cindex crypto backend
795 @acronym{GPGME} supports several cryptographic protocols, however, it
796 does not implement them. Rather it uses backends (also called
797 engines) which implement the protocol. @acronym{GPGME} uses
798 inter-process communication to pass data back and forth between the
799 application and the backend, but the details of the communication
800 protocol and invocation of the backend is completely hidden by the
801 interface. All complexity is handled by @acronym{GPGME}. Where an
802 exchange of information between the application and the backend is
803 necessary, @acronym{GPGME} provides the necessary callback function
804 hooks and further interfaces.
806 @deftp {Data type} {enum gpgme_protocol_t}
807 @tindex gpgme_protocol_t
808 The @code{gpgme_protocol_t} type specifies the set of possible protocol
809 values that are supported by @acronym{GPGME}. The following protocols
813 @item GPGME_PROTOCOL_OpenPGP
814 This specifies the OpenPGP protocol.
816 @item GPGME_PROTOCOL_CMS
817 This specifies the Cryptographic Message Syntax.
819 @item GPGME_PROTOCOL_ASSUAN
820 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
822 @item GPGME_PROTOCOL_G13
823 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
825 @item GPGME_PROTOCOL_UISERVER
826 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
828 @item GPGME_PROTOCOL_UNKNOWN
829 Reserved for future extension. You may use this to indicate that the
830 used protocol is not known to the application. Currently,
831 @acronym{GPGME} does not accept this value in any operation, though,
832 except for @code{gpgme_get_protocol_name}.
837 @deftypefun {const char *} gpgme_get_protocol_name (@w{gpgme_protocol_t @var{protocol}})
838 The function @code{gpgme_get_protocol_name} returns a statically
839 allocated string describing the protocol @var{protocol}, or
840 @code{NULL} if the protocol number is not valid.
844 * Engine Version Check:: Verifying the engine version.
845 * Engine Information:: Obtaining more information about the engines.
846 * Engine Configuration:: Changing the engine configuration.
847 * OpenPGP:: Support for the OpenPGP protocol.
848 * Cryptographic Message Syntax:: Support for the CMS.
852 @node Engine Version Check
853 @section Engine Version Check
854 @cindex version check, of the engines
856 @deftypefun gpgme_error_t gpgme_engine_check_version (@w{gpgme_protocol_t @var{protocol}})
857 The function @code{gpgme_engine_check_version} verifies that the
858 engine implementing the protocol @var{PROTOCOL} is installed in the
859 expected path and meets the version requirement of @acronym{GPGME}.
861 This function returns the error code @code{GPG_ERR_NO_ERROR} if the
862 engine is available and @code{GPG_ERR_INV_ENGINE} if it is not.
866 @node Engine Information
867 @section Engine Information
868 @cindex engine, information about
870 @deftp {Data type} {gpgme_engine_info_t}
871 @tindex gpgme_protocol_t
872 The @code{gpgme_engine_info_t} type specifies a pointer to a structure
873 describing a crypto engine. The structure contains the following
877 @item gpgme_engine_info_t next
878 This is a pointer to the next engine info structure in the linked
879 list, or @code{NULL} if this is the last element.
881 @item gpgme_protocol_t protocol
882 This is the protocol for which the crypto engine is used. You can
883 convert this to a string with @code{gpgme_get_protocol_name} for
886 @item const char *file_name
887 This is a string holding the file name of the executable of the crypto
888 engine. Currently, it is never @code{NULL}, but using @code{NULL} is
889 reserved for future use, so always check before you use it.
891 @item const char *home_dir
892 This is a string holding the directory name of the crypto engine's
893 configuration directory. If it is @code{NULL}, then the default
896 @item const char *version
897 This is a string containing the version number of the crypto engine.
898 It might be @code{NULL} if the version number can not be determined,
899 for example because the executable doesn't exist or is invalid.
901 @item const char *req_version
902 This is a string containing the minimum required version number of the
903 crypto engine for @acronym{GPGME} to work correctly. This is the
904 version number that @code{gpgme_engine_check_version} verifies
905 against. Currently, it is never @code{NULL}, but using @code{NULL} is
906 reserved for future use, so always check before you use it.
910 @deftypefun gpgme_error_t gpgme_get_engine_info (@w{gpgme_engine_info_t *@var{info}})
911 The function @code{gpgme_get_engine_info} returns a linked list of
912 engine info structures in @var{info}. Each info structure describes
913 the defaults of one configured backend.
915 The memory for the info structures is allocated the first time this
916 function is invoked, and must not be freed by the caller.
918 This function returns the error code @code{GPG_ERR_NO_ERROR} if
919 successful, and a system error if the memory could not be allocated.
922 Here is an example how you can provide more diagnostics if you receive
923 an error message which indicates that the crypto engine is invalid.
931 if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
933 gpgme_engine_info_t info;
934 err = gpgme_get_engine_info (&info);
937 while (info && info->protocol != gpgme_get_protocol (ctx))
940 fprintf (stderr, "GPGME compiled without support for protocol %s",
941 gpgme_get_protocol_name (info->protocol));
942 else if (info->file_name && !info->version)
943 fprintf (stderr, "Engine %s not installed properly",
945 else if (info->file_name && info->version && info->req_version)
946 fprintf (stderr, "Engine %s version %s installed, "
947 "but at least version %s required", info->file_name,
948 info->version, info->req_version);
950 fprintf (stderr, "Unknown problem with engine for protocol %s",
951 gpgme_get_protocol_name (info->protocol));
957 @node Engine Configuration
958 @section Engine Configuration
959 @cindex engine, configuration of
960 @cindex configuration of crypto backend
962 You can change the configuration of a backend engine, and thus change
963 the executable program and configuration directory to be used. You
964 can make these changes the default or set them for some contexts
967 @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}})
968 The function @code{gpgme_set_engine_info} changes the default
969 configuration of the crypto engine implementing the protocol
972 @var{file_name} is the file name of the executable program
973 implementing this protocol, and @var{home_dir} is the directory name
974 of the configuration directory for this crypto engine. If
975 @var{home_dir} is @code{NULL}, the engine's default will be used.
977 The new defaults are not applied to already created GPGME contexts.
979 This function returns the error code @code{GPG_ERR_NO_ERROR} if
980 successful, or an eror code on failure.
983 The functions @code{gpgme_ctx_get_engine_info} and
984 @code{gpgme_ctx_set_engine_info} can be used to change the engine
985 configuration per context. @xref{Crypto Engine}.
992 @cindex protocol, GnuPG
993 @cindex engine, GnuPG
995 OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard.
996 This is the first protocol that was supported by @acronym{GPGME}.
998 The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}.
1001 @node Cryptographic Message Syntax
1002 @section Cryptographic Message Syntax
1004 @cindex cryptographic message syntax
1006 @cindex protocol, CMS
1007 @cindex engine, GpgSM
1009 @cindex protocol, S/MIME
1011 @acronym{CMS} is implemented by GpgSM, the S/MIME implementation for
1014 The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}.
1021 The crypto backends support a variety of algorithms used in public key
1022 cryptography.@footnote{Some engines also provide symmetric only
1023 encryption; see the description of the encryption function on how to use
1024 this.} The following sections list the identifiers used to denote such
1028 * Public Key Algorithms:: A list of all public key algorithms.
1029 * Hash Algorithms:: A list of all hash algorithms.
1033 @node Public Key Algorithms
1034 @section Public Key Algorithms
1035 @cindex algorithms, public key
1036 @cindex public key algorithms
1038 Public key algorithms are used for encryption, decryption, signing and
1039 verification of signatures.
1041 @deftp {Data type} {enum gpgme_pubkey_algo_t}
1042 @tindex gpgme_pubkey_algo_t
1043 The @code{gpgme_pubkey_algo_t} type specifies the set of all public key
1044 algorithms that are supported by @acronym{GPGME}. Possible values
1049 This value indicates the RSA (Rivest, Shamir, Adleman) algorithm.
1051 @item GPGME_PK_RSA_E
1052 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
1053 algorithm for encryption and decryption only.
1055 @item GPGME_PK_RSA_S
1056 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
1057 algorithm for signing and verification only.
1060 This value indicates DSA, the Digital Signature Algorithm.
1063 This value indicates ElGamal.
1065 @item GPGME_PK_ELG_E
1066 This value also indicates ElGamal and is used specifically in GnuPG.
1068 @item GPGME_PK_ELG_E
1069 This value also indicates ElGamal and is used specifically in GnuPG.
1071 @item GPGME_PK_ECDSA
1072 This value indicates ECDSA, the Elliptic Curve Digital Signature
1073 Algorithm as defined by FIPS 186-2.
1076 This value indicates ECDH, the Eliptic Curve Diffie-Hellmann encryption
1077 algorithm as defined by the ECC in OpenPGP draft.
1082 @deftypefun {const char *} gpgme_pubkey_algo_name (@w{gpgme_pubkey_algo_t @var{algo}})
1083 The function @code{gpgme_pubkey_algo_name} returns a pointer to a
1084 statically allocated string containing a description of the public key
1085 algorithm @var{algo}. This string can be used to output the name of
1086 the public key algorithm to the user.
1088 If @var{algo} is not a valid public key algorithm, @code{NULL} is
1093 @node Hash Algorithms
1094 @section Hash Algorithms
1095 @cindex algorithms, hash
1096 @cindex algorithms, message digest
1097 @cindex hash algorithms
1098 @cindex message digest algorithms
1100 Hash (message digest) algorithms are used to compress a long message
1101 to make it suitable for public key cryptography.
1103 @deftp {Data type} {enum gpgme_hash_algo_t}
1104 @tindex gpgme_hash_algo_t
1105 The @code{gpgme_hash_algo_t} type specifies the set of all hash algorithms
1106 that are supported by @acronym{GPGME}. Possible values are:
1111 @item GPGME_MD_RMD160
1113 @item GPGME_MD_TIGER
1114 @item GPGME_MD_HAVAL
1115 @item GPGME_MD_SHA256
1116 @item GPGME_MD_SHA384
1117 @item GPGME_MD_SHA512
1119 @item GPGME_MD_CRC32
1120 @item GPGME_MD_CRC32_RFC1510
1121 @item GPGME_MD_CRC24_RFC2440
1125 @deftypefun {const char *} gpgme_hash_algo_name (@w{gpgme_hash_algo_t @var{algo}})
1126 The function @code{gpgme_hash_algo_name} returns a pointer to a
1127 statically allocated string containing a description of the hash
1128 algorithm @var{algo}. This string can be used to output the name of
1129 the hash algorithm to the user.
1131 If @var{algo} is not a valid hash algorithm, @code{NULL} is returned.
1135 @node Error Handling
1136 @chapter Error Handling
1137 @cindex error handling
1139 Many functions in @acronym{GPGME} can return an error if they fail.
1140 For this reason, the application should always catch the error
1141 condition and take appropriate measures, for example by releasing the
1142 resources and passing the error up to the caller, or by displaying a
1143 descriptive message to the user and cancelling the operation.
1145 Some error values do not indicate a system error or an error in the
1146 operation, but the result of an operation that failed properly. For
1147 example, if you try to decrypt a tempered message, the decryption will
1148 fail. Another error value actually means that the end of a data
1149 buffer or list has been reached. The following descriptions explain
1150 for many error codes what they mean usually. Some error values have
1151 specific meanings if returned by a certain functions. Such cases are
1152 described in the documentation of those functions.
1154 @acronym{GPGME} uses the @code{libgpg-error} library. This allows to
1155 share the error codes with other components of the GnuPG system, and
1156 thus pass error values transparently from the crypto engine, or some
1157 helper application of the crypto engine, to the user. This way no
1158 information is lost. As a consequence, @acronym{GPGME} does not use
1159 its own identifiers for error codes, but uses those provided by
1160 @code{libgpg-error}. They usually start with @code{GPG_ERR_}.
1162 However, @acronym{GPGME} does provide aliases for the functions
1163 defined in libgpg-error, which might be preferred for name space
1167 * Error Values:: The error value and what it means.
1168 * Error Sources:: A list of important error sources.
1169 * Error Codes:: A list of important error codes.
1170 * Error Strings:: How to get a descriptive string from a value.
1175 @section Error Values
1176 @cindex error values
1178 @cindex error sources
1180 @deftp {Data type} {gpgme_err_code_t}
1181 The @code{gpgme_err_code_t} type is an alias for the @code{libgpg-error}
1182 type @code{gpg_err_code_t}. The error code indicates the type of an
1183 error, or the reason why an operation failed.
1185 A list of important error codes can be found in the next section.
1188 @deftp {Data type} {gpgme_err_source_t}
1189 The @code{gpgme_err_source_t} type is an alias for the
1190 @code{libgpg-error} type @code{gpg_err_source_t}. The error source
1191 has not a precisely defined meaning. Sometimes it is the place where
1192 the error happened, sometimes it is the place where an error was
1193 encoded into an error value. Usually the error source will give an
1194 indication to where to look for the problem. This is not always true,
1195 but it is attempted to achieve this goal.
1197 A list of important error sources can be found in the next section.
1200 @deftp {Data type} {gpgme_error_t}
1201 The @code{gpgme_error_t} type is an alias for the @code{libgpg-error}
1202 type @code{gpg_error_t}. An error value like this has always two
1203 components, an error code and an error source. Both together form the
1206 Thus, the error value can not be directly compared against an error
1207 code, but the accessor functions described below must be used.
1208 However, it is guaranteed that only 0 is used to indicate success
1209 (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of
1210 the error value are set to 0, too.
1212 Note that in @acronym{GPGME}, the error source is used purely for
1213 diagnostical purposes. Only the error code should be checked to test
1214 for a certain outcome of a function. The manual only documents the
1215 error code part of an error value. The error source is left
1216 unspecified and might be anything.
1219 @deftypefun {static inline gpgme_err_code_t} gpgme_err_code (@w{gpgme_error_t @var{err}})
1220 The static inline function @code{gpgme_err_code} returns the
1221 @code{gpgme_err_code_t} component of the error value @var{err}. This
1222 function must be used to extract the error code from an error value in
1223 order to compare it with the @code{GPG_ERR_*} error code macros.
1226 @deftypefun {static inline gpgme_err_source_t} gpgme_err_source (@w{gpgme_error_t @var{err}})
1227 The static inline function @code{gpgme_err_source} returns the
1228 @code{gpgme_err_source_t} component of the error value @var{err}. This
1229 function must be used to extract the error source from an error value in
1230 order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros.
1233 @deftypefun {static inline gpgme_error_t} gpgme_err_make (@w{gpgme_err_source_t @var{source}}, @w{gpgme_err_code_t @var{code}})
1234 The static inline function @code{gpgme_err_make} returns the error
1235 value consisting of the error source @var{source} and the error code
1238 This function can be used in callback functions to construct an error
1239 value to return it to the library.
1242 @deftypefun {static inline gpgme_error_t} gpgme_error (@w{gpgme_err_code_t @var{code}})
1243 The static inline function @code{gpgme_error} returns the error value
1244 consisting of the default error source and the error code @var{code}.
1246 For @acronym{GPGME} applications, the default error source is
1247 @code{GPG_ERR_SOURCE_USER_1}. You can define
1248 @code{GPGME_ERR_SOURCE_DEFAULT} before including @file{gpgme.h} to
1249 change this default.
1251 This function can be used in callback functions to construct an error
1252 value to return it to the library.
1255 The @code{libgpg-error} library provides error codes for all system
1256 error numbers it knows about. If @var{err} is an unknown error
1257 number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The
1258 following functions can be used to construct error values from system
1261 @deftypefun {gpgme_error_t} gpgme_err_make_from_errno (@w{gpgme_err_source_t @var{source}}, @w{int @var{err}})
1262 The function @code{gpgme_err_make_from_errno} is like
1263 @code{gpgme_err_make}, but it takes a system error like @code{errno}
1264 instead of a @code{gpgme_err_code_t} error code.
1267 @deftypefun {gpgme_error_t} gpgme_error_from_errno (@w{int @var{err}})
1268 The function @code{gpgme_error_from_errno} is like @code{gpgme_error},
1269 but it takes a system error like @code{errno} instead of a
1270 @code{gpgme_err_code_t} error code.
1273 Sometimes you might want to map system error numbers to error codes
1274 directly, or map an error code representing a system error back to the
1275 system error number. The following functions can be used to do that.
1277 @deftypefun {gpgme_err_code_t} gpgme_err_code_from_errno (@w{int @var{err}})
1278 The function @code{gpgme_err_code_from_errno} returns the error code
1279 for the system error @var{err}. If @var{err} is not a known system
1280 error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}.
1283 @deftypefun {int} gpgme_err_code_to_errno (@w{gpgme_err_code_t @var{err}})
1284 The function @code{gpgme_err_code_to_errno} returns the system error
1285 for the error code @var{err}. If @var{err} is not an error code
1286 representing a system error, or if this system error is not defined on
1287 this system, the function returns @code{0}.
1292 @section Error Sources
1293 @cindex error codes, list of
1295 The library @code{libgpg-error} defines an error source for every
1296 component of the GnuPG system. The error source part of an error
1297 value is not well defined. As such it is mainly useful to improve the
1298 diagnostic error message for the user.
1300 If the error code part of an error value is @code{0}, the whole error
1301 value will be @code{0}. In this case the error source part is of
1302 course @code{GPG_ERR_SOURCE_UNKNOWN}.
1304 The list of error sources that might occur in applications using
1308 @item GPG_ERR_SOURCE_UNKNOWN
1309 The error source is not known. The value of this error source is
1312 @item GPG_ERR_SOURCE_GPGME
1313 The error source is @acronym{GPGME} itself. This is the default for
1314 errors that occur in the @acronym{GPGME} library.
1316 @item GPG_ERR_SOURCE_GPG
1317 The error source is GnuPG, which is the crypto engine used for the
1320 @item GPG_ERR_SOURCE_GPGSM
1321 The error source is GPGSM, which is the crypto engine used for the
1324 @item GPG_ERR_SOURCE_GCRYPT
1325 The error source is @code{libgcrypt}, which is used by crypto engines
1326 to perform cryptographic operations.
1328 @item GPG_ERR_SOURCE_GPGAGENT
1329 The error source is @command{gpg-agent}, which is used by crypto
1330 engines to perform operations with the secret key.
1332 @item GPG_ERR_SOURCE_PINENTRY
1333 The error source is @command{pinentry}, which is used by
1334 @command{gpg-agent} to query the passphrase to unlock a secret key.
1336 @item GPG_ERR_SOURCE_SCD
1337 The error source is the SmartCard Daemon, which is used by
1338 @command{gpg-agent} to delegate operations with the secret key to a
1341 @item GPG_ERR_SOURCE_KEYBOX
1342 The error source is @code{libkbx}, a library used by the crypto
1343 engines to manage local keyrings.
1345 @item GPG_ERR_SOURCE_USER_1
1346 @item GPG_ERR_SOURCE_USER_2
1347 @item GPG_ERR_SOURCE_USER_3
1348 @item GPG_ERR_SOURCE_USER_4
1349 These error sources are not used by any GnuPG component and can be
1350 used by other software. For example, applications using
1351 @acronym{GPGME} can use them to mark error values coming from callback
1352 handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors
1353 created with @code{gpgme_error} and @code{gpgme_error_from_errno},
1354 unless you define @code{GPGME_ERR_SOURCE_DEFAULT} before including
1360 @section Error Codes
1361 @cindex error codes, list of
1363 The library @code{libgpg-error} defines many error values. Most of
1364 them are not used by @code{GPGME} directly, but might be returned by
1365 @acronym{GPGME} because it received them from the crypto engine. The
1366 below list only includes such error codes that have a specific meaning
1367 in @code{GPGME}, or which are so common that you should know about
1372 This value indicates the end of a list, buffer or file.
1374 @item GPG_ERR_NO_ERROR
1375 This value indicates success. The value of this error code is
1376 @code{0}. Also, it is guaranteed that an error value made from the
1377 error code @code{0} will be @code{0} itself (as a whole). This means
1378 that the error source information is lost for this error code,
1379 however, as this error code indicates that no error occured, this is
1380 generally not a problem.
1382 @item GPG_ERR_GENERAL
1383 This value means that something went wrong, but either there is not
1384 enough information about the problem to return a more useful error
1385 value, or there is no separate error value for this type of problem.
1387 @item GPG_ERR_ENOMEM
1388 This value means that an out-of-memory condition occurred.
1391 System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
1394 @item GPG_ERR_INV_VALUE
1395 This value means that some user provided data was out of range. This
1396 can also refer to objects. For example, if an empty
1397 @code{gpgme_data_t} object was expected, but one containing data was
1398 provided, this error value is returned.
1400 @item GPG_ERR_UNUSABLE_PUBKEY
1401 This value means that some recipients for a message were invalid.
1403 @item GPG_ERR_UNUSABLE_SECKEY
1404 This value means that some signers were invalid.
1406 @item GPG_ERR_NO_DATA
1407 This value means that a @code{gpgme_data_t} object which was expected
1408 to have content was found empty.
1410 @item GPG_ERR_CONFLICT
1411 This value means that a conflict of some sort occurred.
1413 @item GPG_ERR_NOT_IMPLEMENTED
1414 This value indicates that the specific function (or operation) is not
1415 implemented. This error should never happen. It can only occur if
1416 you use certain values or configuration options which do not work,
1417 but for which we think that they should work at some later time.
1419 @item GPG_ERR_DECRYPT_FAILED
1420 This value indicates that a decryption operation was unsuccessful.
1422 @item GPG_ERR_BAD_PASSPHRASE
1423 This value means that the user did not provide a correct passphrase
1426 @item GPG_ERR_CANCELED
1427 This value means that the operation was canceled.
1429 @item GPG_ERR_INV_ENGINE
1430 This value means that the engine that implements the desired protocol
1431 is currently not available. This can either be because the sources
1432 were configured to exclude support for this engine, or because the
1433 engine is not installed properly.
1435 @item GPG_ERR_AMBIGUOUS_NAME
1436 This value indicates that a user ID or other specifier did not specify
1439 @item GPG_ERR_WRONG_KEY_USAGE
1440 This value indicates that a key is not used appropriately.
1442 @item GPG_ERR_CERT_REVOKED
1443 This value indicates that a key signature was revoced.
1445 @item GPG_ERR_CERT_EXPIRED
1446 This value indicates that a key signature expired.
1448 @item GPG_ERR_NO_CRL_KNOWN
1449 This value indicates that no certificate revocation list is known for
1452 @item GPG_ERR_NO_POLICY_MATCH
1453 This value indicates that a policy issue occured.
1455 @item GPG_ERR_NO_SECKEY
1456 This value indicates that no secret key for the user ID is available.
1458 @item GPG_ERR_MISSING_CERT
1459 This value indicates that a key could not be imported because the
1460 issuer certificate is missing.
1462 @item GPG_ERR_BAD_CERT_CHAIN
1463 This value indicates that a key could not be imported because its
1464 certificate chain is not good, for example it could be too long.
1466 @item GPG_ERR_UNSUPPORTED_ALGORITHM
1467 This value means a verification failed because the cryptographic
1468 algorithm is not supported by the crypto backend.
1470 @item GPG_ERR_BAD_SIGNATURE
1471 This value means a verification failed because the signature is bad.
1473 @item GPG_ERR_NO_PUBKEY
1474 This value means a verification failed because the public key is not
1477 @item GPG_ERR_USER_1
1478 @item GPG_ERR_USER_2
1480 @item GPG_ERR_USER_16
1481 These error codes are not used by any GnuPG component and can be
1482 freely used by other software. Applications using @acronym{GPGME}
1483 might use them to mark specific errors returned by callback handlers
1484 if no suitable error codes (including the system errors) for
1485 these errors exist already.
1490 @section Error Strings
1491 @cindex error values, printing of
1492 @cindex error codes, printing of
1493 @cindex error sources, printing of
1494 @cindex error strings
1496 @deftypefun {const char *} gpgme_strerror (@w{gpgme_error_t @var{err}})
1497 The function @code{gpgme_strerror} returns a pointer to a statically
1498 allocated string containing a description of the error code contained
1499 in the error value @var{err}. This string can be used to output a
1500 diagnostic message to the user.
1502 This function is not thread safe. Use @code{gpgme_strerror_r} in
1503 multi-threaded programs.
1507 @deftypefun {int} gpgme_strerror_r (@w{gpgme_error_t @var{err}}, @w{char *@var{buf}}, @w{size_t @var{buflen}})
1508 The function @code{gpgme_strerror_r} returns the error string for
1509 @var{err} in the user-supplied buffer @var{buf} of size @var{buflen}.
1510 This function is, in contrast to @code{gpgme_strerror}, thread-safe if
1511 a thread-safe @code{strerror_r} function is provided by the system.
1512 If the function succeeds, 0 is returned and @var{buf} contains the
1513 string describing the error. If the buffer was not large enough,
1514 ERANGE is returned and @var{buf} contains as much of the beginning of
1515 the error string as fits into the buffer.
1519 @deftypefun {const char *} gpgme_strsource (@w{gpgme_error_t @var{err}})
1520 The function @code{gpgme_strerror} returns a pointer to a statically
1521 allocated string containing a description of the error source
1522 contained in the error value @var{err}. This string can be used to
1523 output a diagnostic message to the user.
1526 The following example illustrates the use of @code{gpgme_strerror}:
1530 gpgme_error_t err = gpgme_new (&ctx);
1533 fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
1534 argv[0], gpgme_strsource (err), gpgme_strerror (err));
1540 @node Exchanging Data
1541 @chapter Exchanging Data
1542 @cindex data, exchanging
1544 A lot of data has to be exchanged between the user and the crypto
1545 engine, like plaintext messages, ciphertext, signatures and
1546 information about the keys. The technical details about exchanging
1547 the data information are completely abstracted by @acronym{GPGME}.
1548 The user provides and receives the data via @code{gpgme_data_t} objects,
1549 regardless of the communication protocol between @acronym{GPGME} and
1550 the crypto engine in use.
1552 @deftp {Data type} {gpgme_data_t}
1553 The @code{gpgme_data_t} type is a handle for a container for generic
1554 data, which is used by @acronym{GPGME} to exchange data with the user.
1557 @code{gpgme_data_t} objects do not provide notifications on events.
1558 It is assumed that read and write operations are blocking until data
1559 is available. If this is undesirable, the application must ensure
1560 that all GPGME data operations always have data available, for example
1561 by using memory buffers or files rather than pipes or sockets. This
1562 might be relevant, for example, if the external event loop mechanism
1565 @deftp {Data type} {gpgme_off_t}
1566 On POSIX platforms the @code{gpgme_off_t} type is an alias for
1567 @code{off_t}; it may be used interchangeable. On Windows platforms
1568 @code{gpgme_off_t} is defined as a long (i.e. 32 bit) for 32 bit
1569 Windows and as a 64 bit signed integer for 64 bit Windows.
1572 @deftp {Data type} {gpgme_ssize_t}
1573 The @code{gpgme_ssize_t} type is an alias for @code{ssize_t}. It has
1574 only been introduced to overcome portability problems pertaining to
1575 the declaration of @code{ssize_t} by different toolchains.
1580 * Creating Data Buffers:: Creating new data buffers.
1581 * Destroying Data Buffers:: Releasing data buffers.
1582 * Manipulating Data Buffers:: Operations on data buffers.
1586 @node Creating Data Buffers
1587 @section Creating Data Buffers
1588 @cindex data buffer, creation
1590 Data objects can be based on memory, files, or callback functions
1591 provided by the user. Not all operations are supported by all
1596 * Memory Based Data Buffers:: Creating memory based data buffers.
1597 * File Based Data Buffers:: Creating file based data buffers.
1598 * Callback Based Data Buffers:: Creating callback based data buffers.
1602 @node Memory Based Data Buffers
1603 @subsection Memory Based Data Buffers
1605 Memory based data objects store all data in allocated memory. This is
1606 convenient, but only practical for an amount of data that is a
1607 fraction of the available physical memory. The data has to be copied
1608 from its source and to its destination, which can often be avoided by
1609 using one of the other data object
1611 @deftypefun gpgme_error_t gpgme_data_new (@w{gpgme_data_t *@var{dh}})
1612 The function @code{gpgme_data_new} creates a new @code{gpgme_data_t}
1613 object and returns a handle for it in @var{dh}. The data object is
1614 memory based and initially empty.
1616 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1617 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1618 @var{dh} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1619 enough memory is available.
1622 @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}})
1623 The function @code{gpgme_data_new_from_mem} creates a new
1624 @code{gpgme_data_t} object and fills it with @var{size} bytes starting
1627 If @var{copy} is not zero, a private copy of the data is made. If
1628 @var{copy} is zero, the data is taken from the specified buffer as
1629 needed, and the user has to ensure that the buffer remains valid for
1630 the whole life span of the data object.
1632 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1633 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1634 @var{dh} or @var{buffer} is not a valid pointer, and
1635 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1638 @deftypefun gpgme_error_t gpgme_data_new_from_file (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}})
1639 The function @code{gpgme_data_new_from_file} creates a new
1640 @code{gpgme_data_t} object and fills it with the content of the file
1643 If @var{copy} is not zero, the whole file is read in at initialization
1644 time and the file is not used anymore after that. This is the only
1645 mode supported currently. Later, a value of zero for @var{copy} might
1646 cause all reads to be delayed until the data is needed, but this is
1647 not yet implemented.
1649 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1650 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1651 @var{dh} or @var{filename} is not a valid pointer,
1652 @code{GPG_ERR_NOT_IMPLEMENTED} if @var{code} is zero, and
1653 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1656 @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}})
1657 The function @code{gpgme_data_new_from_filepart} creates a new
1658 @code{gpgme_data_t} object and fills it with a part of the file specified
1659 by @var{filename} or @var{fp}.
1661 Exactly one of @var{filename} and @var{fp} must be non-zero, the other
1662 must be zero. The argument that is not zero specifies the file from
1663 which @var{length} bytes are read into the data object, starting from
1666 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1667 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1668 @var{dh} and exactly one of @var{filename} and @var{fp} is not a valid
1669 pointer, and @code{GPG_ERR_ENOMEM} if not enough memory is available.
1673 @node File Based Data Buffers
1674 @subsection File Based Data Buffers
1676 File based data objects operate directly on file descriptors or
1677 streams. Only a small amount of data is stored in core at any time,
1678 so the size of the data objects is not limited by @acronym{GPGME}.
1680 @deftypefun gpgme_error_t gpgme_data_new_from_fd (@w{gpgme_data_t *@var{dh}}, @w{int @var{fd}})
1681 The function @code{gpgme_data_new_from_fd} creates a new
1682 @code{gpgme_data_t} object and uses the file descriptor @var{fd} to read
1683 from (if used as an input data object) and write to (if used as an
1684 output data object).
1686 When using the data object as an input buffer, the function might read
1687 a bit more from the file descriptor than is actually needed by the
1688 crypto engine in the desired operation because of internal buffering.
1690 Note that GPGME assumes that the file descriptor is set to blocking
1691 mode. Errors during I/O operations, except for EINTR, are usually
1692 fatal for crypto operations.
1694 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1695 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1696 enough memory is available.
1699 @deftypefun gpgme_error_t gpgme_data_new_from_stream (@w{gpgme_data_t *@var{dh}}, @w{FILE *@var{stream}})
1700 The function @code{gpgme_data_new_from_stream} creates a new
1701 @code{gpgme_data_t} object and uses the I/O stream @var{stream} to read
1702 from (if used as an input data object) and write to (if used as an
1703 output data object).
1705 When using the data object as an input buffer, the function might read
1706 a bit more from the stream than is actually needed by the crypto
1707 engine in the desired operation because of internal buffering.
1709 Note that GPGME assumes that the stream is in blocking mode. Errors
1710 during I/O operations, except for EINTR, are usually fatal for crypto
1713 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1714 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1715 enough memory is available.
1719 @node Callback Based Data Buffers
1720 @subsection Callback Based Data Buffers
1722 If neither memory nor file based data objects are a good fit for your
1723 application, you can implement the functions a data object provides
1724 yourself and create a data object from these callback functions.
1726 @deftp {Data type} {ssize_t (*gpgme_data_read_cb_t) (@w{void *@var{handle}}, @w{void @var{*buffer}}, @w{size_t @var{size}})}
1727 @tindex gpgme_data_read_cb_t
1728 The @code{gpgme_data_read_cb_t} type is the type of functions which
1729 @acronym{GPGME} calls if it wants to read data from a user-implemented
1730 data object. The function should read up to @var{size} bytes from the
1731 current read position into the space starting at @var{buffer}. The
1732 @var{handle} is provided by the user at data object creation time.
1734 Note that GPGME assumes that the read blocks until data is available.
1735 Errors during I/O operations, except for EINTR, are usually fatal for
1738 The function should return the number of bytes read, 0 on EOF, and -1
1739 on error. If an error occurs, @var{errno} should be set to describe
1740 the type of the error.
1743 @deftp {Data type} {ssize_t (*gpgme_data_write_cb_t) (@w{void *@var{handle}}, @w{const void @var{*buffer}}, @w{size_t @var{size}})}
1744 @tindex gpgme_data_write_cb_t
1745 The @code{gpgme_data_write_cb_t} type is the type of functions which
1746 @acronym{GPGME} calls if it wants to write data to a user-implemented
1747 data object. The function should write up to @var{size} bytes to the
1748 current write position from the space starting at @var{buffer}. The
1749 @var{handle} is provided by the user at data object creation time.
1751 Note that GPGME assumes that the write blocks until data is available.
1752 Errors during I/O operations, except for EINTR, are usually fatal for
1755 The function should return the number of bytes written, and -1 on
1756 error. If an error occurs, @var{errno} should be set to describe the
1760 @deftp {Data type} {off_t (*gpgme_data_seek_cb_t) (@w{void *@var{handle}}, @w{off_t @var{offset}}, @w{int @var{whence}})}
1761 @tindex gpgme_data_seek_cb_t
1762 The @code{gpgme_data_seek_cb_t} type is the type of functions which
1763 @acronym{GPGME} calls if it wants to change the current read/write
1764 position in a user-implemented data object, just like the @code{lseek}
1767 The function should return the new read/write position, and -1 on
1768 error. If an error occurs, @var{errno} should be set to describe the
1772 @deftp {Data type} {void (*gpgme_data_release_cb_t) (@w{void *@var{handle}})}
1773 @tindex gpgme_data_release_cb_t
1774 The @code{gpgme_data_release_cb_t} type is the type of functions which
1775 @acronym{GPGME} calls if it wants to destroy a user-implemented data
1776 object. The @var{handle} is provided by the user at data object
1780 @deftp {Data type} {struct gpgme_data_cbs}
1781 This structure is used to store the data callback interface functions
1782 described above. It has the following members:
1785 @item gpgme_data_read_cb_t read
1786 This is the function called by @acronym{GPGME} to read data from the
1787 data object. It is only required for input data object.
1789 @item gpgme_data_write_cb_t write
1790 This is the function called by @acronym{GPGME} to write data to the
1791 data object. It is only required for output data object.
1793 @item gpgme_data_seek_cb_t seek
1794 This is the function called by @acronym{GPGME} to change the current
1795 read/write pointer in the data object (if available). It is optional.
1797 @item gpgme_data_release_cb_t release
1798 This is the function called by @acronym{GPGME} to release a data
1799 object. It is optional.
1803 @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}})
1804 The function @code{gpgme_data_new_from_cbs} creates a new
1805 @code{gpgme_data_t} object and uses the user-provided callback functions
1806 to operate on the data object.
1808 The handle @var{handle} is passed as first argument to the callback
1809 functions. This can be used to identify this data object.
1811 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1812 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1813 enough memory is available.
1816 The following interface is deprecated and only provided for backward
1817 compatibility. Don't use it. It will be removed in a future version
1820 @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}})
1821 The function @code{gpgme_data_new_with_read_cb} creates a new
1822 @code{gpgme_data_t} object and uses the callback function @var{readfunc}
1823 to retrieve the data on demand. As the callback function can supply
1824 the data in any way it wants, this is the most flexible data type
1825 @acronym{GPGME} provides. However, it can not be used to write data.
1827 The callback function receives @var{hook_value} as its first argument
1828 whenever it is invoked. It should return up to @var{count} bytes in
1829 @var{buffer}, and return the number of bytes actually read in
1830 @var{nread}. It may return @code{0} in @var{nread} if no data is
1831 currently available. To indicate @code{EOF} the function should
1832 return with an error code of @code{-1} and set @var{nread} to
1833 @code{0}. The callback function may support to reset its internal
1834 read pointer if it is invoked with @var{buffer} and @var{nread} being
1835 @code{NULL} and @var{count} being @code{0}.
1837 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1838 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1839 @var{dh} or @var{readfunc} is not a valid pointer, and
1840 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1844 @node Destroying Data Buffers
1845 @section Destroying Data Buffers
1846 @cindex data buffer, destruction
1848 @deftypefun void gpgme_data_release (@w{gpgme_data_t @var{dh}})
1849 The function @code{gpgme_data_release} destroys the data object with
1850 the handle @var{dh}. It releases all associated resources that were
1851 not provided by the user in the first place.
1854 @deftypefun {char *} gpgme_data_release_and_get_mem (@w{gpgme_data_t @var{dh}}, @w{size_t *@var{length}})
1855 The function @code{gpgme_data_release_and_get_mem} is like
1856 @code{gpgme_data_release}, except that it returns the data buffer and
1857 its length that was provided by the object.
1859 The user has to release the buffer with @code{gpgme_free}. In case
1860 the user provided the data buffer in non-copy mode, a copy will be
1861 made for this purpose.
1863 In case an error returns, or there is no suitable data buffer that can
1864 be returned to the user, the function will return @code{NULL}. In any
1865 case, the data object @var{dh} is destroyed.
1869 @deftypefun void gpgme_free (@w{void *@var{buffer}})
1870 The function @code{gpgme_free} releases the memory returned by
1871 @code{gpgme_data_release_and_get_mem}. It should be used instead of
1872 the system libraries @code{free} function in case different allocators
1873 are used in a single program.
1877 @node Manipulating Data Buffers
1878 @section Manipulating Data Buffers
1879 @cindex data buffer, manipulation
1881 Data buffers contain data and meta-data. The following operations can
1882 be used to manipulate both.
1886 * Data Buffer I/O Operations:: I/O operations on data buffers.
1887 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
1888 * Data Buffer Convenience:: Convenience fucntion for data buffers.
1892 @node Data Buffer I/O Operations
1893 @subsection Data Buffer I/O Operations
1894 @cindex data buffer, I/O operations
1895 @cindex data buffer, read
1896 @cindex data buffer, write
1897 @cindex data buffer, seek
1899 @deftypefun ssize_t gpgme_data_read (@w{gpgme_data_t @var{dh}}, @w{void *@var{buffer}}, @w{size_t @var{length}})
1900 The function @code{gpgme_data_read} reads up to @var{length} bytes
1901 from the data object with the handle @var{dh} into the space starting
1904 If no error occurs, the actual amount read is returned. If the end of
1905 the data object is reached, the function returns 0.
1907 In all other cases, the function returns -1 and sets @var{errno}.
1910 @deftypefun ssize_t gpgme_data_write (@w{gpgme_data_t @var{dh}}, @w{const void *@var{buffer}}, @w{size_t @var{size}})
1911 The function @code{gpgme_data_write} writes up to @var{size} bytes
1912 starting from @var{buffer} into the data object with the handle
1913 @var{dh} at the current write position.
1915 The function returns the number of bytes actually written, or -1 if an
1916 error occurs. If an error occurs, @var{errno} is set.
1919 @deftypefun off_t gpgme_data_seek (@w{gpgme_data_t @var{dh}}, @w{off_t @var{offset}}, @w{int @var{whence}})
1920 The function @code{gpgme_data_seek} changes the current read/write
1923 The @var{whence} argument specifies how the @var{offset} should be
1924 interpreted. It must be one of the following symbolic constants:
1928 Specifies that @var{offset} is a count of characters from the
1929 beginning of the data object.
1932 Specifies that @var{offset} is a count of characters from the current
1933 file position. This count may be positive or negative.
1936 Specifies that @var{offset} is a count of characters from the end of
1937 the data object. A negative count specifies a position within the
1938 current extent of the data object; a positive count specifies a
1939 position past the current end. If you set the position past the
1940 current end, and actually write data, you will extend the data object
1941 with zeros up to that position.
1944 If successful, the function returns the resulting file position,
1945 measured in bytes from the beginning of the data object. You can use
1946 this feature together with @code{SEEK_CUR} to read the current
1947 read/write position.
1949 If the function fails, -1 is returned and @var{errno} is set.
1952 The following function is deprecated and should not be used. It will
1953 be removed in a future version of @acronym{GPGME}.
1955 @deftypefun gpgme_error_t gpgme_data_rewind (@w{gpgme_data_t @var{dh}})
1956 The function @code{gpgme_data_rewind} is equivalent to:
1959 return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
1960 ? gpgme_error_from_errno (errno) : 0;
1967 @node Data Buffer Meta-Data
1968 @subsection Data Buffer Meta-Data
1969 @cindex data buffer, meta-data
1970 @cindex data buffer, file name
1971 @cindex data buffer, encoding
1973 @deftypefun {char *} gpgme_data_get_file_name (@w{gpgme_data_t @var{dh}})
1974 The function @code{gpgme_data_get_file_name} returns a pointer to a
1975 string containing the file name associated with the data object. The
1976 file name will be stored in the output when encrypting or signing the
1977 data and will be returned to the user when decrypting or verifying the
1980 If no error occurs, the string containing the file name is returned.
1981 Otherwise, @code{NULL} will be returned.
1985 @deftypefun gpgme_error_t gpgme_data_set_file_name (@w{gpgme_data_t @var{dh}}, @w{const char *@var{file_name}})
1986 The function @code{gpgme_data_set_file_name} sets the file name
1987 associated with the data object. The file name will be stored in the
1988 output when encrypting or signing the data and will be returned to the
1989 user when decrypting or verifying the output data.
1991 The function returns the error code @code{GPG_ERR_INV_VALUE} if
1992 @var{dh} is not a valid pointer and @code{GPG_ERR_ENOMEM} if not
1993 enough memory is available.
1997 @deftp {Data type} {enum gpgme_data_encoding_t}
1998 @tindex gpgme_data_encoding_t
1999 The @code{gpgme_data_encoding_t} type specifies the encoding of a
2000 @code{gpgme_data_t} object. For input data objects, the encoding is
2001 useful to give the backend a hint on the type of data. For output
2002 data objects, the encoding can specify the output data format on
2003 certain operations. Please note that not all backends support all
2004 encodings on all operations. The following data types are available:
2007 @item GPGME_DATA_ENCODING_NONE
2008 This specifies that the encoding is not known. This is the default
2009 for a new data object. The backend will try its best to detect the
2010 encoding automatically.
2012 @item GPGME_DATA_ENCODING_BINARY
2013 This specifies that the data is encoding in binary form; i.e. there is
2014 no special encoding.
2016 @item GPGME_DATA_ENCODING_BASE64
2017 This specifies that the data is encoded using the Base-64 encoding
2018 scheme as used by @acronym{MIME} and other protocols.
2020 @item GPGME_DATA_ENCODING_ARMOR
2021 This specifies that the data is encoded in an armored form as used by
2024 @item GPGME_DATA_ENCODING_URL
2025 The data is a list of linefeed delimited URLs. This is only useful with
2026 @code{gpgme_op_import}.
2028 @item GPGME_DATA_ENCODING_URL0
2029 The data is a list of binary zero delimited URLs. This is only useful
2030 with @code{gpgme_op_import}.
2032 @item GPGME_DATA_ENCODING_URLESC
2033 The data is a list of linefeed delimited URLs with all control and space
2034 characters percent escaped. This mode is is not yet implemented.
2039 @deftypefun gpgme_data_encoding_t gpgme_data_get_encoding (@w{gpgme_data_t @var{dh}})
2040 The function @code{gpgme_data_get_encoding} returns the encoding of
2041 the data object with the handle @var{dh}. If @var{dh} is not a valid
2042 pointer (e.g. @code{NULL}) @code{GPGME_DATA_ENCODING_NONE} is
2046 @deftypefun gpgme_error_t gpgme_data_set_encoding (@w{gpgme_data_t @var{dh}, gpgme_data_encoding_t @var{enc}})
2047 The function @code{gpgme_data_set_encoding} changes the encoding of
2048 the data object with the handle @var{dh} to @var{enc}.
2051 @node Data Buffer Convenience
2052 @subsection Data Buffer Convenience Functions
2053 @cindex data buffer, convenience
2054 @cindex type of data
2057 @deftp {Data type} {enum gpgme_data_type_t}
2058 @tindex gpgme_data_type_t
2059 The @code{gpgme_data_type_t} type is used to return the detected type
2060 of the content of a data buffer.
2064 @item GPGME_DATA_TYPE_INVALID
2065 This is returned by @code{gpgme_data_identify} if it was not possible
2066 to identify the data. Reasons for this might be a non-seekable stream
2067 or a memory problem. The value is 0.
2068 @item GPGME_DATA_TYPE_UNKNOWN
2069 The type of the data is not known.
2070 @item GPGME_DATA_TYPE_PGP_SIGNED
2071 The data is an OpenPGP signed message. This may be a binary
2072 signature, a detached one or a cleartext signature.
2073 @item GPGME_DATA_TYPE_PGP_OTHER
2074 This is a generic OpenPGP message. In most cases this will be
2076 @item GPGME_DATA_TYPE_PGP_KEY
2077 This is an OpenPGP key (private or public).
2078 @item GPGME_DATA_TYPE_CMS_SIGNED
2079 This is a CMS signed message.
2080 @item GPGME_DATA_TYPE_CMS_ENCRYPTED
2081 This is a CMS encrypted (enveloped data) message.
2082 @item GPGME_DATA_TYPE_CMS_OTHER
2083 This is used for other CMS message types.
2084 @item GPGME_DATA_TYPE_X509_CERT
2085 The data is a X.509 certificate
2086 @item GPGME_DATA_TYPE_PKCS12
2087 The data is a PKCS#12 message. This is commonly used to exchange
2088 private keys for X.509.
2091 @deftypefun gpgme_data_type_t gpgme_data_identify (@w{gpgme_data_t @var{dh}})
2092 The function @code{gpgme_data_identify} returns the type of the data
2093 with the handle @var{dh}. If it is not possible to perform the
2094 identification, the function returns zero
2095 (@code{GPGME_DATA_TYPE_INVALID}). Note that depending on how the data
2096 object has been created the identification may not be possible or the
2097 data object may change its internal state (file pointer moved). For
2098 file or memory based data object, the state should not change.
2109 All cryptographic operations in @acronym{GPGME} are performed within a
2110 context, which contains the internal state of the operation as well as
2111 configuration parameters. By using several contexts you can run
2112 several cryptographic operations in parallel, with different
2115 @deftp {Data type} {gpgme_ctx_t}
2116 The @code{gpgme_ctx_t} type is a handle for a @acronym{GPGME} context,
2117 which is used to hold the configuration, status and result of
2118 cryptographic operations.
2122 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
2123 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
2124 * Result Management:: Managing the result of crypto operations.
2125 * Context Attributes:: Setting properties of a context.
2126 * Key Management:: Managing keys with @acronym{GPGME}.
2127 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
2128 * Crypto Operations:: Using a context for cryptography.
2129 * Run Control:: Controlling how operations are run.
2133 @node Creating Contexts
2134 @section Creating Contexts
2135 @cindex context, creation
2137 @deftypefun gpgme_error_t gpgme_new (@w{gpgme_ctx_t *@var{ctx}})
2138 The function @code{gpgme_new} creates a new @code{gpgme_ctx_t} object
2139 and returns a handle for it in @var{ctx}.
2141 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2142 context was successfully created, @code{GPG_ERR_INV_VALUE} if
2143 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
2144 enough memory is available. Also, it returns
2145 @code{GPG_ERR_NOT_OPERATIONAL} if @code{gpgme_check_version} was not
2146 called to initialize GPGME, and @code{GPG_ERR_SELFTEST_FAILED} if a
2147 selftest failed. Currently, the only selftest is for Windows MingW32
2148 targets to see if @code{-mms-bitfields} was used (as required).
2152 @node Destroying Contexts
2153 @section Destroying Contexts
2154 @cindex context, destruction
2156 @deftypefun void gpgme_release (@w{gpgme_ctx_t @var{ctx}})
2157 The function @code{gpgme_release} destroys the context with the handle
2158 @var{ctx} and releases all associated resources.
2162 @node Result Management
2163 @section Result Management
2164 @cindex context, result of operation
2166 The detailed result of an operation is returned in operation-specific
2167 structures such as @code{gpgme_decrypt_result_t}. The corresponding
2168 retrieval functions such as @code{gpgme_op_decrypt_result} provide
2169 static access to the results after an operation completes. The
2170 following interfaces make it possible to detach a result structure
2171 from its associated context and give it a lifetime beyond that of the
2172 current operation or context.
2174 @deftypefun void gpgme_result_ref (@w{void *@var{result}})
2175 The function @code{gpgme_result_ref} acquires an additional reference
2176 for the result @var{result}, which may be of any type
2177 @code{gpgme_*_result_t}. As long as the user holds a reference, the
2178 result structure is guaranteed to be valid and unmodified.
2181 @deftypefun void gpgme_result_unref (@w{void *@var{result}})
2182 The function @code{gpgme_result_unref} releases a reference for the
2183 result @var{result}. If this was the last reference, the result
2184 structure will be destroyed and all resources associated to it will be
2188 Note that a context may hold its own references to result structures,
2189 typically until the context is destroyed or the next operation is
2190 started. In fact, these references are accessed through the
2191 @code{gpgme_op_*_result} functions.
2194 @node Context Attributes
2195 @section Context Attributes
2196 @cindex context, attributes
2199 * Protocol Selection:: Selecting the protocol used by a context.
2200 * Crypto Engine:: Configuring the crypto engine.
2201 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
2202 * Text Mode:: Choosing canonical text mode.
2203 * Included Certificates:: Including a number of certificates.
2204 * Key Listing Mode:: Selecting key listing mode.
2205 * Passphrase Callback:: Getting the passphrase from the user.
2206 * Progress Meter Callback:: Being informed about the progress.
2207 * Locale:: Setting the locale of a context.
2211 @node Protocol Selection
2212 @subsection Protocol Selection
2213 @cindex context, selecting protocol
2214 @cindex protocol, selecting
2216 @deftypefun gpgme_error_t gpgme_set_protocol (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}})
2217 The function @code{gpgme_set_protocol} sets the protocol used within
2218 the context @var{ctx} to @var{proto}. All crypto operations will be
2219 performed by the crypto engine configured for that protocol.
2220 @xref{Protocols and Engines}.
2222 Setting the protocol with @code{gpgme_set_protocol} does not check if
2223 the crypto engine for that protocol is available and installed
2224 correctly. @xref{Engine Version Check}.
2226 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2227 protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if
2228 @var{protocol} is not a valid protocol.
2231 @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}})
2232 The function @code{gpgme_get_protocol} retrieves the protocol currently
2233 use with the context @var{ctx}.
2238 @subsection Crypto Engine
2239 @cindex context, configuring engine
2240 @cindex engine, configuration per context
2242 The following functions can be used to set and retrieve the
2243 configuration of the crypto engines of a specific context. The
2244 default can also be retrieved without any particular context.
2245 @xref{Engine Information}. The default can also be changed globally.
2246 @xref{Engine Configuration}.
2248 @deftypefun gpgme_engine_info_t gpgme_ctx_get_engine_info (@w{gpgme_ctx_t @var{ctx}})
2249 The function @code{gpgme_ctx_get_engine_info} returns a linked list of
2250 engine info structures. Each info structure describes the
2251 configuration of one configured backend, as used by the context
2254 The result is valid until the next invocation of
2255 @code{gpgme_ctx_set_engine_info} for this particular context.
2257 This function can not fail.
2260 @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}})
2261 The function @code{gpgme_ctx_set_engine_info} changes the
2262 configuration of the crypto engine implementing the protocol
2263 @var{proto} for the context @var{ctx}.
2265 @var{file_name} is the file name of the executable program
2266 implementing this protocol, and @var{home_dir} is the directory name
2267 of the configuration directory for this crypto engine. If
2268 @var{home_dir} is @code{NULL}, the engine's default will be used.
2270 Currently this function must be used before starting the first crypto
2271 operation. It is unspecified if and when the changes will take effect
2272 if the function is called after starting the first operation on the
2275 This function returns the error code @code{GPG_ERR_NO_ERROR} if
2276 successful, or an eror code on failure.
2280 @c FIXME: Unfortunately, using @acronym here breaks texi2dvi.
2282 @subsection @acronym{ASCII} Armor
2283 @cindex context, armor mode
2284 @cindex @acronym{ASCII} armor
2287 @deftypefun void gpgme_set_armor (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2288 The function @code{gpgme_set_armor} specifies if the output should be
2289 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
2292 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
2296 @deftypefun int gpgme_get_armor (@w{gpgme_ctx_t @var{ctx}})
2297 The function @code{gpgme_get_armor} returns 1 if the output is
2298 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
2299 not a valid pointer.
2304 @subsection Text Mode
2305 @cindex context, text mode
2307 @cindex canonical text mode
2309 @deftypefun void gpgme_set_textmode (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2310 The function @code{gpgme_set_textmode} specifies if canonical text mode
2311 should be used. By default, text mode is not used.
2313 Text mode is for example used for the RFC2015 signatures; note that
2314 the updated RFC 3156 mandates that the mail user agent does some
2315 preparations so that text mode is not needed anymore.
2317 This option is only relevant to the OpenPGP crypto engine, and ignored
2318 by all other engines.
2320 Canonical text mode is disabled if @var{yes} is zero, and enabled
2324 @deftypefun int gpgme_get_textmode (@w{gpgme_ctx_t @var{ctx}})
2325 The function @code{gpgme_get_textmode} returns 1 if canonical text
2326 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2331 @node Included Certificates
2332 @subsection Included Certificates
2333 @cindex certificates, included
2335 @deftypefun void gpgme_set_include_certs (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{nr_of_certs}})
2336 The function @code{gpgme_set_include_certs} specifies how many
2337 certificates should be included in an S/MIME signed message. By
2338 default, only the sender's certificate is included. The possible
2339 values of @var{nr_of_certs} are:
2342 @item GPGME_INCLUDE_CERTS_DEFAULT
2343 Fall back to the default of the crypto backend. This is the default
2346 Include all certificates except the root certificate.
2348 Include all certificates.
2350 Include no certificates.
2352 Include the sender's certificate only.
2354 Include the first n certificates of the certificates path, starting
2355 from the sender's certificate. The number @code{n} must be positive.
2358 Values of @var{nr_of_certs} smaller than -2 are undefined.
2360 This option is only relevant to the CMS crypto engine, and ignored by
2364 @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}})
2365 The function @code{gpgme_get_include_certs} returns the number of
2366 certificates to include into an S/MIME signed message.
2370 @node Key Listing Mode
2371 @subsection Key Listing Mode
2372 @cindex key listing mode
2373 @cindex key listing, mode of
2375 @deftypefun gpgme_error_t gpgme_set_keylist_mode (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_keylist_mode_t @var{mode}})
2376 The function @code{gpgme_set_keylist_mode} changes the default
2377 behaviour of the key listing functions. The value in @var{mode} is a
2378 bitwise-or combination of one or multiple of the following bit values:
2381 @item GPGME_KEYLIST_MODE_LOCAL
2382 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
2383 keyring should be searched for keys in the keylisting operation. This
2386 @item GPGME_KEYLIST_MODE_EXTERN
2387 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
2388 source should be searched for keys in the keylisting operation. The
2389 type of external source is dependant on the crypto engine used and
2390 whether it is combined with @code{GPGME_KEYLIST_MODE_LOCAL}. For
2391 example, it can be a remote keyserver or LDAP certificate server.
2393 @item GPGME_KEYLIST_MODE_SIGS
2394 The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key
2395 signatures should be included in the listed keys.
2397 @item GPGME_KEYLIST_MODE_SIG_NOTATIONS
2398 The @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} symbol specifies that the
2399 signature notations on key signatures should be included in the listed
2400 keys. This only works if @code{GPGME_KEYLIST_MODE_SIGS} is also
2403 @item GPGME_KEYLIST_MODE_EPHEMERAL
2404 The @code{GPGME_KEYLIST_MODE_EPHEMERAL} symbol specifies that keys
2405 flagged as ephemeral are included in the listing.
2407 @item GPGME_KEYLIST_MODE_VALIDATE
2408 The @code{GPGME_KEYLIST_MODE_VALIDATE} symbol specifies that the
2409 backend should do key or certificate validation and not just get the
2410 validity information from an internal cache. This might be an
2411 expensive operation and is in general not useful. Currently only
2412 implemented for the S/MIME backend and ignored for other backends.
2416 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
2417 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
2418 compatibility, you should get the current mode with
2419 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
2420 appropriate bits, and then using that calculated value in the
2421 @code{gpgme_set_keylisting_mode} operation. This will leave all other
2422 bits in the mode value intact (in particular those that are not used
2423 in the current version of the library).
2425 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2426 mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx}
2427 is not a valid pointer or @var{mode} is not a valid mode.
2431 @deftypefun gpgme_keylist_mode_t gpgme_get_keylist_mode (@w{gpgme_ctx_t @var{ctx}})
2432 The function @code{gpgme_get_keylist_mode} returns the current key
2433 listing mode of the context @var{ctx}. This value can then be
2434 modified and used in a subsequent @code{gpgme_set_keylist_mode}
2435 operation to only affect the desired bits (and leave all others
2438 The function returns 0 if @var{ctx} is not a valid pointer, and the
2439 current mode otherwise. Note that 0 is not a valid mode value.
2443 @node Passphrase Callback
2444 @subsection Passphrase Callback
2445 @cindex callback, passphrase
2446 @cindex passphrase callback
2448 @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}})}
2449 @tindex gpgme_passphrase_cb_t
2450 The @code{gpgme_passphrase_cb_t} type is the type of functions usable as
2451 passphrase callback function.
2453 The argument @var{uid_hint} might contain a string that gives an
2454 indication for which user ID the passphrase is required. If this is
2455 not available, or not applicable (in the case of symmetric encryption,
2456 for example), @var{uid_hint} will be @code{NULL}.
2458 The argument @var{passphrase_info}, if not @code{NULL}, will give
2459 further information about the context in which the passphrase is
2460 required. This information is engine and operation specific.
2462 If this is the repeated attempt to get the passphrase, because
2463 previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
2466 The user must write the passphrase, followed by a newline character,
2467 to the file descriptor @var{fd}. The function @code{gpgme_io_writen}
2468 should be used for the write operation. Note that if the user returns
2469 0 to indicate success, the user must at least write a newline
2470 character before returning from the callback.
2472 If an error occurs, return the corresponding @code{gpgme_error_t}
2473 value. You can use the error code @code{GPG_ERR_CANCELED} to abort
2474 the operation. Otherwise, return @code{0}.
2477 @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}})
2478 The function @code{gpgme_set_passphrase_cb} sets the function that is
2479 used when a passphrase needs to be provided by the user to
2480 @var{passfunc}. The function @var{passfunc} needs to implemented by
2481 the user, and whenever it is called, it is called with its first
2482 argument being @var{hook_value}. By default, no passphrase callback
2485 Not all crypto engines require this callback to retrieve the
2486 passphrase. It is better if the engine retrieves the passphrase from
2487 a trusted agent (a daemon process), rather than having each user to
2488 implement their own passphrase query. Some engines do not even
2489 support an external passphrase callback at all, in this case the error
2490 code @code{GPG_ERR_NOT_SUPPORTED} is returned.
2492 The user can disable the use of a passphrase callback function by
2493 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
2497 @deftypefun void gpgme_get_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t *@var{passfunc}}, @w{void **@var{hook_value}})
2498 The function @code{gpgme_get_passphrase_cb} returns the function that
2499 is used when a passphrase needs to be provided by the user in
2500 @var{*passfunc}, and the first argument for this function in
2501 @var{*hook_value}. If no passphrase callback is set, or @var{ctx} is
2502 not a valid pointer, @code{NULL} is returned in both variables.
2504 @var{passfunc} or @var{hook_value} can be @code{NULL}. In this case,
2505 the corresponding value will not be returned.
2509 @node Progress Meter Callback
2510 @subsection Progress Meter Callback
2511 @cindex callback, progress meter
2512 @cindex progress meter callback
2514 @deftp {Data type} {void (*gpgme_progress_cb_t)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
2515 @tindex gpgme_progress_cb_t
2516 The @code{gpgme_progress_cb_t} type is the type of functions usable as
2517 progress callback function.
2519 The arguments are specific to the crypto engine. More information
2520 about the progress information returned from the GnuPG engine can be
2521 found in the GnuPG source code in the file @file{doc/DETAILS} in the
2525 @deftypefun void gpgme_set_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t @var{progfunc}}, @w{void *@var{hook_value}})
2526 The function @code{gpgme_set_progress_cb} sets the function that is
2527 used when progress information about a cryptographic operation is
2528 available. The function @var{progfunc} needs to implemented by the
2529 user, and whenever it is called, it is called with its first argument
2530 being @var{hook_value}. By default, no progress callback function
2533 Setting a callback function allows an interactive program to display
2534 progress information about a long operation to the user.
2536 The user can disable the use of a progress callback function by
2537 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
2541 @deftypefun void gpgme_get_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t *@var{progfunc}}, @w{void **@var{hook_value}})
2542 The function @code{gpgme_get_progress_cb} returns the function that is
2543 used to inform the user about the progress made in @var{*progfunc},
2544 and the first argument for this function in @var{*hook_value}. If no
2545 progress callback is set, or @var{ctx} is not a valid pointer,
2546 @code{NULL} is returned in both variables.
2548 @var{progfunc} or @var{hook_value} can be @code{NULL}. In this case,
2549 the corresponding value will not be returned.
2555 @cindex locale, default
2556 @cindex locale, of a context
2558 A locale setting can be associated with a context. This locale is
2559 passed to the crypto engine, and used for applications like the PIN
2560 entry, which is displayed to the user when entering a passphrase is
2563 The default locale is used to initialize the locale setting of all
2564 contexts created afterwards.
2566 @deftypefun gpgme_error_t gpgme_set_locale (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{category}}, @w{const char *@var{value}})
2567 The function @code{gpgme_set_locale} sets the locale of the context
2568 @var{ctx}, or the default locale if @var{ctx} is a null pointer.
2570 The locale settings that should be changed are specified by
2571 @var{category}. Supported categories are @code{LC_CTYPE},
2572 @code{LC_MESSAGES}, and @code{LC_ALL}, which is a wildcard you can use
2573 if you want to change all the categories at once.
2575 The value to be used for the locale setting is @var{value}, which will
2576 be copied to @acronym{GPGME}'s internal data structures. @var{value}
2577 can be a null pointer, which disables setting the locale, and will
2578 make PIN entry and other applications use their default setting, which
2579 is usually not what you want.
2581 Note that the settings are only used if the application runs on a text
2582 terminal, and that the settings should fit the configuration of the
2583 output terminal. Normally, it is sufficient to initialize the default
2586 The function returns an error if not enough memory is available.
2590 @node Key Management
2591 @section Key Management
2592 @cindex key management
2594 Some of the cryptographic operations require that recipients or
2595 signers are specified. This is always done by specifying the
2596 respective keys that should be used for the operation. The following
2597 section describes how such keys can be selected and manipulated.
2599 @deftp {Data type} gpgme_subkey_t
2600 The @code{gpgme_subkey_t} type is a pointer to a subkey structure.
2601 Sub keys are one component of a @code{gpgme_key_t} object. In fact,
2602 subkeys are those parts that contains the real information about the
2603 individual cryptographic keys that belong to the same key object. One
2604 @code{gpgme_key_t} can contain several subkeys. The first subkey in
2605 the linked list is also called the primary key.
2607 The subkey structure has the following members:
2610 @item gpgme_subkey_t next
2611 This is a pointer to the next subkey structure in the linked list, or
2612 @code{NULL} if this is the last element.
2614 @item unsigned int revoked : 1
2615 This is true if the subkey is revoked.
2617 @item unsigned int expired : 1
2618 This is true if the subkey is expired.
2620 @item unsigned int disabled : 1
2621 This is true if the subkey is disabled.
2623 @item unsigned int invalid : 1
2624 This is true if the subkey is invalid.
2626 @item unsigned int can_encrypt : 1
2627 This is true if the subkey can be used for encryption.
2629 @item unsigned int can_sign : 1
2630 This is true if the subkey can be used to create data signatures.
2632 @item unsigned int can_certify : 1
2633 This is true if the subkey can be used to create key certificates.
2635 @item unsigned int can_authenticate : 1
2636 This is true if the subkey can be used for authentication.
2638 @item unsigned int is_qualified : 1
2639 This is true if the subkey can be used for qualified signatures
2640 according to local government regulations.
2642 @item unsigned int secret : 1
2643 This is true if the subkey is a secret key. Note that it will be false
2644 if the key is actually a stub key; i.e. a secret key operation is
2645 currently not possible (offline-key).
2647 @item gpgme_pubkey_algo_t pubkey_algo
2648 This is the public key algorithm supported by this subkey.
2650 @item unsigned int length
2651 This is the length of the subkey (in bits).
2654 This is the key ID of the subkey in hexadecimal digits.
2657 This is the fingerprint of the subkey in hexadecimal digits, if
2660 @item long int timestamp
2661 This is the creation timestamp of the subkey. This is -1 if the
2662 timestamp is invalid, and 0 if it is not available.
2664 @item long int expires
2665 This is the expiration timestamp of the subkey, or 0 if the subkey
2670 @deftp {Data type} gpgme_key_sig_t
2671 The @code{gpgme_key_sig_t} type is a pointer to a key signature structure.
2672 Key signatures are one component of a @code{gpgme_key_t} object, and
2673 validate user IDs on the key.
2675 The signatures on a key are only available if the key was retrieved
2676 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
2677 enabled, because it can be expensive to retrieve all signatures of a
2680 The signature notations on a key signature are only available if the
2681 key was retrieved via a listing operation with the
2682 @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} mode enabled, because it can
2683 be expensive to retrieve all signature notations.
2685 The key signature structure has the following members:
2688 @item gpgme_key_sig_t next
2689 This is a pointer to the next key signature structure in the linked
2690 list, or @code{NULL} if this is the last element.
2692 @item unsigned int revoked : 1
2693 This is true if the key signature is a revocation signature.
2695 @item unsigned int expired : 1
2696 This is true if the key signature is expired.
2698 @item unsigned int invalid : 1
2699 This is true if the key signature is invalid.
2701 @item unsigned int exportable : 1
2702 This is true if the key signature is exportable.
2704 @item gpgme_pubkey_algo_t pubkey_algo
2705 This is the public key algorithm used to create the signature.
2708 This is the key ID of the key (in hexadecimal digits) used to create
2711 @item long int timestamp
2712 This is the creation timestamp of the key signature. This is -1 if
2713 the timestamp is invalid, and 0 if it is not available.
2715 @item long int expires
2716 This is the expiration timestamp of the key signature, or 0 if the key
2717 signature does not expire.
2719 @item gpgme_error_t status
2720 This is the status of the signature and has the same meaning as the
2721 member of the same name in a @code{gpgme_signature_t} object.
2723 @item unsigned int sig_class
2724 This specifies the signature class of the key signature. The meaning
2725 is specific to the crypto engine.
2728 This is the main user ID of the key used to create the signature.
2731 This is the name component of @code{uid}, if available.
2734 This is the comment component of @code{uid}, if available.
2737 This is the email component of @code{uid}, if available.
2739 @item gpgme_sig_notation_t notations
2740 This is a linked list with the notation data and policy URLs.
2744 @deftp {Data type} gpgme_user_id_t
2745 A user ID is a component of a @code{gpgme_key_t} object. One key can
2746 have many user IDs. The first one in the list is the main (or
2749 The user ID structure has the following members.
2752 @item gpgme_user_id_t next
2753 This is a pointer to the next user ID structure in the linked list, or
2754 @code{NULL} if this is the last element.
2756 @item unsigned int revoked : 1
2757 This is true if the user ID is revoked.
2759 @item unsigned int invalid : 1
2760 This is true if the user ID is invalid.
2762 @item gpgme_validity_t validity
2763 This specifies the validity of the user ID.
2766 This is the user ID string.
2769 This is the name component of @code{uid}, if available.
2772 This is the comment component of @code{uid}, if available.
2775 This is the email component of @code{uid}, if available.
2777 @item gpgme_key_sig_t signatures
2778 This is a linked list with the signatures on this user ID.
2782 @deftp {Data type} gpgme_key_t
2783 The @code{gpgme_key_t} type is a pointer to a key object. It has the
2787 @item gpgme_keylist_mode_t keylist_mode
2788 The keylist mode that was active when the key was retrieved.
2790 @item unsigned int revoked : 1
2791 This is true if the key is revoked.
2793 @item unsigned int expired : 1
2794 This is true if the key is expired.
2796 @item unsigned int disabled : 1
2797 This is true if the key is disabled.
2799 @item unsigned int invalid : 1
2800 This is true if the key is invalid. This might have several reasons,
2801 for a example for the S/MIME backend, it will be set in during key
2802 listsing if the key could not be validated due to a missing
2803 certificates or unmatched policies.
2805 @item unsigned int can_encrypt : 1
2806 This is true if the key (ie one of its subkeys) can be used for
2809 @item unsigned int can_sign : 1
2810 This is true if the key (ie one of its subkeys) can be used to create
2813 @item unsigned int can_certify : 1
2814 This is true if the key (ie one of its subkeys) can be used to create
2817 @item unsigned int can_authenticate : 1
2818 This is true if the key (ie one of its subkeys) can be used for
2821 @item unsigned int is_qualified : 1
2822 This is true if the key can be used for qualified signatures according
2823 to local government regulations.
2825 @item unsigned int secret : 1
2826 This is true if the key is a secret key. Note, that this will always be
2827 true even if the corresponding subkey flag may be false (offline/stub
2830 @item gpgme_protocol_t protocol
2831 This is the protocol supported by this key.
2833 @item char *issuer_serial
2834 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2837 @item char *issuer_name
2838 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2841 @item char *chain_id
2842 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2843 chain ID, which can be used to built the certificate chain.
2845 @item gpgme_validity_t owner_trust
2846 If @code{protocol} is @code{GPGME_PROTOCOL_OpenPGP}, then this is the
2849 @item gpgme_subkey_t subkeys
2850 This is a linked list with the subkeys of the key. The first subkey
2851 in the list is the primary key and usually available.
2853 @item gpgme_user_id_t uids
2854 This is a linked list with the user IDs of the key. The first user ID
2855 in the list is the main (or primary) user ID.
2860 * Listing Keys:: Browsing the list of available keys.
2861 * Information About Keys:: Requesting detailed information about keys.
2862 * Key Signatures:: Listing the signatures on a key.
2863 * Manipulating Keys:: Operations on keys.
2864 * Generating Keys:: Creating new key pairs.
2865 * Exporting Keys:: Retrieving key data from the key ring.
2866 * Importing Keys:: Adding keys to the key ring.
2867 * Deleting Keys:: Removing keys from the key ring.
2868 * Changing Passphrases:: Change the passphrase of a key.
2869 * Advanced Key Editing:: Advanced key edit operation.
2874 @subsection Listing Keys
2875 @cindex listing keys
2877 @cindex key listing, start
2878 @cindex key ring, list
2879 @cindex key ring, search
2881 @deftypefun gpgme_error_t gpgme_op_keylist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
2882 The function @code{gpgme_op_keylist_start} initiates a key listing
2883 operation inside the context @var{ctx}. It sets everything up so that
2884 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
2887 If @var{pattern} is @code{NULL}, all available keys are returned.
2888 Otherwise, @var{pattern} contains an engine specific expression that
2889 is used to limit the list to all keys matching the pattern. Note that
2890 the total length of the pattern is restricted to an engine-specific
2891 maximum (a couple of hundred characters are usually accepted). The
2892 pattern should be used to restrict the search to a certain common name
2893 or user, not to list many specific keys at once by listing their
2894 fingerprints or key IDs.
2896 If @var{secret_only} is not @code{0}, the list is restricted to secret
2899 The context will be busy until either all keys are received (and
2900 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2901 @code{gpgme_op_keylist_end} is called to finish the operation.
2903 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2904 @var{ctx} is not a valid pointer, and passes through any errors that
2905 are reported by the crypto engine support routines.
2908 @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}})
2909 The function @code{gpgme_op_keylist_ext_start} initiates an extended
2910 key listing operation inside the context @var{ctx}. It sets
2911 everything up so that subsequent invocations of
2912 @code{gpgme_op_keylist_next} return the keys in the list.
2914 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
2915 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
2916 array of strings that are used to limit the list to all keys matching
2917 at least one of the patterns verbatim. Note that the total length of
2918 all patterns is restricted to an engine-specific maximum (the exact
2919 limit also depends on the number of patterns and amount of quoting
2920 required, but a couple of hundred characters are usually accepted).
2921 Patterns should be used to restrict the search to a certain common
2922 name or user, not to list many specific keys at once by listing their
2923 fingerprints or key IDs.
2925 If @var{secret_only} is not @code{0}, the list is restricted to secret
2928 The value of @var{reserved} must be @code{0}.
2930 The context will be busy until either all keys are received (and
2931 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2932 @code{gpgme_op_keylist_end} is called to finish the operation.
2934 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2935 @var{ctx} is not a valid pointer, and passes through any errors that
2936 are reported by the crypto engine support routines.
2939 @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}})
2940 The function @code{gpgme_op_keylist_next} returns the next key in the
2941 list created by a previous @code{gpgme_op_keylist_start} operation in
2942 the context @var{ctx}. The key will have one reference for the user.
2943 @xref{Manipulating Keys}.
2945 This is the only way to get at @code{gpgme_key_t} objects in
2948 If the last key in the list has already been returned,
2949 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}.
2951 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2952 @var{ctx} or @var{r_key} is not a valid pointer, and
2953 @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation.
2956 @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}})
2957 The function @code{gpgme_op_keylist_end} ends a pending key list
2958 operation in the context @var{ctx}.
2960 After the operation completed successfully, the result of the key
2961 listing operation can be retrieved with
2962 @code{gpgme_op_keylist_result}.
2964 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2965 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
2966 time during the operation there was not enough memory available.
2969 The following example illustrates how all keys containing a certain
2970 string (@code{g10code}) can be listed with their key ID and the name
2971 and e-mail address of the main user ID:
2976 gpgme_error_t err = gpgme_new (&ctx);
2980 err = gpgme_op_keylist_start (ctx, "g10code", 0);
2983 err = gpgme_op_keylist_next (ctx, &key);
2986 printf ("%s:", key->subkeys->keyid);
2987 if (key->uids && key->uids->name)
2988 printf (" %s", key->uids->name);
2989 if (key->uids && key->uids->email)
2990 printf (" <%s>", key->uids->email);
2992 gpgme_key_release (key);
2994 gpgme_release (ctx);
2996 if (gpg_err_code (err) != GPG_ERR_EOF)
2998 fprintf (stderr, "can not list keys: %s\n", gpgme_strerror (err));
3003 @deftp {Data type} {gpgme_keylist_result_t}
3004 This is a pointer to a structure used to store the result of a
3005 @code{gpgme_op_keylist_*} operation. After successfully ending a key
3006 listing operation, you can retrieve the pointer to the result with
3007 @code{gpgme_op_keylist_result}. The structure contains the following
3011 @item unsigned int truncated : 1
3012 This is true if the crypto backend had to truncate the result, and
3013 less than the desired keys could be listed.
3017 @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}})
3018 The function @code{gpgme_op_keylist_result} returns a
3019 @code{gpgme_keylist_result_t} pointer to a structure holding the
3020 result of a @code{gpgme_op_keylist_*} operation. The pointer is only
3021 valid if the last operation on the context was a key listing
3022 operation, and if this operation finished successfully. The returned
3023 pointer is only valid until the next operation is started on the
3027 In a simple program, for which a blocking operation is acceptable, the
3028 following function can be used to retrieve a single key.
3030 @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}})
3031 The function @code{gpgme_get_key} gets the key with the fingerprint
3032 (or key ID) @var{fpr} from the crypto backend and return it in
3033 @var{r_key}. If @var{secret} is true, get the secret key. The
3034 currently active keylist mode is used to retrieve the key. The key
3035 will have one reference for the user.
3037 If the key is not found in the keyring, @code{gpgme_get_key} returns
3038 the error code @code{GPG_ERR_EOF} and *@var{r_key} will be set to
3041 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3042 @var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a
3043 fingerprint or key ID, @code{GPG_ERR_AMBIGUOUS_NAME} if the key ID was
3044 not a unique specifier for a key, and @code{GPG_ERR_ENOMEM} if at some
3045 time during the operation there was not enough memory available.
3049 @node Information About Keys
3050 @subsection Information About Keys
3051 @cindex key, information about
3052 @cindex key, attributes
3053 @cindex attributes, of a key
3055 Please see the beginning of this section for more information about
3056 @code{gpgme_key_t} objects.
3058 @deftp {Data type} gpgme_validity_t
3059 The @code{gpgme_validity_t} type is used to specify the validity of a user ID
3060 in a key. The following validities are defined:
3063 @item GPGME_VALIDITY_UNKNOWN
3064 The user ID is of unknown validity. The string representation of this
3067 @item GPGME_VALIDITY_UNDEFINED
3068 The validity of the user ID is undefined. The string representation of this
3071 @item GPGME_VALIDITY_NEVER
3072 The user ID is never valid. The string representation of this
3075 @item GPGME_VALIDITY_MARGINAL
3076 The user ID is marginally valid. The string representation of this
3079 @item GPGME_VALIDITY_FULL
3080 The user ID is fully valid. The string representation of this
3083 @item GPGME_VALIDITY_ULTIMATE
3084 The user ID is ultimately valid. The string representation of this
3090 The following interfaces are deprecated and only provided for backward
3091 compatibility. Don't use them. They will be removed in a future
3092 version of @acronym{GPGME}.
3094 @deftp {Data type} gpgme_attr_t
3095 The @code{gpgme_attr_t} type is used to specify a key or trust item
3096 attribute. The following attributes are defined:
3099 @item GPGME_ATTR_KEYID
3100 This is the key ID of a sub key. It is representable as a string.
3102 For trust items, the trust item refers to the key with this ID.
3104 @item GPGME_ATTR_FPR
3105 This is the fingerprint of a sub key. It is representable as a
3108 @item GPGME_ATTR_ALGO
3109 This is the crypto algorithm for which the sub key can be used. It
3110 is representable as a string and as a number. The numbers correspond
3111 to the @code{enum gcry_pk_algos} values in the gcrypt library.
3113 @item GPGME_ATTR_LEN
3114 This is the key length of a sub key. It is representable as a
3117 @item GPGME_ATTR_CREATED
3118 This is the timestamp at creation time of a sub key. It is
3119 representable as a number.
3121 @item GPGME_ATTR_EXPIRE
3122 This is the expiration time of a sub key. It is representable as a
3125 @item GPGME_ATTR_OTRUST
3126 XXX FIXME (also for trust items)
3128 @item GPGME_ATTR_USERID
3129 This is a user ID. There can be more than one user IDs in a
3130 @var{gpgme_key_t} object. The first one (with index 0) is the primary
3131 user ID. The user ID is representable as a number.
3133 For trust items, this is the user ID associated with this trust item.
3135 @item GPGME_ATTR_NAME
3136 This is the name belonging to a user ID. It is representable as a string.
3138 @item GPGME_ATTR_EMAIL
3139 This is the email address belonging to a user ID. It is representable
3142 @item GPGME_ATTR_COMMENT
3143 This is the comment belonging to a user ID. It is representable as a
3146 @item GPGME_ATTR_VALIDITY
3147 This is the validity belonging to a user ID. It is representable as a
3148 string and as a number. See below for a list of available validities.
3150 For trust items, this is the validity that is associated with this
3153 @item GPGME_ATTR_UID_REVOKED
3154 This specifies if a user ID is revoked. It is representable as a
3155 number, and is @code{1} if the user ID is revoked, and @code{0}
3158 @item GPGME_ATTR_UID_INVALID
3159 This specifies if a user ID is invalid. It is representable as a
3160 number, and is @code{1} if the user ID is invalid, and @code{0}
3163 @item GPGME_ATTR_LEVEL
3164 This is the trust level of a trust item.
3166 @item GPGME_ATTR_TYPE
3167 This returns information about the type of key. For the string function
3168 this will eother be "PGP" or "X.509". The integer function returns 0
3169 for PGP and 1 for X.509. It is also used for the type of a trust item.
3171 @item GPGME_ATTR_IS_SECRET
3172 This specifies if the key is a secret key. It is representable as a
3173 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
3175 @item GPGME_ATTR_KEY_REVOKED
3176 This specifies if a sub key is revoked. It is representable as a
3177 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
3179 @item GPGME_ATTR_KEY_INVALID
3180 This specifies if a sub key is invalid. It is representable as a
3181 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
3183 @item GPGME_ATTR_KEY_EXPIRED
3184 This specifies if a sub key is expired. It is representable as a
3185 number, and is @code{1} if the key is expired, and @code{0} otherwise.
3187 @item GPGME_ATTR_KEY_DISABLED
3188 This specifies if a sub key is disabled. It is representable as a
3189 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
3191 @item GPGME_ATTR_KEY_CAPS
3192 This is a description of the capabilities of a sub key. It is
3193 representable as a string. The string contains the letter ``e'' if
3194 the key can be used for encryption, ``s'' if the key can be used for
3195 signatures, and ``c'' if the key can be used for certifications.
3197 @item GPGME_ATTR_CAN_ENCRYPT
3198 This specifies if a sub key can be used for encryption. It is
3199 representable as a number, and is @code{1} if the sub key can be used
3200 for encryption, and @code{0} otherwise.
3202 @item GPGME_ATTR_CAN_SIGN
3203 This specifies if a sub key can be used to create data signatures. It
3204 is representable as a number, and is @code{1} if the sub key can be
3205 used for signatures, and @code{0} otherwise.
3207 @item GPGME_ATTR_CAN_CERTIFY
3208 This specifies if a sub key can be used to create key certificates.
3209 It is representable as a number, and is @code{1} if the sub key can be
3210 used for certifications, and @code{0} otherwise.
3212 @item GPGME_ATTR_SERIAL
3213 The X.509 issuer serial attribute of the key. It is representable as
3216 @item GPGME_ATTR_ISSUE
3217 The X.509 issuer name attribute of the key. It is representable as a
3220 @item GPGME_ATTR_CHAINID
3221 The X.509 chain ID can be used to build the certification chain. It
3222 is representable as a string.
3226 @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}})
3227 The function @code{gpgme_key_get_string_attr} returns the value of the
3228 string-representable attribute @var{what} of key @var{key}. If the
3229 attribute is an attribute of a sub key or an user ID, @var{idx}
3230 specifies the sub key or user ID of which the attribute value is
3231 returned. The argument @var{reserved} is reserved for later use and
3232 should be @code{NULL}.
3234 The string returned is only valid as long as the key is valid.
3236 The function returns @code{0} if an attribute can't be returned as a
3237 string, @var{key} is not a valid pointer, @var{idx} out of range,
3238 or @var{reserved} not @code{NULL}.
3241 @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}})
3242 The function @code{gpgme_key_get_ulong_attr} returns the value of the
3243 number-representable attribute @var{what} of key @var{key}. If the
3244 attribute is an attribute of a sub key or an user ID, @var{idx}
3245 specifies the sub key or user ID of which the attribute value is
3246 returned. The argument @var{reserved} is reserved for later use and
3247 should be @code{NULL}.
3249 The function returns @code{0} if the attribute can't be returned as a
3250 number, @var{key} is not a valid pointer, @var{idx} out of range, or
3251 @var{reserved} not @code{NULL}.
3255 @node Key Signatures
3256 @subsection Key Signatures
3257 @cindex key, signatures
3258 @cindex signatures, on a key
3260 The following interfaces are deprecated and only provided for backward
3261 compatibility. Don't use them. They will be removed in a future
3262 version of @acronym{GPGME}.
3264 The signatures on a key are only available if the key was retrieved
3265 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
3266 enabled, because it is expensive to retrieve all signatures of a key.
3268 So, before using the below interfaces to retrieve the signatures on a
3269 key, you have to make sure that the key was listed with signatures
3270 enabled. One convenient, but blocking, way to do this is to use the
3271 function @code{gpgme_get_key}.
3273 @deftp {Data type} gpgme_attr_t
3274 The @code{gpgme_attr_t} type is used to specify a key signature
3275 attribute. The following attributes are defined:
3278 @item GPGME_ATTR_KEYID
3279 This is the key ID of the key which was used for the signature. It is
3280 representable as a string.
3282 @item GPGME_ATTR_ALGO
3283 This is the crypto algorithm used to create the signature. It is
3284 representable as a string and as a number. The numbers correspond to
3285 the @code{enum gcry_pk_algos} values in the gcrypt library.
3287 @item GPGME_ATTR_CREATED
3288 This is the timestamp at creation time of the signature. It is
3289 representable as a number.
3291 @item GPGME_ATTR_EXPIRE
3292 This is the expiration time of the signature. It is representable as
3295 @item GPGME_ATTR_USERID
3296 This is the user ID associated with the signing key. The user ID is
3297 representable as a number.
3299 @item GPGME_ATTR_NAME
3300 This is the name belonging to a user ID. It is representable as a string.
3302 @item GPGME_ATTR_EMAIL
3303 This is the email address belonging to a user ID. It is representable
3306 @item GPGME_ATTR_COMMENT
3307 This is the comment belonging to a user ID. It is representable as a
3310 @item GPGME_ATTR_KEY_REVOKED
3311 This specifies if a key signature is a revocation signature. It is
3312 representable as a number, and is @code{1} if the key is revoked, and
3315 @c @item GPGME_ATTR_KEY_EXPIRED
3316 @c This specifies if a key signature is expired. It is representable as
3317 @c a number, and is @code{1} if the key is revoked, and @code{0}
3320 @item GPGME_ATTR_SIG_CLASS
3321 This specifies the signature class of a key signature. It is
3322 representable as a number. The meaning is specific to the crypto
3325 @item GPGME_ATTR_SIG_CLASS
3326 This specifies the signature class of a key signature. It is
3327 representable as a number. The meaning is specific to the crypto
3330 @item GPGME_ATTR_SIG_STATUS
3331 This is the same value as returned by @code{gpgme_get_sig_status}.
3335 @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}})
3336 The function @code{gpgme_key_sig_get_string_attr} returns the value of
3337 the string-representable attribute @var{what} of the signature
3338 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3339 argument @var{reserved} is reserved for later use and should be
3342 The string returned is only valid as long as the key is valid.
3344 The function returns @code{0} if an attribute can't be returned as a
3345 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3346 out of range, or @var{reserved} not @code{NULL}.
3349 @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}})
3350 The function @code{gpgme_key_sig_get_ulong_attr} returns the value of
3351 the number-representable attribute @var{what} of the signature
3352 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3353 argument @var{reserved} is reserved for later use and should be
3356 The function returns @code{0} if an attribute can't be returned as a
3357 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3358 out of range, or @var{reserved} not @code{NULL}.
3362 @node Manipulating Keys
3363 @subsection Manipulating Keys
3364 @cindex key, manipulation
3366 @deftypefun void gpgme_key_ref (@w{gpgme_key_t @var{key}})
3367 The function @code{gpgme_key_ref} acquires an additional reference for
3371 @deftypefun void gpgme_key_unref (@w{gpgme_key_t @var{key}})
3372 The function @code{gpgme_key_unref} releases a reference for the key
3373 @var{key}. If this was the last reference, the key will be destroyed
3374 and all resources associated to it will be released.
3378 The following interface is deprecated and only provided for backward
3379 compatibility. Don't use it. It will be removed in a future version
3382 @deftypefun void gpgme_key_release (@w{gpgme_key_t @var{key}})
3383 The function @code{gpgme_key_release} is equivalent to
3384 @code{gpgme_key_unref}.
3388 @node Generating Keys
3389 @subsection Generating Keys
3390 @cindex key, creation
3391 @cindex key ring, add
3393 @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}})
3394 The function @code{gpgme_op_genkey} generates a new key pair in the
3395 context @var{ctx}. The meaning of @var{public} and @var{secret}
3396 depends on the crypto backend.
3398 GnuPG does not support @var{public} and @var{secret}, they should be
3399 @code{NULL}. GnuPG will generate a key pair and add it to the
3400 standard key ring. The fingerprint of the generated key is available
3401 with @code{gpgme_op_genkey_result}.
3403 GpgSM requires @var{public} to be a writable data object. GpgSM will
3404 generate a secret key (which will be stored by @command{gpg-agent},
3405 and return a certificate request in @var{public}, which then needs to
3406 be signed by the certification authority and imported before it can be
3407 used. GpgSM does not make the fingerprint available.
3409 The argument @var{parms} specifies parameters for the key in an XML
3410 string. The details about the format of @var{parms} are specific to
3411 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
3412 the crypto engine (all parameters of OpenPGP key generation are
3413 documented in the GPG manual):
3416 <GnupgKeyParms format="internal">
3418 Subkey-Type: default
3419 Name-Real: Joe Tester
3420 Name-Comment: with stupid passphrase
3421 Name-Email: joe@@foo.bar
3427 Here is an example for GpgSM as the crypto engine (all parameters of
3428 OpenPGP key generation are documented in the GPGSM manual):
3431 <GnupgKeyParms format="internal">
3434 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3435 Name-Email: joe@@foo.bar
3439 Strings should be given in UTF-8 encoding. The only format supported
3440 for now is ``internal''. The content of the @code{GnupgKeyParms}
3441 container is passed verbatim to the crypto backend. Control
3442 statements are not allowed.
3444 After the operation completed successfully, the result can be
3445 retrieved with @code{gpgme_op_genkey_result}.
3447 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3448 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3449 @var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if
3450 @var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL}
3451 if no key was created by the backend.
3454 @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}})
3455 The function @code{gpgme_op_genkey_start} initiates a
3456 @code{gpgme_op_genkey} operation. It can be completed by calling
3457 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3459 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3460 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3461 @var{parms} is not a valid XML string, and
3462 @code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not
3466 @deftp {Data type} {gpgme_genkey_result_t}
3467 This is a pointer to a structure used to store the result of a
3468 @code{gpgme_op_genkey} operation. After successfully generating a
3469 key, you can retrieve the pointer to the result with
3470 @code{gpgme_op_genkey_result}. The structure contains the following
3474 @item unsigned int primary : 1
3475 This is a flag that is set to 1 if a primary key was created and to 0
3478 @item unsigned int sub : 1
3479 This is a flag that is set to 1 if a subkey was created and to 0
3483 This is the fingerprint of the key that was created. If both a
3484 primary and a sub key were generated, the fingerprint of the primary
3485 key will be returned. If the crypto engine does not provide the
3486 fingerprint, @code{fpr} will be a null pointer.
3490 @deftypefun gpgme_genkey_result_t gpgme_op_genkey_result (@w{gpgme_ctx_t @var{ctx}})
3491 The function @code{gpgme_op_genkey_result} returns a
3492 @code{gpgme_genkey_result_t} pointer to a structure holding the result of
3493 a @code{gpgme_op_genkey} operation. The pointer is only valid if the
3494 last operation on the context was a @code{gpgme_op_genkey} or
3495 @code{gpgme_op_genkey_start} operation, and if this operation finished
3496 successfully. The returned pointer is only valid until the next
3497 operation is started on the context.
3501 @node Exporting Keys
3502 @subsection Exporting Keys
3504 @cindex key ring, export from
3506 Exporting keys means the same as running @command{gpg} with the command
3507 @option{--export}. However, a mode flag can be used to change the way
3508 the export works. The available mode flags are described below, they
3509 may be or-ed together.
3513 @item GPGME_EXPORT_MODE_EXTERN
3514 If this bit is set, the output is send directly to the default
3515 keyserver. This is currently only allowed for OpenPGP keys. It is good
3516 practise to not send more than a few dozens key to a keyserver at one
3517 time. Using this flag requires that the @var{keydata} argument of the
3518 export function is set to @code{NULL}.
3520 @item GPGME_EXPORT_MODE_MINIMAL
3521 If this bit is set, the smallest possible key is exported. For OpenPGP
3522 keys it removes all signatures except for the latest self-signatures.
3523 For X.509 keys it has no effect.
3530 @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}})
3531 The function @code{gpgme_op_export} extracts public keys and returns
3532 them in the data buffer @var{keydata}. The output format of the key
3533 data returned is determined by the @acronym{ASCII} armor attribute set
3534 for the context @var{ctx}, or, if that is not set, by the encoding
3535 specified for @var{keydata}.
3537 If @var{pattern} is @code{NULL}, all available keys are returned.
3538 Otherwise, @var{pattern} contains an engine specific expression that
3539 is used to limit the list to all keys matching the pattern.
3541 @var{mode} is usually 0; other values are described above.
3543 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3544 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3545 @var{keydata} is not a valid empty data buffer, and passes through any
3546 errors that are reported by the crypto engine support routines.
3549 @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}})
3550 The function @code{gpgme_op_export_start} initiates a
3551 @code{gpgme_op_export} operation. It can be completed by calling
3552 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3554 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3555 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3556 if @var{keydata} is not a valid empty data buffer.
3559 @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}})
3560 The function @code{gpgme_op_export} extracts public keys and returns
3561 them in the data buffer @var{keydata}. The output format of the key
3562 data returned is determined by the @acronym{ASCII} armor attribute set
3563 for the context @var{ctx}, or, if that is not set, by the encoding
3564 specified for @var{keydata}.
3566 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3567 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3568 array of strings that are used to limit the list to all keys matching
3569 at least one of the patterns verbatim.
3571 @var{mode} is usually 0; other values are described above.
3573 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3574 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3575 @var{keydata} is not a valid empty data buffer, and passes through any
3576 errors that are reported by the crypto engine support routines.
3579 @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}})
3580 The function @code{gpgme_op_export_ext_start} initiates a
3581 @code{gpgme_op_export_ext} operation. It can be completed by calling
3582 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3584 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3585 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3586 if @var{keydata} is not a valid empty data buffer.
3590 @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}})
3591 The function @code{gpgme_op_export_keys} extracts public keys and returns
3592 them in the data buffer @var{keydata}. The output format of the key
3593 data returned is determined by the @acronym{ASCII} armor attribute set
3594 for the context @var{ctx}, or, if that is not set, by the encoding
3595 specified for @var{keydata}.
3597 The keys to export are taken form the @code{NULL} terminated array
3598 @var{keys}. Only keys of the the currently selected protocol of
3599 @var{ctx} which do have a fingerprint set are considered for export.
3600 Other keys specified by the @var{keys} are ignored. In particular
3601 OpenPGP keys retrieved via an external key listing are not included.
3603 @var{mode} is usually 0; other values are described above.
3605 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3606 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3607 @var{keydata} is not a valid empty data buffer, @code{GPG_ERR_NO_DATA}
3608 if no useful keys are in @var{keys} and passes through any errors that
3609 are reported by the crypto engine support routines.
3612 @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}})
3613 The function @code{gpgme_op_export_keys_start} initiates a
3614 @code{gpgme_op_export_ext} operation. It can be completed by calling
3615 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3617 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3618 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3619 if @var{keydata} is not a valid empty data buffer, @code{GPG_ERR_NO_DATA}
3620 if no useful keys are in @var{keys} and passes through any errors that
3621 are reported by the crypto engine support routines.
3625 @node Importing Keys
3626 @subsection Importing Keys
3628 @cindex key ring, import to
3630 Importing keys means the same as running @command{gpg} with the command
3634 @deftypefun gpgme_error_t gpgme_op_import (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3635 The function @code{gpgme_op_import} adds the keys in the data buffer
3636 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
3637 The format of @var{keydata} can be @acronym{ASCII} armored, for example,
3638 but the details are specific to the crypto engine.
3640 After the operation completed successfully, the result can be
3641 retrieved with @code{gpgme_op_import_result}.
3643 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3644 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3645 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3646 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3649 @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3650 The function @code{gpgme_op_import_start} initiates a
3651 @code{gpgme_op_import} operation. It can be completed by calling
3652 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3654 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3655 import could be started successfully, @code{GPG_ERR_INV_VALUE} if
3656 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3657 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3660 @deftypefun gpgme_error_t gpgme_op_import_keys (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{keys}})
3661 The function @code{gpgme_op_import_keys} adds the keys described by the
3662 @code{NULL} terminated array @var{keys} to the key ring of the crypto
3663 engine used by @var{ctx}. This function is the general interface to
3664 move a key from one crypto engine to another as long as they are
3665 compatible. In particular it is used to actually import and make keys
3666 permanent which have been retrieved from an external source (i.e. using
3667 @code{GPGME_KEYLIST_MODE_EXTERN}). @footnote{Thus it is a replacement
3668 for the usual workaround of exporting and then importing a key to make
3669 an X.509 key permanent.}
3671 Only keys of the the currently selected protocol of @var{ctx} are
3672 considered for import. Other keys specified by the @var{keys} are
3673 ignored. As of now all considered keys must have been retrieved using
3674 the same method, that is the used key listing mode must be identical.
3676 After the operation completed successfully, the result can be
3677 retrieved with @code{gpgme_op_import_result}.
3679 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3680 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3681 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3682 @code{GPG_ERR_CONFLICT} if the key listing mode does not match, and
3683 @code{GPG_ERR_NO_DATA} if no keys are considered for export.
3686 @deftypefun gpgme_error_t gpgme_op_import_keys_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{keys}})
3687 The function @code{gpgme_op_import_keys_start} initiates a
3688 @code{gpgme_op_import_keys} operation. It can be completed by calling
3689 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3691 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3692 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3693 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3694 @code{GPG_ERR_CONFLICT} if the key listing mode does not match, and
3695 @code{GPG_ERR_NO_DATA} if no keys are considered for export.
3698 @deftp {Data type} {gpgme_import_status_t}
3699 This is a pointer to a structure used to store a part of the result of
3700 a @code{gpgme_op_import} operation. For each considered key one
3701 status is added that contains information about the result of the
3702 import. The structure contains the following members:
3705 @item gpgme_import_status_t next
3706 This is a pointer to the next status structure in the linked list, or
3707 @code{NULL} if this is the last element.
3710 This is the fingerprint of the key that was considered.
3712 @item gpgme_error_t result
3713 If the import was not successful, this is the error value that caused
3714 the import to fail. Otherwise the error code is
3715 @code{GPG_ERR_NO_ERROR}.
3717 @item unsigned int status
3718 This is a bit-wise OR of the following flags that give more
3719 information about what part of the key was imported. If the key was
3720 already known, this might be 0.
3723 @item GPGME_IMPORT_NEW
3726 @item GPGME_IMPORT_UID
3727 The key contained new user IDs.
3729 @item GPGME_IMPORT_SIG
3730 The key contained new signatures.
3732 @item GPGME_IMPORT_SUBKEY
3733 The key contained new sub keys.
3735 @item GPGME_IMPORT_SECRET
3736 The key contained a secret key.
3741 @deftp {Data type} {gpgme_import_result_t}
3742 This is a pointer to a structure used to store the result of a
3743 @code{gpgme_op_import} operation. After a successful import
3744 operation, you can retrieve the pointer to the result with
3745 @code{gpgme_op_import_result}. The structure contains the following
3749 @item int considered
3750 The total number of considered keys.
3752 @item int no_user_id
3753 The number of keys without user ID.
3756 The total number of imported keys.
3759 The number of imported RSA keys.
3762 The number of unchanged keys.
3765 The number of new user IDs.
3768 The number of new sub keys.
3770 @item new_signatures
3771 The number of new signatures.
3773 @item new_revocations
3774 The number of new revocations.
3777 The total number of secret keys read.
3779 @item secret_imported
3780 The number of imported secret keys.
3782 @item secret_unchanged
3783 The number of unchanged secret keys.
3786 The number of keys not imported.
3788 @item gpgme_import_status_t imports
3789 A list of gpgme_import_status_t objects which contain more information
3790 about the keys for which an import was attempted.
3794 @deftypefun gpgme_import_result_t gpgme_op_import_result (@w{gpgme_ctx_t @var{ctx}})
3795 The function @code{gpgme_op_import_result} returns a
3796 @code{gpgme_import_result_t} pointer to a structure holding the result
3797 of a @code{gpgme_op_import} operation. The pointer is only valid if
3798 the last operation on the context was a @code{gpgme_op_import} or
3799 @code{gpgme_op_import_start} operation, and if this operation finished
3800 successfully. The returned pointer is only valid until the next
3801 operation is started on the context.
3804 The following interface is deprecated and only provided for backward
3805 compatibility. Don't use it. It will be removed in a future version
3808 @deftypefun gpgme_error_t gpgme_op_import_ext (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}}, @w{int *@var{nr}})
3809 The function @code{gpgme_op_import_ext} is equivalent to:
3812 gpgme_error_t err = gpgme_op_import (ctx, keydata);
3815 gpgme_import_result_t result = gpgme_op_import_result (ctx);
3816 *nr = result->considered;
3823 @subsection Deleting Keys
3825 @cindex key ring, delete from
3827 @deftypefun gpgme_error_t gpgme_op_delete (@w{gpgme_ctx_t @var{ctx}}, @w{const gpgme_key_t @var{key}}, @w{int @var{allow_secret}})
3828 The function @code{gpgme_op_delete} deletes the key @var{key} from the
3829 key ring of the crypto engine used by @var{ctx}. If
3830 @var{allow_secret} is @code{0}, only public keys are deleted,
3831 otherwise secret keys are deleted as well, if that is supported.
3833 The function returns the error code @code{GPG_ERR_NO_ERROR} if the key
3834 was deleted successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3835 @var{key} is not a valid pointer, @code{GPG_ERR_NO_PUBKEY} if
3836 @var{key} could not be found in the keyring,
3837 @code{GPG_ERR_AMBIGUOUS_NAME} if the key was not specified
3838 unambiguously, and @code{GPG_ERR_CONFLICT} if the secret key for
3839 @var{key} is available, but @var{allow_secret} is zero.
3842 @deftypefun gpgme_error_t gpgme_op_delete_start (@w{gpgme_ctx_t @var{ctx}}, @w{const gpgme_key_t @var{key}}, @w{int @var{allow_secret}})
3843 The function @code{gpgme_op_delete_start} initiates a
3844 @code{gpgme_op_delete} operation. It can be completed by calling
3845 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3847 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3848 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3849 @var{ctx} or @var{key} is not a valid pointer.
3853 @node Changing Passphrases
3854 @subsection Changing Passphrases
3855 @cindex passphrase, change
3857 @deftypefun gpgme_error_t gpgme_op_passwd @
3858 (@w{gpgme_ctx_t @var{ctx}}, @
3859 @w{const gpgme_key_t @var{key}}, @
3860 @w{unsigned int @var{flags}})
3862 The function @code{gpgme_op_passwd} changes the passphrase of the
3863 private key associated with @var{key}. The only allowed value for
3864 @var{flags} is @code{0}. The backend engine will usually popup a window
3865 to ask for the old and the new passphrase. Thus this function is not
3866 useful in a server application (where passphrases are not required
3869 Note that old @code{gpg} engines (before version 2.0.15) do not support
3870 this command and will silently ignore it.
3873 @deftypefun gpgme_error_t gpgme_op_passwd_start @
3874 (@w{gpgme_ctx_t @var{ctx}}, @
3875 @w{const gpgme_key_t @var{key}}, @
3876 @w{unsigned int @var{flags}})
3878 The function @code{gpgme_op_passwd_start} initiates a
3879 @code{gpgme_op_passwd} operation. It can be completed by calling
3880 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3882 The function returns @code{0} if the operation was started successfully,
3883 and an error code if one of the arguments is not valid or the oepration
3884 could not be started.
3888 @node Advanced Key Editing
3889 @subsection Advanced Key Editing
3892 @deftp {Data type} {gpgme_error_t (*gpgme_edit_cb_t) (@w{void *@var{handle}}, @w{gpgme_status_code_t @var{status}}, @w{const char *@var{args}}, @w{int @var{fd}})}
3893 @tindex gpgme_edit_cb_t
3894 The @code{gpgme_edit_cb_t} type is the type of functions which
3895 @acronym{GPGME} calls if it a key edit operation is on-going. The
3896 status code @var{status} and the argument line @var{args} are passed
3897 through by @acronym{GPGME} from the crypto engine. The file
3898 descriptor @var{fd} is -1 for normal status messages. If @var{status}
3899 indicates a command rather than a status message, the response to the
3900 command should be written to @var{fd}. The @var{handle} is provided
3901 by the user at start of operation.
3903 The function should return @code{GPG_ERR_NO_ERROR} or an error value.
3906 @deftypefun gpgme_error_t gpgme_op_edit (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3907 The function @code{gpgme_op_edit} processes the key @var{KEY}
3908 interactively, using the edit callback function @var{FNC} with the
3909 handle @var{HANDLE}. The callback is invoked for every status and
3910 command request from the crypto engine. The output of the crypto
3911 engine is written to the data object @var{out}.
3913 Note that the protocol between the callback function and the crypto
3914 engine is specific to the crypto engine and no further support in
3915 implementing this protocol correctly is provided by @acronym{GPGME}.
3917 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3918 edit operation completes successfully, @code{GPG_ERR_INV_VALUE} if
3919 @var{ctx} or @var{key} is not a valid pointer, and any error returned
3920 by the crypto engine or the edit callback handler.
3923 @deftypefun gpgme_error_t gpgme_op_edit_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3924 The function @code{gpgme_op_edit_start} initiates a
3925 @code{gpgme_op_edit} operation. It can be completed by calling
3926 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3928 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3929 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3930 @var{ctx} or @var{key} is not a valid pointer.
3934 @deftypefun gpgme_error_t gpgme_op_card_edit (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3935 The function @code{gpgme_op_card_edit} is analogous to
3936 @code{gpgme_op_edit}, but should be used to process the smart card corresponding to the key @var{key}.
3939 @deftypefun gpgme_error_t gpgme_op_card_edit_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{key}}, @w{gpgme_edit_cb_t @var{fnc}}, @w{void *@var{handle}}, @w{gpgme_data_t @var{out}})
3940 The function @code{gpgme_op_card_edit_start} initiates a
3941 @code{gpgme_op_card_edit} operation. It can be completed by calling
3942 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3944 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3945 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3946 @var{ctx} or @var{key} is not a valid pointer.
3950 @node Trust Item Management
3951 @section Trust Item Management
3954 @strong{Caution:} The trust items interface is experimental.
3956 @deftp {Data type} gpgme_trust_item_t
3957 The @code{gpgme_trust_item_t} type is a pointer to a trust item object.
3958 It has the following members:
3962 This is a string describing the key to which this trust items belongs.
3965 This is the type of the trust item. A value of 1 refers to a key, a
3966 value of 2 refers to a user ID.
3969 This is the trust level.
3971 @item char *owner_trust
3972 The owner trust if @code{type} is 1.
3974 @item char *validity
3975 The calculated validity.
3978 The user name if @code{type} is 2.
3983 * Listing Trust Items:: Browsing the list of available trust items.
3984 * Information About Trust Items:: Requesting information about trust items.
3985 * Manipulating Trust Items:: Operations on trust items.
3989 @node Listing Trust Items
3990 @subsection Listing Trust Items
3991 @cindex trust item list
3993 @deftypefun gpgme_error_t gpgme_op_trustlist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}})
3994 The function @code{gpgme_op_trustlist_start} initiates a trust item
3995 listing operation inside the context @var{ctx}. It sets everything up
3996 so that subsequent invocations of @code{gpgme_op_trustlist_next} return
3997 the trust items in the list.
3999 The string @var{pattern} contains an engine specific expression that
4000 is used to limit the list to all trust items matching the pattern. It
4001 can not be the empty string.
4003 The argument @var{max_level} is currently ignored.
4005 The context will be busy until either all trust items are received
4006 (and @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}), or
4007 @code{gpgme_op_trustlist_end} is called to finish the operation.
4009 The function returns the error code @code{GPG_ERR_INV_VALUE} if
4010 @var{ctx} is not a valid pointer, and passes through any errors that
4011 are reported by the crypto engine support routines.
4014 @deftypefun gpgme_error_t gpgme_op_trustlist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_trust_item_t *@var{r_item}})
4015 The function @code{gpgme_op_trustlist_next} returns the next trust
4016 item in the list created by a previous @code{gpgme_op_trustlist_start}
4017 operation in the context @var{ctx}. The trust item can be destroyed
4018 with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}.
4020 This is the only way to get at @code{gpgme_trust_item_t} objects in
4023 If the last trust item in the list has already been returned,
4024 @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}.
4026 The function returns the error code @code{GPG_ERR_INV_VALUE} if @var{ctx} or
4027 @var{r_item} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if
4028 there is not enough memory for the operation.
4031 @deftypefun gpgme_error_t gpgme_op_trustlist_end (@w{gpgme_ctx_t @var{ctx}})
4032 The function @code{gpgme_op_trustlist_end} ends a pending trust list
4033 operation in the context @var{ctx}.
4035 The function returns the error code @code{GPG_ERR_INV_VALUE} if
4036 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
4037 time during the operation there was not enough memory available.
4041 @node Information About Trust Items
4042 @subsection Information About Trust Items
4043 @cindex trust item, information about
4044 @cindex trust item, attributes
4045 @cindex attributes, of a trust item
4047 The following interfaces are deprecated and only provided for backward
4048 compatibility. Don't use them. They will be removed in a future
4049 version of @acronym{GPGME}.
4051 Trust items have attributes which can be queried using the interfaces
4052 below. The attribute identifiers are shared with those for key
4053 attributes. @xref{Information About Keys}.
4055 @deftypefun {const char *} gpgme_trust_item_get_string_attr (@w{gpgme_trust_item_t @var{item}}, @w{gpgme_attr_t @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
4056 The function @code{gpgme_trust_item_get_string_attr} returns the value
4057 of the string-representable attribute @var{what} of trust item
4058 @var{item}. The arguments @var{idx} and @var{reserved} are reserved
4059 for later use and should be @code{0} and @code{NULL} respectively.
4061 The string returned is only valid as long as the key is valid.
4063 The function returns @code{0} if an attribute can't be returned as a
4064 string, @var{key} is not a valid pointer, @var{idx} out of range,
4065 or @var{reserved} not @code{NULL}.
4068 @deftypefun int gpgme_trust_item_get_int_attr (@w{gpgme_trust_item_t @var{item}}, @w{gpgme_attr_t @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
4069 The function @code{gpgme_trust_item_get_int_attr} returns the value of
4070 the number-representable attribute @var{what} of trust item
4071 @var{item}. If the attribute occurs more than once in the trust item,
4072 the index is specified by @var{idx}. However, currently no such
4073 attribute exists, so @var{idx} should be @code{0}. The argument
4074 @var{reserved} is reserved for later use and should be @code{NULL}.
4076 The function returns @code{0} if the attribute can't be returned as a
4077 number, @var{key} is not a valid pointer, @var{idx} out of range,
4078 or @var{reserved} not @code{NULL}.
4082 @node Manipulating Trust Items
4083 @subsection Manipulating Trust Items
4084 @cindex trust item, manipulation
4086 @deftypefun void gpgme_trust_item_ref (@w{gpgme_trust_item_t @var{item}})
4087 The function @code{gpgme_trust_item_ref} acquires an additional
4088 reference for the trust item @var{item}.
4091 @deftypefun void gpgme_trust_item_unref (@w{gpgme_trust_item_t @var{item}})
4092 The function @code{gpgme_trust_item_unref} releases a reference for
4093 the trust item @var{item}. If this was the last reference, the trust
4094 item will be destroyed and all resources associated to it will be
4099 The following interface is deprecated and only provided for backward
4100 compatibility. Don't use it. It will be removed in a future version
4103 @deftypefun void gpgme_trust_item_release (@w{gpgme_trust_item_t @var{item}})
4104 The function @code{gpgme_trust_item_release} is an alias for
4105 @code{gpgme_trust_item_unref}.
4109 @node Crypto Operations
4110 @section Crypto Operations
4111 @cindex cryptographic operation
4113 Sometimes, the result of a crypto operation returns a list of invalid
4114 keys encountered in processing the request. The following structure
4115 is used to hold information about such a key.
4117 @deftp {Data type} {gpgme_invalid_key_t}
4118 This is a pointer to a structure used to store a part of the result of
4119 a crypto operation which takes user IDs as one input parameter. The
4120 structure contains the following members:
4123 @item gpgme_invalid_key_t next
4124 This is a pointer to the next invalid key structure in the linked
4125 list, or @code{NULL} if this is the last element.
4128 The fingerprint or key ID of the invalid key encountered.
4130 @item gpgme_error_t reason
4131 An error code describing the reason why the key was found invalid.
4137 * Decrypt:: Decrypting a ciphertext.
4138 * Verify:: Verifying a signature.
4139 * Decrypt and Verify:: Decrypting a signed ciphertext.
4140 * Sign:: Creating a signature.
4141 * Encrypt:: Encrypting a plaintext.
4148 @cindex cryptographic operation, decryption
4150 @deftypefun gpgme_error_t gpgme_op_decrypt (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{cipher}}, @w{gpgme_data_t @var{plain}})
4151 The function @code{gpgme_op_decrypt} decrypts the ciphertext in the
4152 data object @var{cipher} and stores it into the data object
4155 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4156 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
4157 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
4158 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
4159 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
4160 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
4161 secret key could not be retrieved, and passes through any errors that
4162 are reported by the crypto engine support routines.
4165 @deftypefun gpgme_error_t gpgme_op_decrypt_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{cipher}}, @w{gpgme_data_t @var{plain}})
4166 The function @code{gpgme_op_decrypt_start} initiates a
4167 @code{gpgme_op_decrypt} operation. It can be completed by calling
4168 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4170 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4171 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
4172 if @var{cipher} or @var{plain} is not a valid pointer.
4175 @deftp {Data type} {gpgme_recipient_t}
4176 This is a pointer to a structure used to store information about the
4177 recipient of an encrypted text which is decrypted in a
4178 @code{gpgme_op_decrypt} operation. This information (except for the
4179 status field) is even available before the operation finished
4180 successfully, for example in a passphrase callback. The structure
4181 contains the following members:
4184 @item gpgme_recipient_t next
4185 This is a pointer to the next recipient structure in the linked list,
4186 or @code{NULL} if this is the last element.
4188 @item gpgme_pubkey_algo_t
4189 The public key algorithm used in the encryption.
4191 @item unsigned int wrong_key_usage : 1
4192 This is true if the key was not used according to its policy.
4195 This is the key ID of the key (in hexadecimal digits) used as
4198 @item gpgme_error_t status
4199 This is an error number with the error code GPG_ERR_NO_SECKEY if the
4200 secret key for this recipient is not available, and 0 otherwise.
4204 @deftp {Data type} {gpgme_decrypt_result_t}
4205 This is a pointer to a structure used to store the result of a
4206 @code{gpgme_op_decrypt} operation. After successfully decrypting
4207 data, you can retrieve the pointer to the result with
4208 @code{gpgme_op_decrypt_result}. The structure contains the following
4212 @item char *unsupported_algorithm
4213 If an unsupported algorithm was encountered, this string describes the
4214 algorithm that is not supported.
4216 @item unsigned int wrong_key_usage : 1
4217 This is true if the key was not used according to its policy.
4219 @item gpgme_recipient_t recipients
4220 This is a linked list of recipients to which this message was encrypted.
4222 @item char *file_name
4223 This is the filename of the original plaintext message file if it is
4224 known, otherwise this is a null pointer.
4228 @deftypefun gpgme_decrypt_result_t gpgme_op_decrypt_result (@w{gpgme_ctx_t @var{ctx}})
4229 The function @code{gpgme_op_decrypt_result} returns a
4230 @code{gpgme_decrypt_result_t} pointer to a structure holding the
4231 result of a @code{gpgme_op_decrypt} operation. The pointer is only
4232 valid if the last operation on the context was a
4233 @code{gpgme_op_decrypt} or @code{gpgme_op_decrypt_start} operation.
4234 If the operation failed this might be a @code{NULL} pointer. The
4235 returned pointer is only valid until the next operation is started on
4242 @cindex verification
4243 @cindex signature, verification
4244 @cindex cryptographic operation, verification
4245 @cindex cryptographic operation, signature check
4246 @cindex signature notation data
4247 @cindex notation data
4249 @deftypefun gpgme_error_t gpgme_op_verify (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{sig}}, @w{gpgme_data_t @var{signed_text}}, @w{gpgme_data_t @var{plain}})
4250 The function @code{gpgme_op_verify} verifies that the signature in the
4251 data object @var{sig} is a valid signature. If @var{sig} is a
4252 detached signature, then the signed text should be provided in
4253 @var{signed_text} and @var{plain} should be a null pointer.
4254 Otherwise, if @var{sig} is a normal (or cleartext) signature,
4255 @var{signed_text} should be a null pointer and @var{plain} should be a
4256 writable data object that will contain the plaintext after successful
4259 The results of the individual signature verifications can be retrieved
4260 with @code{gpgme_op_verify_result}.
4262 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4263 operation could be completed successfully, @code{GPG_ERR_INV_VALUE} if
4264 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer,
4265 @code{GPG_ERR_NO_DATA} if @var{sig} does not contain any data to
4266 verify, and passes through any errors that are reported by the crypto
4267 engine support routines.
4270 @deftypefun gpgme_error_t gpgme_op_verify_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{sig}}, @w{gpgme_data_t @var{signed_text}}, @w{gpgme_data_t @var{plain}})
4271 The function @code{gpgme_op_verify_start} initiates a
4272 @code{gpgme_op_verify} operation. It can be completed by calling
4273 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4275 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4276 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
4277 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer, and
4278 @code{GPG_ERR_NO_DATA} if @var{sig} or @var{plain} does not contain
4282 @deftp {Data type} {gpgme_sig_notation_t}
4283 This is a pointer to a structure used to store a part of the result of
4284 a @code{gpgme_op_verify} operation. The structure contains the
4288 @item gpgme_sig_notation_t next
4289 This is a pointer to the next new signature notation structure in the
4290 linked list, or @code{NULL} if this is the last element.
4293 The name of the notation field. If this is @code{NULL}, then the
4294 member @code{value} will contain a policy URL.
4297 The length of the @code{name} field. For strings the length is
4298 counted without the trailing binary zero.
4301 The value of the notation field. If @code{name} is @code{NULL}, then
4302 this is a policy URL.
4305 The length of the @code{value} field. For strings the length is
4306 counted without the trailing binary zero.
4308 @item gpgme_sig_notation_flags_t flags
4309 The accumulated flags field. This field contains the flags associated
4310 with the notation data in an accumulated form which can be used as an
4311 argument to the function @code{gpgme_sig_notation_add}. The value
4312 @code{flags} is a bitwise-or combination of one or multiple of the
4313 following bit values:
4316 @item GPGME_SIG_NOTATION_HUMAN_READABLE
4317 The @code{GPGME_SIG_NOTATION_HUMAN_READABLE} symbol specifies that the
4318 notation data is in human readable form
4320 @item GPGME_SIG_NOTATION_CRITICAL
4321 The @code{GPGME_SIG_NOTATION_CRITICAL} symbol specifies that the
4322 notation data is critical.
4326 @item unsigned int human_readable : 1
4327 This is true if the @code{GPGME_SIG_NOTATION_HUMAN_READABLE} flag is
4328 set and false otherwise. This flag is only valid for notation data,
4329 not for policy URLs.
4331 @item unsigned int critical : 1
4332 This is true if the @code{GPGME_SIG_NOTATION_CRITICAL} flag is set and
4333 false otherwise. This flag is valid for notation data and policy URLs.
4338 @deftp {Data type} {gpgme_signature_t}
4339 This is a pointer to a structure used to store a part of the result of
4340 a @code{gpgme_op_verify} operation. The structure contains the
4344 @item gpgme_signature_t next
4345 This is a pointer to the next new signature structure in the linked
4346 list, or @code{NULL} if this is the last element.
4348 @item gpgme_sigsum_t summary
4349 This is a bit vector giving a summary of the signature status. It
4350 provides an easy interface to a defined semantic of the signature
4351 status. Checking just one bit is sufficient to see whether a
4352 signature is valid without any restrictions.
4354 The defined bits are: