1 \input texinfo @c -*- mode: texinfo; coding: utf-8; -*-
2 @documentencoding UTF-8
3 @setfilename gpgme.info
4 @settitle The `GnuPG Made Easy' Reference Manual
6 @dircategory GNU Libraries
8 * @acronym{GPGME}: (gpgme). Adding support for cryptography to your program.
11 @c Unify some of the indices.
16 Copyright @copyright{} 2002, 2003, 2004, 2005, 2006, 2007,
17 2008, 2010, 2012, 2013, 2014 g10 Code GmbH.
20 Permission is granted to copy, distribute and/or modify this document
21 under the terms of the GNU General Public License as published by the
22 Free Software Foundation; either version 3 of the License, or (at your
23 option) any later version. The text of the license can be found in the
24 section entitled ``Copying''.
27 This document is distributed in the hope that it will be useful, but
28 WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 General Public License for more details.
35 @c Macros used by the description of the UI server protocol
48 This file documents the @acronym{GPGME} library.
50 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
51 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
54 @c NOTE: Don't forget to update the year for the TeX version, too.
59 @c We do not want that bastard short titlepage.
61 @c @shorttitlepage The `GnuPG Made Easy' Reference Manual
64 @center @titlefont{The `GnuPG Made Easy'}
66 @center @titlefont{Reference Manual}
68 @center Edition @value{EDITION}
70 @center last updated @value{UPDATED}
72 @center for version @value{VERSION}
74 @vskip 0pt plus 1filll
75 Published by g10 Code GmbH@* Hüttenstr. 61@* 40699 Erkrath, Germany
87 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
88 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
89 @value{VERSION} of the @acronym{GPGME} library.
93 * Introduction:: How to use this manual.
94 * Preparation:: What you should do before using the library.
95 * Protocols and Engines:: Supported crypto protocols.
96 * Algorithms:: Supported algorithms.
97 * Error Handling:: Error numbers and their meanings.
98 * Exchanging Data:: Passing data to and from @acronym{GPGME}.
99 * Contexts:: Handling @acronym{GPGME} contexts.
103 * UI Server Protocol:: The GnuPG UI Server Protocol.
104 * Debugging:: How to solve problems.
106 * Library Copying:: The GNU Lesser General Public License says
107 how you can copy and share `GnuPG Made Easy'.
108 * Copying:: The GNU General Public License says how you
109 can copy and share this manual.
113 * Concept Index:: Index of concepts and programs.
114 * Function and Data Index:: Index of functions, variables and data types.
117 --- The Detailed Node Listing ---
121 * Getting Started:: Purpose of the manual, and how to use it.
122 * Features:: Reasons to install and use @acronym{GPGME}.
123 * Overview:: Basic architecture of the @acronym{GPGME} library.
127 * Header:: What header file you need to include.
128 * Building the Source:: Compiler options to be used.
129 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
130 * Using Automake:: Compiler options to be used the easy way.
131 * Using Libtool:: Avoiding compiler options entirely.
132 * Library Version Check:: Getting and verifying the library version.
133 * Signal Handling:: How @acronym{GPGME} affects signal handling.
134 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
136 Protocols and Engines
138 * Engine Version Check:: Verifying the engine version.
139 * Engine Information:: Obtaining more information about the engines.
140 * Engine Configuration:: Changing the engine configuration.
141 * OpenPGP:: Support for the OpenPGP protocol.
142 * Cryptographic Message Syntax:: Support for the CMS.
146 * Public Key Algorithms:: A list of all public key algorithms.
147 * Hash Algorithms:: A list of all hash algorithms.
151 * Error Values:: The error value and what it means.
152 * Error Codes:: A list of important error codes.
153 * Error Sources:: A list of important error sources.
154 * Error Strings:: How to get a descriptive string from a value.
158 * Creating Data Buffers:: Creating new data buffers.
159 * Destroying Data Buffers:: Releasing data buffers.
160 * Manipulating Data Buffers:: Operations on data buffers.
162 Creating Data Buffers
164 * Memory Based Data Buffers:: Creating memory based data buffers.
165 * File Based Data Buffers:: Creating file based data buffers.
166 * Callback Based Data Buffers:: Creating callback based data buffers.
168 Manipulating Data Buffers
170 * Data Buffer I/O Operations:: I/O operations on data buffers.
171 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
172 * Data Buffer Convenience:: Convenience function for 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 * Miscellaneous:: Miscellaneous operations.
184 * Run Control:: Controlling how operations are run.
188 * Protocol Selection:: Selecting the protocol used by a context.
189 * Crypto Engine:: Configuring the crypto engine.
190 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
191 * Text Mode:: Choosing canonical text mode.
192 * Included Certificates:: Including a number of certificates.
193 * Key Listing Mode:: Selecting key listing mode.
194 * Passphrase Callback:: Getting the passphrase from the user.
195 * Progress Meter Callback:: Being informed about the progress.
196 * Locale:: Setting the locale of a context.
200 * Listing Keys:: Browsing the list of available keys.
201 * Information About Keys:: Requesting detailed information about keys.
202 * Key Signatures:: Listing the signatures on a key.
203 * Manipulating Keys:: Operations on keys.
204 * Generating Keys:: Creating new key pairs.
205 * Exporting Keys:: Retrieving key data from the key ring.
206 * Importing Keys:: Adding keys to the key ring.
207 * Deleting Keys:: Removing keys from the key ring.
208 * Changing Passphrases:: Change the passphrase of a key.
209 * Advanced Key Editing:: Advanced key edit operation.
211 Trust Item Management
213 * Listing Trust Items:: Browsing the list of available trust items.
214 * Information About Trust Items:: Requesting information about trust items.
215 * Manipulating Trust Items:: Operations on trust items.
219 * Decrypt:: Decrypting a ciphertext.
220 * Verify:: Verifying a signature.
221 * Decrypt and Verify:: Decrypting a signed ciphertext.
222 * Sign:: Creating a signature.
223 * Encrypt:: Encrypting a plaintext.
227 * Selecting Signers:: How to choose the keys to sign with.
228 * Creating a Signature:: How to create a signature.
229 * Signature Notation Data:: How to add notation data to a signature.
233 * Encrypting a Plaintext:: How to encrypt a plaintext.
237 * Running other Programs:: Running other Programs
241 * Waiting For Completion:: Waiting until an operation is completed.
242 * Using External Event Loops:: Advanced control over what happens when.
243 * Cancellation:: How to end pending operations prematurely.
245 Using External Event Loops
247 * I/O Callback Interface:: How I/O callbacks are registered.
248 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
249 * I/O Callback Example:: An example how to use I/O callbacks.
250 * I/O Callback Example GTK+:: How to integrate @acronym{GPGME} in GTK+.
251 * I/O Callback Example GDK:: How to integrate @acronym{GPGME} in GDK.
252 * I/O Callback Example Qt:: How to integrate @acronym{GPGME} in Qt.
258 @chapter Introduction
260 `GnuPG Made Easy' (@acronym{GPGME}) is a C language library that
261 allows to add support for cryptography to a program. It is designed
262 to make access to public key crypto engines like GnuPG or GpgSM easier
263 for applications. @acronym{GPGME} provides a high-level crypto API
264 for encryption, decryption, signing, signature verification and key
267 @acronym{GPGME} uses GnuPG and GpgSM as its backends to support
268 OpenPGP and the Cryptographic Message Syntax (CMS).
271 * Getting Started:: Purpose of the manual, and how to use it.
272 * Features:: Reasons to install and use @acronym{GPGME}.
273 * Overview:: Basic architecture of the @acronym{GPGME} library.
277 @node Getting Started
278 @section Getting Started
280 This manual documents the @acronym{GPGME} library programming
281 interface. All functions and data types provided by the library are
284 The reader is assumed to possess basic knowledge about cryptography in
285 general, and public key cryptography in particular. The underlying
286 cryptographic engines that are used by the library are not explained,
287 but where necessary, special features or requirements by an engine are
288 mentioned as far as they are relevant to @acronym{GPGME} or its users.
290 This manual can be used in several ways. If read from the beginning
291 to the end, it gives a good introduction into the library and how it
292 can be used in an application. Forward references are included where
293 necessary. Later on, the manual can be used as a reference manual to
294 get just the information needed about any particular interface of the
295 library. Experienced programmers might want to start looking at the
296 examples at the end of the manual, and then only read up those parts
297 of the interface which are unclear.
303 @acronym{GPGME} has a couple of advantages over other libraries doing
304 a similar job, and over implementing support for GnuPG or other crypto
305 engines into your application directly.
308 @item it's free software
309 Anybody can use, modify, and redistribute it under the terms of the GNU
310 Lesser General Public License (@pxref{Library Copying}).
313 @acronym{GPGME} provides transparent support for several cryptographic
314 protocols by different engines. Currently, @acronym{GPGME} supports
315 the OpenPGP protocol using GnuPG as the backend, and the Cryptographic
316 Message Syntax using GpgSM as the backend.
319 @acronym{GPGME} hides the differences between the protocols and
320 engines from the programmer behind an easy-to-use interface. This way
321 the programmer can focus on the other parts of the program, and still
322 integrate strong cryptography in his application. Once support for
323 @acronym{GPGME} has been added to a program, it is easy to add support
324 for other crypto protocols once @acronym{GPGME} backends provide them.
331 @acronym{GPGME} provides a data abstraction that is used to pass data
332 to the crypto engine, and receive returned data from it. Data can be
333 read from memory or from files, but it can also be provided by a
336 The actual cryptographic operations are always set within a context.
337 A context provides configuration parameters that define the behaviour
338 of all operations performed within it. Only one operation per context
339 is allowed at any time, but when one operation is finished, you can
340 run the next operation in the same context. There can be more than
341 one context, and all can run different operations at the same time.
343 Furthermore, @acronym{GPGME} has rich key management facilities
344 including listing keys, querying their attributes, generating,
345 importing, exporting and deleting keys, and acquiring information
346 about the trust path.
348 With some precautions, @acronym{GPGME} can be used in a multi-threaded
349 environment, although it is not completely thread safe and thus needs
350 the support of the application.
356 To use @acronym{GPGME}, you have to perform some changes to your
357 sources and the build system. The necessary changes are small and
358 explained in the following sections. At the end of this chapter, it
359 is described how the library is initialized, and how the requirements
360 of the library are verified.
363 * Header:: What header file you need to include.
364 * Building the Source:: Compiler options to be used.
365 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
366 * Using Automake:: Compiler options to be used the easy way.
367 * Using Libtool:: Avoiding compiler options entirely.
368 * Library Version Check:: Getting and verifying the library version.
369 * Signal Handling:: How @acronym{GPGME} affects signal handling.
370 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
379 All interfaces (data types and functions) of the library are defined
380 in the header file `gpgme.h'. You must include this in all programs
381 using the library, either directly or through some other header file,
388 The name space of @acronym{GPGME} is @code{gpgme_*} for function names
389 and data types and @code{GPGME_*} for other symbols. Symbols internal
390 to @acronym{GPGME} take the form @code{_gpgme_*} and @code{_GPGME_*}.
392 Because @acronym{GPGME} makes use of the GPG Error library, using
393 @acronym{GPGME} will also use the @code{GPG_ERR_*} name space
394 directly, and the @code{gpg_err*} and @code{gpg_str*} name space
398 @node Building the Source
399 @section Building the Source
400 @cindex compiler options
401 @cindex compiler flags
403 If you want to compile a source file including the `gpgme.h' header
404 file, you must make sure that the compiler can find it in the
405 directory hierarchy. This is accomplished by adding the path to the
406 directory in which the header file is located to the compilers include
407 file search path (via the @option{-I} option).
409 However, the path to the include file is determined at the time the
410 source is configured. To solve this problem, gpgme ships with a small
411 helper program @command{gpgme-config} that knows about the path to the
412 include file and other configuration options. The options that need
413 to be added to the compiler invocation at compile time are output by
414 the @option{--cflags} option to @command{gpgme-config}. The following
415 example shows how it can be used at the command line:
418 gcc -c foo.c `gpgme-config --cflags`
421 Adding the output of @samp{gpgme-config --cflags} to the compiler
422 command line will ensure that the compiler can find the
423 @acronym{GPGME} header file.
425 A similar problem occurs when linking the program with the library.
426 Again, the compiler has to find the library files. For this to work,
427 the path to the library files has to be added to the library search
428 path (via the @option{-L} option). For this, the option
429 @option{--libs} to @command{gpgme-config} can be used. For
430 convenience, this option also outputs all other options that are
431 required to link the program with @acronym{GPGME} (in particular, the
432 @samp{-lgpgme} option). The example shows how to link @file{foo.o}
433 with the @acronym{GPGME} library to a program @command{foo}.
436 gcc -o foo foo.o `gpgme-config --libs`
439 Of course you can also combine both examples to a single command by
440 specifying both options to @command{gpgme-config}:
443 gcc -o foo foo.c `gpgme-config --cflags --libs`
446 If you want to link to one of the thread-safe versions of
447 @acronym{GPGME}, you must specify the @option{--thread} option before
448 any other option to select the thread package you want to link with.
449 Supported thread packages are @option{--thread=pth} and
450 @option{--thread=pthread}.
453 @node Largefile Support (LFS)
454 @section Largefile Support (LFS)
455 @cindex largefile support
458 @acronym{GPGME} is compiled with largefile support by default, if it
459 is available on the system. This means that GPGME supports files
460 larger than two gigabyte in size, if the underlying operating system
461 can. On some systems, largefile support is already the default. On
462 such systems, nothing special is required. However, some systems
463 provide only support for files up to two gigabyte in size by default.
464 Support for larger file sizes has to be specifically enabled.
466 To make a difficult situation even more complex, such systems provide
467 two different types of largefile support. You can either get all
468 relevant functions replaced with alternatives that are largefile
469 capable, or you can get new functions and data types for largefile
470 support added. Those new functions have the same name as their
471 smallfile counterparts, but with a suffix of 64.
473 An example: The data type @code{off_t} is 32 bit wide on GNU/Linux PC
474 systems. To address offsets in large files, you can either enable
475 largefile support add-on. Then a new data type @code{off64_t} is
476 provided, which is 64 bit wide. Or you can replace the existing
477 @code{off_t} data type with its 64 bit wide counterpart. All
478 occurences of @code{off_t} are then automagically replaced.
480 As if matters were not complex enough, there are also two different
481 types of file descriptors in such systems. This is important because
482 if file descriptors are exchanged between programs that use a
483 different maximum file size, certain errors must be produced on some
484 file descriptors to prevent subtle overflow bugs from occuring.
486 As you can see, supporting two different maximum file sizes at the
487 same time is not at all an easy task. However, the maximum file size
488 does matter for @acronym{GPGME}, because some data types it uses in
489 its interfaces are affected by that. For example, the @code{off_t}
490 data type is used in the @code{gpgme_data_seek} function, to match its
491 @acronym{POSIX} counterpart. This affects the call-frame of the
492 function, and thus the ABI of the library. Furthermore, file
493 descriptors can be exchanged between GPGME and the application.
495 For you as the user of the library, this means that your program must
496 be compiled in the same file size mode as the library. Luckily, there
497 is absolutely no valid reason for new programs to not enable largefile
498 support by default and just use that. The compatibility modes (small
499 file sizes or dual mode) can be considered an historic artefact, only
500 useful to allow for a transitional period.
502 On POSIX platforms @acronym{GPGME} is compiled using largefile support
503 by default. This means that your application must do the same, at
504 least as far as it is relevant for using the @file{gpgme.h} header
505 file. All types in this header files refer to their largefile
506 counterparts, if they are different from any default types on the
509 On 32 and 64 bit Windows platforms @code{off_t} is declared as 32 bit
510 signed integer. There is no specific support for LFS in the C
511 library. The recommendation from Microsoft is to use the native
512 interface (@code{CreateFile} et al.) for large files. Released binary
513 versions of @acronym{GPGME} (libgpgme-11.dll) have always been build
514 with a 32 bit @code{off_t}. To avoid an ABI break we stick to this
515 convention for 32 bit Windows by using @code{long} there.
516 @acronym{GPGME} versions for 64 bit Windows have never been released
517 and thus we are able to use @code{int64_t} instead of @code{off_t}
518 there. For easier migration the typedef @code{gpgme_off_t} has been
519 defined. The reason we cannot use @code{off_t} directly is that some
520 toolchains (e.g. mingw64) introduce a POSIX compatible hack for
521 @code{off_t}. Some widely used toolkits make use of this hack and in
522 turn @acronym{GPGME} would need to use it also. However, this would
523 introduce an ABI break and existing software making use of libgpgme
524 might suffer from a severe break. Thus with version 1.4.2 we
525 redefined all functions using @code{off_t} to use @code{gpgme_off_t}
526 which is defined as explained above. This way we keep the ABI well
527 defined and independent of any toolchain hacks. The bottom line is
528 that LFS support in @acronym{GPGME} is only available on 64 bit
531 On POSIX platforms you can enable largefile support, if it is
532 different from the default on the system the application is compiled
533 on, by using the Autoconf macro @code{AC_SYS_LARGEFILE}. If you do
534 this, then you don't need to worry about anything else: It will just
535 work. In this case you might also want to use @code{AC_FUNC_FSEEKO}
536 to take advantage of some new interfaces, and @code{AC_TYPE_OFF_T}
539 If you do not use Autoconf, you can define the preprocessor symbol
540 @code{_FILE_OFFSET_BITS} to 64 @emph{before} including any header
541 files, for example by specifying the option
542 @code{-D_FILE_OFFSET_BITS=64} on the compiler command line. You will
543 also want to define the preprocessor symbol @code{LARGEFILE_SOURCE} to
544 1 in this case, to take advantage of some new interfaces.
546 If you do not want to do either of the above, you probably know enough
547 about the issue to invent your own solution. Just keep in mind that
548 the @acronym{GPGME} header file expects that largefile support is
549 enabled, if it is available. In particular, we do not support dual
550 mode (@code{_LARGEFILE64_SOURCE}).
554 @section Using Automake
558 It is much easier if you use GNU Automake instead of writing your own
559 Makefiles. If you do that you do not have to worry about finding and
560 invoking the @command{gpgme-config} script at all. @acronym{GPGME}
561 provides an extension to Automake that does all the work for you.
563 @c A simple macro for optional variables.
565 @r{[}@var{\varname\}@r{]}
567 @defmac AM_PATH_GPGME (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
568 @defmacx AM_PATH_GPGME_PTH (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
569 @defmacx AM_PATH_GPGME_PTHREAD (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
570 Check whether @acronym{GPGME} (at least version @var{minimum-version},
571 if given) exists on the host system. If it is found, execute
572 @var{action-if-found}, otherwise do @var{action-if-not-found}, if
575 Additionally, the function defines @code{GPGME_CFLAGS} to the flags
576 needed for compilation of the program to find the @file{gpgme.h}
577 header file, and @code{GPGME_LIBS} to the linker flags needed to link
578 the program to the @acronym{GPGME} library.
580 @code{AM_PATH_GPGME_PTH} checks for the version of @acronym{GPGME}
581 that can be used with GNU Pth, and defines @code{GPGME_PTH_CFLAGS} and
582 @code{GPGME_PTH_LIBS}.
584 @code{AM_PATH_GPGME_PTHREAD} checks for the version of @acronym{GPGME}
585 that can be used with the native pthread implementation, and defines
586 @code{GPGME_PTHREAD_CFLAGS} and @code{GPGME_PTHREAD_LIBS}.
589 You can use the defined Autoconf variables like this in your
593 AM_CPPFLAGS = $(GPGME_CFLAGS)
594 LDADD = $(GPGME_LIBS)
599 @section Using Libtool
602 The easiest way is to just use GNU Libtool. If you use libtool, and
603 link to @code{libgpgme.la}, @code{libgpgme-pth.la} or
604 @code{libgpgme-pthread.la} respectively, everything will be done
605 automatically by Libtool.
608 @node Library Version Check
609 @section Library Version Check
610 @cindex version check, of the library
612 @deftypefun {const char *} gpgme_check_version (@w{const char *@var{required_version}})
613 The function @code{gpgme_check_version} has four purposes. It can be
614 used to retrieve the version number of the library. In addition it
615 can verify that the version number is higher than a certain required
616 version number. In either case, the function initializes some
617 sub-systems, and for this reason alone it must be invoked early in
618 your program, before you make use of the other functions in
619 @acronym{GPGME}. The last purpose is to run selftests.
621 As a side effect for W32 based systems, the socket layer will get
625 If @var{required_version} is @code{NULL}, the function returns a
626 pointer to a statically allocated string containing the version number
629 If @var{required_version} is not @code{NULL}, it should point to a
630 string containing a version number, and the function checks that the
631 version of the library is at least as high as the version number
632 provided. In this case, the function returns a pointer to a
633 statically allocated string containing the version number of the
634 library. If @var{REQUIRED_VERSION} is not a valid version number, or
635 if the version requirement is not met, the function returns
638 If you use a version of a library that is backwards compatible with
639 older releases, but contains additional interfaces which your program
640 uses, this function provides a run-time check if the necessary
641 features are provided by the installed version of the library.
643 If a selftest fails, the function may still succeed. Selftest errors
644 are returned later when invoking @code{gpgme_new}, so that a detailed
645 error code can be returned (historically, @code{gpgme_check_version}
646 does not return a detailed error code).
650 @deftypefun {int} gpgme_set_global_flag @
651 (@w{const char *@var{name}}, @
652 @w{const char *@var{value}})
654 On some systems it is not easy to set environment variables and thus
655 hard to use @acronym{GPGME}'s internal trace facility for debugging.
656 This function has been introduced as an alternative way to enable
657 debugging and for a couple of other rarely used tweaks. It is
658 important to assure that only one thread accesses @acronym{GPGME}
659 functions between a call to this function and after the return from
660 the call to @code{gpgme_check_version}.
662 All currently supported features require that this function is called
663 as early as possible --- even before @code{gpgme_check_version}. The
664 features are identified by the following values for @var{name}:
668 To enable debugging use the string ``debug'' for @var{name} and
669 @var{value} identical to the value used with the environment variable
672 @item "disable-gpgconf"
673 Using this feature with any @var{value} disables the detection of the
674 gpgconf program and thus forces GPGME to fallback into the simple
675 OpenPGP only mode. It may be used to force the use of GnuPG-1 on
676 systems which have both GPG versions installed. Note that in general
677 the use of @code{gpgme_set_engine_info} is a better way to select a
678 specific engine version.
682 Set the name of the gpgconf respective gpg binary. The defaults are
683 @code{GNU/GnuPG/gpgconf} and @code{GNU/GnuPG/gpg}. Under Unix the
684 leading directory part is ignored. Under Windows the leading
685 directory part is used as the default installation directory; the
686 @code{.exe} suffix is added by GPGME. Use forward slashed even under
691 This function returns @code{0} on success. In contrast to other
692 functions the non-zero return value on failure does not convey any
693 error code. For setting ``debug'' the only possible error cause is an
694 out of memory condition; which would exhibit itself later anyway.
695 Thus the return value may be ignored.
699 After initializing @acronym{GPGME}, you should set the locale
700 information to the locale required for your output terminal. This
701 locale information is needed for example for the curses and Gtk
702 pinentry. Here is an example of a complete initialization:
711 /* Initialize the locale environment. */
712 setlocale (LC_ALL, "");
713 gpgme_check_version (NULL);
714 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
716 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
721 Note that you are highly recommended to initialize the locale settings
722 like this. @acronym{GPGME} can not do this for you because it would
723 not be thread safe. The conditional on LC_MESSAGES is only necessary
724 for portability to W32 systems.
727 @node Signal Handling
728 @section Signal Handling
730 @cindex signal handling
732 The @acronym{GPGME} library communicates with child processes (the
733 crypto engines). If a child process dies unexpectedly, for example
734 due to a bug, or system problem, a @code{SIGPIPE} signal will be
735 delivered to the application. The default action is to abort the
736 program. To protect against this, @code{gpgme_check_version} sets the
737 @code{SIGPIPE} signal action to @code{SIG_IGN}, which means that the
738 signal will be ignored.
740 @acronym{GPGME} will only do that if the signal action for
741 @code{SIGPIPE} is @code{SIG_DEF} at the time
742 @code{gpgme_check_version} is called. If it is something different,
743 @code{GPGME} will take no action.
745 This means that if your application does not install any signal
746 handler for @code{SIGPIPE}, you don't need to take any precautions.
747 If you do install a signal handler for @code{SIGPIPE}, you must be
748 prepared to handle any @code{SIGPIPE} events that occur due to
749 @acronym{GPGME} writing to a defunct pipe. Furthermore, if your
750 application is multi-threaded, and you install a signal action for
751 @code{SIGPIPE}, you must make sure you do this either before
752 @code{gpgme_check_version} is called or afterwards.
755 @node Multi Threading
756 @section Multi Threading
757 @cindex thread-safeness
758 @cindex multi-threading
760 The @acronym{GPGME} library is not entirely thread-safe, but it can
761 still be used in a multi-threaded environment if some care is taken.
762 If the following requirements are met, there should be no race
763 conditions to worry about:
767 @acronym{GPGME} supports the thread libraries pthread and GNU Pth.
768 The support for this has to be enabled at compile time.
769 @acronym{GPGME} will automatically detect the location in which the
770 thread libraries are installed and activate the support for them at
773 Support for other thread libraries is very easy to add. Please
774 contact us if you have the need.
777 If you want to use @acronym{GPGME} with threads, you must link to the
778 right version of the library. The name of the right library is
779 @code{libgpgme-} followed by the name of the thread package you use.
780 For example, if you use GNU Pth, the right name is
781 @code{libgpgme-pth}. Use the Automake macros or
782 @command{gpgme-config} program for simplicity.
786 The function @code{gpgme_check_version} must be called before any
787 other function in the library, because it initializes the thread
788 support subsystem in @acronym{GPGME}. To achieve this in
789 multi-threaded programs, you must synchronize the memory with respect
790 to other threads that also want to use @acronym{GPGME}. For this, it
791 is sufficient to call @code{gpgme_check_version} before creating the
792 other threads using @acronym{GPGME}@footnote{At least this is true for
793 POSIX threads, as @code{pthread_create} is a function that
794 synchronizes memory with respects to other threads. There are many
795 functions which have this property, a complete list can be found in
796 POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the
797 definition of the term ``Memory Synchronization''. For other thread
798 packages other, more relaxed or more strict rules may apply.}.
801 Any @code{gpgme_data_t} and @code{gpgme_ctx_t} object must only be
802 accessed by one thread at a time. If multiple threads want to deal
803 with the same object, the caller has to make sure that operations on
804 that object are fully synchronized.
807 Only one thread at any time is allowed to call @code{gpgme_wait}. If
808 multiple threads call this function, the caller must make sure that
809 all invocations are fully synchronized. It is safe to start
810 asynchronous operations while a thread is running in gpgme_wait.
813 The function @code{gpgme_strerror} is not thread safe. You have to
814 use @code{gpgme_strerror_r} instead.
818 @node Protocols and Engines
819 @chapter Protocols and Engines
822 @cindex crypto engine
824 @cindex crypto backend
826 @acronym{GPGME} supports several cryptographic protocols, however, it
827 does not implement them. Rather it uses backends (also called
828 engines) which implement the protocol. @acronym{GPGME} uses
829 inter-process communication to pass data back and forth between the
830 application and the backend, but the details of the communication
831 protocol and invocation of the backend is completely hidden by the
832 interface. All complexity is handled by @acronym{GPGME}. Where an
833 exchange of information between the application and the backend is
834 necessary, @acronym{GPGME} provides the necessary callback function
835 hooks and further interfaces.
837 @deftp {Data type} {enum gpgme_protocol_t}
838 @tindex gpgme_protocol_t
839 The @code{gpgme_protocol_t} type specifies the set of possible protocol
840 values that are supported by @acronym{GPGME}. The following protocols
844 @item GPGME_PROTOCOL_OpenPGP
845 This specifies the OpenPGP protocol.
847 @item GPGME_PROTOCOL_CMS
848 This specifies the Cryptographic Message Syntax.
850 @item GPGME_PROTOCOL_ASSUAN
851 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
853 @item GPGME_PROTOCOL_G13
854 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
856 @item GPGME_PROTOCOL_UISERVER
857 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
859 @item GPGME_PROTOCOL_SPAWN
860 Special protocol for use with @code{gpgme_op_spawn}.
862 @item GPGME_PROTOCOL_UNKNOWN
863 Reserved for future extension. You may use this to indicate that the
864 used protocol is not known to the application. Currently,
865 @acronym{GPGME} does not accept this value in any operation, though,
866 except for @code{gpgme_get_protocol_name}.
871 @deftypefun {const char *} gpgme_get_protocol_name (@w{gpgme_protocol_t @var{protocol}})
872 The function @code{gpgme_get_protocol_name} returns a statically
873 allocated string describing the protocol @var{protocol}, or
874 @code{NULL} if the protocol number is not valid.
878 * Engine Version Check:: Verifying the engine version.
879 * Engine Information:: Obtaining more information about the engines.
880 * Engine Configuration:: Changing the engine configuration.
881 * OpenPGP:: Support for the OpenPGP protocol.
882 * Cryptographic Message Syntax:: Support for the CMS.
886 @node Engine Version Check
887 @section Engine Version Check
888 @cindex version check, of the engines
890 @deftypefun @w{const char *} gpgme_get_dirinfo (@w{cons char *@var{what}})
891 The function @code{gpgme_get_dirinfo} returns a statically allocated
892 string with the value associated to @var{what}. The returned values
893 are the defaults and won't change even after
894 @code{gpgme_set_engine_info} has been used to configure a different
895 engine. @code{NULL} is returned if no value is available. Commonly
896 supported values for @var{what} are:
900 Return the default home directory.
903 Return the name of the socket to connect to the gpg-agent.
905 @item uiserver-socket
906 Return the name of the socket to connect to the user interface server.
909 Return the file name of the engine configuration tool.
912 Return the file name of the OpenPGP engine.
915 Return the file name of the CMS engine.
918 Return the name of the file container encryption engine.
925 @deftypefun gpgme_error_t gpgme_engine_check_version (@w{gpgme_protocol_t @var{protocol}})
926 The function @code{gpgme_engine_check_version} verifies that the
927 engine implementing the protocol @var{PROTOCOL} is installed in the
928 expected path and meets the version requirement of @acronym{GPGME}.
930 This function returns the error code @code{GPG_ERR_NO_ERROR} if the
931 engine is available and @code{GPG_ERR_INV_ENGINE} if it is not.
935 @node Engine Information
936 @section Engine Information
937 @cindex engine, information about
939 @deftp {Data type} {gpgme_engine_info_t}
940 @tindex gpgme_protocol_t
941 The @code{gpgme_engine_info_t} type specifies a pointer to a structure
942 describing a crypto engine. The structure contains the following
946 @item gpgme_engine_info_t next
947 This is a pointer to the next engine info structure in the linked
948 list, or @code{NULL} if this is the last element.
950 @item gpgme_protocol_t protocol
951 This is the protocol for which the crypto engine is used. You can
952 convert this to a string with @code{gpgme_get_protocol_name} for
955 @item const char *file_name
956 This is a string holding the file name of the executable of the crypto
957 engine. Currently, it is never @code{NULL}, but using @code{NULL} is
958 reserved for future use, so always check before you use it.
960 @item const char *home_dir
961 This is a string holding the directory name of the crypto engine's
962 configuration directory. If it is @code{NULL}, then the default
963 directory is used. See @code{gpgme_get_dirinfo} on how to get the
966 @item const char *version
967 This is a string containing the version number of the crypto engine.
968 It might be @code{NULL} if the version number can not be determined,
969 for example because the executable doesn't exist or is invalid.
971 @item const char *req_version
972 This is a string containing the minimum required version number of the
973 crypto engine for @acronym{GPGME} to work correctly. This is the
974 version number that @code{gpgme_engine_check_version} verifies
975 against. Currently, it is never @code{NULL}, but using @code{NULL} is
976 reserved for future use, so always check before you use it.
980 @deftypefun gpgme_error_t gpgme_get_engine_info (@w{gpgme_engine_info_t *@var{info}})
981 The function @code{gpgme_get_engine_info} returns a linked list of
982 engine info structures in @var{info}. Each info structure describes
983 the defaults of one configured backend.
985 The memory for the info structures is allocated the first time this
986 function is invoked, and must not be freed by the caller.
988 This function returns the error code @code{GPG_ERR_NO_ERROR} if
989 successful, and a system error if the memory could not be allocated.
992 Here is an example how you can provide more diagnostics if you receive
993 an error message which indicates that the crypto engine is invalid.
1001 if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
1003 gpgme_engine_info_t info;
1004 err = gpgme_get_engine_info (&info);
1007 while (info && info->protocol != gpgme_get_protocol (ctx))
1010 fprintf (stderr, "GPGME compiled without support for protocol %s",
1011 gpgme_get_protocol_name (info->protocol));
1012 else if (info->file_name && !info->version)
1013 fprintf (stderr, "Engine %s not installed properly",
1015 else if (info->file_name && info->version && info->req_version)
1016 fprintf (stderr, "Engine %s version %s installed, "
1017 "but at least version %s required", info->file_name,
1018 info->version, info->req_version);
1020 fprintf (stderr, "Unknown problem with engine for protocol %s",
1021 gpgme_get_protocol_name (info->protocol));
1027 @node Engine Configuration
1028 @section Engine Configuration
1029 @cindex engine, configuration of
1030 @cindex configuration of crypto backend
1032 You can change the configuration of a backend engine, and thus change
1033 the executable program and configuration directory to be used. You
1034 can make these changes the default or set them for some contexts
1037 @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}})
1038 The function @code{gpgme_set_engine_info} changes the default
1039 configuration of the crypto engine implementing the protocol
1042 @var{file_name} is the file name of the executable program
1043 implementing this protocol, and @var{home_dir} is the directory name
1044 of the configuration directory for this crypto engine. If
1045 @var{home_dir} is @code{NULL}, the engine's default will be used.
1047 The new defaults are not applied to already created GPGME contexts.
1049 This function returns the error code @code{GPG_ERR_NO_ERROR} if
1050 successful, or an eror code on failure.
1053 The functions @code{gpgme_ctx_get_engine_info} and
1054 @code{gpgme_ctx_set_engine_info} can be used to change the engine
1055 configuration per context. @xref{Crypto Engine}.
1062 @cindex protocol, GnuPG
1063 @cindex engine, GnuPG
1065 OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard.
1066 This is the first protocol that was supported by @acronym{GPGME}.
1068 The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}.
1071 @node Cryptographic Message Syntax
1072 @section Cryptographic Message Syntax
1074 @cindex cryptographic message syntax
1076 @cindex protocol, CMS
1077 @cindex engine, GpgSM
1079 @cindex protocol, S/MIME
1081 @acronym{CMS} is implemented by GpgSM, the S/MIME implementation for
1084 The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}.
1091 The crypto backends support a variety of algorithms used in public key
1092 cryptography.@footnote{Some engines also provide symmetric only
1093 encryption; see the description of the encryption function on how to use
1094 this.} The following sections list the identifiers used to denote such
1098 * Public Key Algorithms:: A list of all public key algorithms.
1099 * Hash Algorithms:: A list of all hash algorithms.
1103 @node Public Key Algorithms
1104 @section Public Key Algorithms
1105 @cindex algorithms, public key
1106 @cindex public key algorithms
1108 Public key algorithms are used for encryption, decryption, signing and
1109 verification of signatures.
1111 @deftp {Data type} {enum gpgme_pubkey_algo_t}
1112 @tindex gpgme_pubkey_algo_t
1113 The @code{gpgme_pubkey_algo_t} type specifies the set of all public key
1114 algorithms that are supported by @acronym{GPGME}. Possible values
1119 This value indicates the RSA (Rivest, Shamir, Adleman) algorithm.
1121 @item GPGME_PK_RSA_E
1122 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
1123 algorithm for encryption and decryption only.
1125 @item GPGME_PK_RSA_S
1126 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
1127 algorithm for signing and verification only.
1130 This value indicates DSA, the Digital Signature Algorithm.
1133 This value indicates ElGamal.
1135 @item GPGME_PK_ELG_E
1136 This value also indicates ElGamal and is used specifically in GnuPG.
1138 @item GPGME_PK_ELG_E
1139 This value also indicates ElGamal and is used specifically in GnuPG.
1141 @item GPGME_PK_ECDSA
1142 This value indicates ECDSA, the Elliptic Curve Digital Signature
1143 Algorithm as defined by FIPS 186-2.
1146 This value indicates ECDH, the Eliptic Curve Diffie-Hellmann encryption
1147 algorithm as defined by the ECC in OpenPGP draft.
1152 @deftypefun {const char *} gpgme_pubkey_algo_name (@w{gpgme_pubkey_algo_t @var{algo}})
1153 The function @code{gpgme_pubkey_algo_name} returns a pointer to a
1154 statically allocated string containing a description of the public key
1155 algorithm @var{algo}. This string can be used to output the name of
1156 the public key algorithm to the user.
1158 If @var{algo} is not a valid public key algorithm, @code{NULL} is
1163 @node Hash Algorithms
1164 @section Hash Algorithms
1165 @cindex algorithms, hash
1166 @cindex algorithms, message digest
1167 @cindex hash algorithms
1168 @cindex message digest algorithms
1170 Hash (message digest) algorithms are used to compress a long message
1171 to make it suitable for public key cryptography.
1173 @deftp {Data type} {enum gpgme_hash_algo_t}
1174 @tindex gpgme_hash_algo_t
1175 The @code{gpgme_hash_algo_t} type specifies the set of all hash algorithms
1176 that are supported by @acronym{GPGME}. Possible values are:
1181 @item GPGME_MD_RMD160
1183 @item GPGME_MD_TIGER
1184 @item GPGME_MD_HAVAL
1185 @item GPGME_MD_SHA256
1186 @item GPGME_MD_SHA384
1187 @item GPGME_MD_SHA512
1189 @item GPGME_MD_CRC32
1190 @item GPGME_MD_CRC32_RFC1510
1191 @item GPGME_MD_CRC24_RFC2440
1195 @deftypefun {const char *} gpgme_hash_algo_name (@w{gpgme_hash_algo_t @var{algo}})
1196 The function @code{gpgme_hash_algo_name} returns a pointer to a
1197 statically allocated string containing a description of the hash
1198 algorithm @var{algo}. This string can be used to output the name of
1199 the hash algorithm to the user.
1201 If @var{algo} is not a valid hash algorithm, @code{NULL} is returned.
1205 @node Error Handling
1206 @chapter Error Handling
1207 @cindex error handling
1209 Many functions in @acronym{GPGME} can return an error if they fail.
1210 For this reason, the application should always catch the error
1211 condition and take appropriate measures, for example by releasing the
1212 resources and passing the error up to the caller, or by displaying a
1213 descriptive message to the user and cancelling the operation.
1215 Some error values do not indicate a system error or an error in the
1216 operation, but the result of an operation that failed properly. For
1217 example, if you try to decrypt a tempered message, the decryption will
1218 fail. Another error value actually means that the end of a data
1219 buffer or list has been reached. The following descriptions explain
1220 for many error codes what they mean usually. Some error values have
1221 specific meanings if returned by a certain functions. Such cases are
1222 described in the documentation of those functions.
1224 @acronym{GPGME} uses the @code{libgpg-error} library. This allows to
1225 share the error codes with other components of the GnuPG system, and
1226 thus pass error values transparently from the crypto engine, or some
1227 helper application of the crypto engine, to the user. This way no
1228 information is lost. As a consequence, @acronym{GPGME} does not use
1229 its own identifiers for error codes, but uses those provided by
1230 @code{libgpg-error}. They usually start with @code{GPG_ERR_}.
1232 However, @acronym{GPGME} does provide aliases for the functions
1233 defined in libgpg-error, which might be preferred for name space
1237 * Error Values:: The error value and what it means.
1238 * Error Sources:: A list of important error sources.
1239 * Error Codes:: A list of important error codes.
1240 * Error Strings:: How to get a descriptive string from a value.
1245 @section Error Values
1246 @cindex error values
1248 @cindex error sources
1250 @deftp {Data type} {gpgme_err_code_t}
1251 The @code{gpgme_err_code_t} type is an alias for the @code{libgpg-error}
1252 type @code{gpg_err_code_t}. The error code indicates the type of an
1253 error, or the reason why an operation failed.
1255 A list of important error codes can be found in the next section.
1258 @deftp {Data type} {gpgme_err_source_t}
1259 The @code{gpgme_err_source_t} type is an alias for the
1260 @code{libgpg-error} type @code{gpg_err_source_t}. The error source
1261 has not a precisely defined meaning. Sometimes it is the place where
1262 the error happened, sometimes it is the place where an error was
1263 encoded into an error value. Usually the error source will give an
1264 indication to where to look for the problem. This is not always true,
1265 but it is attempted to achieve this goal.
1267 A list of important error sources can be found in the next section.
1270 @deftp {Data type} {gpgme_error_t}
1271 The @code{gpgme_error_t} type is an alias for the @code{libgpg-error}
1272 type @code{gpg_error_t}. An error value like this has always two
1273 components, an error code and an error source. Both together form the
1276 Thus, the error value can not be directly compared against an error
1277 code, but the accessor functions described below must be used.
1278 However, it is guaranteed that only 0 is used to indicate success
1279 (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of
1280 the error value are set to 0, too.
1282 Note that in @acronym{GPGME}, the error source is used purely for
1283 diagnostical purposes. Only the error code should be checked to test
1284 for a certain outcome of a function. The manual only documents the
1285 error code part of an error value. The error source is left
1286 unspecified and might be anything.
1289 @deftypefun {static inline gpgme_err_code_t} gpgme_err_code (@w{gpgme_error_t @var{err}})
1290 The static inline function @code{gpgme_err_code} returns the
1291 @code{gpgme_err_code_t} component of the error value @var{err}. This
1292 function must be used to extract the error code from an error value in
1293 order to compare it with the @code{GPG_ERR_*} error code macros.
1296 @deftypefun {static inline gpgme_err_source_t} gpgme_err_source (@w{gpgme_error_t @var{err}})
1297 The static inline function @code{gpgme_err_source} returns the
1298 @code{gpgme_err_source_t} component of the error value @var{err}. This
1299 function must be used to extract the error source from an error value in
1300 order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros.
1303 @deftypefun {static inline gpgme_error_t} gpgme_err_make (@w{gpgme_err_source_t @var{source}}, @w{gpgme_err_code_t @var{code}})
1304 The static inline function @code{gpgme_err_make} returns the error
1305 value consisting of the error source @var{source} and the error code
1308 This function can be used in callback functions to construct an error
1309 value to return it to the library.
1312 @deftypefun {static inline gpgme_error_t} gpgme_error (@w{gpgme_err_code_t @var{code}})
1313 The static inline function @code{gpgme_error} returns the error value
1314 consisting of the default error source and the error code @var{code}.
1316 For @acronym{GPGME} applications, the default error source is
1317 @code{GPG_ERR_SOURCE_USER_1}. You can define
1318 @code{GPGME_ERR_SOURCE_DEFAULT} before including @file{gpgme.h} to
1319 change this default.
1321 This function can be used in callback functions to construct an error
1322 value to return it to the library.
1325 The @code{libgpg-error} library provides error codes for all system
1326 error numbers it knows about. If @var{err} is an unknown error
1327 number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The
1328 following functions can be used to construct error values from system
1331 @deftypefun {gpgme_error_t} gpgme_err_make_from_errno (@w{gpgme_err_source_t @var{source}}, @w{int @var{err}})
1332 The function @code{gpgme_err_make_from_errno} is like
1333 @code{gpgme_err_make}, but it takes a system error like @code{errno}
1334 instead of a @code{gpgme_err_code_t} error code.
1337 @deftypefun {gpgme_error_t} gpgme_error_from_errno (@w{int @var{err}})
1338 The function @code{gpgme_error_from_errno} is like @code{gpgme_error},
1339 but it takes a system error like @code{errno} instead of a
1340 @code{gpgme_err_code_t} error code.
1343 Sometimes you might want to map system error numbers to error codes
1344 directly, or map an error code representing a system error back to the
1345 system error number. The following functions can be used to do that.
1347 @deftypefun {gpgme_err_code_t} gpgme_err_code_from_errno (@w{int @var{err}})
1348 The function @code{gpgme_err_code_from_errno} returns the error code
1349 for the system error @var{err}. If @var{err} is not a known system
1350 error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}.
1353 @deftypefun {int} gpgme_err_code_to_errno (@w{gpgme_err_code_t @var{err}})
1354 The function @code{gpgme_err_code_to_errno} returns the system error
1355 for the error code @var{err}. If @var{err} is not an error code
1356 representing a system error, or if this system error is not defined on
1357 this system, the function returns @code{0}.
1362 @section Error Sources
1363 @cindex error codes, list of
1365 The library @code{libgpg-error} defines an error source for every
1366 component of the GnuPG system. The error source part of an error
1367 value is not well defined. As such it is mainly useful to improve the
1368 diagnostic error message for the user.
1370 If the error code part of an error value is @code{0}, the whole error
1371 value will be @code{0}. In this case the error source part is of
1372 course @code{GPG_ERR_SOURCE_UNKNOWN}.
1374 The list of error sources that might occur in applications using
1378 @item GPG_ERR_SOURCE_UNKNOWN
1379 The error source is not known. The value of this error source is
1382 @item GPG_ERR_SOURCE_GPGME
1383 The error source is @acronym{GPGME} itself. This is the default for
1384 errors that occur in the @acronym{GPGME} library.
1386 @item GPG_ERR_SOURCE_GPG
1387 The error source is GnuPG, which is the crypto engine used for the
1390 @item GPG_ERR_SOURCE_GPGSM
1391 The error source is GPGSM, which is the crypto engine used for the
1394 @item GPG_ERR_SOURCE_GCRYPT
1395 The error source is @code{libgcrypt}, which is used by crypto engines
1396 to perform cryptographic operations.
1398 @item GPG_ERR_SOURCE_GPGAGENT
1399 The error source is @command{gpg-agent}, which is used by crypto
1400 engines to perform operations with the secret key.
1402 @item GPG_ERR_SOURCE_PINENTRY
1403 The error source is @command{pinentry}, which is used by
1404 @command{gpg-agent} to query the passphrase to unlock a secret key.
1406 @item GPG_ERR_SOURCE_SCD
1407 The error source is the SmartCard Daemon, which is used by
1408 @command{gpg-agent} to delegate operations with the secret key to a
1411 @item GPG_ERR_SOURCE_KEYBOX
1412 The error source is @code{libkbx}, a library used by the crypto
1413 engines to manage local keyrings.
1415 @item GPG_ERR_SOURCE_USER_1
1416 @item GPG_ERR_SOURCE_USER_2
1417 @item GPG_ERR_SOURCE_USER_3
1418 @item GPG_ERR_SOURCE_USER_4
1419 These error sources are not used by any GnuPG component and can be
1420 used by other software. For example, applications using
1421 @acronym{GPGME} can use them to mark error values coming from callback
1422 handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors
1423 created with @code{gpgme_error} and @code{gpgme_error_from_errno},
1424 unless you define @code{GPGME_ERR_SOURCE_DEFAULT} before including
1430 @section Error Codes
1431 @cindex error codes, list of
1433 The library @code{libgpg-error} defines many error values. Most of
1434 them are not used by @code{GPGME} directly, but might be returned by
1435 @acronym{GPGME} because it received them from the crypto engine. The
1436 below list only includes such error codes that have a specific meaning
1437 in @code{GPGME}, or which are so common that you should know about
1442 This value indicates the end of a list, buffer or file.
1444 @item GPG_ERR_NO_ERROR
1445 This value indicates success. The value of this error code is
1446 @code{0}. Also, it is guaranteed that an error value made from the
1447 error code @code{0} will be @code{0} itself (as a whole). This means
1448 that the error source information is lost for this error code,
1449 however, as this error code indicates that no error occured, this is
1450 generally not a problem.
1452 @item GPG_ERR_GENERAL
1453 This value means that something went wrong, but either there is not
1454 enough information about the problem to return a more useful error
1455 value, or there is no separate error value for this type of problem.
1457 @item GPG_ERR_ENOMEM
1458 This value means that an out-of-memory condition occurred.
1461 System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
1464 @item GPG_ERR_INV_VALUE
1465 This value means that some user provided data was out of range. This
1466 can also refer to objects. For example, if an empty
1467 @code{gpgme_data_t} object was expected, but one containing data was
1468 provided, this error value is returned.
1470 @item GPG_ERR_UNUSABLE_PUBKEY
1471 This value means that some recipients for a message were invalid.
1473 @item GPG_ERR_UNUSABLE_SECKEY
1474 This value means that some signers were invalid.
1476 @item GPG_ERR_NO_DATA
1477 This value means that a @code{gpgme_data_t} object which was expected
1478 to have content was found empty.
1480 @item GPG_ERR_CONFLICT
1481 This value means that a conflict of some sort occurred.
1483 @item GPG_ERR_NOT_IMPLEMENTED
1484 This value indicates that the specific function (or operation) is not
1485 implemented. This error should never happen. It can only occur if
1486 you use certain values or configuration options which do not work,
1487 but for which we think that they should work at some later time.
1489 @item GPG_ERR_DECRYPT_FAILED
1490 This value indicates that a decryption operation was unsuccessful.
1492 @item GPG_ERR_BAD_PASSPHRASE
1493 This value means that the user did not provide a correct passphrase
1496 @item GPG_ERR_CANCELED
1497 This value means that the operation was canceled.
1499 @item GPG_ERR_INV_ENGINE
1500 This value means that the engine that implements the desired protocol
1501 is currently not available. This can either be because the sources
1502 were configured to exclude support for this engine, or because the
1503 engine is not installed properly.
1505 @item GPG_ERR_AMBIGUOUS_NAME
1506 This value indicates that a user ID or other specifier did not specify
1509 @item GPG_ERR_WRONG_KEY_USAGE
1510 This value indicates that a key is not used appropriately.
1512 @item GPG_ERR_CERT_REVOKED
1513 This value indicates that a key signature was revoced.
1515 @item GPG_ERR_CERT_EXPIRED
1516 This value indicates that a key signature expired.
1518 @item GPG_ERR_NO_CRL_KNOWN
1519 This value indicates that no certificate revocation list is known for
1522 @item GPG_ERR_NO_POLICY_MATCH
1523 This value indicates that a policy issue occured.
1525 @item GPG_ERR_NO_SECKEY
1526 This value indicates that no secret key for the user ID is available.
1528 @item GPG_ERR_MISSING_CERT
1529 This value indicates that a key could not be imported because the
1530 issuer certificate is missing.
1532 @item GPG_ERR_BAD_CERT_CHAIN
1533 This value indicates that a key could not be imported because its
1534 certificate chain is not good, for example it could be too long.
1536 @item GPG_ERR_UNSUPPORTED_ALGORITHM
1537 This value means a verification failed because the cryptographic
1538 algorithm is not supported by the crypto backend.
1540 @item GPG_ERR_BAD_SIGNATURE
1541 This value means a verification failed because the signature is bad.
1543 @item GPG_ERR_NO_PUBKEY
1544 This value means a verification failed because the public key is not
1547 @item GPG_ERR_USER_1
1548 @item GPG_ERR_USER_2
1550 @item GPG_ERR_USER_16
1551 These error codes are not used by any GnuPG component and can be
1552 freely used by other software. Applications using @acronym{GPGME}
1553 might use them to mark specific errors returned by callback handlers
1554 if no suitable error codes (including the system errors) for
1555 these errors exist already.
1560 @section Error Strings
1561 @cindex error values, printing of
1562 @cindex error codes, printing of
1563 @cindex error sources, printing of
1564 @cindex error strings
1566 @deftypefun {const char *} gpgme_strerror (@w{gpgme_error_t @var{err}})
1567 The function @code{gpgme_strerror} returns a pointer to a statically
1568 allocated string containing a description of the error code contained
1569 in the error value @var{err}. This string can be used to output a
1570 diagnostic message to the user.
1572 This function is not thread safe. Use @code{gpgme_strerror_r} in
1573 multi-threaded programs.
1577 @deftypefun {int} gpgme_strerror_r (@w{gpgme_error_t @var{err}}, @w{char *@var{buf}}, @w{size_t @var{buflen}})
1578 The function @code{gpgme_strerror_r} returns the error string for
1579 @var{err} in the user-supplied buffer @var{buf} of size @var{buflen}.
1580 This function is, in contrast to @code{gpgme_strerror}, thread-safe if
1581 a thread-safe @code{strerror_r} function is provided by the system.
1582 If the function succeeds, 0 is returned and @var{buf} contains the
1583 string describing the error. If the buffer was not large enough,
1584 ERANGE is returned and @var{buf} contains as much of the beginning of
1585 the error string as fits into the buffer.
1589 @deftypefun {const char *} gpgme_strsource (@w{gpgme_error_t @var{err}})
1590 The function @code{gpgme_strerror} returns a pointer to a statically
1591 allocated string containing a description of the error source
1592 contained in the error value @var{err}. This string can be used to
1593 output a diagnostic message to the user.
1596 The following example illustrates the use of @code{gpgme_strerror}:
1600 gpgme_error_t err = gpgme_new (&ctx);
1603 fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
1604 argv[0], gpgme_strsource (err), gpgme_strerror (err));
1610 @node Exchanging Data
1611 @chapter Exchanging Data
1612 @cindex data, exchanging
1614 A lot of data has to be exchanged between the user and the crypto
1615 engine, like plaintext messages, ciphertext, signatures and
1616 information about the keys. The technical details about exchanging
1617 the data information are completely abstracted by @acronym{GPGME}.
1618 The user provides and receives the data via @code{gpgme_data_t} objects,
1619 regardless of the communication protocol between @acronym{GPGME} and
1620 the crypto engine in use.
1622 @deftp {Data type} {gpgme_data_t}
1623 The @code{gpgme_data_t} type is a handle for a container for generic
1624 data, which is used by @acronym{GPGME} to exchange data with the user.
1627 @code{gpgme_data_t} objects do not provide notifications on events.
1628 It is assumed that read and write operations are blocking until data
1629 is available. If this is undesirable, the application must ensure
1630 that all GPGME data operations always have data available, for example
1631 by using memory buffers or files rather than pipes or sockets. This
1632 might be relevant, for example, if the external event loop mechanism
1635 @deftp {Data type} {gpgme_off_t}
1636 On POSIX platforms the @code{gpgme_off_t} type is an alias for
1637 @code{off_t}; it may be used interchangeable. On Windows platforms
1638 @code{gpgme_off_t} is defined as a long (i.e. 32 bit) for 32 bit
1639 Windows and as a 64 bit signed integer for 64 bit Windows.
1642 @deftp {Data type} {gpgme_ssize_t}
1643 The @code{gpgme_ssize_t} type is an alias for @code{ssize_t}. It has
1644 only been introduced to overcome portability problems pertaining to
1645 the declaration of @code{ssize_t} by different toolchains.
1650 * Creating Data Buffers:: Creating new data buffers.
1651 * Destroying Data Buffers:: Releasing data buffers.
1652 * Manipulating Data Buffers:: Operations on data buffers.
1656 @node Creating Data Buffers
1657 @section Creating Data Buffers
1658 @cindex data buffer, creation
1660 Data objects can be based on memory, files, or callback functions
1661 provided by the user. Not all operations are supported by all
1666 * Memory Based Data Buffers:: Creating memory based data buffers.
1667 * File Based Data Buffers:: Creating file based data buffers.
1668 * Callback Based Data Buffers:: Creating callback based data buffers.
1672 @node Memory Based Data Buffers
1673 @subsection Memory Based Data Buffers
1675 Memory based data objects store all data in allocated memory. This is
1676 convenient, but only practical for an amount of data that is a
1677 fraction of the available physical memory. The data has to be copied
1678 from its source and to its destination, which can often be avoided by
1679 using one of the other data object
1681 @deftypefun gpgme_error_t gpgme_data_new (@w{gpgme_data_t *@var{dh}})
1682 The function @code{gpgme_data_new} creates a new @code{gpgme_data_t}
1683 object and returns a handle for it in @var{dh}. The data object is
1684 memory based and initially empty.
1686 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1687 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1688 @var{dh} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1689 enough memory is available.
1692 @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}})
1693 The function @code{gpgme_data_new_from_mem} creates a new
1694 @code{gpgme_data_t} object and fills it with @var{size} bytes starting
1697 If @var{copy} is not zero, a private copy of the data is made. If
1698 @var{copy} is zero, the data is taken from the specified buffer as
1699 needed, and the user has to ensure that the buffer remains valid for
1700 the whole life span of the data object.
1702 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1703 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1704 @var{dh} or @var{buffer} is not a valid pointer, and
1705 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1708 @deftypefun gpgme_error_t gpgme_data_new_from_file (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}})
1709 The function @code{gpgme_data_new_from_file} creates a new
1710 @code{gpgme_data_t} object and fills it with the content of the file
1713 If @var{copy} is not zero, the whole file is read in at initialization
1714 time and the file is not used anymore after that. This is the only
1715 mode supported currently. Later, a value of zero for @var{copy} might
1716 cause all reads to be delayed until the data is needed, but this is
1717 not yet implemented.
1719 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1720 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1721 @var{dh} or @var{filename} is not a valid pointer,
1722 @code{GPG_ERR_NOT_IMPLEMENTED} if @var{code} is zero, and
1723 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1726 @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}})
1727 The function @code{gpgme_data_new_from_filepart} creates a new
1728 @code{gpgme_data_t} object and fills it with a part of the file specified
1729 by @var{filename} or @var{fp}.
1731 Exactly one of @var{filename} and @var{fp} must be non-zero, the other
1732 must be zero. The argument that is not zero specifies the file from
1733 which @var{length} bytes are read into the data object, starting from
1736 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1737 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1738 @var{dh} and exactly one of @var{filename} and @var{fp} is not a valid
1739 pointer, and @code{GPG_ERR_ENOMEM} if not enough memory is available.
1743 @node File Based Data Buffers
1744 @subsection File Based Data Buffers
1746 File based data objects operate directly on file descriptors or
1747 streams. Only a small amount of data is stored in core at any time,
1748 so the size of the data objects is not limited by @acronym{GPGME}.
1750 @deftypefun gpgme_error_t gpgme_data_new_from_fd (@w{gpgme_data_t *@var{dh}}, @w{int @var{fd}})
1751 The function @code{gpgme_data_new_from_fd} creates a new
1752 @code{gpgme_data_t} object and uses the file descriptor @var{fd} to read
1753 from (if used as an input data object) and write to (if used as an
1754 output data object).
1756 When using the data object as an input buffer, the function might read
1757 a bit more from the file descriptor than is actually needed by the
1758 crypto engine in the desired operation because of internal buffering.
1760 Note that GPGME assumes that the file descriptor is set to blocking
1761 mode. Errors during I/O operations, except for EINTR, are usually
1762 fatal for crypto operations.
1764 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1765 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1766 enough memory is available.
1769 @deftypefun gpgme_error_t gpgme_data_new_from_stream (@w{gpgme_data_t *@var{dh}}, @w{FILE *@var{stream}})
1770 The function @code{gpgme_data_new_from_stream} creates a new
1771 @code{gpgme_data_t} object and uses the I/O stream @var{stream} to read
1772 from (if used as an input data object) and write to (if used as an
1773 output data object).
1775 When using the data object as an input buffer, the function might read
1776 a bit more from the stream than is actually needed by the crypto
1777 engine in the desired operation because of internal buffering.
1779 Note that GPGME assumes that the stream is in blocking mode. Errors
1780 during I/O operations, except for EINTR, are usually fatal for crypto
1783 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1784 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1785 enough memory is available.
1789 @node Callback Based Data Buffers
1790 @subsection Callback Based Data Buffers
1792 If neither memory nor file based data objects are a good fit for your
1793 application, you can implement the functions a data object provides
1794 yourself and create a data object from these callback functions.
1796 @deftp {Data type} {ssize_t (*gpgme_data_read_cb_t) (@w{void *@var{handle}}, @w{void @var{*buffer}}, @w{size_t @var{size}})}
1797 @tindex gpgme_data_read_cb_t
1798 The @code{gpgme_data_read_cb_t} type is the type of functions which
1799 @acronym{GPGME} calls if it wants to read data from a user-implemented
1800 data object. The function should read up to @var{size} bytes from the
1801 current read position into the space starting at @var{buffer}. The
1802 @var{handle} is provided by the user at data object creation time.
1804 Note that GPGME assumes that the read blocks until data is available.
1805 Errors during I/O operations, except for EINTR, are usually fatal for
1808 The function should return the number of bytes read, 0 on EOF, and -1
1809 on error. If an error occurs, @var{errno} should be set to describe
1810 the type of the error.
1813 @deftp {Data type} {ssize_t (*gpgme_data_write_cb_t) (@w{void *@var{handle}}, @w{const void @var{*buffer}}, @w{size_t @var{size}})}
1814 @tindex gpgme_data_write_cb_t
1815 The @code{gpgme_data_write_cb_t} type is the type of functions which
1816 @acronym{GPGME} calls if it wants to write data to a user-implemented
1817 data object. The function should write up to @var{size} bytes to the
1818 current write position from the space starting at @var{buffer}. The
1819 @var{handle} is provided by the user at data object creation time.
1821 Note that GPGME assumes that the write blocks until data is available.
1822 Errors during I/O operations, except for EINTR, are usually fatal for
1825 The function should return the number of bytes written, and -1 on
1826 error. If an error occurs, @var{errno} should be set to describe the
1830 @deftp {Data type} {off_t (*gpgme_data_seek_cb_t) (@w{void *@var{handle}}, @w{off_t @var{offset}}, @w{int @var{whence}})}
1831 @tindex gpgme_data_seek_cb_t
1832 The @code{gpgme_data_seek_cb_t} type is the type of functions which
1833 @acronym{GPGME} calls if it wants to change the current read/write
1834 position in a user-implemented data object, just like the @code{lseek}
1837 The function should return the new read/write position, and -1 on
1838 error. If an error occurs, @var{errno} should be set to describe the
1842 @deftp {Data type} {void (*gpgme_data_release_cb_t) (@w{void *@var{handle}})}
1843 @tindex gpgme_data_release_cb_t
1844 The @code{gpgme_data_release_cb_t} type is the type of functions which
1845 @acronym{GPGME} calls if it wants to destroy a user-implemented data
1846 object. The @var{handle} is provided by the user at data object
1850 @deftp {Data type} {struct gpgme_data_cbs}
1851 This structure is used to store the data callback interface functions
1852 described above. It has the following members:
1855 @item gpgme_data_read_cb_t read
1856 This is the function called by @acronym{GPGME} to read data from the
1857 data object. It is only required for input data object.
1859 @item gpgme_data_write_cb_t write
1860 This is the function called by @acronym{GPGME} to write data to the
1861 data object. It is only required for output data object.
1863 @item gpgme_data_seek_cb_t seek
1864 This is the function called by @acronym{GPGME} to change the current
1865 read/write pointer in the data object (if available). It is optional.
1867 @item gpgme_data_release_cb_t release
1868 This is the function called by @acronym{GPGME} to release a data
1869 object. It is optional.
1873 @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}})
1874 The function @code{gpgme_data_new_from_cbs} creates a new
1875 @code{gpgme_data_t} object and uses the user-provided callback functions
1876 to operate on the data object.
1878 The handle @var{handle} is passed as first argument to the callback
1879 functions. This can be used to identify this data object.
1881 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1882 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1883 enough memory is available.
1886 The following interface is deprecated and only provided for backward
1887 compatibility. Don't use it. It will be removed in a future version
1890 @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}})
1891 The function @code{gpgme_data_new_with_read_cb} creates a new
1892 @code{gpgme_data_t} object and uses the callback function @var{readfunc}
1893 to retrieve the data on demand. As the callback function can supply
1894 the data in any way it wants, this is the most flexible data type
1895 @acronym{GPGME} provides. However, it can not be used to write data.
1897 The callback function receives @var{hook_value} as its first argument
1898 whenever it is invoked. It should return up to @var{count} bytes in
1899 @var{buffer}, and return the number of bytes actually read in
1900 @var{nread}. It may return @code{0} in @var{nread} if no data is
1901 currently available. To indicate @code{EOF} the function should
1902 return with an error code of @code{-1} and set @var{nread} to
1903 @code{0}. The callback function may support to reset its internal
1904 read pointer if it is invoked with @var{buffer} and @var{nread} being
1905 @code{NULL} and @var{count} being @code{0}.
1907 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1908 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1909 @var{dh} or @var{readfunc} is not a valid pointer, and
1910 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1914 @node Destroying Data Buffers
1915 @section Destroying Data Buffers
1916 @cindex data buffer, destruction
1918 @deftypefun void gpgme_data_release (@w{gpgme_data_t @var{dh}})
1919 The function @code{gpgme_data_release} destroys the data object with
1920 the handle @var{dh}. It releases all associated resources that were
1921 not provided by the user in the first place.
1924 @deftypefun {char *} gpgme_data_release_and_get_mem (@w{gpgme_data_t @var{dh}}, @w{size_t *@var{length}})
1925 The function @code{gpgme_data_release_and_get_mem} is like
1926 @code{gpgme_data_release}, except that it returns the data buffer and
1927 its length that was provided by the object.
1929 The user has to release the buffer with @code{gpgme_free}. In case
1930 the user provided the data buffer in non-copy mode, a copy will be
1931 made for this purpose.
1933 In case an error returns, or there is no suitable data buffer that can
1934 be returned to the user, the function will return @code{NULL}. In any
1935 case, the data object @var{dh} is destroyed.
1939 @deftypefun void gpgme_free (@w{void *@var{buffer}})
1940 The function @code{gpgme_free} releases the memory returned by
1941 @code{gpgme_data_release_and_get_mem}. It should be used instead of
1942 the system libraries @code{free} function in case different allocators
1943 are used in a single program.
1947 @node Manipulating Data Buffers
1948 @section Manipulating Data Buffers
1949 @cindex data buffer, manipulation
1951 Data buffers contain data and meta-data. The following operations can
1952 be used to manipulate both.
1956 * Data Buffer I/O Operations:: I/O operations on data buffers.
1957 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
1958 * Data Buffer Convenience:: Convenience function for data buffers.
1962 @node Data Buffer I/O Operations
1963 @subsection Data Buffer I/O Operations
1964 @cindex data buffer, I/O operations
1965 @cindex data buffer, read
1966 @cindex data buffer, write
1967 @cindex data buffer, seek
1969 @deftypefun ssize_t gpgme_data_read (@w{gpgme_data_t @var{dh}}, @w{void *@var{buffer}}, @w{size_t @var{length}})
1970 The function @code{gpgme_data_read} reads up to @var{length} bytes
1971 from the data object with the handle @var{dh} into the space starting
1974 If no error occurs, the actual amount read is returned. If the end of
1975 the data object is reached, the function returns 0.
1977 In all other cases, the function returns -1 and sets @var{errno}.
1980 @deftypefun ssize_t gpgme_data_write (@w{gpgme_data_t @var{dh}}, @w{const void *@var{buffer}}, @w{size_t @var{size}})
1981 The function @code{gpgme_data_write} writes up to @var{size} bytes
1982 starting from @var{buffer} into the data object with the handle
1983 @var{dh} at the current write position.
1985 The function returns the number of bytes actually written, or -1 if an
1986 error occurs. If an error occurs, @var{errno} is set.
1989 @deftypefun off_t gpgme_data_seek (@w{gpgme_data_t @var{dh}}, @w{off_t @var{offset}}, @w{int @var{whence}})
1990 The function @code{gpgme_data_seek} changes the current read/write
1993 The @var{whence} argument specifies how the @var{offset} should be
1994 interpreted. It must be one of the following symbolic constants:
1998 Specifies that @var{offset} is a count of characters from the
1999 beginning of the data object.
2002 Specifies that @var{offset} is a count of characters from the current
2003 file position. This count may be positive or negative.
2006 Specifies that @var{offset} is a count of characters from the end of
2007 the data object. A negative count specifies a position within the
2008 current extent of the data object; a positive count specifies a
2009 position past the current end. If you set the position past the
2010 current end, and actually write data, you will extend the data object
2011 with zeros up to that position.
2014 If successful, the function returns the resulting file position,
2015 measured in bytes from the beginning of the data object. You can use
2016 this feature together with @code{SEEK_CUR} to read the current
2017 read/write position.
2019 If the function fails, -1 is returned and @var{errno} is set.
2022 The following function is deprecated and should not be used. It will
2023 be removed in a future version of @acronym{GPGME}.
2025 @deftypefun gpgme_error_t gpgme_data_rewind (@w{gpgme_data_t @var{dh}})
2026 The function @code{gpgme_data_rewind} is equivalent to:
2029 return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
2030 ? gpgme_error_from_errno (errno) : 0;
2037 @node Data Buffer Meta-Data
2038 @subsection Data Buffer Meta-Data
2039 @cindex data buffer, meta-data
2040 @cindex data buffer, file name
2041 @cindex data buffer, encoding
2043 @deftypefun {char *} gpgme_data_get_file_name (@w{gpgme_data_t @var{dh}})
2044 The function @code{gpgme_data_get_file_name} returns a pointer to a
2045 string containing the file name associated with the data object. The
2046 file name will be stored in the output when encrypting or signing the
2047 data and will be returned to the user when decrypting or verifying the
2050 If no error occurs, the string containing the file name is returned.
2051 Otherwise, @code{NULL} will be returned.
2055 @deftypefun gpgme_error_t gpgme_data_set_file_name (@w{gpgme_data_t @var{dh}}, @w{const char *@var{file_name}})
2056 The function @code{gpgme_data_set_file_name} sets the file name
2057 associated with the data object. The file name will be stored in the
2058 output when encrypting or signing the data and will be returned to the
2059 user when decrypting or verifying the output data.
2061 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2062 @var{dh} is not a valid pointer and @code{GPG_ERR_ENOMEM} if not
2063 enough memory is available.
2067 @deftp {Data type} {enum gpgme_data_encoding_t}
2068 @tindex gpgme_data_encoding_t
2069 The @code{gpgme_data_encoding_t} type specifies the encoding of a
2070 @code{gpgme_data_t} object. For input data objects, the encoding is
2071 useful to give the backend a hint on the type of data. For output
2072 data objects, the encoding can specify the output data format on
2073 certain operations. Please note that not all backends support all
2074 encodings on all operations. The following data types are available:
2077 @item GPGME_DATA_ENCODING_NONE
2078 This specifies that the encoding is not known. This is the default
2079 for a new data object. The backend will try its best to detect the
2080 encoding automatically.
2082 @item GPGME_DATA_ENCODING_BINARY
2083 This specifies that the data is encoding in binary form; i.e. there is
2084 no special encoding.
2086 @item GPGME_DATA_ENCODING_BASE64
2087 This specifies that the data is encoded using the Base-64 encoding
2088 scheme as used by @acronym{MIME} and other protocols.
2090 @item GPGME_DATA_ENCODING_ARMOR
2091 This specifies that the data is encoded in an armored form as used by
2094 @item GPGME_DATA_ENCODING_URL
2095 The data is a list of linefeed delimited URLs. This is only useful with
2096 @code{gpgme_op_import}.
2098 @item GPGME_DATA_ENCODING_URL0
2099 The data is a list of binary zero delimited URLs. This is only useful
2100 with @code{gpgme_op_import}.
2102 @item GPGME_DATA_ENCODING_URLESC
2103 The data is a list of linefeed delimited URLs with all control and space
2104 characters percent escaped. This mode is is not yet implemented.
2109 @deftypefun gpgme_data_encoding_t gpgme_data_get_encoding (@w{gpgme_data_t @var{dh}})
2110 The function @code{gpgme_data_get_encoding} returns the encoding of
2111 the data object with the handle @var{dh}. If @var{dh} is not a valid
2112 pointer (e.g. @code{NULL}) @code{GPGME_DATA_ENCODING_NONE} is
2116 @deftypefun gpgme_error_t gpgme_data_set_encoding (@w{gpgme_data_t @var{dh}, gpgme_data_encoding_t @var{enc}})
2117 The function @code{gpgme_data_set_encoding} changes the encoding of
2118 the data object with the handle @var{dh} to @var{enc}.
2121 @node Data Buffer Convenience
2122 @subsection Data Buffer Convenience Functions
2123 @cindex data buffer, convenience
2124 @cindex type of data
2127 @deftp {Data type} {enum gpgme_data_type_t}
2128 @tindex gpgme_data_type_t
2129 The @code{gpgme_data_type_t} type is used to return the detected type
2130 of the content of a data buffer.
2134 @item GPGME_DATA_TYPE_INVALID
2135 This is returned by @code{gpgme_data_identify} if it was not possible
2136 to identify the data. Reasons for this might be a non-seekable stream
2137 or a memory problem. The value is 0.
2138 @item GPGME_DATA_TYPE_UNKNOWN
2139 The type of the data is not known.
2140 @item GPGME_DATA_TYPE_PGP_SIGNED
2141 The data is an OpenPGP signed message. This may be a binary
2142 signature, a detached one or a cleartext signature.
2143 @item GPGME_DATA_TYPE_PGP_OTHER
2144 This is a generic OpenPGP message. In most cases this will be
2146 @item GPGME_DATA_TYPE_PGP_KEY
2147 This is an OpenPGP key (private or public).
2148 @item GPGME_DATA_TYPE_CMS_SIGNED
2149 This is a CMS signed message.
2150 @item GPGME_DATA_TYPE_CMS_ENCRYPTED
2151 This is a CMS encrypted (enveloped data) message.
2152 @item GPGME_DATA_TYPE_CMS_OTHER
2153 This is used for other CMS message types.
2154 @item GPGME_DATA_TYPE_X509_CERT
2155 The data is a X.509 certificate
2156 @item GPGME_DATA_TYPE_PKCS12
2157 The data is a PKCS#12 message. This is commonly used to exchange
2158 private keys for X.509.
2161 @deftypefun gpgme_data_type_t gpgme_data_identify (@w{gpgme_data_t @var{dh}})
2162 The function @code{gpgme_data_identify} returns the type of the data
2163 with the handle @var{dh}. If it is not possible to perform the
2164 identification, the function returns zero
2165 (@code{GPGME_DATA_TYPE_INVALID}). Note that depending on how the data
2166 object has been created the identification may not be possible or the
2167 data object may change its internal state (file pointer moved). For
2168 file or memory based data object, the state should not change.
2179 All cryptographic operations in @acronym{GPGME} are performed within a
2180 context, which contains the internal state of the operation as well as
2181 configuration parameters. By using several contexts you can run
2182 several cryptographic operations in parallel, with different
2185 @deftp {Data type} {gpgme_ctx_t}
2186 The @code{gpgme_ctx_t} type is a handle for a @acronym{GPGME} context,
2187 which is used to hold the configuration, status and result of
2188 cryptographic operations.
2192 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
2193 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
2194 * Result Management:: Managing the result of crypto operations.
2195 * Context Attributes:: Setting properties of a context.
2196 * Key Management:: Managing keys with @acronym{GPGME}.
2197 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
2198 * Crypto Operations:: Using a context for cryptography.
2199 * Miscellaneous:: Miscellaneous operations
2200 * Run Control:: Controlling how operations are run.
2204 @node Creating Contexts
2205 @section Creating Contexts
2206 @cindex context, creation
2208 @deftypefun gpgme_error_t gpgme_new (@w{gpgme_ctx_t *@var{ctx}})
2209 The function @code{gpgme_new} creates a new @code{gpgme_ctx_t} object
2210 and returns a handle for it in @var{ctx}.
2212 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2213 context was successfully created, @code{GPG_ERR_INV_VALUE} if
2214 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
2215 enough memory is available. Also, it returns
2216 @code{GPG_ERR_NOT_OPERATIONAL} if @code{gpgme_check_version} was not
2217 called to initialize GPGME, and @code{GPG_ERR_SELFTEST_FAILED} if a
2218 selftest failed. Currently, the only selftest is for Windows MingW32
2219 targets to see if @code{-mms-bitfields} was used (as required).
2223 @node Destroying Contexts
2224 @section Destroying Contexts
2225 @cindex context, destruction
2227 @deftypefun void gpgme_release (@w{gpgme_ctx_t @var{ctx}})
2228 The function @code{gpgme_release} destroys the context with the handle
2229 @var{ctx} and releases all associated resources.
2233 @node Result Management
2234 @section Result Management
2235 @cindex context, result of operation
2237 The detailed result of an operation is returned in operation-specific
2238 structures such as @code{gpgme_decrypt_result_t}. The corresponding
2239 retrieval functions such as @code{gpgme_op_decrypt_result} provide
2240 static access to the results after an operation completes. The
2241 following interfaces make it possible to detach a result structure
2242 from its associated context and give it a lifetime beyond that of the
2243 current operation or context.
2245 @deftypefun void gpgme_result_ref (@w{void *@var{result}})
2246 The function @code{gpgme_result_ref} acquires an additional reference
2247 for the result @var{result}, which may be of any type
2248 @code{gpgme_*_result_t}. As long as the user holds a reference, the
2249 result structure is guaranteed to be valid and unmodified.
2252 @deftypefun void gpgme_result_unref (@w{void *@var{result}})
2253 The function @code{gpgme_result_unref} releases a reference for the
2254 result @var{result}. If this was the last reference, the result
2255 structure will be destroyed and all resources associated to it will be
2259 Note that a context may hold its own references to result structures,
2260 typically until the context is destroyed or the next operation is
2261 started. In fact, these references are accessed through the
2262 @code{gpgme_op_*_result} functions.
2265 @node Context Attributes
2266 @section Context Attributes
2267 @cindex context, attributes
2270 * Protocol Selection:: Selecting the protocol used by a context.
2271 * Crypto Engine:: Configuring the crypto engine.
2272 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
2273 * Text Mode:: Choosing canonical text mode.
2274 * Included Certificates:: Including a number of certificates.
2275 * Key Listing Mode:: Selecting key listing mode.
2276 * Passphrase Callback:: Getting the passphrase from the user.
2277 * Progress Meter Callback:: Being informed about the progress.
2278 * Locale:: Setting the locale of a context.
2282 @node Protocol Selection
2283 @subsection Protocol Selection
2284 @cindex context, selecting protocol
2285 @cindex protocol, selecting
2287 @deftypefun gpgme_error_t gpgme_set_protocol (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}})
2288 The function @code{gpgme_set_protocol} sets the protocol used within
2289 the context @var{ctx} to @var{proto}. All crypto operations will be
2290 performed by the crypto engine configured for that protocol.
2291 @xref{Protocols and Engines}.
2293 Setting the protocol with @code{gpgme_set_protocol} does not check if
2294 the crypto engine for that protocol is available and installed
2295 correctly. @xref{Engine Version Check}.
2297 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2298 protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if
2299 @var{protocol} is not a valid protocol.
2302 @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}})
2303 The function @code{gpgme_get_protocol} retrieves the protocol currently
2304 use with the context @var{ctx}.
2309 @subsection Crypto Engine
2310 @cindex context, configuring engine
2311 @cindex engine, configuration per context
2313 The following functions can be used to set and retrieve the
2314 configuration of the crypto engines of a specific context. The
2315 default can also be retrieved without any particular context.
2316 @xref{Engine Information}. The default can also be changed globally.
2317 @xref{Engine Configuration}.
2319 @deftypefun gpgme_engine_info_t gpgme_ctx_get_engine_info (@w{gpgme_ctx_t @var{ctx}})
2320 The function @code{gpgme_ctx_get_engine_info} returns a linked list of
2321 engine info structures. Each info structure describes the
2322 configuration of one configured backend, as used by the context
2325 The result is valid until the next invocation of
2326 @code{gpgme_ctx_set_engine_info} for this particular context.
2328 This function can not fail.
2331 @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}})
2332 The function @code{gpgme_ctx_set_engine_info} changes the
2333 configuration of the crypto engine implementing the protocol
2334 @var{proto} for the context @var{ctx}.
2336 @var{file_name} is the file name of the executable program
2337 implementing this protocol, and @var{home_dir} is the directory name
2338 of the configuration directory for this crypto engine. If
2339 @var{home_dir} is @code{NULL}, the engine's default will be used.
2341 Currently this function must be used before starting the first crypto
2342 operation. It is unspecified if and when the changes will take effect
2343 if the function is called after starting the first operation on the
2346 This function returns the error code @code{GPG_ERR_NO_ERROR} if
2347 successful, or an eror code on failure.
2351 @c FIXME: Unfortunately, using @acronym here breaks texi2dvi.
2353 @subsection @acronym{ASCII} Armor
2354 @cindex context, armor mode
2355 @cindex @acronym{ASCII} armor
2358 @deftypefun void gpgme_set_armor (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2359 The function @code{gpgme_set_armor} specifies if the output should be
2360 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
2363 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
2367 @deftypefun int gpgme_get_armor (@w{gpgme_ctx_t @var{ctx}})
2368 The function @code{gpgme_get_armor} returns 1 if the output is
2369 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
2370 not a valid pointer.
2375 @subsection Text Mode
2376 @cindex context, text mode
2378 @cindex canonical text mode
2380 @deftypefun void gpgme_set_textmode (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2381 The function @code{gpgme_set_textmode} specifies if canonical text mode
2382 should be used. By default, text mode is not used.
2384 Text mode is for example used for the RFC2015 signatures; note that
2385 the updated RFC 3156 mandates that the mail user agent does some
2386 preparations so that text mode is not needed anymore.
2388 This option is only relevant to the OpenPGP crypto engine, and ignored
2389 by all other engines.
2391 Canonical text mode is disabled if @var{yes} is zero, and enabled
2395 @deftypefun int gpgme_get_textmode (@w{gpgme_ctx_t @var{ctx}})
2396 The function @code{gpgme_get_textmode} returns 1 if canonical text
2397 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2402 @node Included Certificates
2403 @subsection Included Certificates
2404 @cindex certificates, included
2406 @deftypefun void gpgme_set_include_certs (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{nr_of_certs}})
2407 The function @code{gpgme_set_include_certs} specifies how many
2408 certificates should be included in an S/MIME signed message. By
2409 default, only the sender's certificate is included. The possible
2410 values of @var{nr_of_certs} are:
2413 @item GPGME_INCLUDE_CERTS_DEFAULT
2414 Fall back to the default of the crypto backend. This is the default
2417 Include all certificates except the root certificate.
2419 Include all certificates.
2421 Include no certificates.
2423 Include the sender's certificate only.
2425 Include the first n certificates of the certificates path, starting
2426 from the sender's certificate. The number @code{n} must be positive.
2429 Values of @var{nr_of_certs} smaller than -2 are undefined.
2431 This option is only relevant to the CMS crypto engine, and ignored by
2435 @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}})
2436 The function @code{gpgme_get_include_certs} returns the number of
2437 certificates to include into an S/MIME signed message.
2441 @node Key Listing Mode
2442 @subsection Key Listing Mode
2443 @cindex key listing mode
2444 @cindex key listing, mode of
2446 @deftypefun gpgme_error_t gpgme_set_keylist_mode (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_keylist_mode_t @var{mode}})
2447 The function @code{gpgme_set_keylist_mode} changes the default
2448 behaviour of the key listing functions. The value in @var{mode} is a
2449 bitwise-or combination of one or multiple of the following bit values:
2452 @item GPGME_KEYLIST_MODE_LOCAL
2453 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
2454 keyring should be searched for keys in the keylisting operation. This
2457 @item GPGME_KEYLIST_MODE_EXTERN
2458 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
2459 source should be searched for keys in the keylisting operation. The
2460 type of external source is dependant on the crypto engine used and
2461 whether it is combined with @code{GPGME_KEYLIST_MODE_LOCAL}. For
2462 example, it can be a remote keyserver or LDAP certificate server.
2464 @item GPGME_KEYLIST_MODE_SIGS
2465 The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key
2466 signatures should be included in the listed keys.
2468 @item GPGME_KEYLIST_MODE_SIG_NOTATIONS
2469 The @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} symbol specifies that the
2470 signature notations on key signatures should be included in the listed
2471 keys. This only works if @code{GPGME_KEYLIST_MODE_SIGS} is also
2474 @item GPGME_KEYLIST_MODE_EPHEMERAL
2475 The @code{GPGME_KEYLIST_MODE_EPHEMERAL} symbol specifies that keys
2476 flagged as ephemeral are included in the listing.
2478 @item GPGME_KEYLIST_MODE_VALIDATE
2479 The @code{GPGME_KEYLIST_MODE_VALIDATE} symbol specifies that the
2480 backend should do key or certificate validation and not just get the
2481 validity information from an internal cache. This might be an
2482 expensive operation and is in general not useful. Currently only
2483 implemented for the S/MIME backend and ignored for other backends.
2487 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
2488 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
2489 compatibility, you should get the current mode with
2490 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
2491 appropriate bits, and then using that calculated value in the
2492 @code{gpgme_set_keylisting_mode} operation. This will leave all other
2493 bits in the mode value intact (in particular those that are not used
2494 in the current version of the library).
2496 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2497 mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx}
2498 is not a valid pointer or @var{mode} is not a valid mode.
2502 @deftypefun gpgme_keylist_mode_t gpgme_get_keylist_mode (@w{gpgme_ctx_t @var{ctx}})
2503 The function @code{gpgme_get_keylist_mode} returns the current key
2504 listing mode of the context @var{ctx}. This value can then be
2505 modified and used in a subsequent @code{gpgme_set_keylist_mode}
2506 operation to only affect the desired bits (and leave all others
2509 The function returns 0 if @var{ctx} is not a valid pointer, and the
2510 current mode otherwise. Note that 0 is not a valid mode value.
2514 @node Passphrase Callback
2515 @subsection Passphrase Callback
2516 @cindex callback, passphrase
2517 @cindex passphrase callback
2519 @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}})}
2520 @tindex gpgme_passphrase_cb_t
2521 The @code{gpgme_passphrase_cb_t} type is the type of functions usable as
2522 passphrase callback function.
2524 The argument @var{uid_hint} might contain a string that gives an
2525 indication for which user ID the passphrase is required. If this is
2526 not available, or not applicable (in the case of symmetric encryption,
2527 for example), @var{uid_hint} will be @code{NULL}.
2529 The argument @var{passphrase_info}, if not @code{NULL}, will give
2530 further information about the context in which the passphrase is
2531 required. This information is engine and operation specific.
2533 If this is the repeated attempt to get the passphrase, because
2534 previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
2537 The user must write the passphrase, followed by a newline character,
2538 to the file descriptor @var{fd}. The function @code{gpgme_io_writen}
2539 should be used for the write operation. Note that if the user returns
2540 0 to indicate success, the user must at least write a newline
2541 character before returning from the callback.
2543 If an error occurs, return the corresponding @code{gpgme_error_t}
2544 value. You can use the error code @code{GPG_ERR_CANCELED} to abort
2545 the operation. Otherwise, return @code{0}.
2548 @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}})
2549 The function @code{gpgme_set_passphrase_cb} sets the function that is
2550 used when a passphrase needs to be provided by the user to
2551 @var{passfunc}. The function @var{passfunc} needs to implemented by
2552 the user, and whenever it is called, it is called with its first
2553 argument being @var{hook_value}. By default, no passphrase callback
2556 Not all crypto engines require this callback to retrieve the
2557 passphrase. It is better if the engine retrieves the passphrase from
2558 a trusted agent (a daemon process), rather than having each user to
2559 implement their own passphrase query. Some engines do not even
2560 support an external passphrase callback at all, in this case the error
2561 code @code{GPG_ERR_NOT_SUPPORTED} is returned.
2563 The user can disable the use of a passphrase callback function by
2564 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
2568 @deftypefun void gpgme_get_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t *@var{passfunc}}, @w{void **@var{hook_value}})
2569 The function @code{gpgme_get_passphrase_cb} returns the function that
2570 is used when a passphrase needs to be provided by the user in
2571 @var{*passfunc}, and the first argument for this function in
2572 @var{*hook_value}. If no passphrase callback is set, or @var{ctx} is
2573 not a valid pointer, @code{NULL} is returned in both variables.
2575 @var{passfunc} or @var{hook_value} can be @code{NULL}. In this case,
2576 the corresponding value will not be returned.
2580 @node Progress Meter Callback
2581 @subsection Progress Meter Callback
2582 @cindex callback, progress meter
2583 @cindex progress meter callback
2585 @deftp {Data type} {void (*gpgme_progress_cb_t)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
2586 @tindex gpgme_progress_cb_t
2587 The @code{gpgme_progress_cb_t} type is the type of functions usable as
2588 progress callback function.
2590 The arguments are specific to the crypto engine. More information
2591 about the progress information returned from the GnuPG engine can be
2592 found in the GnuPG source code in the file @file{doc/DETAILS} in the
2596 @deftypefun void gpgme_set_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t @var{progfunc}}, @w{void *@var{hook_value}})
2597 The function @code{gpgme_set_progress_cb} sets the function that is
2598 used when progress information about a cryptographic operation is
2599 available. The function @var{progfunc} needs to implemented by the
2600 user, and whenever it is called, it is called with its first argument
2601 being @var{hook_value}. By default, no progress callback function
2604 Setting a callback function allows an interactive program to display
2605 progress information about a long operation to the user.
2607 The user can disable the use of a progress callback function by
2608 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
2612 @deftypefun void gpgme_get_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t *@var{progfunc}}, @w{void **@var{hook_value}})
2613 The function @code{gpgme_get_progress_cb} returns the function that is
2614 used to inform the user about the progress made in @var{*progfunc},
2615 and the first argument for this function in @var{*hook_value}. If no
2616 progress callback is set, or @var{ctx} is not a valid pointer,
2617 @code{NULL} is returned in both variables.
2619 @var{progfunc} or @var{hook_value} can be @code{NULL}. In this case,
2620 the corresponding value will not be returned.
2626 @cindex locale, default
2627 @cindex locale, of a context
2629 A locale setting can be associated with a context. This locale is
2630 passed to the crypto engine, and used for applications like the PIN
2631 entry, which is displayed to the user when entering a passphrase is
2634 The default locale is used to initialize the locale setting of all
2635 contexts created afterwards.
2637 @deftypefun gpgme_error_t gpgme_set_locale (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{category}}, @w{const char *@var{value}})
2638 The function @code{gpgme_set_locale} sets the locale of the context
2639 @var{ctx}, or the default locale if @var{ctx} is a null pointer.
2641 The locale settings that should be changed are specified by
2642 @var{category}. Supported categories are @code{LC_CTYPE},
2643 @code{LC_MESSAGES}, and @code{LC_ALL}, which is a wildcard you can use
2644 if you want to change all the categories at once.
2646 The value to be used for the locale setting is @var{value}, which will
2647 be copied to @acronym{GPGME}'s internal data structures. @var{value}
2648 can be a null pointer, which disables setting the locale, and will
2649 make PIN entry and other applications use their default setting, which
2650 is usually not what you want.
2652 Note that the settings are only used if the application runs on a text
2653 terminal, and that the settings should fit the configuration of the
2654 output terminal. Normally, it is sufficient to initialize the default
2657 The function returns an error if not enough memory is available.
2661 @node Key Management
2662 @section Key Management
2663 @cindex key management
2665 Some of the cryptographic operations require that recipients or
2666 signers are specified. This is always done by specifying the
2667 respective keys that should be used for the operation. The following
2668 section describes how such keys can be selected and manipulated.
2670 @deftp {Data type} gpgme_subkey_t
2671 The @code{gpgme_subkey_t} type is a pointer to a subkey structure.
2672 Sub keys are one component of a @code{gpgme_key_t} object. In fact,
2673 subkeys are those parts that contains the real information about the
2674 individual cryptographic keys that belong to the same key object. One
2675 @code{gpgme_key_t} can contain several subkeys. The first subkey in
2676 the linked list is also called the primary key.
2678 The subkey structure has the following members:
2681 @item gpgme_subkey_t next
2682 This is a pointer to the next subkey structure in the linked list, or
2683 @code{NULL} if this is the last element.
2685 @item unsigned int revoked : 1
2686 This is true if the subkey is revoked.
2688 @item unsigned int expired : 1
2689 This is true if the subkey is expired.
2691 @item unsigned int disabled : 1
2692 This is true if the subkey is disabled.
2694 @item unsigned int invalid : 1
2695 This is true if the subkey is invalid.
2697 @item unsigned int can_encrypt : 1
2698 This is true if the subkey can be used for encryption.
2700 @item unsigned int can_sign : 1
2701 This is true if the subkey can be used to create data signatures.
2703 @item unsigned int can_certify : 1
2704 This is true if the subkey can be used to create key certificates.
2706 @item unsigned int can_authenticate : 1
2707 This is true if the subkey can be used for authentication.
2709 @item unsigned int is_qualified : 1
2710 This is true if the subkey can be used for qualified signatures
2711 according to local government regulations.
2713 @item unsigned int secret : 1
2714 This is true if the subkey is a secret key. Note that it will be false
2715 if the key is actually a stub key; i.e. a secret key operation is
2716 currently not possible (offline-key).
2718 @item gpgme_pubkey_algo_t pubkey_algo
2719 This is the public key algorithm supported by this subkey.
2721 @item unsigned int length
2722 This is the length of the subkey (in bits).
2725 This is the key ID of the subkey in hexadecimal digits.
2728 This is the fingerprint of the subkey in hexadecimal digits, if
2731 @item long int timestamp
2732 This is the creation timestamp of the subkey. This is -1 if the
2733 timestamp is invalid, and 0 if it is not available.
2735 @item long int expires
2736 This is the expiration timestamp of the subkey, or 0 if the subkey
2739 @item unsigned int is_cardkey : 1
2740 True if the secret key is stored on a smart card.
2742 @item char *card_number
2743 The serial number of a smart card holding this key or @code{NULL}.
2747 @deftp {Data type} gpgme_key_sig_t
2748 The @code{gpgme_key_sig_t} type is a pointer to a key signature structure.
2749 Key signatures are one component of a @code{gpgme_key_t} object, and
2750 validate user IDs on the key.
2752 The signatures on a key are only available if the key was retrieved
2753 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
2754 enabled, because it can be expensive to retrieve all signatures of a
2757 The signature notations on a key signature are only available if the
2758 key was retrieved via a listing operation with the
2759 @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} mode enabled, because it can
2760 be expensive to retrieve all signature notations.
2762 The key signature structure has the following members:
2765 @item gpgme_key_sig_t next
2766 This is a pointer to the next key signature structure in the linked
2767 list, or @code{NULL} if this is the last element.
2769 @item unsigned int revoked : 1
2770 This is true if the key signature is a revocation signature.
2772 @item unsigned int expired : 1
2773 This is true if the key signature is expired.
2775 @item unsigned int invalid : 1
2776 This is true if the key signature is invalid.
2778 @item unsigned int exportable : 1
2779 This is true if the key signature is exportable.
2781 @item gpgme_pubkey_algo_t pubkey_algo
2782 This is the public key algorithm used to create the signature.
2785 This is the key ID of the key (in hexadecimal digits) used to create
2788 @item long int timestamp
2789 This is the creation timestamp of the key signature. This is -1 if
2790 the timestamp is invalid, and 0 if it is not available.
2792 @item long int expires
2793 This is the expiration timestamp of the key signature, or 0 if the key
2794 signature does not expire.
2796 @item gpgme_error_t status
2797 This is the status of the signature and has the same meaning as the
2798 member of the same name in a @code{gpgme_signature_t} object.
2800 @item unsigned int sig_class
2801 This specifies the signature class of the key signature. The meaning
2802 is specific to the crypto engine.
2805 This is the main user ID of the key used to create the signature.
2808 This is the name component of @code{uid}, if available.
2811 This is the comment component of @code{uid}, if available.
2814 This is the email component of @code{uid}, if available.
2816 @item gpgme_sig_notation_t notations
2817 This is a linked list with the notation data and policy URLs.
2821 @deftp {Data type} gpgme_user_id_t
2822 A user ID is a component of a @code{gpgme_key_t} object. One key can
2823 have many user IDs. The first one in the list is the main (or
2826 The user ID structure has the following members.
2829 @item gpgme_user_id_t next
2830 This is a pointer to the next user ID structure in the linked list, or
2831 @code{NULL} if this is the last element.
2833 @item unsigned int revoked : 1
2834 This is true if the user ID is revoked.
2836 @item unsigned int invalid : 1
2837 This is true if the user ID is invalid.
2839 @item gpgme_validity_t validity
2840 This specifies the validity of the user ID.
2843 This is the user ID string.
2846 This is the name component of @code{uid}, if available.
2849 This is the comment component of @code{uid}, if available.
2852 This is the email component of @code{uid}, if available.
2854 @item gpgme_key_sig_t signatures
2855 This is a linked list with the signatures on this user ID.
2859 @deftp {Data type} gpgme_key_t
2860 The @code{gpgme_key_t} type is a pointer to a key object. It has the
2864 @item gpgme_keylist_mode_t keylist_mode
2865 The keylist mode that was active when the key was retrieved.
2867 @item unsigned int revoked : 1
2868 This is true if the key is revoked.
2870 @item unsigned int expired : 1
2871 This is true if the key is expired.
2873 @item unsigned int disabled : 1
2874 This is true if the key is disabled.
2876 @item unsigned int invalid : 1
2877 This is true if the key is invalid. This might have several reasons,
2878 for a example for the S/MIME backend, it will be set in during key
2879 listsing if the key could not be validated due to a missing
2880 certificates or unmatched policies.
2882 @item unsigned int can_encrypt : 1
2883 This is true if the key (ie one of its subkeys) can be used for
2886 @item unsigned int can_sign : 1
2887 This is true if the key (ie one of its subkeys) can be used to create
2890 @item unsigned int can_certify : 1
2891 This is true if the key (ie one of its subkeys) can be used to create
2894 @item unsigned int can_authenticate : 1
2895 This is true if the key (ie one of its subkeys) can be used for
2898 @item unsigned int is_qualified : 1
2899 This is true if the key can be used for qualified signatures according
2900 to local government regulations.
2902 @item unsigned int secret : 1
2903 This is true if the key is a secret key. Note, that this will always be
2904 true even if the corresponding subkey flag may be false (offline/stub
2907 @item gpgme_protocol_t protocol
2908 This is the protocol supported by this key.
2910 @item char *issuer_serial
2911 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2914 @item char *issuer_name
2915 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2918 @item char *chain_id
2919 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2920 chain ID, which can be used to built the certificate chain.
2922 @item gpgme_validity_t owner_trust
2923 If @code{protocol} is @code{GPGME_PROTOCOL_OpenPGP}, then this is the
2926 @item gpgme_subkey_t subkeys
2927 This is a linked list with the subkeys of the key. The first subkey
2928 in the list is the primary key and usually available.
2930 @item gpgme_user_id_t uids
2931 This is a linked list with the user IDs of the key. The first user ID
2932 in the list is the main (or primary) user ID.
2937 * Listing Keys:: Browsing the list of available keys.
2938 * Information About Keys:: Requesting detailed information about keys.
2939 * Key Signatures:: Listing the signatures on a key.
2940 * Manipulating Keys:: Operations on keys.
2941 * Generating Keys:: Creating new key pairs.
2942 * Exporting Keys:: Retrieving key data from the key ring.
2943 * Importing Keys:: Adding keys to the key ring.
2944 * Deleting Keys:: Removing keys from the key ring.
2945 * Changing Passphrases:: Change the passphrase of a key.
2946 * Advanced Key Editing:: Advanced key edit operation.
2951 @subsection Listing Keys
2952 @cindex listing keys
2954 @cindex key listing, start
2955 @cindex key ring, list
2956 @cindex key ring, search
2958 @deftypefun gpgme_error_t gpgme_op_keylist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
2959 The function @code{gpgme_op_keylist_start} initiates a key listing
2960 operation inside the context @var{ctx}. It sets everything up so that
2961 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
2964 If @var{pattern} is @code{NULL}, all available keys are returned.
2965 Otherwise, @var{pattern} contains an engine specific expression that
2966 is used to limit the list to all keys matching the pattern. Note that
2967 the total length of the pattern is restricted to an engine-specific
2968 maximum (a couple of hundred characters are usually accepted). The
2969 pattern should be used to restrict the search to a certain common name
2970 or user, not to list many specific keys at once by listing their
2971 fingerprints or key IDs.
2973 If @var{secret_only} is not @code{0}, the list is restricted to secret
2976 The context will be busy until either all keys are received (and
2977 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2978 @code{gpgme_op_keylist_end} is called to finish the operation.
2980 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2981 @var{ctx} is not a valid pointer, and passes through any errors that
2982 are reported by the crypto engine support routines.
2985 @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}})
2986 The function @code{gpgme_op_keylist_ext_start} initiates an extended
2987 key listing operation inside the context @var{ctx}. It sets
2988 everything up so that subsequent invocations of
2989 @code{gpgme_op_keylist_next} return the keys in the list.
2991 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
2992 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
2993 array of strings that are used to limit the list to all keys matching
2994 at least one of the patterns verbatim. Note that the total length of
2995 all patterns is restricted to an engine-specific maximum (the exact
2996 limit also depends on the number of patterns and amount of quoting
2997 required, but a couple of hundred characters are usually accepted).
2998 Patterns should be used to restrict the search to a certain common
2999 name or user, not to list many specific keys at once by listing their
3000 fingerprints or key IDs.
3002 If @var{secret_only} is not @code{0}, the list is restricted to secret
3005 The value of @var{reserved} must be @code{0}.
3007 The context will be busy until either all keys are received (and
3008 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
3009 @code{gpgme_op_keylist_end} is called to finish the operation.
3011 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3012 @var{ctx} is not a valid pointer, and passes through any errors that
3013 are reported by the crypto engine support routines.
3016 @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}})
3017 The function @code{gpgme_op_keylist_next} returns the next key in the
3018 list created by a previous @code{gpgme_op_keylist_start} operation in
3019 the context @var{ctx}. The key will have one reference for the user.
3020 @xref{Manipulating Keys}.
3022 This is the only way to get at @code{gpgme_key_t} objects in
3025 If the last key in the list has already been returned,
3026 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}.
3028 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3029 @var{ctx} or @var{r_key} is not a valid pointer, and
3030 @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation.
3033 @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}})
3034 The function @code{gpgme_op_keylist_end} ends a pending key list
3035 operation in the context @var{ctx}.
3037 After the operation completed successfully, the result of the key
3038 listing operation can be retrieved with
3039 @code{gpgme_op_keylist_result}.
3041 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3042 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
3043 time during the operation there was not enough memory available.
3046 The following example illustrates how all keys containing a certain
3047 string (@code{g10code}) can be listed with their key ID and the name
3048 and e-mail address of the main user ID:
3053 gpgme_error_t err = gpgme_new (&ctx);
3057 err = gpgme_op_keylist_start (ctx, "g10code", 0);
3060 err = gpgme_op_keylist_next (ctx, &key);
3063 printf ("%s:", key->subkeys->keyid);
3064 if (key->uids && key->uids->name)
3065 printf (" %s", key->uids->name);
3066 if (key->uids && key->uids->email)
3067 printf (" <%s>", key->uids->email);
3069 gpgme_key_release (key);
3071 gpgme_release (ctx);
3073 if (gpg_err_code (err) != GPG_ERR_EOF)
3075 fprintf (stderr, "can not list keys: %s\n", gpgme_strerror (err));
3080 @deftp {Data type} {gpgme_keylist_result_t}
3081 This is a pointer to a structure used to store the result of a
3082 @code{gpgme_op_keylist_*} operation. After successfully ending a key
3083 listing operation, you can retrieve the pointer to the result with
3084 @code{gpgme_op_keylist_result}. The structure contains the following
3088 @item unsigned int truncated : 1
3089 This is true if the crypto backend had to truncate the result, and
3090 less than the desired keys could be listed.
3094 @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}})
3095 The function @code{gpgme_op_keylist_result} returns a
3096 @code{gpgme_keylist_result_t} pointer to a structure holding the
3097 result of a @code{gpgme_op_keylist_*} operation. The pointer is only
3098 valid if the last operation on the context was a key listing
3099 operation, and if this operation finished successfully. The returned
3100 pointer is only valid until the next operation is started on the
3104 In a simple program, for which a blocking operation is acceptable, the
3105 following function can be used to retrieve a single key.
3107 @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}})
3108 The function @code{gpgme_get_key} gets the key with the fingerprint
3109 (or key ID) @var{fpr} from the crypto backend and return it in
3110 @var{r_key}. If @var{secret} is true, get the secret key. The
3111 currently active keylist mode is used to retrieve the key. The key
3112 will have one reference for the user.
3114 If the key is not found in the keyring, @code{gpgme_get_key} returns
3115 the error code @code{GPG_ERR_EOF} and *@var{r_key} will be set to
3118 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3119 @var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a
3120 fingerprint or key ID, @code{GPG_ERR_AMBIGUOUS_NAME} if the key ID was
3121 not a unique specifier for a key, and @code{GPG_ERR_ENOMEM} if at some
3122 time during the operation there was not enough memory available.
3126 @node Information About Keys
3127 @subsection Information About Keys
3128 @cindex key, information about
3129 @cindex key, attributes
3130 @cindex attributes, of a key
3132 Please see the beginning of this section for more information about
3133 @code{gpgme_key_t} objects.
3135 @deftp {Data type} gpgme_validity_t
3136 The @code{gpgme_validity_t} type is used to specify the validity of a user ID
3137 in a key. The following validities are defined:
3140 @item GPGME_VALIDITY_UNKNOWN
3141 The user ID is of unknown validity. The string representation of this
3144 @item GPGME_VALIDITY_UNDEFINED
3145 The validity of the user ID is undefined. The string representation of this
3148 @item GPGME_VALIDITY_NEVER
3149 The user ID is never valid. The string representation of this
3152 @item GPGME_VALIDITY_MARGINAL
3153 The user ID is marginally valid. The string representation of this
3156 @item GPGME_VALIDITY_FULL
3157 The user ID is fully valid. The string representation of this
3160 @item GPGME_VALIDITY_ULTIMATE
3161 The user ID is ultimately valid. The string representation of this
3167 The following interfaces are deprecated and only provided for backward
3168 compatibility. Don't use them. They will be removed in a future
3169 version of @acronym{GPGME}.
3171 @deftp {Data type} gpgme_attr_t
3172 The @code{gpgme_attr_t} type is used to specify a key or trust item
3173 attribute. The following attributes are defined:
3176 @item GPGME_ATTR_KEYID
3177 This is the key ID of a sub key. It is representable as a string.
3179 For trust items, the trust item refers to the key with this ID.
3181 @item GPGME_ATTR_FPR
3182 This is the fingerprint of a sub key. It is representable as a
3185 @item GPGME_ATTR_ALGO
3186 This is the crypto algorithm for which the sub key can be used. It
3187 is representable as a string and as a number. The numbers correspond
3188 to the @code{enum gcry_pk_algos} values in the gcrypt library.
3190 @item GPGME_ATTR_LEN
3191 This is the key length of a sub key. It is representable as a
3194 @item GPGME_ATTR_CREATED
3195 This is the timestamp at creation time of a sub key. It is
3196 representable as a number.
3198 @item GPGME_ATTR_EXPIRE
3199 This is the expiration time of a sub key. It is representable as a
3202 @item GPGME_ATTR_OTRUST
3203 XXX FIXME (also for trust items)
3205 @item GPGME_ATTR_USERID
3206 This is a user ID. There can be more than one user IDs in a
3207 @var{gpgme_key_t} object. The first one (with index 0) is the primary
3208 user ID. The user ID is representable as a number.
3210 For trust items, this is the user ID associated with this trust item.
3212 @item GPGME_ATTR_NAME
3213 This is the name belonging to a user ID. It is representable as a string.
3215 @item GPGME_ATTR_EMAIL
3216 This is the email address belonging to a user ID. It is representable
3219 @item GPGME_ATTR_COMMENT
3220 This is the comment belonging to a user ID. It is representable as a
3223 @item GPGME_ATTR_VALIDITY
3224 This is the validity belonging to a user ID. It is representable as a
3225 string and as a number. See below for a list of available validities.
3227 For trust items, this is the validity that is associated with this
3230 @item GPGME_ATTR_UID_REVOKED
3231 This specifies if a user ID is revoked. It is representable as a
3232 number, and is @code{1} if the user ID is revoked, and @code{0}
3235 @item GPGME_ATTR_UID_INVALID
3236 This specifies if a user ID is invalid. It is representable as a
3237 number, and is @code{1} if the user ID is invalid, and @code{0}
3240 @item GPGME_ATTR_LEVEL
3241 This is the trust level of a trust item.
3243 @item GPGME_ATTR_TYPE
3244 This returns information about the type of key. For the string function
3245 this will eother be "PGP" or "X.509". The integer function returns 0
3246 for PGP and 1 for X.509. It is also used for the type of a trust item.
3248 @item GPGME_ATTR_IS_SECRET
3249 This specifies if the key is a secret key. It is representable as a
3250 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
3252 @item GPGME_ATTR_KEY_REVOKED
3253 This specifies if a sub key is revoked. It is representable as a
3254 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
3256 @item GPGME_ATTR_KEY_INVALID
3257 This specifies if a sub key is invalid. It is representable as a
3258 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
3260 @item GPGME_ATTR_KEY_EXPIRED
3261 This specifies if a sub key is expired. It is representable as a
3262 number, and is @code{1} if the key is expired, and @code{0} otherwise.
3264 @item GPGME_ATTR_KEY_DISABLED
3265 This specifies if a sub key is disabled. It is representable as a
3266 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
3268 @item GPGME_ATTR_KEY_CAPS
3269 This is a description of the capabilities of a sub key. It is
3270 representable as a string. The string contains the letter ``e'' if
3271 the key can be used for encryption, ``s'' if the key can be used for
3272 signatures, and ``c'' if the key can be used for certifications.
3274 @item GPGME_ATTR_CAN_ENCRYPT
3275 This specifies if a sub key can be used for encryption. It is
3276 representable as a number, and is @code{1} if the sub key can be used
3277 for encryption, and @code{0} otherwise.
3279 @item GPGME_ATTR_CAN_SIGN
3280 This specifies if a sub key can be used to create data signatures. It
3281 is representable as a number, and is @code{1} if the sub key can be
3282 used for signatures, and @code{0} otherwise.
3284 @item GPGME_ATTR_CAN_CERTIFY
3285 This specifies if a sub key can be used to create key certificates.
3286 It is representable as a number, and is @code{1} if the sub key can be
3287 used for certifications, and @code{0} otherwise.
3289 @item GPGME_ATTR_SERIAL
3290 The X.509 issuer serial attribute of the key. It is representable as
3293 @item GPGME_ATTR_ISSUE
3294 The X.509 issuer name attribute of the key. It is representable as a
3297 @item GPGME_ATTR_CHAINID
3298 The X.509 chain ID can be used to build the certification chain. It
3299 is representable as a string.
3303 @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}})
3304 The function @code{gpgme_key_get_string_attr} returns the value of the
3305 string-representable attribute @var{what} of key @var{key}. If the
3306 attribute is an attribute of a sub key or an user ID, @var{idx}
3307 specifies the sub key or user ID of which the attribute value is
3308 returned. The argument @var{reserved} is reserved for later use and
3309 should be @code{NULL}.
3311 The string returned is only valid as long as the key is valid.
3313 The function returns @code{0} if an attribute can't be returned as a
3314 string, @var{key} is not a valid pointer, @var{idx} out of range,
3315 or @var{reserved} not @code{NULL}.
3318 @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}})
3319 The function @code{gpgme_key_get_ulong_attr} returns the value of the
3320 number-representable attribute @var{what} of key @var{key}. If the
3321 attribute is an attribute of a sub key or an user ID, @var{idx}
3322 specifies the sub key or user ID of which the attribute value is
3323 returned. The argument @var{reserved} is reserved for later use and
3324 should be @code{NULL}.
3326 The function returns @code{0} if the attribute can't be returned as a
3327 number, @var{key} is not a valid pointer, @var{idx} out of range, or
3328 @var{reserved} not @code{NULL}.
3332 @node Key Signatures
3333 @subsection Key Signatures
3334 @cindex key, signatures
3335 @cindex signatures, on a key
3337 The following interfaces are deprecated and only provided for backward
3338 compatibility. Don't use them. They will be removed in a future
3339 version of @acronym{GPGME}.
3341 The signatures on a key are only available if the key was retrieved
3342 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
3343 enabled, because it is expensive to retrieve all signatures of a key.
3345 So, before using the below interfaces to retrieve the signatures on a
3346 key, you have to make sure that the key was listed with signatures
3347 enabled. One convenient, but blocking, way to do this is to use the
3348 function @code{gpgme_get_key}.
3350 @deftp {Data type} gpgme_attr_t
3351 The @code{gpgme_attr_t} type is used to specify a key signature
3352 attribute. The following attributes are defined:
3355 @item GPGME_ATTR_KEYID
3356 This is the key ID of the key which was used for the signature. It is
3357 representable as a string.
3359 @item GPGME_ATTR_ALGO
3360 This is the crypto algorithm used to create the signature. It is
3361 representable as a string and as a number. The numbers correspond to
3362 the @code{enum gcry_pk_algos} values in the gcrypt library.
3364 @item GPGME_ATTR_CREATED
3365 This is the timestamp at creation time of the signature. It is
3366 representable as a number.
3368 @item GPGME_ATTR_EXPIRE
3369 This is the expiration time of the signature. It is representable as
3372 @item GPGME_ATTR_USERID
3373 This is the user ID associated with the signing key. The user ID is
3374 representable as a number.
3376 @item GPGME_ATTR_NAME
3377 This is the name belonging to a user ID. It is representable as a string.
3379 @item GPGME_ATTR_EMAIL
3380 This is the email address belonging to a user ID. It is representable
3383 @item GPGME_ATTR_COMMENT
3384 This is the comment belonging to a user ID. It is representable as a
3387 @item GPGME_ATTR_KEY_REVOKED
3388 This specifies if a key signature is a revocation signature. It is
3389 representable as a number, and is @code{1} if the key is revoked, and
3392 @c @item GPGME_ATTR_KEY_EXPIRED
3393 @c This specifies if a key signature is expired. It is representable as
3394 @c a number, and is @code{1} if the key is revoked, and @code{0}
3397 @item GPGME_ATTR_SIG_CLASS
3398 This specifies the signature class of a key signature. It is
3399 representable as a number. The meaning is specific to the crypto
3402 @item GPGME_ATTR_SIG_CLASS
3403 This specifies the signature class of a key signature. It is
3404 representable as a number. The meaning is specific to the crypto
3407 @item GPGME_ATTR_SIG_STATUS
3408 This is the same value as returned by @code{gpgme_get_sig_status}.
3412 @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}})
3413 The function @code{gpgme_key_sig_get_string_attr} returns the value of
3414 the string-representable attribute @var{what} of the signature
3415 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3416 argument @var{reserved} is reserved for later use and should be
3419 The string returned is only valid as long as the key is valid.
3421 The function returns @code{0} if an attribute can't be returned as a
3422 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3423 out of range, or @var{reserved} not @code{NULL}.
3426 @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}})
3427 The function @code{gpgme_key_sig_get_ulong_attr} returns the value of
3428 the number-representable attribute @var{what} of the signature
3429 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3430 argument @var{reserved} is reserved for later use and should be
3433 The function returns @code{0} if an attribute can't be returned as a
3434 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3435 out of range, or @var{reserved} not @code{NULL}.
3439 @node Manipulating Keys
3440 @subsection Manipulating Keys
3441 @cindex key, manipulation
3443 @deftypefun void gpgme_key_ref (@w{gpgme_key_t @var{key}})
3444 The function @code{gpgme_key_ref} acquires an additional reference for
3448 @deftypefun void gpgme_key_unref (@w{gpgme_key_t @var{key}})
3449 The function @code{gpgme_key_unref} releases a reference for the key
3450 @var{key}. If this was the last reference, the key will be destroyed
3451 and all resources associated to it will be released.
3455 The following interface is deprecated and only provided for backward
3456 compatibility. Don't use it. It will be removed in a future version
3459 @deftypefun void gpgme_key_release (@w{gpgme_key_t @var{key}})
3460 The function @code{gpgme_key_release} is equivalent to
3461 @code{gpgme_key_unref}.
3465 @node Generating Keys
3466 @subsection Generating Keys
3467 @cindex key, creation
3468 @cindex key ring, add
3470 @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}})
3471 The function @code{gpgme_op_genkey} generates a new key pair in the
3472 context @var{ctx}. The meaning of @var{public} and @var{secret}
3473 depends on the crypto backend.
3475 GnuPG does not support @var{public} and @var{secret}, they should be
3476 @code{NULL}. GnuPG will generate a key pair and add it to the
3477 standard key ring. The fingerprint of the generated key is available
3478 with @code{gpgme_op_genkey_result}.
3480 GpgSM requires @var{public} to be a writable data object. GpgSM will
3481 generate a secret key (which will be stored by @command{gpg-agent},
3482 and return a certificate request in @var{public}, which then needs to
3483 be signed by the certification authority and imported before it can be
3484 used. GpgSM does not make the fingerprint available.
3486 The argument @var{parms} specifies parameters for the key in an XML
3487 string. The details about the format of @var{parms} are specific to
3488 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
3489 the crypto engine (all parameters of OpenPGP key generation are
3490 documented in the GPG manual):
3493 <GnupgKeyParms format="internal">
3495 Subkey-Type: default
3496 Name-Real: Joe Tester
3497 Name-Comment: with stupid passphrase
3498 Name-Email: joe@@foo.bar
3504 Here is an example for GpgSM as the crypto engine (all parameters of
3505 OpenPGP key generation are documented in the GPGSM manual):
3508 <GnupgKeyParms format="internal">
3511 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3512 Name-Email: joe@@foo.bar
3516 Strings should be given in UTF-8 encoding. The only format supported
3517 for now is ``internal''. The content of the @code{GnupgKeyParms}
3518 container is passed verbatim to the crypto backend. Control
3519 statements are not allowed.
3521 After the operation completed successfully, the result can be
3522 retrieved with @code{gpgme_op_genkey_result}.
3524 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3525 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3526 @var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if
3527 @var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL}
3528 if no key was created by the backend.
3531 @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}})
3532 The function @code{gpgme_op_genkey_start} initiates a
3533 @code{gpgme_op_genkey} operation. It can be completed by calling
3534 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3536 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3537 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3538 @var{parms} is not a valid XML string, and
3539 @code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not
3543 @deftp {Data type} {gpgme_genkey_result_t}
3544 This is a pointer to a structure used to store the result of a
3545 @code{gpgme_op_genkey} operation. After successfully generating a
3546 key, you can retrieve the pointer to the result with
3547 @code{gpgme_op_genkey_result}. The structure contains the following
3551 @item unsigned int primary : 1
3552 This is a flag that is set to 1 if a primary key was created and to 0
3555 @item unsigned int sub : 1
3556 This is a flag that is set to 1 if a subkey was created and to 0
3560 This is the fingerprint of the key that was created. If both a
3561 primary and a sub key were generated, the fingerprint of the primary
3562 key will be returned. If the crypto engine does not provide the
3563 fingerprint, @code{fpr} will be a null pointer.
3567 @deftypefun gpgme_genkey_result_t gpgme_op_genkey_result (@w{gpgme_ctx_t @var{ctx}})
3568 The function @code{gpgme_op_genkey_result} returns a
3569 @code{gpgme_genkey_result_t} pointer to a structure holding the result of
3570 a @code{gpgme_op_genkey} operation. The pointer is only valid if the
3571 last operation on the context was a @code{gpgme_op_genkey} or
3572 @code{gpgme_op_genkey_start} operation, and if this operation finished
3573 successfully. The returned pointer is only valid until the next
3574 operation is started on the context.
3578 @node Exporting Keys
3579 @subsection Exporting Keys
3581 @cindex key ring, export from
3583 Exporting keys means the same as running @command{gpg} with the command
3584 @option{--export}. However, a mode flag can be used to change the way
3585 the export works. The available mode flags are described below, they
3586 may be or-ed together.
3590 @item GPGME_EXPORT_MODE_EXTERN
3591 If this bit is set, the output is send directly to the default
3592 keyserver. This is currently only allowed for OpenPGP keys. It is good
3593 practise to not send more than a few dozens key to a keyserver at one
3594 time. Using this flag requires that the @var{keydata} argument of the
3595 export function is set to @code{NULL}.
3597 @item GPGME_EXPORT_MODE_MINIMAL
3598 If this bit is set, the smallest possible key is exported. For OpenPGP
3599 keys it removes all signatures except for the latest self-signatures.
3600 For X.509 keys it has no effect.
3607 @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}})
3608 The function @code{gpgme_op_export} extracts public keys and returns
3609 them in the data buffer @var{keydata}. The output format of the key
3610 data returned is determined by the @acronym{ASCII} armor attribute set
3611 for the context @var{ctx}, or, if that is not set, by the encoding
3612 specified for @var{keydata}.
3614 If @var{pattern} is @code{NULL}, all available keys are returned.
3615 Otherwise, @var{pattern} contains an engine specific expression that
3616 is used to limit the list to all keys matching the pattern.
3618 @var{mode} is usually 0; other values are described above.
3620 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3621 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3622 @var{keydata} is not a valid empty data buffer, and passes through any
3623 errors that are reported by the crypto engine support routines.
3626 @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}})
3627 The function @code{gpgme_op_export_start} initiates a
3628 @code{gpgme_op_export} operation. It can be completed by calling
3629 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3631 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3632 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3633 if @var{keydata} is not a valid empty data buffer.
3636 @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}})
3637 The function @code{gpgme_op_export} extracts public keys and returns
3638 them in the data buffer @var{keydata}. The output format of the key
3639 data returned is determined by the @acronym{ASCII} armor attribute set
3640 for the context @var{ctx}, or, if that is not set, by the encoding
3641 specified for @var{keydata}.
3643 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3644 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3645 array of strings that are used to limit the list to all keys matching
3646 at least one of the patterns verbatim.
3648 @var{mode} is usually 0; other values are described above.
3650 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3651 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3652 @var{keydata} is not a valid empty data buffer, and passes through any
3653 errors that are reported by the crypto engine support routines.
3656 @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}})
3657 The function @code{gpgme_op_export_ext_start} initiates a
3658 @code{gpgme_op_export_ext} operation. It can be completed by calling
3659 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3661 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3662 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3663 if @var{keydata} is not a valid empty data buffer.
3667 @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}})
3668 The function @code{gpgme_op_export_keys} extracts public keys and returns
3669 them in the data buffer @var{keydata}. The output format of the key
3670 data returned is determined by the @acronym{ASCII} armor attribute set
3671 for the context @var{ctx}, or, if that is not set, by the encoding
3672 specified for @var{keydata}.
3674 The keys to export are taken form the @code{NULL} terminated array
3675 @var{keys}. Only keys of the the currently selected protocol of
3676 @var{ctx} which do have a fingerprint set are considered for export.
3677 Other keys specified by the @var{keys} are ignored. In particular
3678 OpenPGP keys retrieved via an external key listing are not included.
3680 @var{mode} is usually 0; other values are described above.
3682 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3683 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3684 @var{keydata} is not a valid empty data buffer, @code{GPG_ERR_NO_DATA}
3685 if no useful keys are in @var{keys} and passes through any errors that
3686 are reported by the crypto engine support routines.
3689 @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}})
3690 The function @code{gpgme_op_export_keys_start} initiates a
3691 @code{gpgme_op_export_ext} operation. It can be completed by calling
3692 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3694 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3695 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3696 if @var{keydata} is not a valid empty data buffer, @code{GPG_ERR_NO_DATA}
3697 if no useful keys are in @var{keys} and passes through any errors that
3698 are reported by the crypto engine support routines.
3702 @node Importing Keys
3703 @subsection Importing Keys
3705 @cindex key ring, import to
3707 Importing keys means the same as running @command{gpg} with the command
3711 @deftypefun gpgme_error_t gpgme_op_import (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3712 The function @code{gpgme_op_import} adds the keys in the data buffer
3713 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
3714 The format of @var{keydata} can be @acronym{ASCII} armored, for example,
3715 but the details are specific to the crypto engine.
3717 After the operation completed successfully, the result can be
3718 retrieved with @code{gpgme_op_import_result}.
3720 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3721 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3722 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3723 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3726 @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3727 The function @code{gpgme_op_import_start} initiates a
3728 @code{gpgme_op_import} operation. It can be completed by calling
3729 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3731 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3732 import could be started successfully, @code{GPG_ERR_INV_VALUE} if
3733 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3734 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3737 @deftypefun gpgme_error_t gpgme_op_import_keys (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{keys}})
3738 The function @code{gpgme_op_import_keys} adds the keys described by the
3739 @code{NULL} terminated array @var{keys} to the key ring of the crypto
3740 engine used by @var{ctx}. This function is the general interface to
3741 move a key from one crypto engine to another as long as they are
3742 compatible. In particular it is used to actually import and make keys
3743 permanent which have been retrieved from an external source (i.e. using
3744 @code{GPGME_KEYLIST_MODE_EXTERN}). @footnote{Thus it is a replacement
3745 for the usual workaround of exporting and then importing a key to make
3746 an X.509 key permanent.}
3748 Only keys of the the currently selected protocol of @var{ctx} are
3749 considered for import. Other keys specified by the @var{keys} are
3750 ignored. As of now all considered keys must have been retrieved using
3751 the same method, that is the used key listing mode must be identical.
3753 After the operation completed successfully, the result can be
3754 retrieved with @code{gpgme_op_import_result}.
3756 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3757 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3758 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3759 @code{GPG_ERR_CONFLICT} if the key listing mode does not match, and
3760 @code{GPG_ERR_NO_DATA} if no keys are considered for export.
3763 @deftypefun gpgme_error_t gpgme_op_import_keys_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{keys}})
3764 The function @code{gpgme_op_import_keys_start} initiates a
3765 @code{gpgme_op_import_keys} operation. It can be completed by calling
3766 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3768 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3769 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3770 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3771 @code{GPG_ERR_CONFLICT} if the key listing mode does not match, and
3772 @code{GPG_ERR_NO_DATA} if no keys are considered for export.
3775 @deftp {Data type} {gpgme_import_status_t}
3776 This is a pointer to a structure used to store a part of the result of
3777 a @code{gpgme_op_import} operation. For each considered key one
3778 status is added that contains information about the result of the
3779 import. The structure contains the following members:
3782 @item gpgme_import_status_t next
3783 This is a pointer to the next status structure in the linked list, or
3784 @code{NULL} if this is the last element.
3787 This is the fingerprint of the key that was considered.
3789 @item gpgme_error_t result
3790 If the import was not successful, this is the error value that caused
3791 the import to fail. Otherwise the error code is
3792 @code{GPG_ERR_NO_ERROR}.
3794 @item unsigned int status
3795 This is a bit-wise OR of the following flags that give more
3796 information about what part of the key was imported. If the key was
3797 already known, this might be 0.
3800 @item GPGME_IMPORT_NEW
3803 @item GPGME_IMPORT_UID
3804 The key contained new user IDs.
3806 @item GPGME_IMPORT_SIG
3807 The key contained new signatures.
3809 @item GPGME_IMPORT_SUBKEY
3810 The key contained new sub keys.
3812 @item GPGME_IMPORT_SECRET
3813 The key contained a secret key.
3818 @deftp {Data type} {gpgme_import_result_t}
3819 This is a pointer to a structure used to store the result of a
3820 @code{gpgme_op_import} operation. After a successful import
3821 operation, you can retrieve the pointer to the result with
3822 @code{gpgme_op_import_result}. The structure contains the following
3826 @item int considered
3827 The total number of considered keys.
3829 @item int no_user_id
3830 The number of keys without user ID.
3833 The total number of imported keys.
3836 The number of imported RSA keys.
3839 The number of unchanged keys.
3842 The number of new user IDs.
3845 The number of new sub keys.
3847 @item new_signatures
3848 The number of new signatures.
3850 @item new_revocations
3851 The number of new revocations.
3854 The total number of secret keys read.
3856 @item secret_imported
3857 The number of imported secret keys.
3859 @item secret_unchanged
3860 The number of unchanged secret keys.
3863 The number of keys not imported.
3865 @item gpgme_import_status_t imports
3866 A list of gpgme_import_status_t objects which contain more information
3867 about the keys for which an import was attempted.
3871 @deftypefun gpgme_import_result_t gpgme_op_import_result (@w{gpgme_ctx_t @var{ctx}})
3872 The function @code{gpgme_op_import_result} returns a
3873 @code{gpgme_import_result_t} pointer to a structure holding the result
3874 of a @code{gpgme_op_import} operation. The pointer is only valid if
3875 the last operation on the context was a @code{gpgme_op_import} or
3876 @code{gpgme_op_import_start} operation, and if this operation finished
3877 successfully. The returned pointer is only valid until the next
3878 operation is started on the context.
3881 The following interface is deprecated and only provided for backward
3882 compatibility. Don't use it. It will be removed in a future version
3885 @deftypefun gpgme_error_t gpgme_op_import_ext (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}}, @w{int *@var{nr}})
3886 The function @code{gpgme_op_import_ext} is equivalent to:
3889 gpgme_error_t err = gpgme_op_import (ctx, keydata);
3892 gpgme_import_result_t result = gpgme_op_import_result (ctx);
3893 *nr = result->considered;
3900 @subsection Deleting Keys
3902 @cindex key ring, delete from
3904 @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}})
3905 The function @code{gpgme_op_delete} deletes the key @var{key} from the
3906 key ring of the crypto engine used by @var{ctx}. If
3907 @var{allow_secret} is @code{0}, only public keys are deleted,
3908 otherwise secret keys are deleted as well, if that is supported.
3910 The function returns the error code @code{GPG_ERR_NO_ERROR} if the key
3911 was deleted successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3912 @var{key} is not a valid pointer, @code{GPG_ERR_NO_PUBKEY} if
3913 @var{key} could not be found in the keyring,
3914 @code{GPG_ERR_AMBIGUOUS_NAME} if the key was not specified
3915 unambiguously, and @code{GPG_ERR_CONFLICT} if the secret key for
3916 @var{key} is available, but @var{allow_secret} is zero.
3919 @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}})
3920 The function @code{gpgme_op_delete_start} initiates a
3921 @code{gpgme_op_delete} operation. It can be completed by calling
3922 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3924 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3925 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3926 @var{ctx} or @var{key} is not a valid pointer.
3930 @node Changing Passphrases
3931 @subsection Changing Passphrases
3932 @cindex passphrase, change
3934 @deftypefun gpgme_error_t gpgme_op_passwd @
3935 (@w{gpgme_ctx_t @var{ctx}}, @
3936 @w{const gpgme_key_t @var{key}}, @
3937 @w{unsigned int @var{flags}})
3939 The function @code{gpgme_op_passwd} changes the passphrase of the
3940 private key associated with @var{key}. The only allowed value for
3941 @var{flags} is @code{0}. The backend engine will usually popup a window
3942 to ask for the old and the new passphrase. Thus this function is not
3943 useful in a server application (where passphrases are not required
3946 Note that old @code{gpg} engines (before version 2.0.15) do not support
3947 this command and will silently ignore it.
3950 @deftypefun gpgme_error_t gpgme_op_passwd_start @
3951 (@w{gpgme_ctx_t @var{ctx}}, @
3952 @w{const gpgme_key_t @var{key}}, @
3953 @w{unsigned int @var{flags}})
3955 The function @code{gpgme_op_passwd_start} initiates a
3956 @code{gpgme_op_passwd} operation. It can be completed by calling
3957 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3959 The function returns @code{0} if the operation was started successfully,
3960 and an error code if one of the arguments is not valid or the oepration
3961 could not be started.
3965 @node Advanced Key Editing
3966 @subsection Advanced Key Editing
3969 @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}})}
3970 @tindex gpgme_edit_cb_t
3971 The @code{gpgme_edit_cb_t} type is the type of functions which
3972 @acronym{GPGME} calls if it a key edit operation is on-going. The
3973 status code @var{status} and the argument line @var{args} are passed
3974 through by @acronym{GPGME} from the crypto engine. The file
3975 descriptor @var{fd} is -1 for normal status messages. If @var{status}
3976 indicates a command rather than a status message, the response to the
3977 command should be written to @var{fd}. The @var{handle} is provided
3978 by the user at start of operation.
3980 The function should return @code{GPG_ERR_NO_ERROR} or an error value.
3983 @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}})
3984 The function @code{gpgme_op_edit} processes the key @var{KEY}
3985 interactively, using the edit callback function @var{FNC} with the
3986 handle @var{HANDLE}. The callback is invoked for every status and
3987 command request from the crypto engine. The output of the crypto
3988 engine is written to the data object @var{out}.
3990 Note that the protocol between the callback function and the crypto
3991 engine is specific to the crypto engine and no further support in
3992 implementing this protocol correctly is provided by @acronym{GPGME}.
3994 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3995 edit operation completes successfully, @code{GPG_ERR_INV_VALUE} if
3996 @var{ctx} or @var{key} is not a valid pointer, and any error returned
3997 by the crypto engine or the edit callback handler.
4000 @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}})
4001 The function @code{gpgme_op_edit_start} initiates a
4002 @code{gpgme_op_edit} operation. It can be completed by calling
4003 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4005 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4006 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
4007 @var{ctx} or @var{key} is not a valid pointer.
4011 @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}})
4012 The function @code{gpgme_op_card_edit} is analogous to
4013 @code{gpgme_op_edit}, but should be used to process the smart card corresponding to the key @var{key}.
4016 @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}})
4017 The function @code{gpgme_op_card_edit_start} initiates a
4018 @code{gpgme_op_card_edit} operation. It can be completed by calling
4019 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4021 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4022 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
4023 @var{ctx} or @var{key} is not a valid pointer.
4027 @node Trust Item Management
4028 @section Trust Item Management
4031 @strong{Caution:} The trust items interface is experimental.
4033 @deftp {Data type} gpgme_trust_item_t
4034 The @code{gpgme_trust_item_t} type is a pointer to a trust item object.
4035 It has the following members:
4039 This is a string describing the key to which this trust items belongs.
4042 This is the type of the trust item. A value of 1 refers to a key, a
4043 value of 2 refers to a user ID.
4046 This is the trust level.
4048 @item char *owner_trust
4049 The owner trust if @code{type} is 1.
4051 @item char *validity
4052 The calculated validity.
4055 The user name if @code{type} is 2.
4060 * Listing Trust Items:: Browsing the list of available trust items.
4061 * Information About Trust Items:: Requesting information about trust items.
4062 * Manipulating Trust Items:: Operations on trust items.
4066 @node Listing Trust Items
4067 @subsection Listing Trust Items
4068 @cindex trust item list
4070 @deftypefun gpgme_error_t gpgme_op_trustlist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}})
4071 The function @code{gpgme_op_trustlist_start} initiates a trust item
4072 listing operation inside the context @var{ctx}. It sets everything up
4073 so that subsequent invocations of @code{gpgme_op_trustlist_next} return
4074 the trust items in the list.
4076 The string @var{pattern} contains an engine specific expression that
4077 is used to limit the list to all trust items matching the pattern. It
4078 can not be the empty string.
4080 The argument @var{max_level} is currently ignored.
4082 The context will be busy until either all trust items are received
4083 (and @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}), or
4084 @code{gpgme_op_trustlist_end} is called to finish the operation.
4086 The function returns the error code @code{GPG_ERR_INV_VALUE} if
4087 @var{ctx} is not a valid pointer, and passes through any errors that
4088 are reported by the crypto engine support routines.
4091 @deftypefun gpgme_error_t gpgme_op_trustlist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_trust_item_t *@var{r_item}})
4092 The function @code{gpgme_op_trustlist_next} returns the next trust
4093 item in the list created by a previous @code{gpgme_op_trustlist_start}
4094 operation in the context @var{ctx}. The trust item can be destroyed
4095 with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}.
4097 This is the only way to get at @code{gpgme_trust_item_t} objects in
4100 If the last trust item in the list has already been returned,
4101 @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}.
4103 The function returns the error code @code{GPG_ERR_INV_VALUE} if @var{ctx} or
4104 @var{r_item} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if
4105 there is not enough memory for the operation.
4108 @deftypefun gpgme_error_t gpgme_op_trustlist_end (@w{gpgme_ctx_t @var{ctx}})
4109 The function @code{gpgme_op_trustlist_end} ends a pending trust list
4110 operation in the context @var{ctx}.
4112 The function returns the error code @code{GPG_ERR_INV_VALUE} if
4113 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
4114 time during the operation there was not enough memory available.
4118 @node Information About Trust Items
4119 @subsection Information About Trust Items
4120 @cindex trust item, information about
4121 @cindex trust item, attributes
4122 @cindex attributes, of a trust item
4124 The following interfaces are deprecated and only provided for backward
4125 compatibility. Don't use them. They will be removed in a future
4126 version of @acronym{GPGME}.
4128 Trust items have attributes which can be queried using the interfaces
4129 below. The attribute identifiers are shared with those for key
4130 attributes. @xref{Information About Keys}.
4132 @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}})
4133 The function @code{gpgme_trust_item_get_string_attr} returns the value
4134 of the string-representable attribute @var{what} of trust item
4135 @var{item}. The arguments @var{idx} and @var{reserved} are reserved
4136 for later use and should be @code{0} and @code{NULL} respectively.
4138 The string returned is only valid as long as the key is valid.
4140 The function returns @code{0} if an attribute can't be returned as a
4141 string, @var{key} is not a valid pointer, @var{idx} out of range,
4142 or @var{reserved} not @code{NULL}.
4145 @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}})
4146 The function @code{gpgme_trust_item_get_int_attr} returns the value of
4147 the number-representable attribute @var{what} of trust item
4148 @var{item}. If the attribute occurs more than once in the trust item,
4149 the index is specified by @var{idx}. However, currently no such
4150 attribute exists, so @var{idx} should be @code{0}. The argument
4151 @var{reserved} is reserved for later use and should be @code{NULL}.
4153 The function returns @code{0} if the attribute can't be returned as a
4154 number, @var{key} is not a valid pointer, @var{idx} out of range,
4155 or @var{reserved} not @code{NULL}.
4159 @node Manipulating Trust Items
4160 @subsection Manipulating Trust Items
4161 @cindex trust item, manipulation
4163 @deftypefun void gpgme_trust_item_ref (@w{gpgme_trust_item_t @var{item}})
4164 The function @code{gpgme_trust_item_ref} acquires an additional
4165 reference for the trust item @var{item}.
4168 @deftypefun void gpgme_trust_item_unref (@w{gpgme_trust_item_t @var{item}})
4169 The function @code{gpgme_trust_item_unref} releases a reference for
4170 the trust item @var{item}. If this was the last reference, the trust
4171 item will be destroyed and all resources associated to it will be
4176 The following interface is deprecated and only provided for backward
4177 compatibility. Don't use it. It will be removed in a future version
4180 @deftypefun void gpgme_trust_item_release (@w{gpgme_trust_item_t @var{item}})
4181 The function @code{gpgme_trust_item_release} is an alias for
4182 @code{gpgme_trust_item_unref}.
4186 @node Crypto Operations
4187 @section Crypto Operations
4188 @cindex cryptographic operation
4190 Sometimes, the result of a crypto operation returns a list of invalid
4191 keys encountered in processing the request. The following structure
4192 is used to hold information about such a key.
4194 @deftp {Data type} {gpgme_invalid_key_t}
4195 This is a pointer to a structure used to store a part of the result of
4196 a crypto operation which takes user IDs as one input parameter. The
4197 structure contains the following members:
4200 @item gpgme_invalid_key_t next
4201 This is a pointer to the next invalid key structure in the linked
4202 list, or @code{NULL} if this is the last element.
4205 The fingerprint or key ID of the invalid key encountered.
4207 @item gpgme_error_t reason
4208 An error code describing the reason why the key was found invalid.
4214 * Decrypt:: Decrypting a ciphertext.
4215 * Verify:: Verifying a signature.
4216 * Decrypt and Verify:: Decrypting a signed ciphertext.
4217 * Sign:: Creating a signature.
4218 * Encrypt:: Encrypting a plaintext.
4225 @cindex cryptographic operation, decryption
4227 @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}})
4228 The function @code{gpgme_op_decrypt} decrypts the ciphertext in the
4229 data object @var{cipher} and stores it into the data object
4232 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4233 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
4234 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
4235 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
4236 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
4237 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
4238 secret key could not be retrieved, and passes through any errors that
4239 are reported by the crypto engine support routines.
4242 @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}})
4243 The function @code{gpgme_op_decrypt_start} initiates a
4244 @code{gpgme_op_decrypt} operation. It can be completed by calling
4245 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4247 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4248 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
4249 if @var{cipher} or @var{plain} is not a valid pointer.
4252 @deftp {Data type} {gpgme_recipient_t}
4253 This is a pointer to a structure used to store information about the
4254 recipient of an encrypted text which is decrypted in a
4255 @code{gpgme_op_decrypt} operation. This information (except for the
4256 status field) is even available before the operation finished
4257 successfully, for example in a passphrase callback. The structure
4258 contains the following members:
4261 @item gpgme_recipient_t next
4262 This is a pointer to the next recipient structure in the linked list,
4263 or @code{NULL} if this is the last element.
4265 @item gpgme_pubkey_algo_t
4266 The public key algorithm used in the encryption.
4269 This is the key ID of the key (in hexadecimal digits) used as
4272 @item gpgme_error_t status
4273 This is an error number with the error code GPG_ERR_NO_SECKEY if the
4274 secret key for this recipient is not available, and 0 otherwise.
4278 @deftp {Data type} {gpgme_decrypt_result_t}
4279 This is a pointer to a structure used to store the result of a
4280 @code{gpgme_op_decrypt} operation. After successfully decrypting
4281 data, you can retrieve the pointer to the result with
4282 @code{gpgme_op_decrypt_result}. The structure contains the following
4286 @item char *unsupported_algorithm
4287 If an unsupported algorithm was encountered, this string describes the
4288 algorithm that is not supported.
4290 @item unsigned int wrong_key_usage : 1
4291 This is true if the key was not used according to its policy.
4293 @item gpgme_recipient_t recipients
4294 This is a linked list of recipients to which this message was encrypted.
4296 @item char *file_name
4297 This is the filename of the original plaintext message file if it is
4298 known, otherwise this is a null pointer.
4302 @deftypefun gpgme_decrypt_result_t gpgme_op_decrypt_result (@w{gpgme_ctx_t @var{ctx}})
4303 The function @code{gpgme_op_decrypt_result} returns a
4304 @code{gpgme_decrypt_result_t} pointer to a structure holding the
4305 result of a @code{gpgme_op_decrypt} operation. The pointer is only
4306 valid if the last operation on the context was a
4307 @code{gpgme_op_decrypt} or @code{gpgme_op_decrypt_start} operation.
4308 If the operation failed this might be a @code{NULL} pointer. The
4309 returned pointer is only valid until the next operation is started on
4316 @cindex verification
4317 @cindex signature, verification
4318 @cindex cryptographic operation, verification
4319 @cindex cryptographic operation, signature check
4320 @cindex signature notation data
4321 @cindex notation data
4323 @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}})
4324 The function @code{gpgme_op_verify} verifies that the signature in the
4325 data object @var{sig} is a valid signature. If @var{sig} is a
4326 detached signature, then the signed text should be provided in
4327 @var{signed_text} and @var{plain} should be a null pointer.
4328 Otherwise, if @var{sig} is a normal (or cleartext) signature,
4329 @var{signed_text} should be a null pointer and @var{plain} should be a
4330 writable data object that will contain the plaintext after successful
4333 The results of the individual signature verifications can be retrieved
4334 with @code{gpgme_op_verify_result}.
4336 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4337 operation could be completed successfully, @code{GPG_ERR_INV_VALUE} if
4338 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer,
4339 @code{GPG_ERR_NO_DATA} if @var{sig} does not contain any data to
4340 verify, and passes through any errors that are reported by the crypto
4341 engine support routines.
4344 @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}})
4345 The function @code{gpgme_op_verify_start} initiates a
4346 @code{gpgme_op_verify} operation. It can be completed by calling
4347 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4349 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4350 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
4351 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer, and
4352 @code{GPG_ERR_NO_DATA} if @var{sig} or @var{plain} does not contain