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 * Offline Mode:: Choosing offline mode.
193 * Included Certificates:: Including a number of certificates.
194 * Key Listing Mode:: Selecting key listing mode.
195 * Passphrase Callback:: Getting the passphrase from the user.
196 * Progress Meter Callback:: Being informed about the progress.
197 * Status Message Callback:: Status messages received from gpg.
198 * Locale:: Setting the locale of a context.
202 * Listing Keys:: Browsing the list of available keys.
203 * Information About Keys:: Requesting detailed information about keys.
204 * Key Signatures:: Listing the signatures on a key.
205 * Manipulating Keys:: Operations on keys.
206 * Generating Keys:: Creating new key pairs.
207 * Exporting Keys:: Retrieving key data from the key ring.
208 * Importing Keys:: Adding keys to the key ring.
209 * Deleting Keys:: Removing keys from the key ring.
210 * Changing Passphrases:: Change the passphrase of a key.
211 * Advanced Key Editing:: Advanced key edit operation.
213 Trust Item Management
215 * Listing Trust Items:: Browsing the list of available trust items.
216 * Information About Trust Items:: Requesting information about trust items.
217 * Manipulating Trust Items:: Operations on trust items.
221 * Decrypt:: Decrypting a ciphertext.
222 * Verify:: Verifying a signature.
223 * Decrypt and Verify:: Decrypting a signed ciphertext.
224 * Sign:: Creating a signature.
225 * Encrypt:: Encrypting a plaintext.
229 * Selecting Signers:: How to choose the keys to sign with.
230 * Creating a Signature:: How to create a signature.
231 * Signature Notation Data:: How to add notation data to a signature.
235 * Encrypting a Plaintext:: How to encrypt a plaintext.
239 * Running other Programs:: Running other Programs
243 * Waiting For Completion:: Waiting until an operation is completed.
244 * Using External Event Loops:: Advanced control over what happens when.
245 * Cancellation:: How to end pending operations prematurely.
247 Using External Event Loops
249 * I/O Callback Interface:: How I/O callbacks are registered.
250 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
251 * I/O Callback Example:: An example how to use I/O callbacks.
252 * I/O Callback Example GTK+:: How to integrate @acronym{GPGME} in GTK+.
253 * I/O Callback Example GDK:: How to integrate @acronym{GPGME} in GDK.
254 * I/O Callback Example Qt:: How to integrate @acronym{GPGME} in Qt.
260 @chapter Introduction
262 `GnuPG Made Easy' (@acronym{GPGME}) is a C language library that
263 allows to add support for cryptography to a program. It is designed
264 to make access to public key crypto engines like GnuPG or GpgSM easier
265 for applications. @acronym{GPGME} provides a high-level crypto API
266 for encryption, decryption, signing, signature verification and key
269 @acronym{GPGME} uses GnuPG and GpgSM as its backends to support
270 OpenPGP and the Cryptographic Message Syntax (CMS).
273 * Getting Started:: Purpose of the manual, and how to use it.
274 * Features:: Reasons to install and use @acronym{GPGME}.
275 * Overview:: Basic architecture of the @acronym{GPGME} library.
279 @node Getting Started
280 @section Getting Started
282 This manual documents the @acronym{GPGME} library programming
283 interface. All functions and data types provided by the library are
286 The reader is assumed to possess basic knowledge about cryptography in
287 general, and public key cryptography in particular. The underlying
288 cryptographic engines that are used by the library are not explained,
289 but where necessary, special features or requirements by an engine are
290 mentioned as far as they are relevant to @acronym{GPGME} or its users.
292 This manual can be used in several ways. If read from the beginning
293 to the end, it gives a good introduction into the library and how it
294 can be used in an application. Forward references are included where
295 necessary. Later on, the manual can be used as a reference manual to
296 get just the information needed about any particular interface of the
297 library. Experienced programmers might want to start looking at the
298 examples at the end of the manual, and then only read up those parts
299 of the interface which are unclear.
305 @acronym{GPGME} has a couple of advantages over other libraries doing
306 a similar job, and over implementing support for GnuPG or other crypto
307 engines into your application directly.
310 @item it's free software
311 Anybody can use, modify, and redistribute it under the terms of the GNU
312 Lesser General Public License (@pxref{Library Copying}).
315 @acronym{GPGME} provides transparent support for several cryptographic
316 protocols by different engines. Currently, @acronym{GPGME} supports
317 the OpenPGP protocol using GnuPG as the backend, and the Cryptographic
318 Message Syntax using GpgSM as the backend.
321 @acronym{GPGME} hides the differences between the protocols and
322 engines from the programmer behind an easy-to-use interface. This way
323 the programmer can focus on the other parts of the program, and still
324 integrate strong cryptography in his application. Once support for
325 @acronym{GPGME} has been added to a program, it is easy to add support
326 for other crypto protocols once @acronym{GPGME} backends provide them.
333 @acronym{GPGME} provides a data abstraction that is used to pass data
334 to the crypto engine, and receive returned data from it. Data can be
335 read from memory or from files, but it can also be provided by a
338 The actual cryptographic operations are always set within a context.
339 A context provides configuration parameters that define the behaviour
340 of all operations performed within it. Only one operation per context
341 is allowed at any time, but when one operation is finished, you can
342 run the next operation in the same context. There can be more than
343 one context, and all can run different operations at the same time.
345 Furthermore, @acronym{GPGME} has rich key management facilities
346 including listing keys, querying their attributes, generating,
347 importing, exporting and deleting keys, and acquiring information
348 about the trust path.
350 With some precautions, @acronym{GPGME} can be used in a multi-threaded
351 environment, although it is not completely thread safe and thus needs
352 the support of the application.
358 To use @acronym{GPGME}, you have to perform some changes to your
359 sources and the build system. The necessary changes are small and
360 explained in the following sections. At the end of this chapter, it
361 is described how the library is initialized, and how the requirements
362 of the library are verified.
365 * Header:: What header file you need to include.
366 * Building the Source:: Compiler options to be used.
367 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
368 * Using Automake:: Compiler options to be used the easy way.
369 * Using Libtool:: Avoiding compiler options entirely.
370 * Library Version Check:: Getting and verifying the library version.
371 * Signal Handling:: How @acronym{GPGME} affects signal handling.
372 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
381 All interfaces (data types and functions) of the library are defined
382 in the header file `gpgme.h'. You must include this in all programs
383 using the library, either directly or through some other header file,
390 The name space of @acronym{GPGME} is @code{gpgme_*} for function names
391 and data types and @code{GPGME_*} for other symbols. Symbols internal
392 to @acronym{GPGME} take the form @code{_gpgme_*} and @code{_GPGME_*}.
394 Because @acronym{GPGME} makes use of the GPG Error library, using
395 @acronym{GPGME} will also use the @code{GPG_ERR_*} name space
396 directly, and the @code{gpg_err*}, @code{gpg_str*}, and @code{gpgrt_*}
397 name space indirectly.
400 @node Building the Source
401 @section Building the Source
402 @cindex compiler options
403 @cindex compiler flags
405 If you want to compile a source file including the `gpgme.h' header
406 file, you must make sure that the compiler can find it in the
407 directory hierarchy. This is accomplished by adding the path to the
408 directory in which the header file is located to the compilers include
409 file search path (via the @option{-I} option).
411 However, the path to the include file is determined at the time the
412 source is configured. To solve this problem, gpgme ships with a small
413 helper program @command{gpgme-config} that knows about the path to the
414 include file and other configuration options. The options that need
415 to be added to the compiler invocation at compile time are output by
416 the @option{--cflags} option to @command{gpgme-config}. The following
417 example shows how it can be used at the command line:
420 gcc -c foo.c `gpgme-config --cflags`
423 Adding the output of @samp{gpgme-config --cflags} to the compiler
424 command line will ensure that the compiler can find the
425 @acronym{GPGME} header file.
427 A similar problem occurs when linking the program with the library.
428 Again, the compiler has to find the library files. For this to work,
429 the path to the library files has to be added to the library search
430 path (via the @option{-L} option). For this, the option
431 @option{--libs} to @command{gpgme-config} can be used. For
432 convenience, this option also outputs all other options that are
433 required to link the program with @acronym{GPGME} (in particular, the
434 @samp{-lgpgme} option). The example shows how to link @file{foo.o}
435 with the @acronym{GPGME} library to a program @command{foo}.
438 gcc -o foo foo.o `gpgme-config --libs`
441 Of course you can also combine both examples to a single command by
442 specifying both options to @command{gpgme-config}:
445 gcc -o foo foo.c `gpgme-config --cflags --libs`
448 If you want to link to one of the thread-safe versions of
449 @acronym{GPGME}, you must specify the @option{--thread} option before
450 any other option to select the thread package you want to link with.
451 Supported thread packages are @option{--thread=pth} and
452 @option{--thread=pthread}.
455 @node Largefile Support (LFS)
456 @section Largefile Support (LFS)
457 @cindex largefile support
460 @acronym{GPGME} is compiled with largefile support by default, if it
461 is available on the system. This means that GPGME supports files
462 larger than two gigabyte in size, if the underlying operating system
463 can. On some systems, largefile support is already the default. On
464 such systems, nothing special is required. However, some systems
465 provide only support for files up to two gigabyte in size by default.
466 Support for larger file sizes has to be specifically enabled.
468 To make a difficult situation even more complex, such systems provide
469 two different types of largefile support. You can either get all
470 relevant functions replaced with alternatives that are largefile
471 capable, or you can get new functions and data types for largefile
472 support added. Those new functions have the same name as their
473 smallfile counterparts, but with a suffix of 64.
475 An example: The data type @code{off_t} is 32 bit wide on GNU/Linux PC
476 systems. To address offsets in large files, you can either enable
477 largefile support add-on. Then a new data type @code{off64_t} is
478 provided, which is 64 bit wide. Or you can replace the existing
479 @code{off_t} data type with its 64 bit wide counterpart. All
480 occurences of @code{off_t} are then automagically replaced.
482 As if matters were not complex enough, there are also two different
483 types of file descriptors in such systems. This is important because
484 if file descriptors are exchanged between programs that use a
485 different maximum file size, certain errors must be produced on some
486 file descriptors to prevent subtle overflow bugs from occuring.
488 As you can see, supporting two different maximum file sizes at the
489 same time is not at all an easy task. However, the maximum file size
490 does matter for @acronym{GPGME}, because some data types it uses in
491 its interfaces are affected by that. For example, the @code{off_t}
492 data type is used in the @code{gpgme_data_seek} function, to match its
493 @acronym{POSIX} counterpart. This affects the call-frame of the
494 function, and thus the ABI of the library. Furthermore, file
495 descriptors can be exchanged between GPGME and the application.
497 For you as the user of the library, this means that your program must
498 be compiled in the same file size mode as the library. Luckily, there
499 is absolutely no valid reason for new programs to not enable largefile
500 support by default and just use that. The compatibility modes (small
501 file sizes or dual mode) can be considered an historic artefact, only
502 useful to allow for a transitional period.
504 On POSIX platforms @acronym{GPGME} is compiled using largefile support
505 by default. This means that your application must do the same, at
506 least as far as it is relevant for using the @file{gpgme.h} header
507 file. All types in this header files refer to their largefile
508 counterparts, if they are different from any default types on the
511 On 32 and 64 bit Windows platforms @code{off_t} is declared as 32 bit
512 signed integer. There is no specific support for LFS in the C
513 library. The recommendation from Microsoft is to use the native
514 interface (@code{CreateFile} et al.) for large files. Released binary
515 versions of @acronym{GPGME} (libgpgme-11.dll) have always been build
516 with a 32 bit @code{off_t}. To avoid an ABI break we stick to this
517 convention for 32 bit Windows by using @code{long} there.
518 @acronym{GPGME} versions for 64 bit Windows have never been released
519 and thus we are able to use @code{int64_t} instead of @code{off_t}
520 there. For easier migration the typedef @code{gpgme_off_t} has been
521 defined. The reason we cannot use @code{off_t} directly is that some
522 toolchains (e.g. mingw64) introduce a POSIX compatible hack for
523 @code{off_t}. Some widely used toolkits make use of this hack and in
524 turn @acronym{GPGME} would need to use it also. However, this would
525 introduce an ABI break and existing software making use of libgpgme
526 might suffer from a severe break. Thus with version 1.4.2 we
527 redefined all functions using @code{off_t} to use @code{gpgme_off_t}
528 which is defined as explained above. This way we keep the ABI well
529 defined and independent of any toolchain hacks. The bottom line is
530 that LFS support in @acronym{GPGME} is only available on 64 bit
533 On POSIX platforms you can enable largefile support, if it is
534 different from the default on the system the application is compiled
535 on, by using the Autoconf macro @code{AC_SYS_LARGEFILE}. If you do
536 this, then you don't need to worry about anything else: It will just
537 work. In this case you might also want to use @code{AC_FUNC_FSEEKO}
538 to take advantage of some new interfaces, and @code{AC_TYPE_OFF_T}
541 If you do not use Autoconf, you can define the preprocessor symbol
542 @code{_FILE_OFFSET_BITS} to 64 @emph{before} including any header
543 files, for example by specifying the option
544 @code{-D_FILE_OFFSET_BITS=64} on the compiler command line. You will
545 also want to define the preprocessor symbol @code{LARGEFILE_SOURCE} to
546 1 in this case, to take advantage of some new interfaces.
548 If you do not want to do either of the above, you probably know enough
549 about the issue to invent your own solution. Just keep in mind that
550 the @acronym{GPGME} header file expects that largefile support is
551 enabled, if it is available. In particular, we do not support dual
552 mode (@code{_LARGEFILE64_SOURCE}).
556 @section Using Automake
560 It is much easier if you use GNU Automake instead of writing your own
561 Makefiles. If you do that you do not have to worry about finding and
562 invoking the @command{gpgme-config} script at all. @acronym{GPGME}
563 provides an extension to Automake that does all the work for you.
565 @c A simple macro for optional variables.
567 @r{[}@var{\varname\}@r{]}
569 @defmac AM_PATH_GPGME (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
570 @defmacx AM_PATH_GPGME_PTH (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
571 @defmacx AM_PATH_GPGME_PTHREAD (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
572 Check whether @acronym{GPGME} (at least version @var{minimum-version},
573 if given) exists on the host system. If it is found, execute
574 @var{action-if-found}, otherwise do @var{action-if-not-found}, if
577 Additionally, the function defines @code{GPGME_CFLAGS} to the flags
578 needed for compilation of the program to find the @file{gpgme.h}
579 header file, and @code{GPGME_LIBS} to the linker flags needed to link
580 the program to the @acronym{GPGME} library. If the used helper script
581 does not match the target type you are building for a warning is
582 printed and the string @code{libgcrypt} is appended to the variable
583 @code{gpg_config_script_warn}.
585 @code{AM_PATH_GPGME_PTH} checks for the version of @acronym{GPGME}
586 that can be used with GNU Pth, and defines @code{GPGME_PTH_CFLAGS} and
587 @code{GPGME_PTH_LIBS}.
589 @code{AM_PATH_GPGME_PTHREAD} checks for the version of @acronym{GPGME}
590 that can be used with the native pthread implementation, and defines
591 @code{GPGME_PTHREAD_CFLAGS} and @code{GPGME_PTHREAD_LIBS}.
593 This macro searches for @command{gpgme-config} along the PATH. If
594 you are cross-compiling, it is useful to set the environment variable
595 @code{SYSROOT} to the top directory of your target. The macro will
596 then first look for the helper program in the @file{bin} directory
597 below that top directory. An absolute directory name must be used for
598 @code{SYSROOT}. Finally, if the configure command line option
599 @code{--with-gpgme-prefix} is used, only its value is used for the top
600 directory below which the helper script is expected.
604 You can use the defined Autoconf variables like this in your
608 AM_CPPFLAGS = $(GPGME_CFLAGS)
609 LDADD = $(GPGME_LIBS)
614 @section Using Libtool
617 The easiest way is to just use GNU Libtool. If you use libtool, and
618 link to @code{libgpgme.la}, @code{libgpgme-pth.la} or
619 @code{libgpgme-pthread.la} respectively, everything will be done
620 automatically by Libtool.
623 @node Library Version Check
624 @section Library Version Check
625 @cindex version check, of the library
627 @deftypefun {const char *} gpgme_check_version (@w{const char *@var{required_version}})
628 The function @code{gpgme_check_version} has four purposes. It can be
629 used to retrieve the version number of the library. In addition it
630 can verify that the version number is higher than a certain required
631 version number. In either case, the function initializes some
632 sub-systems, and for this reason alone it must be invoked early in
633 your program, before you make use of the other functions in
634 @acronym{GPGME}. The last purpose is to run selftests.
636 As a side effect for W32 based systems, the socket layer will get
640 If @var{required_version} is @code{NULL}, the function returns a
641 pointer to a statically allocated string containing the version number
644 If @var{required_version} is not @code{NULL}, it should point to a
645 string containing a version number, and the function checks that the
646 version of the library is at least as high as the version number
647 provided. In this case, the function returns a pointer to a
648 statically allocated string containing the version number of the
649 library. If @var{REQUIRED_VERSION} is not a valid version number, or
650 if the version requirement is not met, the function returns
653 If you use a version of a library that is backwards compatible with
654 older releases, but contains additional interfaces which your program
655 uses, this function provides a run-time check if the necessary
656 features are provided by the installed version of the library.
658 If a selftest fails, the function may still succeed. Selftest errors
659 are returned later when invoking @code{gpgme_new}, so that a detailed
660 error code can be returned (historically, @code{gpgme_check_version}
661 does not return a detailed error code).
665 @deftypefun {int} gpgme_set_global_flag @
666 (@w{const char *@var{name}}, @
667 @w{const char *@var{value}})
669 On some systems it is not easy to set environment variables and thus
670 hard to use @acronym{GPGME}'s internal trace facility for debugging.
671 This function has been introduced as an alternative way to enable
672 debugging and for a couple of other rarely used tweaks. It is
673 important to assure that only one thread accesses @acronym{GPGME}
674 functions between a call to this function and after the return from
675 the call to @code{gpgme_check_version}.
677 All currently supported features require that this function is called
678 as early as possible --- even before @code{gpgme_check_version}. The
679 features are identified by the following values for @var{name}:
683 To enable debugging use the string ``debug'' for @var{name} and
684 @var{value} identical to the value used with the environment variable
687 @item "disable-gpgconf"
688 Using this feature with any @var{value} disables the detection of the
689 gpgconf program and thus forces GPGME to fallback into the simple
690 OpenPGP only mode. It may be used to force the use of GnuPG-1 on
691 systems which have both GPG versions installed. Note that in general
692 the use of @code{gpgme_set_engine_info} is a better way to select a
693 specific engine version.
697 Set the name of the gpgconf respective gpg binary. The defaults are
698 @code{GNU/GnuPG/gpgconf} and @code{GNU/GnuPG/gpg}. Under Unix the
699 leading directory part is ignored. Under Windows the leading
700 directory part is used as the default installation directory; the
701 @code{.exe} suffix is added by GPGME. Use forward slashed even under
706 This function returns @code{0} on success. In contrast to other
707 functions the non-zero return value on failure does not convey any
708 error code. For setting ``debug'' the only possible error cause is an
709 out of memory condition; which would exhibit itself later anyway.
710 Thus the return value may be ignored.
714 After initializing @acronym{GPGME}, you should set the locale
715 information to the locale required for your output terminal. This
716 locale information is needed for example for the curses and Gtk
717 pinentry. Here is an example of a complete initialization:
726 /* Initialize the locale environment. */
727 setlocale (LC_ALL, "");
728 gpgme_check_version (NULL);
729 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
731 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
736 Note that you are highly recommended to initialize the locale settings
737 like this. @acronym{GPGME} can not do this for you because it would
738 not be thread safe. The conditional on LC_MESSAGES is only necessary
739 for portability to W32 systems.
742 @node Signal Handling
743 @section Signal Handling
745 @cindex signal handling
747 The @acronym{GPGME} library communicates with child processes (the
748 crypto engines). If a child process dies unexpectedly, for example
749 due to a bug, or system problem, a @code{SIGPIPE} signal will be
750 delivered to the application. The default action is to abort the
751 program. To protect against this, @code{gpgme_check_version} sets the
752 @code{SIGPIPE} signal action to @code{SIG_IGN}, which means that the
753 signal will be ignored.
755 @acronym{GPGME} will only do that if the signal action for
756 @code{SIGPIPE} is @code{SIG_DEF} at the time
757 @code{gpgme_check_version} is called. If it is something different,
758 @code{GPGME} will take no action.
760 This means that if your application does not install any signal
761 handler for @code{SIGPIPE}, you don't need to take any precautions.
762 If you do install a signal handler for @code{SIGPIPE}, you must be
763 prepared to handle any @code{SIGPIPE} events that occur due to
764 @acronym{GPGME} writing to a defunct pipe. Furthermore, if your
765 application is multi-threaded, and you install a signal action for
766 @code{SIGPIPE}, you must make sure you do this either before
767 @code{gpgme_check_version} is called or afterwards.
770 @node Multi Threading
771 @section Multi Threading
772 @cindex thread-safeness
773 @cindex multi-threading
775 The @acronym{GPGME} library is not entirely thread-safe, but it can
776 still be used in a multi-threaded environment if some care is taken.
777 If the following requirements are met, there should be no race
778 conditions to worry about:
782 @acronym{GPGME} supports the thread libraries pthread and GNU Pth.
783 The support for this has to be enabled at compile time.
784 @acronym{GPGME} will automatically detect the location in which the
785 thread libraries are installed and activate the support for them at
788 Support for other thread libraries is very easy to add. Please
789 contact us if you have the need.
792 If you want to use @acronym{GPGME} with threads, you must link to the
793 right version of the library. The name of the right library is
794 @code{libgpgme-} followed by the name of the thread package you use.
795 For example, if you use GNU Pth, the right name is
796 @code{libgpgme-pth}. Use the Automake macros or
797 @command{gpgme-config} program for simplicity.
801 The function @code{gpgme_check_version} must be called before any
802 other function in the library, because it initializes the thread
803 support subsystem in @acronym{GPGME}. To achieve this in
804 multi-threaded programs, you must synchronize the memory with respect
805 to other threads that also want to use @acronym{GPGME}. For this, it
806 is sufficient to call @code{gpgme_check_version} before creating the
807 other threads using @acronym{GPGME}@footnote{At least this is true for
808 POSIX threads, as @code{pthread_create} is a function that
809 synchronizes memory with respects to other threads. There are many
810 functions which have this property, a complete list can be found in
811 POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the
812 definition of the term ``Memory Synchronization''. For other thread
813 packages other, more relaxed or more strict rules may apply.}.
816 Any @code{gpgme_data_t} and @code{gpgme_ctx_t} object must only be
817 accessed by one thread at a time. If multiple threads want to deal
818 with the same object, the caller has to make sure that operations on
819 that object are fully synchronized.
822 Only one thread at any time is allowed to call @code{gpgme_wait}. If
823 multiple threads call this function, the caller must make sure that
824 all invocations are fully synchronized. It is safe to start
825 asynchronous operations while a thread is running in gpgme_wait.
828 The function @code{gpgme_strerror} is not thread safe. You have to
829 use @code{gpgme_strerror_r} instead.
833 @node Protocols and Engines
834 @chapter Protocols and Engines
837 @cindex crypto engine
839 @cindex crypto backend
841 @acronym{GPGME} supports several cryptographic protocols, however, it
842 does not implement them. Rather it uses backends (also called
843 engines) which implement the protocol. @acronym{GPGME} uses
844 inter-process communication to pass data back and forth between the
845 application and the backend, but the details of the communication
846 protocol and invocation of the backend is completely hidden by the
847 interface. All complexity is handled by @acronym{GPGME}. Where an
848 exchange of information between the application and the backend is
849 necessary, @acronym{GPGME} provides the necessary callback function
850 hooks and further interfaces.
852 @deftp {Data type} {enum gpgme_protocol_t}
853 @tindex gpgme_protocol_t
854 The @code{gpgme_protocol_t} type specifies the set of possible protocol
855 values that are supported by @acronym{GPGME}. The following protocols
859 @item GPGME_PROTOCOL_OpenPGP
860 This specifies the OpenPGP protocol.
862 @item GPGME_PROTOCOL_CMS
863 This specifies the Cryptographic Message Syntax.
865 @item GPGME_PROTOCOL_ASSUAN
866 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
868 @item GPGME_PROTOCOL_G13
869 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
871 @item GPGME_PROTOCOL_UISERVER
872 Under development. Please ask on @email{gnupg-devel@@gnupg.org} for help.
874 @item GPGME_PROTOCOL_SPAWN
875 Special protocol for use with @code{gpgme_op_spawn}.
877 @item GPGME_PROTOCOL_UNKNOWN
878 Reserved for future extension. You may use this to indicate that the
879 used protocol is not known to the application. Currently,
880 @acronym{GPGME} does not accept this value in any operation, though,
881 except for @code{gpgme_get_protocol_name}.
886 @deftypefun {const char *} gpgme_get_protocol_name (@w{gpgme_protocol_t @var{protocol}})
887 The function @code{gpgme_get_protocol_name} returns a statically
888 allocated string describing the protocol @var{protocol}, or
889 @code{NULL} if the protocol number is not valid.
893 * Engine Version Check:: Verifying the engine version.
894 * Engine Information:: Obtaining more information about the engines.
895 * Engine Configuration:: Changing the engine configuration.
896 * OpenPGP:: Support for the OpenPGP protocol.
897 * Cryptographic Message Syntax:: Support for the CMS.
901 @node Engine Version Check
902 @section Engine Version Check
903 @cindex version check, of the engines
905 @deftypefun @w{const char *} gpgme_get_dirinfo (@w{cons char *@var{what}})
906 The function @code{gpgme_get_dirinfo} returns a statically allocated
907 string with the value associated to @var{what}. The returned values
908 are the defaults and won't change even after
909 @code{gpgme_set_engine_info} has been used to configure a different
910 engine. @code{NULL} is returned if no value is available. Commonly
911 supported values for @var{what} are:
915 Return the default home directory.
918 Return the name of the socket to connect to the gpg-agent.
920 @item uiserver-socket
921 Return the name of the socket to connect to the user interface server.
924 Return the file name of the engine configuration tool.
927 Return the file name of the OpenPGP engine.
930 Return the file name of the CMS engine.
933 Return the name of the file container encryption engine.
940 @deftypefun gpgme_error_t gpgme_engine_check_version (@w{gpgme_protocol_t @var{protocol}})
941 The function @code{gpgme_engine_check_version} verifies that the
942 engine implementing the protocol @var{PROTOCOL} is installed in the
943 expected path and meets the version requirement of @acronym{GPGME}.
945 This function returns the error code @code{GPG_ERR_NO_ERROR} if the
946 engine is available and @code{GPG_ERR_INV_ENGINE} if it is not.
950 @node Engine Information
951 @section Engine Information
952 @cindex engine, information about
954 @deftp {Data type} {gpgme_engine_info_t}
955 @tindex gpgme_protocol_t
956 The @code{gpgme_engine_info_t} type specifies a pointer to a structure
957 describing a crypto engine. The structure contains the following
961 @item gpgme_engine_info_t next
962 This is a pointer to the next engine info structure in the linked
963 list, or @code{NULL} if this is the last element.
965 @item gpgme_protocol_t protocol
966 This is the protocol for which the crypto engine is used. You can
967 convert this to a string with @code{gpgme_get_protocol_name} for
970 @item const char *file_name
971 This is a string holding the file name of the executable of the crypto
972 engine. Currently, it is never @code{NULL}, but using @code{NULL} is
973 reserved for future use, so always check before you use it.
975 @item const char *home_dir
976 This is a string holding the directory name of the crypto engine's
977 configuration directory. If it is @code{NULL}, then the default
978 directory is used. See @code{gpgme_get_dirinfo} on how to get the
981 @item const char *version
982 This is a string containing the version number of the crypto engine.
983 It might be @code{NULL} if the version number can not be determined,
984 for example because the executable doesn't exist or is invalid.
986 @item const char *req_version
987 This is a string containing the minimum required version number of the
988 crypto engine for @acronym{GPGME} to work correctly. This is the
989 version number that @code{gpgme_engine_check_version} verifies
990 against. Currently, it is never @code{NULL}, but using @code{NULL} is
991 reserved for future use, so always check before you use it.
995 @deftypefun gpgme_error_t gpgme_get_engine_info (@w{gpgme_engine_info_t *@var{info}})
996 The function @code{gpgme_get_engine_info} returns a linked list of
997 engine info structures in @var{info}. Each info structure describes
998 the defaults of one configured backend.
1000 The memory for the info structures is allocated the first time this
1001 function is invoked, and must not be freed by the caller.
1003 This function returns the error code @code{GPG_ERR_NO_ERROR} if
1004 successful, and a system error if the memory could not be allocated.
1007 Here is an example how you can provide more diagnostics if you receive
1008 an error message which indicates that the crypto engine is invalid.
1016 if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
1018 gpgme_engine_info_t info;
1019 err = gpgme_get_engine_info (&info);
1022 while (info && info->protocol != gpgme_get_protocol (ctx))
1025 fprintf (stderr, "GPGME compiled without support for protocol %s",
1026 gpgme_get_protocol_name (info->protocol));
1027 else if (info->file_name && !info->version)
1028 fprintf (stderr, "Engine %s not installed properly",
1030 else if (info->file_name && info->version && info->req_version)
1031 fprintf (stderr, "Engine %s version %s installed, "
1032 "but at least version %s required", info->file_name,
1033 info->version, info->req_version);
1035 fprintf (stderr, "Unknown problem with engine for protocol %s",
1036 gpgme_get_protocol_name (info->protocol));
1042 @node Engine Configuration
1043 @section Engine Configuration
1044 @cindex engine, configuration of
1045 @cindex configuration of crypto backend
1047 You can change the configuration of a backend engine, and thus change
1048 the executable program and configuration directory to be used. You
1049 can make these changes the default or set them for some contexts
1052 @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}})
1053 The function @code{gpgme_set_engine_info} changes the default
1054 configuration of the crypto engine implementing the protocol
1057 @var{file_name} is the file name of the executable program
1058 implementing this protocol, and @var{home_dir} is the directory name
1059 of the configuration directory for this crypto engine. If
1060 @var{home_dir} is @code{NULL}, the engine's default will be used.
1062 The new defaults are not applied to already created GPGME contexts.
1064 This function returns the error code @code{GPG_ERR_NO_ERROR} if
1065 successful, or an eror code on failure.
1068 The functions @code{gpgme_ctx_get_engine_info} and
1069 @code{gpgme_ctx_set_engine_info} can be used to change the engine
1070 configuration per context. @xref{Crypto Engine}.
1077 @cindex protocol, GnuPG
1078 @cindex engine, GnuPG
1080 OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard.
1081 This is the first protocol that was supported by @acronym{GPGME}.
1083 The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}.
1086 @node Cryptographic Message Syntax
1087 @section Cryptographic Message Syntax
1089 @cindex cryptographic message syntax
1091 @cindex protocol, CMS
1092 @cindex engine, GpgSM
1094 @cindex protocol, S/MIME
1096 @acronym{CMS} is implemented by GpgSM, the S/MIME implementation for
1099 The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}.
1106 The crypto backends support a variety of algorithms used in public key
1107 cryptography.@footnote{Some engines also provide symmetric only
1108 encryption; see the description of the encryption function on how to use
1109 this.} The following sections list the identifiers used to denote such
1113 * Public Key Algorithms:: A list of all public key algorithms.
1114 * Hash Algorithms:: A list of all hash algorithms.
1118 @node Public Key Algorithms
1119 @section Public Key Algorithms
1120 @cindex algorithms, public key
1121 @cindex public key algorithms
1123 Public key algorithms are used for encryption, decryption, signing and
1124 verification of signatures.
1126 @deftp {Data type} {enum gpgme_pubkey_algo_t}
1127 @tindex gpgme_pubkey_algo_t
1128 The @code{gpgme_pubkey_algo_t} type specifies the set of all public key
1129 algorithms that are supported by @acronym{GPGME}. Possible values
1134 This value indicates the RSA (Rivest, Shamir, Adleman) algorithm.
1136 @item GPGME_PK_RSA_E
1137 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
1138 algorithm for encryption and decryption only.
1140 @item GPGME_PK_RSA_S
1141 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
1142 algorithm for signing and verification only.
1145 This value indicates DSA, the Digital Signature Algorithm.
1148 This value indicates ElGamal.
1150 @item GPGME_PK_ELG_E
1151 This value also indicates ElGamal and is used specifically in GnuPG.
1154 This value is a generic indicator for ellipic curve algorithms.
1156 @item GPGME_PK_ECDSA
1157 This value indicates ECDSA, the Elliptic Curve Digital Signature
1158 Algorithm as defined by FIPS 186-2 and RFC-6637.
1161 This value indicates ECDH, the Eliptic Curve Diffie-Hellmann
1162 encryption algorithm as defined by RFC-6637.
1167 @deftypefun {const char *} gpgme_pubkey_algo_name (@w{gpgme_pubkey_algo_t @var{algo}})
1168 The function @code{gpgme_pubkey_algo_name} returns a pointer to a
1169 statically allocated string containing a description of the public key
1170 algorithm @var{algo}. This string can be used to output the name of
1171 the public key algorithm to the user.
1173 If @var{algo} is not a valid public key algorithm, @code{NULL} is
1178 @node Hash Algorithms
1179 @section Hash Algorithms
1180 @cindex algorithms, hash
1181 @cindex algorithms, message digest
1182 @cindex hash algorithms
1183 @cindex message digest algorithms
1185 Hash (message digest) algorithms are used to compress a long message
1186 to make it suitable for public key cryptography.
1188 @deftp {Data type} {enum gpgme_hash_algo_t}
1189 @tindex gpgme_hash_algo_t
1190 The @code{gpgme_hash_algo_t} type specifies the set of all hash algorithms
1191 that are supported by @acronym{GPGME}. Possible values are:
1196 @item GPGME_MD_RMD160
1198 @item GPGME_MD_TIGER
1199 @item GPGME_MD_HAVAL
1200 @item GPGME_MD_SHA256
1201 @item GPGME_MD_SHA384
1202 @item GPGME_MD_SHA512
1203 @item GPGME_MD_SHA224
1205 @item GPGME_MD_CRC32
1206 @item GPGME_MD_CRC32_RFC1510
1207 @item GPGME_MD_CRC24_RFC2440
1211 @deftypefun {const char *} gpgme_hash_algo_name (@w{gpgme_hash_algo_t @var{algo}})
1212 The function @code{gpgme_hash_algo_name} returns a pointer to a
1213 statically allocated string containing a description of the hash
1214 algorithm @var{algo}. This string can be used to output the name of
1215 the hash algorithm to the user.
1217 If @var{algo} is not a valid hash algorithm, @code{NULL} is returned.
1221 @node Error Handling
1222 @chapter Error Handling
1223 @cindex error handling
1225 Many functions in @acronym{GPGME} can return an error if they fail.
1226 For this reason, the application should always catch the error
1227 condition and take appropriate measures, for example by releasing the
1228 resources and passing the error up to the caller, or by displaying a
1229 descriptive message to the user and cancelling the operation.
1231 Some error values do not indicate a system error or an error in the
1232 operation, but the result of an operation that failed properly. For
1233 example, if you try to decrypt a tempered message, the decryption will
1234 fail. Another error value actually means that the end of a data
1235 buffer or list has been reached. The following descriptions explain
1236 for many error codes what they mean usually. Some error values have
1237 specific meanings if returned by a certain functions. Such cases are
1238 described in the documentation of those functions.
1240 @acronym{GPGME} uses the @code{libgpg-error} library. This allows to
1241 share the error codes with other components of the GnuPG system, and
1242 thus pass error values transparently from the crypto engine, or some
1243 helper application of the crypto engine, to the user. This way no
1244 information is lost. As a consequence, @acronym{GPGME} does not use
1245 its own identifiers for error codes, but uses those provided by
1246 @code{libgpg-error}. They usually start with @code{GPG_ERR_}.
1248 However, @acronym{GPGME} does provide aliases for the functions
1249 defined in libgpg-error, which might be preferred for name space
1253 * Error Values:: The error value and what it means.
1254 * Error Sources:: A list of important error sources.
1255 * Error Codes:: A list of important error codes.
1256 * Error Strings:: How to get a descriptive string from a value.
1261 @section Error Values
1262 @cindex error values
1264 @cindex error sources
1266 @deftp {Data type} {gpgme_err_code_t}
1267 The @code{gpgme_err_code_t} type is an alias for the @code{libgpg-error}
1268 type @code{gpg_err_code_t}. The error code indicates the type of an
1269 error, or the reason why an operation failed.
1271 A list of important error codes can be found in the next section.
1274 @deftp {Data type} {gpgme_err_source_t}
1275 The @code{gpgme_err_source_t} type is an alias for the
1276 @code{libgpg-error} type @code{gpg_err_source_t}. The error source
1277 has not a precisely defined meaning. Sometimes it is the place where
1278 the error happened, sometimes it is the place where an error was
1279 encoded into an error value. Usually the error source will give an
1280 indication to where to look for the problem. This is not always true,
1281 but it is attempted to achieve this goal.
1283 A list of important error sources can be found in the next section.
1286 @deftp {Data type} {gpgme_error_t}
1287 The @code{gpgme_error_t} type is an alias for the @code{libgpg-error}
1288 type @code{gpg_error_t}. An error value like this has always two
1289 components, an error code and an error source. Both together form the
1292 Thus, the error value can not be directly compared against an error
1293 code, but the accessor functions described below must be used.
1294 However, it is guaranteed that only 0 is used to indicate success
1295 (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of
1296 the error value are set to 0, too.
1298 Note that in @acronym{GPGME}, the error source is used purely for
1299 diagnostical purposes. Only the error code should be checked to test
1300 for a certain outcome of a function. The manual only documents the
1301 error code part of an error value. The error source is left
1302 unspecified and might be anything.
1305 @deftypefun {static inline gpgme_err_code_t} gpgme_err_code (@w{gpgme_error_t @var{err}})
1306 The static inline function @code{gpgme_err_code} returns the
1307 @code{gpgme_err_code_t} component of the error value @var{err}. This
1308 function must be used to extract the error code from an error value in
1309 order to compare it with the @code{GPG_ERR_*} error code macros.
1312 @deftypefun {static inline gpgme_err_source_t} gpgme_err_source (@w{gpgme_error_t @var{err}})
1313 The static inline function @code{gpgme_err_source} returns the
1314 @code{gpgme_err_source_t} component of the error value @var{err}. This
1315 function must be used to extract the error source from an error value in
1316 order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros.
1319 @deftypefun {static inline gpgme_error_t} gpgme_err_make (@w{gpgme_err_source_t @var{source}}, @w{gpgme_err_code_t @var{code}})
1320 The static inline function @code{gpgme_err_make} returns the error
1321 value consisting of the error source @var{source} and the error code
1324 This function can be used in callback functions to construct an error
1325 value to return it to the library.
1328 @deftypefun {static inline gpgme_error_t} gpgme_error (@w{gpgme_err_code_t @var{code}})
1329 The static inline function @code{gpgme_error} returns the error value
1330 consisting of the default error source and the error code @var{code}.
1332 For @acronym{GPGME} applications, the default error source is
1333 @code{GPG_ERR_SOURCE_USER_1}. You can define
1334 @code{GPGME_ERR_SOURCE_DEFAULT} before including @file{gpgme.h} to
1335 change this default.
1337 This function can be used in callback functions to construct an error
1338 value to return it to the library.
1341 The @code{libgpg-error} library provides error codes for all system
1342 error numbers it knows about. If @var{err} is an unknown error
1343 number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The
1344 following functions can be used to construct error values from system
1347 @deftypefun {gpgme_error_t} gpgme_err_make_from_errno (@w{gpgme_err_source_t @var{source}}, @w{int @var{err}})
1348 The function @code{gpgme_err_make_from_errno} is like
1349 @code{gpgme_err_make}, but it takes a system error like @code{errno}
1350 instead of a @code{gpgme_err_code_t} error code.
1353 @deftypefun {gpgme_error_t} gpgme_error_from_errno (@w{int @var{err}})
1354 The function @code{gpgme_error_from_errno} is like @code{gpgme_error},
1355 but it takes a system error like @code{errno} instead of a
1356 @code{gpgme_err_code_t} error code.
1359 Sometimes you might want to map system error numbers to error codes
1360 directly, or map an error code representing a system error back to the
1361 system error number. The following functions can be used to do that.
1363 @deftypefun {gpgme_err_code_t} gpgme_err_code_from_errno (@w{int @var{err}})
1364 The function @code{gpgme_err_code_from_errno} returns the error code
1365 for the system error @var{err}. If @var{err} is not a known system
1366 error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}.
1369 @deftypefun {int} gpgme_err_code_to_errno (@w{gpgme_err_code_t @var{err}})
1370 The function @code{gpgme_err_code_to_errno} returns the system error
1371 for the error code @var{err}. If @var{err} is not an error code
1372 representing a system error, or if this system error is not defined on
1373 this system, the function returns @code{0}.
1378 @section Error Sources
1379 @cindex error codes, list of
1381 The library @code{libgpg-error} defines an error source for every
1382 component of the GnuPG system. The error source part of an error
1383 value is not well defined. As such it is mainly useful to improve the
1384 diagnostic error message for the user.
1386 If the error code part of an error value is @code{0}, the whole error
1387 value will be @code{0}. In this case the error source part is of
1388 course @code{GPG_ERR_SOURCE_UNKNOWN}.
1390 The list of error sources that might occur in applications using
1394 @item GPG_ERR_SOURCE_UNKNOWN
1395 The error source is not known. The value of this error source is
1398 @item GPG_ERR_SOURCE_GPGME
1399 The error source is @acronym{GPGME} itself. This is the default for
1400 errors that occur in the @acronym{GPGME} library.
1402 @item GPG_ERR_SOURCE_GPG
1403 The error source is GnuPG, which is the crypto engine used for the
1406 @item GPG_ERR_SOURCE_GPGSM
1407 The error source is GPGSM, which is the crypto engine used for the
1410 @item GPG_ERR_SOURCE_GCRYPT
1411 The error source is @code{libgcrypt}, which is used by crypto engines
1412 to perform cryptographic operations.
1414 @item GPG_ERR_SOURCE_GPGAGENT
1415 The error source is @command{gpg-agent}, which is used by crypto
1416 engines to perform operations with the secret key.
1418 @item GPG_ERR_SOURCE_PINENTRY
1419 The error source is @command{pinentry}, which is used by
1420 @command{gpg-agent} to query the passphrase to unlock a secret key.
1422 @item GPG_ERR_SOURCE_SCD
1423 The error source is the SmartCard Daemon, which is used by
1424 @command{gpg-agent} to delegate operations with the secret key to a
1427 @item GPG_ERR_SOURCE_KEYBOX
1428 The error source is @code{libkbx}, a library used by the crypto
1429 engines to manage local keyrings.
1431 @item GPG_ERR_SOURCE_USER_1
1432 @item GPG_ERR_SOURCE_USER_2
1433 @item GPG_ERR_SOURCE_USER_3
1434 @item GPG_ERR_SOURCE_USER_4
1435 These error sources are not used by any GnuPG component and can be
1436 used by other software. For example, applications using
1437 @acronym{GPGME} can use them to mark error values coming from callback
1438 handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors
1439 created with @code{gpgme_error} and @code{gpgme_error_from_errno},
1440 unless you define @code{GPGME_ERR_SOURCE_DEFAULT} before including
1446 @section Error Codes
1447 @cindex error codes, list of
1449 The library @code{libgpg-error} defines many error values. Most of
1450 them are not used by @code{GPGME} directly, but might be returned by
1451 @acronym{GPGME} because it received them from the crypto engine. The
1452 below list only includes such error codes that have a specific meaning
1453 in @code{GPGME}, or which are so common that you should know about
1458 This value indicates the end of a list, buffer or file.
1460 @item GPG_ERR_NO_ERROR
1461 This value indicates success. The value of this error code is
1462 @code{0}. Also, it is guaranteed that an error value made from the
1463 error code @code{0} will be @code{0} itself (as a whole). This means
1464 that the error source information is lost for this error code,
1465 however, as this error code indicates that no error occured, this is
1466 generally not a problem.
1468 @item GPG_ERR_GENERAL
1469 This value means that something went wrong, but either there is not
1470 enough information about the problem to return a more useful error
1471 value, or there is no separate error value for this type of problem.
1473 @item GPG_ERR_ENOMEM
1474 This value means that an out-of-memory condition occurred.
1477 System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
1480 @item GPG_ERR_INV_VALUE
1481 This value means that some user provided data was out of range. This
1482 can also refer to objects. For example, if an empty
1483 @code{gpgme_data_t} object was expected, but one containing data was
1484 provided, this error value is returned.
1486 @item GPG_ERR_UNUSABLE_PUBKEY
1487 This value means that some recipients for a message were invalid.
1489 @item GPG_ERR_UNUSABLE_SECKEY
1490 This value means that some signers were invalid.
1492 @item GPG_ERR_NO_DATA
1493 This value means that a @code{gpgme_data_t} object which was expected
1494 to have content was found empty.
1496 @item GPG_ERR_CONFLICT
1497 This value means that a conflict of some sort occurred.
1499 @item GPG_ERR_NOT_IMPLEMENTED
1500 This value indicates that the specific function (or operation) is not
1501 implemented. This error should never happen. It can only occur if
1502 you use certain values or configuration options which do not work,
1503 but for which we think that they should work at some later time.
1505 @item GPG_ERR_DECRYPT_FAILED
1506 This value indicates that a decryption operation was unsuccessful.
1508 @item GPG_ERR_BAD_PASSPHRASE
1509 This value means that the user did not provide a correct passphrase
1512 @item GPG_ERR_CANCELED
1513 This value means that the operation was canceled.
1515 @item GPG_ERR_INV_ENGINE
1516 This value means that the engine that implements the desired protocol
1517 is currently not available. This can either be because the sources
1518 were configured to exclude support for this engine, or because the
1519 engine is not installed properly.
1521 @item GPG_ERR_AMBIGUOUS_NAME
1522 This value indicates that a user ID or other specifier did not specify
1525 @item GPG_ERR_WRONG_KEY_USAGE
1526 This value indicates that a key is not used appropriately.
1528 @item GPG_ERR_CERT_REVOKED
1529 This value indicates that a key signature was revoced.
1531 @item GPG_ERR_CERT_EXPIRED
1532 This value indicates that a key signature expired.
1534 @item GPG_ERR_NO_CRL_KNOWN
1535 This value indicates that no certificate revocation list is known for
1538 @item GPG_ERR_NO_POLICY_MATCH
1539 This value indicates that a policy issue occured.
1541 @item GPG_ERR_NO_SECKEY
1542 This value indicates that no secret key for the user ID is available.
1544 @item GPG_ERR_MISSING_CERT
1545 This value indicates that a key could not be imported because the
1546 issuer certificate is missing.
1548 @item GPG_ERR_BAD_CERT_CHAIN
1549 This value indicates that a key could not be imported because its
1550 certificate chain is not good, for example it could be too long.
1552 @item GPG_ERR_UNSUPPORTED_ALGORITHM
1553 This value means a verification failed because the cryptographic
1554 algorithm is not supported by the crypto backend.
1556 @item GPG_ERR_BAD_SIGNATURE
1557 This value means a verification failed because the signature is bad.
1559 @item GPG_ERR_NO_PUBKEY
1560 This value means a verification failed because the public key is not
1563 @item GPG_ERR_USER_1
1564 @item GPG_ERR_USER_2
1566 @item GPG_ERR_USER_16
1567 These error codes are not used by any GnuPG component and can be
1568 freely used by other software. Applications using @acronym{GPGME}
1569 might use them to mark specific errors returned by callback handlers
1570 if no suitable error codes (including the system errors) for
1571 these errors exist already.
1576 @section Error Strings
1577 @cindex error values, printing of
1578 @cindex error codes, printing of
1579 @cindex error sources, printing of
1580 @cindex error strings
1582 @deftypefun {const char *} gpgme_strerror (@w{gpgme_error_t @var{err}})
1583 The function @code{gpgme_strerror} returns a pointer to a statically
1584 allocated string containing a description of the error code contained
1585 in the error value @var{err}. This string can be used to output a
1586 diagnostic message to the user.
1588 This function is not thread safe. Use @code{gpgme_strerror_r} in
1589 multi-threaded programs.
1593 @deftypefun {int} gpgme_strerror_r (@w{gpgme_error_t @var{err}}, @w{char *@var{buf}}, @w{size_t @var{buflen}})
1594 The function @code{gpgme_strerror_r} returns the error string for
1595 @var{err} in the user-supplied buffer @var{buf} of size @var{buflen}.
1596 This function is, in contrast to @code{gpgme_strerror}, thread-safe if
1597 a thread-safe @code{strerror_r} function is provided by the system.
1598 If the function succeeds, 0 is returned and @var{buf} contains the
1599 string describing the error. If the buffer was not large enough,
1600 ERANGE is returned and @var{buf} contains as much of the beginning of
1601 the error string as fits into the buffer.
1605 @deftypefun {const char *} gpgme_strsource (@w{gpgme_error_t @var{err}})
1606 The function @code{gpgme_strerror} returns a pointer to a statically
1607 allocated string containing a description of the error source
1608 contained in the error value @var{err}. This string can be used to
1609 output a diagnostic message to the user.
1612 The following example illustrates the use of @code{gpgme_strerror}:
1616 gpgme_error_t err = gpgme_new (&ctx);
1619 fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
1620 argv[0], gpgme_strsource (err), gpgme_strerror (err));
1626 @node Exchanging Data
1627 @chapter Exchanging Data
1628 @cindex data, exchanging
1630 A lot of data has to be exchanged between the user and the crypto
1631 engine, like plaintext messages, ciphertext, signatures and
1632 information about the keys. The technical details about exchanging
1633 the data information are completely abstracted by @acronym{GPGME}.
1634 The user provides and receives the data via @code{gpgme_data_t} objects,
1635 regardless of the communication protocol between @acronym{GPGME} and
1636 the crypto engine in use.
1638 @deftp {Data type} {gpgme_data_t}
1639 The @code{gpgme_data_t} type is a handle for a container for generic
1640 data, which is used by @acronym{GPGME} to exchange data with the user.
1643 @code{gpgme_data_t} objects do not provide notifications on events.
1644 It is assumed that read and write operations are blocking until data
1645 is available. If this is undesirable, the application must ensure
1646 that all GPGME data operations always have data available, for example
1647 by using memory buffers or files rather than pipes or sockets. This
1648 might be relevant, for example, if the external event loop mechanism
1651 @deftp {Data type} {gpgme_off_t}
1652 On POSIX platforms the @code{gpgme_off_t} type is an alias for
1653 @code{off_t}; it may be used interchangeable. On Windows platforms
1654 @code{gpgme_off_t} is defined as a long (i.e. 32 bit) for 32 bit
1655 Windows and as a 64 bit signed integer for 64 bit Windows.
1658 @deftp {Data type} {gpgme_ssize_t}
1659 The @code{gpgme_ssize_t} type is an alias for @code{ssize_t}. It has
1660 only been introduced to overcome portability problems pertaining to
1661 the declaration of @code{ssize_t} by different toolchains.
1666 * Creating Data Buffers:: Creating new data buffers.
1667 * Destroying Data Buffers:: Releasing data buffers.
1668 * Manipulating Data Buffers:: Operations on data buffers.
1672 @node Creating Data Buffers
1673 @section Creating Data Buffers
1674 @cindex data buffer, creation
1676 Data objects can be based on memory, files, or callback functions
1677 provided by the user. Not all operations are supported by all
1682 * Memory Based Data Buffers:: Creating memory based data buffers.
1683 * File Based Data Buffers:: Creating file based data buffers.
1684 * Callback Based Data Buffers:: Creating callback based data buffers.
1688 @node Memory Based Data Buffers
1689 @subsection Memory Based Data Buffers
1691 Memory based data objects store all data in allocated memory. This is
1692 convenient, but only practical for an amount of data that is a
1693 fraction of the available physical memory. The data has to be copied
1694 from its source and to its destination, which can often be avoided by
1695 using one of the other data object
1697 @deftypefun gpgme_error_t gpgme_data_new (@w{gpgme_data_t *@var{dh}})
1698 The function @code{gpgme_data_new} creates a new @code{gpgme_data_t}
1699 object and returns a handle for it in @var{dh}. The data object is
1700 memory based and initially empty.
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} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1705 enough memory is available.
1708 @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}})
1709 The function @code{gpgme_data_new_from_mem} creates a new
1710 @code{gpgme_data_t} object and fills it with @var{size} bytes starting
1713 If @var{copy} is not zero, a private copy of the data is made. If
1714 @var{copy} is zero, the data is taken from the specified buffer as
1715 needed, and the user has to ensure that the buffer remains valid for
1716 the whole life span of the data object.
1718 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1719 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1720 @var{dh} or @var{buffer} is not a valid pointer, and
1721 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1724 @deftypefun gpgme_error_t gpgme_data_new_from_file (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}})
1725 The function @code{gpgme_data_new_from_file} creates a new
1726 @code{gpgme_data_t} object and fills it with the content of the file
1729 If @var{copy} is not zero, the whole file is read in at initialization
1730 time and the file is not used anymore after that. This is the only
1731 mode supported currently. Later, a value of zero for @var{copy} might
1732 cause all reads to be delayed until the data is needed, but this is
1733 not yet implemented.
1735 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1736 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1737 @var{dh} or @var{filename} is not a valid pointer,
1738 @code{GPG_ERR_NOT_IMPLEMENTED} if @var{code} is zero, and
1739 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1742 @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}})
1743 The function @code{gpgme_data_new_from_filepart} creates a new
1744 @code{gpgme_data_t} object and fills it with a part of the file specified
1745 by @var{filename} or @var{fp}.
1747 Exactly one of @var{filename} and @var{fp} must be non-zero, the other
1748 must be zero. The argument that is not zero specifies the file from
1749 which @var{length} bytes are read into the data object, starting from
1752 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1753 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1754 @var{dh} and exactly one of @var{filename} and @var{fp} is not a valid
1755 pointer, and @code{GPG_ERR_ENOMEM} if not enough memory is available.
1759 @node File Based Data Buffers
1760 @subsection File Based Data Buffers
1762 File based data objects operate directly on file descriptors or
1763 streams. Only a small amount of data is stored in core at any time,
1764 so the size of the data objects is not limited by @acronym{GPGME}.
1766 @deftypefun gpgme_error_t gpgme_data_new_from_fd (@w{gpgme_data_t *@var{dh}}, @w{int @var{fd}})
1767 The function @code{gpgme_data_new_from_fd} creates a new
1768 @code{gpgme_data_t} object and uses the file descriptor @var{fd} to read
1769 from (if used as an input data object) and write to (if used as an
1770 output data object).
1772 When using the data object as an input buffer, the function might read
1773 a bit more from the file descriptor than is actually needed by the
1774 crypto engine in the desired operation because of internal buffering.
1776 Note that GPGME assumes that the file descriptor is set to blocking
1777 mode. Errors during I/O operations, except for EINTR, are usually
1778 fatal for crypto operations.
1780 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1781 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1782 enough memory is available.
1785 @deftypefun gpgme_error_t gpgme_data_new_from_stream (@w{gpgme_data_t *@var{dh}}, @w{FILE *@var{stream}})
1786 The function @code{gpgme_data_new_from_stream} creates a new
1787 @code{gpgme_data_t} object and uses the I/O stream @var{stream} to read
1788 from (if used as an input data object) and write to (if used as an
1789 output data object).
1791 When using the data object as an input buffer, the function might read
1792 a bit more from the stream than is actually needed by the crypto
1793 engine in the desired operation because of internal buffering.
1795 Note that GPGME assumes that the stream is in blocking mode. Errors
1796 during I/O operations, except for EINTR, are usually fatal for crypto
1799 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1800 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1801 enough memory is available.
1805 @node Callback Based Data Buffers
1806 @subsection Callback Based Data Buffers
1808 If neither memory nor file based data objects are a good fit for your
1809 application, you can implement the functions a data object provides
1810 yourself and create a data object from these callback functions.
1812 @deftp {Data type} {ssize_t (*gpgme_data_read_cb_t) (@w{void *@var{handle}}, @w{void @var{*buffer}}, @w{size_t @var{size}})}
1813 @tindex gpgme_data_read_cb_t
1814 The @code{gpgme_data_read_cb_t} type is the type of functions which
1815 @acronym{GPGME} calls if it wants to read data from a user-implemented
1816 data object. The function should read up to @var{size} bytes from the
1817 current read position into the space starting at @var{buffer}. The
1818 @var{handle} is provided by the user at data object creation time.
1820 Note that GPGME assumes that the read blocks until data is available.
1821 Errors during I/O operations, except for EINTR, are usually fatal for
1824 The function should return the number of bytes read, 0 on EOF, and -1
1825 on error. If an error occurs, @var{errno} should be set to describe
1826 the type of the error.
1829 @deftp {Data type} {ssize_t (*gpgme_data_write_cb_t) (@w{void *@var{handle}}, @w{const void @var{*buffer}}, @w{size_t @var{size}})}
1830 @tindex gpgme_data_write_cb_t
1831 The @code{gpgme_data_write_cb_t} type is the type of functions which
1832 @acronym{GPGME} calls if it wants to write data to a user-implemented
1833 data object. The function should write up to @var{size} bytes to the
1834 current write position from the space starting at @var{buffer}. The
1835 @var{handle} is provided by the user at data object creation time.
1837 Note that GPGME assumes that the write blocks until data is available.
1838 Errors during I/O operations, except for EINTR, are usually fatal for
1841 The function should return the number of bytes written, and -1 on
1842 error. If an error occurs, @var{errno} should be set to describe the
1846 @deftp {Data type} {off_t (*gpgme_data_seek_cb_t) (@w{void *@var{handle}}, @w{off_t @var{offset}}, @w{int @var{whence}})}
1847 @tindex gpgme_data_seek_cb_t
1848 The @code{gpgme_data_seek_cb_t} type is the type of functions which
1849 @acronym{GPGME} calls if it wants to change the current read/write
1850 position in a user-implemented data object, just like the @code{lseek}
1853 The function should return the new read/write position, and -1 on
1854 error. If an error occurs, @var{errno} should be set to describe the
1858 @deftp {Data type} {void (*gpgme_data_release_cb_t) (@w{void *@var{handle}})}
1859 @tindex gpgme_data_release_cb_t
1860 The @code{gpgme_data_release_cb_t} type is the type of functions which
1861 @acronym{GPGME} calls if it wants to destroy a user-implemented data
1862 object. The @var{handle} is provided by the user at data object
1866 @deftp {Data type} {struct gpgme_data_cbs}
1867 This structure is used to store the data callback interface functions
1868 described above. It has the following members:
1871 @item gpgme_data_read_cb_t read
1872 This is the function called by @acronym{GPGME} to read data from the
1873 data object. It is only required for input data object.
1875 @item gpgme_data_write_cb_t write
1876 This is the function called by @acronym{GPGME} to write data to the
1877 data object. It is only required for output data object.
1879 @item gpgme_data_seek_cb_t seek
1880 This is the function called by @acronym{GPGME} to change the current
1881 read/write pointer in the data object (if available). It is optional.
1883 @item gpgme_data_release_cb_t release
1884 This is the function called by @acronym{GPGME} to release a data
1885 object. It is optional.
1889 @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}})
1890 The function @code{gpgme_data_new_from_cbs} creates a new
1891 @code{gpgme_data_t} object and uses the user-provided callback functions
1892 to operate on the data object.
1894 The handle @var{handle} is passed as first argument to the callback
1895 functions. This can be used to identify this data object.
1897 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1898 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1899 enough memory is available.
1902 The following interface is deprecated and only provided for backward
1903 compatibility. Don't use it. It will be removed in a future version
1906 @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}})
1907 The function @code{gpgme_data_new_with_read_cb} creates a new
1908 @code{gpgme_data_t} object and uses the callback function @var{readfunc}
1909 to retrieve the data on demand. As the callback function can supply
1910 the data in any way it wants, this is the most flexible data type
1911 @acronym{GPGME} provides. However, it can not be used to write data.
1913 The callback function receives @var{hook_value} as its first argument
1914 whenever it is invoked. It should return up to @var{count} bytes in
1915 @var{buffer}, and return the number of bytes actually read in
1916 @var{nread}. It may return @code{0} in @var{nread} if no data is
1917 currently available. To indicate @code{EOF} the function should
1918 return with an error code of @code{-1} and set @var{nread} to
1919 @code{0}. The callback function may support to reset its internal
1920 read pointer if it is invoked with @var{buffer} and @var{nread} being
1921 @code{NULL} and @var{count} being @code{0}.
1923 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1924 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1925 @var{dh} or @var{readfunc} is not a valid pointer, and
1926 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1930 @node Destroying Data Buffers
1931 @section Destroying Data Buffers
1932 @cindex data buffer, destruction
1934 @deftypefun void gpgme_data_release (@w{gpgme_data_t @var{dh}})
1935 The function @code{gpgme_data_release} destroys the data object with
1936 the handle @var{dh}. It releases all associated resources that were
1937 not provided by the user in the first place.
1940 @deftypefun {char *} gpgme_data_release_and_get_mem (@w{gpgme_data_t @var{dh}}, @w{size_t *@var{length}})
1941 The function @code{gpgme_data_release_and_get_mem} is like
1942 @code{gpgme_data_release}, except that it returns the data buffer and
1943 its length that was provided by the object.
1945 The user has to release the buffer with @code{gpgme_free}. In case
1946 the user provided the data buffer in non-copy mode, a copy will be
1947 made for this purpose.
1949 In case an error returns, or there is no suitable data buffer that can
1950 be returned to the user, the function will return @code{NULL}. In any
1951 case, the data object @var{dh} is destroyed.
1955 @deftypefun void gpgme_free (@w{void *@var{buffer}})
1956 The function @code{gpgme_free} releases the memory returned by
1957 @code{gpgme_data_release_and_get_mem}. It should be used instead of
1958 the system libraries @code{free} function in case different allocators
1959 are used in a single program.
1963 @node Manipulating Data Buffers
1964 @section Manipulating Data Buffers
1965 @cindex data buffer, manipulation
1967 Data buffers contain data and meta-data. The following operations can
1968 be used to manipulate both.
1972 * Data Buffer I/O Operations:: I/O operations on data buffers.
1973 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
1974 * Data Buffer Convenience:: Convenience function for data buffers.
1978 @node Data Buffer I/O Operations
1979 @subsection Data Buffer I/O Operations
1980 @cindex data buffer, I/O operations
1981 @cindex data buffer, read
1982 @cindex data buffer, write
1983 @cindex data buffer, seek
1985 @deftypefun ssize_t gpgme_data_read (@w{gpgme_data_t @var{dh}}, @w{void *@var{buffer}}, @w{size_t @var{length}})
1986 The function @code{gpgme_data_read} reads up to @var{length} bytes
1987 from the data object with the handle @var{dh} into the space starting
1990 If no error occurs, the actual amount read is returned. If the end of
1991 the data object is reached, the function returns 0.
1993 In all other cases, the function returns -1 and sets @var{errno}.
1996 @deftypefun ssize_t gpgme_data_write (@w{gpgme_data_t @var{dh}}, @w{const void *@var{buffer}}, @w{size_t @var{size}})
1997 The function @code{gpgme_data_write} writes up to @var{size} bytes
1998 starting from @var{buffer} into the data object with the handle
1999 @var{dh} at the current write position.
2001 The function returns the number of bytes actually written, or -1 if an
2002 error occurs. If an error occurs, @var{errno} is set.
2005 @deftypefun off_t gpgme_data_seek (@w{gpgme_data_t @var{dh}}, @w{off_t @var{offset}}, @w{int @var{whence}})
2006 The function @code{gpgme_data_seek} changes the current read/write
2009 The @var{whence} argument specifies how the @var{offset} should be
2010 interpreted. It must be one of the following symbolic constants:
2014 Specifies that @var{offset} is a count of characters from the
2015 beginning of the data object.
2018 Specifies that @var{offset} is a count of characters from the current
2019 file position. This count may be positive or negative.
2022 Specifies that @var{offset} is a count of characters from the end of
2023 the data object. A negative count specifies a position within the
2024 current extent of the data object; a positive count specifies a
2025 position past the current end. If you set the position past the
2026 current end, and actually write data, you will extend the data object
2027 with zeros up to that position.
2030 If successful, the function returns the resulting file position,
2031 measured in bytes from the beginning of the data object. You can use
2032 this feature together with @code{SEEK_CUR} to read the current
2033 read/write position.
2035 If the function fails, -1 is returned and @var{errno} is set.
2038 The following function is deprecated and should not be used. It will
2039 be removed in a future version of @acronym{GPGME}.
2041 @deftypefun gpgme_error_t gpgme_data_rewind (@w{gpgme_data_t @var{dh}})
2042 The function @code{gpgme_data_rewind} is equivalent to:
2045 return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
2046 ? gpgme_error_from_errno (errno) : 0;
2053 @node Data Buffer Meta-Data
2054 @subsection Data Buffer Meta-Data
2055 @cindex data buffer, meta-data
2056 @cindex data buffer, file name
2057 @cindex data buffer, encoding
2059 @deftypefun {char *} gpgme_data_get_file_name (@w{gpgme_data_t @var{dh}})
2060 The function @code{gpgme_data_get_file_name} returns a pointer to a
2061 string containing the file name associated with the data object. The
2062 file name will be stored in the output when encrypting or signing the
2063 data and will be returned to the user when decrypting or verifying the
2066 If no error occurs, the string containing the file name is returned.
2067 Otherwise, @code{NULL} will be returned.
2071 @deftypefun gpgme_error_t gpgme_data_set_file_name (@w{gpgme_data_t @var{dh}}, @w{const char *@var{file_name}})
2072 The function @code{gpgme_data_set_file_name} sets the file name
2073 associated with the data object. The file name will be stored in the
2074 output when encrypting or signing the data and will be returned to the
2075 user when decrypting or verifying the output data.
2077 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2078 @var{dh} is not a valid pointer and @code{GPG_ERR_ENOMEM} if not
2079 enough memory is available.
2083 @deftp {Data type} {enum gpgme_data_encoding_t}
2084 @tindex gpgme_data_encoding_t
2085 The @code{gpgme_data_encoding_t} type specifies the encoding of a
2086 @code{gpgme_data_t} object. For input data objects, the encoding is
2087 useful to give the backend a hint on the type of data. For output
2088 data objects, the encoding can specify the output data format on
2089 certain operations. Please note that not all backends support all
2090 encodings on all operations. The following data types are available:
2093 @item GPGME_DATA_ENCODING_NONE
2094 This specifies that the encoding is not known. This is the default
2095 for a new data object. The backend will try its best to detect the
2096 encoding automatically.
2098 @item GPGME_DATA_ENCODING_BINARY
2099 This specifies that the data is encoding in binary form; i.e. there is
2100 no special encoding.
2102 @item GPGME_DATA_ENCODING_BASE64
2103 This specifies that the data is encoded using the Base-64 encoding
2104 scheme as used by @acronym{MIME} and other protocols.
2106 @item GPGME_DATA_ENCODING_ARMOR
2107 This specifies that the data is encoded in an armored form as used by
2110 @item GPGME_DATA_ENCODING_URL
2111 The data is a list of linefeed delimited URLs. This is only useful with
2112 @code{gpgme_op_import}.
2114 @item GPGME_DATA_ENCODING_URL0
2115 The data is a list of binary zero delimited URLs. This is only useful
2116 with @code{gpgme_op_import}.
2118 @item GPGME_DATA_ENCODING_URLESC
2119 The data is a list of linefeed delimited URLs with all control and space
2120 characters percent escaped. This mode is is not yet implemented.
2125 @deftypefun gpgme_data_encoding_t gpgme_data_get_encoding (@w{gpgme_data_t @var{dh}})
2126 The function @code{gpgme_data_get_encoding} returns the encoding of
2127 the data object with the handle @var{dh}. If @var{dh} is not a valid
2128 pointer (e.g. @code{NULL}) @code{GPGME_DATA_ENCODING_NONE} is
2132 @deftypefun gpgme_error_t gpgme_data_set_encoding (@w{gpgme_data_t @var{dh}, gpgme_data_encoding_t @var{enc}})
2133 The function @code{gpgme_data_set_encoding} changes the encoding of
2134 the data object with the handle @var{dh} to @var{enc}.
2137 @node Data Buffer Convenience
2138 @subsection Data Buffer Convenience Functions
2139 @cindex data buffer, convenience
2140 @cindex type of data
2143 @deftp {Data type} {enum gpgme_data_type_t}
2144 @tindex gpgme_data_type_t
2145 The @code{gpgme_data_type_t} type is used to return the detected type
2146 of the content of a data buffer.
2150 @item GPGME_DATA_TYPE_INVALID
2151 This is returned by @code{gpgme_data_identify} if it was not possible
2152 to identify the data. Reasons for this might be a non-seekable stream
2153 or a memory problem. The value is 0.
2154 @item GPGME_DATA_TYPE_UNKNOWN
2155 The type of the data is not known.
2156 @item GPGME_DATA_TYPE_PGP_SIGNED
2157 The data is an OpenPGP signed message. This may be a binary
2158 signature, a detached one or a cleartext signature.
2159 @item GPGME_DATA_TYPE_PGP_OTHER
2160 This is a generic OpenPGP message. In most cases this will be
2162 @item GPGME_DATA_TYPE_PGP_KEY
2163 This is an OpenPGP key (private or public).
2164 @item GPGME_DATA_TYPE_CMS_SIGNED
2165 This is a CMS signed message.
2166 @item GPGME_DATA_TYPE_CMS_ENCRYPTED
2167 This is a CMS encrypted (enveloped data) message.
2168 @item GPGME_DATA_TYPE_CMS_OTHER
2169 This is used for other CMS message types.
2170 @item GPGME_DATA_TYPE_X509_CERT
2171 The data is a X.509 certificate
2172 @item GPGME_DATA_TYPE_PKCS12
2173 The data is a PKCS#12 message. This is commonly used to exchange
2174 private keys for X.509.
2177 @deftypefun gpgme_data_type_t gpgme_data_identify (@w{gpgme_data_t @var{dh}})
2178 The function @code{gpgme_data_identify} returns the type of the data
2179 with the handle @var{dh}. If it is not possible to perform the
2180 identification, the function returns zero
2181 (@code{GPGME_DATA_TYPE_INVALID}). Note that depending on how the data
2182 object has been created the identification may not be possible or the
2183 data object may change its internal state (file pointer moved). For
2184 file or memory based data object, the state should not change.
2195 All cryptographic operations in @acronym{GPGME} are performed within a
2196 context, which contains the internal state of the operation as well as
2197 configuration parameters. By using several contexts you can run
2198 several cryptographic operations in parallel, with different
2201 @deftp {Data type} {gpgme_ctx_t}
2202 The @code{gpgme_ctx_t} type is a handle for a @acronym{GPGME} context,
2203 which is used to hold the configuration, status and result of
2204 cryptographic operations.
2208 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
2209 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
2210 * Result Management:: Managing the result of crypto operations.
2211 * Context Attributes:: Setting properties of a context.
2212 * Key Management:: Managing keys with @acronym{GPGME}.
2213 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
2214 * Crypto Operations:: Using a context for cryptography.
2215 * Miscellaneous:: Miscellaneous operations
2216 * Run Control:: Controlling how operations are run.
2220 @node Creating Contexts
2221 @section Creating Contexts
2222 @cindex context, creation
2224 @deftypefun gpgme_error_t gpgme_new (@w{gpgme_ctx_t *@var{ctx}})
2225 The function @code{gpgme_new} creates a new @code{gpgme_ctx_t} object
2226 and returns a handle for it in @var{ctx}.
2228 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2229 context was successfully created, @code{GPG_ERR_INV_VALUE} if
2230 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
2231 enough memory is available. Also, it returns
2232 @code{GPG_ERR_NOT_OPERATIONAL} if @code{gpgme_check_version} was not
2233 called to initialize GPGME, and @code{GPG_ERR_SELFTEST_FAILED} if a
2234 selftest failed. Currently, the only selftest is for Windows MingW32
2235 targets to see if @code{-mms-bitfields} was used (as required).
2239 @node Destroying Contexts
2240 @section Destroying Contexts
2241 @cindex context, destruction
2243 @deftypefun void gpgme_release (@w{gpgme_ctx_t @var{ctx}})
2244 The function @code{gpgme_release} destroys the context with the handle
2245 @var{ctx} and releases all associated resources.
2249 @node Result Management
2250 @section Result Management
2251 @cindex context, result of operation
2253 The detailed result of an operation is returned in operation-specific
2254 structures such as @code{gpgme_decrypt_result_t}. The corresponding
2255 retrieval functions such as @code{gpgme_op_decrypt_result} provide
2256 static access to the results after an operation completes. The
2257 following interfaces make it possible to detach a result structure
2258 from its associated context and give it a lifetime beyond that of the
2259 current operation or context.
2261 @deftypefun void gpgme_result_ref (@w{void *@var{result}})
2262 The function @code{gpgme_result_ref} acquires an additional reference
2263 for the result @var{result}, which may be of any type
2264 @code{gpgme_*_result_t}. As long as the user holds a reference, the
2265 result structure is guaranteed to be valid and unmodified.
2268 @deftypefun void gpgme_result_unref (@w{void *@var{result}})
2269 The function @code{gpgme_result_unref} releases a reference for the
2270 result @var{result}. If this was the last reference, the result
2271 structure will be destroyed and all resources associated to it will be
2275 Note that a context may hold its own references to result structures,
2276 typically until the context is destroyed or the next operation is
2277 started. In fact, these references are accessed through the
2278 @code{gpgme_op_*_result} functions.
2281 @node Context Attributes
2282 @section Context Attributes
2283 @cindex context, attributes
2286 * Protocol Selection:: Selecting the protocol used by a context.
2287 * Crypto Engine:: Configuring the crypto engine.
2288 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
2289 * Text Mode:: Choosing canonical text mode.
2290 * Offline Mode:: Choosing offline mode.
2291 * Included Certificates:: Including a number of certificates.
2292 * Key Listing Mode:: Selecting key listing mode.
2293 * Passphrase Callback:: Getting the passphrase from the user.
2294 * Progress Meter Callback:: Being informed about the progress.
2295 * Status Message Callback:: Status messages received from gpg.
2296 * Locale:: Setting the locale of a context.
2300 @node Protocol Selection
2301 @subsection Protocol Selection
2302 @cindex context, selecting protocol
2303 @cindex protocol, selecting
2305 @deftypefun gpgme_error_t gpgme_set_protocol (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}})
2306 The function @code{gpgme_set_protocol} sets the protocol used within
2307 the context @var{ctx} to @var{proto}. All crypto operations will be
2308 performed by the crypto engine configured for that protocol.
2309 @xref{Protocols and Engines}.
2311 Setting the protocol with @code{gpgme_set_protocol} does not check if
2312 the crypto engine for that protocol is available and installed
2313 correctly. @xref{Engine Version Check}.
2315 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2316 protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if
2317 @var{protocol} is not a valid protocol.
2320 @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}})
2321 The function @code{gpgme_get_protocol} retrieves the protocol currently
2322 use with the context @var{ctx}.
2327 @subsection Crypto Engine
2328 @cindex context, configuring engine
2329 @cindex engine, configuration per context
2331 The following functions can be used to set and retrieve the
2332 configuration of the crypto engines of a specific context. The
2333 default can also be retrieved without any particular context.
2334 @xref{Engine Information}. The default can also be changed globally.
2335 @xref{Engine Configuration}.
2337 @deftypefun gpgme_engine_info_t gpgme_ctx_get_engine_info (@w{gpgme_ctx_t @var{ctx}})
2338 The function @code{gpgme_ctx_get_engine_info} returns a linked list of
2339 engine info structures. Each info structure describes the
2340 configuration of one configured backend, as used by the context
2343 The result is valid until the next invocation of
2344 @code{gpgme_ctx_set_engine_info} for this particular context.
2346 This function can not fail.
2349 @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}})
2350 The function @code{gpgme_ctx_set_engine_info} changes the
2351 configuration of the crypto engine implementing the protocol
2352 @var{proto} for the context @var{ctx}.
2354 @var{file_name} is the file name of the executable program
2355 implementing this protocol, and @var{home_dir} is the directory name
2356 of the configuration directory for this crypto engine. If
2357 @var{home_dir} is @code{NULL}, the engine's default will be used.
2359 Currently this function must be used before starting the first crypto
2360 operation. It is unspecified if and when the changes will take effect
2361 if the function is called after starting the first operation on the
2364 This function returns the error code @code{GPG_ERR_NO_ERROR} if
2365 successful, or an eror code on failure.
2369 @c FIXME: Unfortunately, using @acronym here breaks texi2dvi.
2371 @subsection @acronym{ASCII} Armor
2372 @cindex context, armor mode
2373 @cindex @acronym{ASCII} armor
2376 @deftypefun void gpgme_set_armor (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2377 The function @code{gpgme_set_armor} specifies if the output should be
2378 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
2381 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
2385 @deftypefun int gpgme_get_armor (@w{gpgme_ctx_t @var{ctx}})
2386 The function @code{gpgme_get_armor} returns 1 if the output is
2387 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
2388 not a valid pointer.
2393 @subsection Text Mode
2394 @cindex context, text mode
2396 @cindex canonical text mode
2398 @deftypefun void gpgme_set_textmode (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2399 The function @code{gpgme_set_textmode} specifies if canonical text mode
2400 should be used. By default, text mode is not used.
2402 Text mode is for example used for the RFC2015 signatures; note that
2403 the updated RFC 3156 mandates that the mail user agent does some
2404 preparations so that text mode is not needed anymore.
2406 This option is only relevant to the OpenPGP crypto engine, and ignored
2407 by all other engines.
2409 Canonical text mode is disabled if @var{yes} is zero, and enabled
2413 @deftypefun int gpgme_get_textmode (@w{gpgme_ctx_t @var{ctx}})
2414 The function @code{gpgme_get_textmode} returns 1 if canonical text
2415 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2421 @subsection Offline Mode
2422 @cindex context, offline mode
2423 @cindex offline mode
2425 @deftypefun void gpgme_set_offline (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2426 The function @code{gpgme_set_offline} specifies if offline mode
2427 should be used. By default, offline mode is not used.
2429 The offline mode specifies if dirmngr should be used to do additional
2430 validation that might require connections to external services.
2431 (e.g. CRL / OCSP checks).
2433 Offline mode only affects the keylist mode @code{GPGME_KEYLIST_MODE_VALIDATE}
2434 and is only relevant to the CMS crypto engine. Offline mode
2435 is ignored otherwise.
2437 This option may be extended in the future to completely disable
2438 the use of dirmngr for any engine.
2440 Offline mode is disabled if @var{yes} is zero, and enabled
2444 @deftypefun int gpgme_get_offline (@w{gpgme_ctx_t @var{ctx}})
2445 The function @code{gpgme_get_offline} returns 1 if offline
2446 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2451 @node Included Certificates
2452 @subsection Included Certificates
2453 @cindex certificates, included
2455 @deftypefun void gpgme_set_include_certs (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{nr_of_certs}})
2456 The function @code{gpgme_set_include_certs} specifies how many
2457 certificates should be included in an S/MIME signed message. By
2458 default, only the sender's certificate is included. The possible
2459 values of @var{nr_of_certs} are:
2462 @item GPGME_INCLUDE_CERTS_DEFAULT
2463 Fall back to the default of the crypto backend. This is the default
2466 Include all certificates except the root certificate.
2468 Include all certificates.
2470 Include no certificates.
2472 Include the sender's certificate only.
2474 Include the first n certificates of the certificates path, starting
2475 from the sender's certificate. The number @code{n} must be positive.
2478 Values of @var{nr_of_certs} smaller than -2 are undefined.
2480 This option is only relevant to the CMS crypto engine, and ignored by
2484 @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}})
2485 The function @code{gpgme_get_include_certs} returns the number of
2486 certificates to include into an S/MIME signed message.
2490 @node Key Listing Mode
2491 @subsection Key Listing Mode
2492 @cindex key listing mode
2493 @cindex key listing, mode of
2495 @deftypefun gpgme_error_t gpgme_set_keylist_mode (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_keylist_mode_t @var{mode}})
2496 The function @code{gpgme_set_keylist_mode} changes the default
2497 behaviour of the key listing functions. The value in @var{mode} is a
2498 bitwise-or combination of one or multiple of the following bit values:
2501 @item GPGME_KEYLIST_MODE_LOCAL
2502 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
2503 keyring should be searched for keys in the keylisting operation. This
2506 @item GPGME_KEYLIST_MODE_EXTERN
2507 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
2508 source should be searched for keys in the keylisting operation. The
2509 type of external source is dependant on the crypto engine used and
2510 whether it is combined with @code{GPGME_KEYLIST_MODE_LOCAL}. For
2511 example, it can be a remote keyserver or LDAP certificate server.
2513 @item GPGME_KEYLIST_MODE_SIGS
2514 The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key
2515 signatures should be included in the listed keys.
2517 @item GPGME_KEYLIST_MODE_SIG_NOTATIONS
2518 The @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} symbol specifies that the
2519 signature notations on key signatures should be included in the listed
2520 keys. This only works if @code{GPGME_KEYLIST_MODE_SIGS} is also
2523 @item GPGME_KEYLIST_MODE_WITH_SECRET
2524 The @code{GPGME_KEYLIST_MODE_WITH_SECRET} returns information about
2525 the presence of a corresponding secret key in a public key listing. A
2526 public key listing with this mode is slower than a standard listing
2527 but can be used instead of a second run to list the secret keys. This
2528 is only supported for GnuPG versions >= 2.1.
2530 @item GPGME_KEYLIST_MODE_EPHEMERAL
2531 The @code{GPGME_KEYLIST_MODE_EPHEMERAL} symbol specifies that keys
2532 flagged as ephemeral are included in the listing.
2534 @item GPGME_KEYLIST_MODE_VALIDATE
2535 The @code{GPGME_KEYLIST_MODE_VALIDATE} symbol specifies that the
2536 backend should do key or certificate validation and not just get the
2537 validity information from an internal cache. This might be an
2538 expensive operation and is in general not useful. Currently only
2539 implemented for the S/MIME backend and ignored for other backends.
2543 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
2544 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
2545 compatibility, you should get the current mode with
2546 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
2547 appropriate bits, and then using that calculated value in the
2548 @code{gpgme_set_keylisting_mode} operation. This will leave all other
2549 bits in the mode value intact (in particular those that are not used
2550 in the current version of the library).
2552 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2553 mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx}
2554 is not a valid pointer or @var{mode} is not a valid mode.
2558 @deftypefun gpgme_keylist_mode_t gpgme_get_keylist_mode (@w{gpgme_ctx_t @var{ctx}})
2559 The function @code{gpgme_get_keylist_mode} returns the current key
2560 listing mode of the context @var{ctx}. This value can then be
2561 modified and used in a subsequent @code{gpgme_set_keylist_mode}
2562 operation to only affect the desired bits (and leave all others
2565 The function returns 0 if @var{ctx} is not a valid pointer, and the
2566 current mode otherwise. Note that 0 is not a valid mode value.
2570 @node Passphrase Callback
2571 @subsection Passphrase Callback
2572 @cindex callback, passphrase
2573 @cindex passphrase callback
2575 @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}})}
2576 @tindex gpgme_passphrase_cb_t
2577 The @code{gpgme_passphrase_cb_t} type is the type of functions usable as
2578 passphrase callback function.
2580 The argument @var{uid_hint} might contain a string that gives an
2581 indication for which user ID the passphrase is required. If this is
2582 not available, or not applicable (in the case of symmetric encryption,
2583 for example), @var{uid_hint} will be @code{NULL}.
2585 The argument @var{passphrase_info}, if not @code{NULL}, will give
2586 further information about the context in which the passphrase is
2587 required. This information is engine and operation specific.
2589 If this is the repeated attempt to get the passphrase, because
2590 previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
2593 The user must write the passphrase, followed by a newline character,
2594 to the file descriptor @var{fd}. The function @code{gpgme_io_writen}
2595 should be used for the write operation. Note that if the user returns
2596 0 to indicate success, the user must at least write a newline
2597 character before returning from the callback.
2599 If an error occurs, return the corresponding @code{gpgme_error_t}
2600 value. You can use the error code @code{GPG_ERR_CANCELED} to abort
2601 the operation. Otherwise, return @code{0}.
2604 @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}})
2605 The function @code{gpgme_set_passphrase_cb} sets the function that is
2606 used when a passphrase needs to be provided by the user to
2607 @var{passfunc}. The function @var{passfunc} needs to implemented by
2608 the user, and whenever it is called, it is called with its first
2609 argument being @var{hook_value}. By default, no passphrase callback
2612 Not all crypto engines require this callback to retrieve the
2613 passphrase. It is better if the engine retrieves the passphrase from
2614 a trusted agent (a daemon process), rather than having each user to
2615 implement their own passphrase query. Some engines do not even
2616 support an external passphrase callback at all, in this case the error
2617 code @code{GPG_ERR_NOT_SUPPORTED} is returned.
2619 The user can disable the use of a passphrase callback function by
2620 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
2624 @deftypefun void gpgme_get_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t *@var{passfunc}}, @w{void **@var{hook_value}})
2625 The function @code{gpgme_get_passphrase_cb} returns the function that
2626 is used when a passphrase needs to be provided by the user in
2627 @var{*passfunc}, and the first argument for this function in
2628 @var{*hook_value}. If no passphrase callback is set, or @var{ctx} is
2629 not a valid pointer, @code{NULL} is returned in both variables.
2631 @var{passfunc} or @var{hook_value} can be @code{NULL}. In this case,
2632 the corresponding value will not be returned.
2636 @node Progress Meter Callback
2637 @subsection Progress Meter Callback
2638 @cindex callback, progress meter
2639 @cindex progress meter callback
2641 @deftp {Data type} {void (*gpgme_progress_cb_t)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
2642 @tindex gpgme_progress_cb_t
2643 The @code{gpgme_progress_cb_t} type is the type of functions usable as
2644 progress callback function.
2646 The arguments are specific to the crypto engine. More information
2647 about the progress information returned from the GnuPG engine can be
2648 found in the GnuPG source code in the file @file{doc/DETAILS} in the
2652 @deftypefun void gpgme_set_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t @var{progfunc}}, @w{void *@var{hook_value}})
2653 The function @code{gpgme_set_progress_cb} sets the function that is
2654 used when progress information about a cryptographic operation is
2655 available. The function @var{progfunc} needs to implemented by the
2656 user, and whenever it is called, it is called with its first argument
2657 being @var{hook_value}. By default, no progress callback function
2660 Setting a callback function allows an interactive program to display
2661 progress information about a long operation to the user.
2663 The user can disable the use of a progress callback function by
2664 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
2668 @deftypefun void gpgme_get_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t *@var{progfunc}}, @w{void **@var{hook_value}})
2669 The function @code{gpgme_get_progress_cb} returns the function that is
2670 used to inform the user about the progress made in @var{*progfunc},
2671 and the first argument for this function in @var{*hook_value}. If no
2672 progress callback is set, or @var{ctx} is not a valid pointer,
2673 @code{NULL} is returned in both variables.
2675 @var{progfunc} or @var{hook_value} can be @code{NULL}. In this case,
2676 the corresponding value will not be returned.
2680 @node Status Message Callback
2681 @subsection Status Message Callback
2682 @cindex callback, status message
2683 @cindex status message callback
2685 @deftp {Data type} {gpgme_error_t (*gpgme_status_cb_t)(void *@var{hook}, const char *@var{keyword}, const char *@var{args})}
2686 @tindex gpgme_status_cb_t
2687 The @code{gpgme_status_cb_t} type is the type of function usable as
2688 a status message callback function.
2690 The argument @var{keyword} is the name of the status message while the
2691 @var{args} argument contains any arguments for the status message.
2693 If an error occurs, return the corresponding @code{gpgme_error_t}
2694 value. Otherwise, return @code{0}.
2697 @deftypefun void gpgme_set_status_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_status_cb_t @var{statusfunc}}, @w{void *@var{hook_value}})
2698 The function @code{gpgme_set_status_cb} sets the function that is used when a
2699 status message is received from gpg to @var{statusfunc}. The function
2700 @var{statusfunc} needs to be implemented by the user, and whenever it is
2701 called, it is called with its first argument being @var{hook_value}. By
2702 default, no status message callback function is set.
2704 The user can disable the use of a status message callback function by calling
2705 @code{gpgme_set_status_cb} with @var{statusfunc} being @code{NULL}.
2708 @deftypefun void gpgme_get_status_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_status_cb_t *@var{statusfunc}}, @w{void **@var{hook_value}})
2709 The function @code{gpgme_get_status_cb} returns the function that is used to
2710 process status messages from gpg in @var{*statusfunc}, and the first argument
2711 for this function in @var{*hook_value}. If no status message callback is set,
2712 or @var{ctx} is not a valid pointer, @code{NULL} is returned in both
2719 @cindex locale, default
2720 @cindex locale, of a context
2722 A locale setting can be associated with a context. This locale is
2723 passed to the crypto engine, and used for applications like the PIN
2724 entry, which is displayed to the user when entering a passphrase is
2727 The default locale is used to initialize the locale setting of all
2728 contexts created afterwards.
2730 @deftypefun gpgme_error_t gpgme_set_locale (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{category}}, @w{const char *@var{value}})
2731 The function @code{gpgme_set_locale} sets the locale of the context
2732 @var{ctx}, or the default locale if @var{ctx} is a null pointer.
2734 The locale settings that should be changed are specified by
2735 @var{category}. Supported categories are @code{LC_CTYPE},
2736 @code{LC_MESSAGES}, and @code{LC_ALL}, which is a wildcard you can use
2737 if you want to change all the categories at once.
2739 The value to be used for the locale setting is @var{value}, which will
2740 be copied to @acronym{GPGME}'s internal data structures. @var{value}
2741 can be a null pointer, which disables setting the locale, and will
2742 make PIN entry and other applications use their default setting, which
2743 is usually not what you want.
2745 Note that the settings are only used if the application runs on a text
2746 terminal, and that the settings should fit the configuration of the
2747 output terminal. Normally, it is sufficient to initialize the default
2750 The function returns an error if not enough memory is available.
2754 @node Key Management
2755 @section Key Management
2756 @cindex key management
2758 Some of the cryptographic operations require that recipients or
2759 signers are specified. This is always done by specifying the
2760 respective keys that should be used for the operation. The following
2761 section describes how such keys can be selected and manipulated.
2763 @deftp {Data type} gpgme_subkey_t
2764 The @code{gpgme_subkey_t} type is a pointer to a subkey structure.
2765 Sub keys are one component of a @code{gpgme_key_t} object. In fact,
2766 subkeys are those parts that contains the real information about the
2767 individual cryptographic keys that belong to the same key object. One
2768 @code{gpgme_key_t} can contain several subkeys. The first subkey in
2769 the linked list is also called the primary key.
2771 The subkey structure has the following members:
2774 @item gpgme_subkey_t next
2775 This is a pointer to the next subkey structure in the linked list, or
2776 @code{NULL} if this is the last element.
2778 @item unsigned int revoked : 1
2779 This is true if the subkey is revoked.
2781 @item unsigned int expired : 1
2782 This is true if the subkey is expired.
2784 @item unsigned int disabled : 1
2785 This is true if the subkey is disabled.
2787 @item unsigned int invalid : 1
2788 This is true if the subkey is invalid.
2790 @item unsigned int can_encrypt : 1
2791 This is true if the subkey can be used for encryption.
2793 @item unsigned int can_sign : 1
2794 This is true if the subkey can be used to create data signatures.
2796 @item unsigned int can_certify : 1
2797 This is true if the subkey can be used to create key certificates.
2799 @item unsigned int can_authenticate : 1
2800 This is true if the subkey can be used for authentication.
2802 @item unsigned int is_qualified : 1
2803 This is true if the subkey can be used for qualified signatures
2804 according to local government regulations.
2806 @item unsigned int secret : 1
2807 This is true if the subkey is a secret key. Note that it will be
2808 false if the key is actually a stub key; i.e. a secret key operation
2809 is currently not possible (offline-key). This is only set if a
2810 listing of secret keys has been requested or if
2811 @code{GPGME_KEYLIST_MODE_WITH_SECRET} is active.
2813 @item gpgme_pubkey_algo_t pubkey_algo
2814 This is the public key algorithm supported by this subkey.
2816 @item unsigned int length
2817 This is the length of the subkey (in bits).
2820 This is the key ID of the subkey in hexadecimal digits.
2823 This is the fingerprint of the subkey in hexadecimal digits, if
2826 @item long int timestamp
2827 This is the creation timestamp of the subkey. This is -1 if the
2828 timestamp is invalid, and 0 if it is not available.
2830 @item long int expires
2831 This is the expiration timestamp of the subkey, or 0 if the subkey
2834 @item unsigned int is_cardkey : 1
2835 True if the secret key is stored on a smart card.
2837 @item char *card_number
2838 The serial number of a smart card holding this key or @code{NULL}.
2841 For ECC algoritms the name of the curve.
2846 @deftp {Data type} gpgme_key_sig_t
2847 The @code{gpgme_key_sig_t} type is a pointer to a key signature structure.
2848 Key signatures are one component of a @code{gpgme_key_t} object, and
2849 validate user IDs on the key.
2851 The signatures on a key are only available if the key was retrieved
2852 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
2853 enabled, because it can be expensive to retrieve all signatures of a
2856 The signature notations on a key signature are only available if the
2857 key was retrieved via a listing operation with the
2858 @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} mode enabled, because it can
2859 be expensive to retrieve all signature notations.
2861 The key signature structure has the following members:
2864 @item gpgme_key_sig_t next
2865 This is a pointer to the next key signature structure in the linked
2866 list, or @code{NULL} if this is the last element.
2868 @item unsigned int revoked : 1
2869 This is true if the key signature is a revocation signature.
2871 @item unsigned int expired : 1
2872 This is true if the key signature is expired.
2874 @item unsigned int invalid : 1
2875 This is true if the key signature is invalid.
2877 @item unsigned int exportable : 1
2878 This is true if the key signature is exportable.
2880 @item gpgme_pubkey_algo_t pubkey_algo
2881 This is the public key algorithm used to create the signature.
2884 This is the key ID of the key (in hexadecimal digits) used to create
2887 @item long int timestamp
2888 This is the creation timestamp of the key signature. This is -1 if
2889 the timestamp is invalid, and 0 if it is not available.
2891 @item long int expires
2892 This is the expiration timestamp of the key signature, or 0 if the key
2893 signature does not expire.
2895 @item gpgme_error_t status
2896 This is the status of the signature and has the same meaning as the
2897 member of the same name in a @code{gpgme_signature_t} object.
2899 @item unsigned int sig_class
2900 This specifies the signature class of the key signature. The meaning
2901 is specific to the crypto engine.
2904 This is the main user ID of the key used to create the signature.
2907 This is the name component of @code{uid}, if available.
2910 This is the comment component of @code{uid}, if available.
2913 This is the email component of @code{uid}, if available.
2915 @item gpgme_sig_notation_t notations
2916 This is a linked list with the notation data and policy URLs.
2920 @deftp {Data type} gpgme_user_id_t
2921 A user ID is a component of a @code{gpgme_key_t} object. One key can
2922 have many user IDs. The first one in the list is the main (or
2925 The user ID structure has the following members.
2928 @item gpgme_user_id_t next
2929 This is a pointer to the next user ID structure in the linked list, or
2930 @code{NULL} if this is the last element.
2932 @item unsigned int revoked : 1
2933 This is true if the user ID is revoked.
2935 @item unsigned int invalid : 1
2936 This is true if the user ID is invalid.
2938 @item gpgme_validity_t validity
2939 This specifies the validity of the user ID.
2942 This is the user ID string.
2945 This is the name component of @code{uid}, if available.
2948 This is the comment component of @code{uid}, if available.
2951 This is the email component of @code{uid}, if available.
2953 @item gpgme_key_sig_t signatures
2954 This is a linked list with the signatures on this user ID.
2958 @deftp {Data type} gpgme_key_t
2959 The @code{gpgme_key_t} type is a pointer to a key object. It has the
2963 @item gpgme_keylist_mode_t keylist_mode
2964 The keylist mode that was active when the key was retrieved.
2966 @item unsigned int revoked : 1
2967 This is true if the key is revoked.
2969 @item unsigned int expired : 1
2970 This is true if the key is expired.
2972 @item unsigned int disabled : 1
2973 This is true if the key is disabled.
2975 @item unsigned int invalid : 1
2976 This is true if the key is invalid. This might have several reasons,
2977 for a example for the S/MIME backend, it will be set in during key
2978 listsing if the key could not be validated due to a missing
2979 certificates or unmatched policies.
2981 @item unsigned int can_encrypt : 1
2982 This is true if the key (ie one of its subkeys) can be used for
2985 @item unsigned int can_sign : 1
2986 This is true if the key (ie one of its subkeys) can be used to create
2989 @item unsigned int can_certify : 1
2990 This is true if the key (ie one of its subkeys) can be used to create
2993 @item unsigned int can_authenticate : 1
2994 This is true if the key (ie one of its subkeys) can be used for
2997 @item unsigned int is_qualified : 1
2998 This is true if the key can be used for qualified signatures according
2999 to local government regulations.
3001 @item unsigned int secret : 1
3002 This is true if the key is a secret key. Note, that this will always
3003 be true even if the corresponding subkey flag may be false
3004 (offline/stub keys). This is only set if a listing of secret keys has
3005 been requested or if @code{GPGME_KEYLIST_MODE_WITH_SECRET} is active.
3007 @item gpgme_protocol_t protocol
3008 This is the protocol supported by this key.
3010 @item char *issuer_serial
3011 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
3014 @item char *issuer_name
3015 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
3018 @item char *chain_id
3019 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
3020 chain ID, which can be used to built the certificate chain.
3022 @item gpgme_validity_t owner_trust
3023 If @code{protocol} is @code{GPGME_PROTOCOL_OpenPGP}, then this is the
3026 @item gpgme_subkey_t subkeys
3027 This is a linked list with the subkeys of the key. The first subkey
3028 in the list is the primary key and usually available.
3030 @item gpgme_user_id_t uids
3031 This is a linked list with the user IDs of the key. The first user ID
3032 in the list is the main (or primary) user ID.
3037 * Listing Keys:: Browsing the list of available keys.
3038 * Information About Keys:: Requesting detailed information about keys.
3039 * Key Signatures:: Listing the signatures on a key.
3040 * Manipulating Keys:: Operations on keys.
3041 * Generating Keys:: Creating new key pairs.
3042 * Exporting Keys:: Retrieving key data from the key ring.
3043 * Importing Keys:: Adding keys to the key ring.
3044 * Deleting Keys:: Removing keys from the key ring.
3045 * Changing Passphrases:: Change the passphrase of a key.
3046 * Advanced Key Editing:: Advanced key edit operation.
3051 @subsection Listing Keys
3052 @cindex listing keys
3054 @cindex key listing, start
3055 @cindex key ring, list
3056 @cindex key ring, search
3058 @deftypefun gpgme_error_t gpgme_op_keylist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
3059 The function @code{gpgme_op_keylist_start} initiates a key listing
3060 operation inside the context @var{ctx}. It sets everything up so that
3061 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
3064 If @var{pattern} is @code{NULL}, all available keys are returned.
3065 Otherwise, @var{pattern} contains an engine specific expression that
3066 is used to limit the list to all keys matching the pattern. Note that
3067 the total length of the pattern is restricted to an engine-specific
3068 maximum (a couple of hundred characters are usually accepted). The
3069 pattern should be used to restrict the search to a certain common name
3070 or user, not to list many specific keys at once by listing their
3071 fingerprints or key IDs.
3073 If @var{secret_only} is not @code{0}, the list is restricted to secret
3076 The context will be busy until either all keys are received (and
3077 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
3078 @code{gpgme_op_keylist_end} is called to finish the operation.
3080 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3081 @var{ctx} is not a valid pointer, and passes through any errors that
3082 are reported by the crypto engine support routines.
3085 @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}})
3086 The function @code{gpgme_op_keylist_ext_start} initiates an extended
3087 key listing operation inside the context @var{ctx}. It sets
3088 everything up so that subsequent invocations of
3089 @code{gpgme_op_keylist_next} return the keys in the list.
3091 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3092 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3093 array of strings that are used to limit the list to all keys matching
3094 at least one of the patterns verbatim. Note that the total length of
3095 all patterns is restricted to an engine-specific maximum (the exact
3096 limit also depends on the number of patterns and amount of quoting
3097 required, but a couple of hundred characters are usually accepted).
3098 Patterns should be used to restrict the search to a certain common
3099 name or user, not to list many specific keys at once by listing their
3100 fingerprints or key IDs.
3102 If @var{secret_only} is not @code{0}, the list is restricted to secret
3105 The value of @var{reserved} must be @code{0}.
3107 The context will be busy until either all keys are received (and
3108 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
3109 @code{gpgme_op_keylist_end} is called to finish the operation.
3111 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3112 @var{ctx} is not a valid pointer, and passes through any errors that
3113 are reported by the crypto engine support routines.
3116 @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}})
3117 The function @code{gpgme_op_keylist_next} returns the next key in the
3118 list created by a previous @code{gpgme_op_keylist_start} operation in
3119 the context @var{ctx}. The key will have one reference for the user.
3120 @xref{Manipulating Keys}.
3122 This is the only way to get at @code{gpgme_key_t} objects in
3125 If the last key in the list has already been returned,
3126 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}.
3128 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3129 @var{ctx} or @var{r_key} is not a valid pointer, and
3130 @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation.
3133 @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}})
3134 The function @code{gpgme_op_keylist_end} ends a pending key list
3135 operation in the context @var{ctx}.
3137 After the operation completed successfully, the result of the key
3138 listing operation can be retrieved with
3139 @code{gpgme_op_keylist_result}.
3141 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3142 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
3143 time during the operation there was not enough memory available.
3146 The following example illustrates how all keys containing a certain
3147 string (@code{g10code}) can be listed with their key ID and the name
3148 and e-mail address of the main user ID:
3153 gpgme_error_t err = gpgme_new (&ctx);
3157 err = gpgme_op_keylist_start (ctx, "g10code", 0);
3160 err = gpgme_op_keylist_next (ctx, &key);
3163 printf ("%s:", key->subkeys->keyid);
3164 if (key->uids && key->uids->name)
3165 printf (" %s", key->uids->name);
3166 if (key->uids && key->uids->email)
3167 printf (" <%s>", key->uids->email);
3169 gpgme_key_release (key);
3171 gpgme_release (ctx);
3173 if (gpg_err_code (err) != GPG_ERR_EOF)
3175 fprintf (stderr, "can not list keys: %s\n", gpgme_strerror (err));
3180 @deftp {Data type} {gpgme_keylist_result_t}
3181 This is a pointer to a structure used to store the result of a
3182 @code{gpgme_op_keylist_*} operation. After successfully ending a key
3183 listing operation, you can retrieve the pointer to the result with
3184 @code{gpgme_op_keylist_result}. The structure contains the following
3188 @item unsigned int truncated : 1
3189 This is true if the crypto backend had to truncate the result, and
3190 less than the desired keys could be listed.
3194 @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}})
3195 The function @code{gpgme_op_keylist_result} returns a
3196 @code{gpgme_keylist_result_t} pointer to a structure holding the
3197 result of a @code{gpgme_op_keylist_*} operation. The pointer is only
3198 valid if the last operation on the context was a key listing
3199 operation, and if this operation finished successfully. The returned
3200 pointer is only valid until the next operation is started on the
3204 In a simple program, for which a blocking operation is acceptable, the
3205 following function can be used to retrieve a single key.
3207 @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}})
3208 The function @code{gpgme_get_key} gets the key with the fingerprint
3209 (or key ID) @var{fpr} from the crypto backend and return it in
3210 @var{r_key}. If @var{secret} is true, get the secret key. The
3211 currently active keylist mode is used to retrieve the key. The key
3212 will have one reference for the user.
3214 If the key is not found in the keyring, @code{gpgme_get_key} returns
3215 the error code @code{GPG_ERR_EOF} and *@var{r_key} will be set to
3218 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3219 @var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a
3220 fingerprint or key ID, @code{GPG_ERR_AMBIGUOUS_NAME} if the key ID was
3221 not a unique specifier for a key, and @code{GPG_ERR_ENOMEM} if at some
3222 time during the operation there was not enough memory available.
3226 @node Information About Keys
3227 @subsection Information About Keys
3228 @cindex key, information about
3229 @cindex key, attributes
3230 @cindex attributes, of a key
3232 Please see the beginning of this section for more information about
3233 @code{gpgme_key_t} objects.
3235 @deftp {Data type} gpgme_validity_t
3236 The @code{gpgme_validity_t} type is used to specify the validity of a user ID
3237 in a key. The following validities are defined:
3240 @item GPGME_VALIDITY_UNKNOWN
3241 The user ID is of unknown validity. The string representation of this
3244 @item GPGME_VALIDITY_UNDEFINED
3245 The validity of the user ID is undefined. The string representation of this
3248 @item GPGME_VALIDITY_NEVER
3249 The user ID is never valid. The string representation of this
3252 @item GPGME_VALIDITY_MARGINAL
3253 The user ID is marginally valid. The string representation of this
3256 @item GPGME_VALIDITY_FULL
3257 The user ID is fully valid. The string representation of this
3260 @item GPGME_VALIDITY_ULTIMATE
3261 The user ID is ultimately valid. The string representation of this
3267 The following interfaces are deprecated and only provided for backward
3268 compatibility. Don't use them. They will be removed in a future
3269 version of @acronym{GPGME}.
3271 @deftp {Data type} gpgme_attr_t
3272 The @code{gpgme_attr_t} type is used to specify a key or trust item
3273 attribute. The following attributes are defined:
3276 @item GPGME_ATTR_KEYID
3277 This is the key ID of a sub key. It is representable as a string.
3279 For trust items, the trust item refers to the key with this ID.
3281 @item GPGME_ATTR_FPR
3282 This is the fingerprint of a sub key. It is representable as a
3285 @item GPGME_ATTR_ALGO
3286 This is the crypto algorithm for which the sub key can be used. It
3287 is representable as a string and as a number. The numbers correspond
3288 to the @code{enum gcry_pk_algos} values in the gcrypt library.
3290 @item GPGME_ATTR_LEN
3291 This is the key length of a sub key. It is representable as a
3294 @item GPGME_ATTR_CREATED
3295 This is the timestamp at creation time of a sub key. It is
3296 representable as a number.
3298 @item GPGME_ATTR_EXPIRE
3299 This is the expiration time of a sub key. It is representable as a
3302 @item GPGME_ATTR_OTRUST
3303 XXX FIXME (also for trust items)
3305 @item GPGME_ATTR_USERID
3306 This is a user ID. There can be more than one user IDs in a
3307 @var{gpgme_key_t} object. The first one (with index 0) is the primary
3308 user ID. The user ID is representable as a number.
3310 For trust items, this is the user ID associated with this trust item.
3312 @item GPGME_ATTR_NAME
3313 This is the name belonging to a user ID. It is representable as a string.
3315 @item GPGME_ATTR_EMAIL
3316 This is the email address belonging to a user ID. It is representable
3319 @item GPGME_ATTR_COMMENT
3320 This is the comment belonging to a user ID. It is representable as a
3323 @item GPGME_ATTR_VALIDITY
3324 This is the validity belonging to a user ID. It is representable as a
3325 string and as a number. See below for a list of available validities.
3327 For trust items, this is the validity that is associated with this
3330 @item GPGME_ATTR_UID_REVOKED
3331 This specifies if a user ID is revoked. It is representable as a
3332 number, and is @code{1} if the user ID is revoked, and @code{0}
3335 @item GPGME_ATTR_UID_INVALID
3336 This specifies if a user ID is invalid. It is representable as a
3337 number, and is @code{1} if the user ID is invalid, and @code{0}
3340 @item GPGME_ATTR_LEVEL
3341 This is the trust level of a trust item.
3343 @item GPGME_ATTR_TYPE
3344 This returns information about the type of key. For the string function
3345 this will eother be "PGP" or "X.509". The integer function returns 0
3346 for PGP and 1 for X.509. It is also used for the type of a trust item.
3348 @item GPGME_ATTR_IS_SECRET
3349 This specifies if the key is a secret key. It is representable as a
3350 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
3352 @item GPGME_ATTR_KEY_REVOKED
3353 This specifies if a sub key is revoked. It is representable as a
3354 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
3356 @item GPGME_ATTR_KEY_INVALID
3357 This specifies if a sub key is invalid. It is representable as a
3358 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
3360 @item GPGME_ATTR_KEY_EXPIRED
3361 This specifies if a sub key is expired. It is representable as a
3362 number, and is @code{1} if the key is expired, and @code{0} otherwise.
3364 @item GPGME_ATTR_KEY_DISABLED
3365 This specifies if a sub key is disabled. It is representable as a
3366 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
3368 @item GPGME_ATTR_KEY_CAPS
3369 This is a description of the capabilities of a sub key. It is
3370 representable as a string. The string contains the letter ``e'' if
3371 the key can be used for encryption, ``s'' if the key can be used for
3372 signatures, and ``c'' if the key can be used for certifications.
3374 @item GPGME_ATTR_CAN_ENCRYPT
3375 This specifies if a sub key can be used for encryption. It is
3376 representable as a number, and is @code{1} if the sub key can be used
3377 for encryption, and @code{0} otherwise.
3379 @item GPGME_ATTR_CAN_SIGN
3380 This specifies if a sub key can be used to create data signatures. It
3381 is representable as a number, and is @code{1} if the sub key can be
3382 used for signatures, and @code{0} otherwise.
3384 @item GPGME_ATTR_CAN_CERTIFY
3385 This specifies if a sub key can be used to create key certificates.
3386 It is representable as a number, and is @code{1} if the sub key can be
3387 used for certifications, and @code{0} otherwise.
3389 @item GPGME_ATTR_SERIAL
3390 The X.509 issuer serial attribute of the key. It is representable as
3393 @item GPGME_ATTR_ISSUE
3394 The X.509 issuer name attribute of the key. It is representable as a
3397 @item GPGME_ATTR_CHAINID
3398 The X.509 chain ID can be used to build the certification chain. It
3399 is representable as a string.
3403 @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}})
3404 The function @code{gpgme_key_get_string_attr} returns the value of the
3405 string-representable attribute @var{what} of key @var{key}. If the
3406 attribute is an attribute of a sub key or an user ID, @var{idx}
3407 specifies the sub key or user ID of which the attribute value is
3408 returned. The argument @var{reserved} is reserved for later use and
3409 should be @code{NULL}.
3411 The string returned is only valid as long as the key is valid.
3413 The function returns @code{0} if an attribute can't be returned as a
3414 string, @var{key} is not a valid pointer, @var{idx} out of range,
3415 or @var{reserved} not @code{NULL}.
3418 @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}})
3419 The function @code{gpgme_key_get_ulong_attr} returns the value of the
3420 number-representable attribute @var{what} of key @var{key}. If the
3421 attribute is an attribute of a sub key or an user ID, @var{idx}
3422 specifies the sub key or user ID of which the attribute value is
3423 returned. The argument @var{reserved} is reserved for later use and
3424 should be @code{NULL}.
3426 The function returns @code{0} if the attribute can't be returned as a
3427 number, @var{key} is not a valid pointer, @var{idx} out of range, or
3428 @var{reserved} not @code{NULL}.
3432 @node Key Signatures
3433 @subsection Key Signatures
3434 @cindex key, signatures
3435 @cindex signatures, on a key
3437 The following interfaces are deprecated and only provided for backward
3438 compatibility. Don't use them. They will be removed in a future
3439 version of @acronym{GPGME}.
3441 The signatures on a key are only available if the key was retrieved
3442 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
3443 enabled, because it is expensive to retrieve all signatures of a key.
3445 So, before using the below interfaces to retrieve the signatures on a
3446 key, you have to make sure that the key was listed with signatures
3447 enabled. One convenient, but blocking, way to do this is to use the
3448 function @code{gpgme_get_key}.
3450 @deftp {Data type} gpgme_attr_t
3451 The @code{gpgme_attr_t} type is used to specify a key signature
3452 attribute. The following attributes are defined:
3455 @item GPGME_ATTR_KEYID
3456 This is the key ID of the key which was used for the signature. It is
3457 representable as a string.
3459 @item GPGME_ATTR_ALGO
3460 This is the crypto algorithm used to create the signature. It is
3461 representable as a string and as a number. The numbers correspond to
3462 the @code{enum gcry_pk_algos} values in the gcrypt library.
3464 @item GPGME_ATTR_CREATED
3465 This is the timestamp at creation time of the signature. It is
3466 representable as a number.
3468 @item GPGME_ATTR_EXPIRE
3469 This is the expiration time of the signature. It is representable as
3472 @item GPGME_ATTR_USERID
3473 This is the user ID associated with the signing key. The user ID is
3474 representable as a number.
3476 @item GPGME_ATTR_NAME
3477 This is the name belonging to a user ID. It is representable as a string.
3479 @item GPGME_ATTR_EMAIL
3480 This is the email address belonging to a user ID. It is representable
3483 @item GPGME_ATTR_COMMENT
3484 This is the comment belonging to a user ID. It is representable as a
3487 @item GPGME_ATTR_KEY_REVOKED
3488 This specifies if a key signature is a revocation signature. It is
3489 representable as a number, and is @code{1} if the key is revoked, and
3492 @c @item GPGME_ATTR_KEY_EXPIRED
3493 @c This specifies if a key signature is expired. It is representable as
3494 @c a number, and is @code{1} if the key is revoked, and @code{0}
3497 @item GPGME_ATTR_SIG_CLASS
3498 This specifies the signature class of a key signature. It is
3499 representable as a number. The meaning is specific to the crypto
3502 @item GPGME_ATTR_SIG_CLASS
3503 This specifies the signature class of a key signature. It is
3504 representable as a number. The meaning is specific to the crypto
3507 @item GPGME_ATTR_SIG_STATUS
3508 This is the same value as returned by @code{gpgme_get_sig_status}.
3512 @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}})
3513 The function @code{gpgme_key_sig_get_string_attr} returns the value of
3514 the string-representable attribute @var{what} of the signature
3515 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3516 argument @var{reserved} is reserved for later use and should be
3519 The string returned is only valid as long as the key is valid.
3521 The function returns @code{0} if an attribute can't be returned as a
3522 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3523 out of range, or @var{reserved} not @code{NULL}.
3526 @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}})
3527 The function @code{gpgme_key_sig_get_ulong_attr} returns the value of
3528 the number-representable attribute @var{what} of the signature
3529 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3530 argument @var{reserved} is reserved for later use and should be
3533 The function returns @code{0} if an attribute can't be returned as a
3534 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3535 out of range, or @var{reserved} not @code{NULL}.
3539 @node Manipulating Keys
3540 @subsection Manipulating Keys
3541 @cindex key, manipulation
3543 @deftypefun void gpgme_key_ref (@w{gpgme_key_t @var{key}})
3544 The function @code{gpgme_key_ref} acquires an additional reference for
3548 @deftypefun void gpgme_key_unref (@w{gpgme_key_t @var{key}})
3549 The function @code{gpgme_key_unref} releases a reference for the key
3550 @var{key}. If this was the last reference, the key will be destroyed
3551 and all resources associated to it will be released.
3555 The following interface is deprecated and only provided for backward
3556 compatibility. Don't use it. It will be removed in a future version
3559 @deftypefun void gpgme_key_release (@w{gpgme_key_t @var{key}})
3560 The function @code{gpgme_key_release} is equivalent to
3561 @code{gpgme_key_unref}.
3565 @node Generating Keys
3566 @subsection Generating Keys
3567 @cindex key, creation
3568 @cindex key ring, add
3570 @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}})
3571 The function @code{gpgme_op_genkey} generates a new key pair in the
3572 context @var{ctx}. The meaning of @var{public} and @var{secret}
3573 depends on the crypto backend.
3575 GnuPG does not support @var{public} and @var{secret}, they should be
3576 @code{NULL}. GnuPG will generate a key pair and add it to the
3577 standard key ring. The fingerprint of the generated key is available
3578 with @code{gpgme_op_genkey_result}.
3580 GpgSM requires @var{public} to be a writable data object. GpgSM will
3581 generate a secret key (which will be stored by @command{gpg-agent},
3582 and return a certificate request in @var{public}, which then needs to
3583 be signed by the certification authority and imported before it can be
3584 used. GpgSM does not make the fingerprint available.
3586 The argument @var{parms} specifies parameters for the key in an XML
3587 string. The details about the format of @var{parms} are specific to
3588 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
3589 the crypto engine (all parameters of OpenPGP key generation are
3590 documented in the GPG manual):
3593 <GnupgKeyParms format="internal">
3595 Subkey-Type: default
3596 Name-Real: Joe Tester
3597 Name-Comment: with stupid passphrase
3598 Name-Email: joe@@foo.bar
3604 Here is an example for GpgSM as the crypto engine (all parameters of
3605 OpenPGP key generation are documented in the GPGSM manual):
3608 <GnupgKeyParms format="internal">
3611 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3612 Name-Email: joe@@foo.bar
3616 Strings should be given in UTF-8 encoding. The only format supported
3617 for now is ``internal''. The content of the @code{GnupgKeyParms}
3618 container is passed verbatim to the crypto backend. Control
3619 statements are not allowed.
3621 After the operation completed successfully, the result can be
3622 retrieved with @code{gpgme_op_genkey_result}.
3624 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3625 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3626 @var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if
3627 @var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL}
3628 if no key was created by the backend.
3631 @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}})
3632 The function @code{gpgme_op_genkey_start} initiates a
3633 @code{gpgme_op_genkey} operation. It can be completed by calling
3634 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3636 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3637 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3638 @var{parms} is not a valid XML string, and
3639 @code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not
3643 @deftp {Data type} {gpgme_genkey_result_t}
3644 This is a pointer to a structure used to store the result of a
3645 @code{gpgme_op_genkey} operation. After successfully generating a
3646 key, you can retrieve the pointer to the result with
3647 @code{gpgme_op_genkey_result}. The structure contains the following
3651 @item unsigned int primary : 1
3652 This is a flag that is set to 1 if a primary key was created and to 0
3655 @item unsigned int sub : 1
3656 This is a flag that is set to 1 if a subkey was created and to 0
3660 This is the fingerprint of the key that was created. If both a
3661 primary and a sub key were generated, the fingerprint of the primary
3662 key will be returned. If the crypto engine does not provide the
3663 fingerprint, @code{fpr} will be a null pointer.
3667 @deftypefun gpgme_genkey_result_t gpgme_op_genkey_result (@w{gpgme_ctx_t @var{ctx}})
3668 The function @code{gpgme_op_genkey_result} returns a
3669 @code{gpgme_genkey_result_t} pointer to a structure holding the result of
3670 a @code{gpgme_op_genkey} operation. The pointer is only valid if the
3671 last operation on the context was a @code{gpgme_op_genkey} or
3672 @code{gpgme_op_genkey_start} operation, and if this operation finished
3673 successfully. The returned pointer is only valid until the next
3674 operation is started on the context.
3678 @node Exporting Keys
3679 @subsection Exporting Keys
3681 @cindex key ring, export from
3683 Exporting keys means the same as running @command{gpg} with the command
3684 @option{--export}. However, a mode flag can be used to change the way
3685 the export works. The available mode flags are described below, they
3686 may be or-ed together.
3690 @item GPGME_EXPORT_MODE_EXTERN
3691 If this bit is set, the output is send directly to the default
3692 keyserver. This is currently only allowed for OpenPGP keys. It is good
3693 practise to not send more than a few dozens key to a keyserver at one
3694 time. Using this flag requires that the @var{keydata} argument of the
3695 export function is set to @code{NULL}.
3697 @item GPGME_EXPORT_MODE_MINIMAL
3698 If this bit is set, the smallest possible key is exported. For OpenPGP
3699 keys it removes all signatures except for the latest self-signatures.
3700 For X.509 keys it has no effect.
3707 @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}})
3708 The function @code{gpgme_op_export} extracts public keys and returns
3709 them in the data buffer @var{keydata}. The output format of the key
3710 data returned is determined by the @acronym{ASCII} armor attribute set
3711 for the context @var{ctx}, or, if that is not set, by the encoding
3712 specified for @var{keydata}.
3714 If @var{pattern} is @code{NULL}, all available keys are returned.
3715 Otherwise, @var{pattern} contains an engine specific expression that
3716 is used to limit the list to all keys matching the pattern.
3718 @var{mode} is usually 0; other values are described above.
3720 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3721 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3722 @var{keydata} is not a valid empty data buffer, and passes through any
3723 errors that are reported by the crypto engine support routines.
3726 @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}})
3727 The function @code{gpgme_op_export_start} initiates a
3728 @code{gpgme_op_export} 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 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3733 if @var{keydata} is not a valid empty data buffer.
3736 @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}})
3737 The function @code{gpgme_op_export} extracts public keys and returns
3738 them in the data buffer @var{keydata}. The output format of the key
3739 data returned is determined by the @acronym{ASCII} armor attribute set
3740 for the context @var{ctx}, or, if that is not set, by the encoding
3741 specified for @var{keydata}.
3743 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3744 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3745 array of strings that are used to limit the list to all keys matching
3746 at least one of the patterns verbatim.
3748 @var{mode} is usually 0; other values are described above.
3750 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3751 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3752 @var{keydata} is not a valid empty data buffer, and passes through any
3753 errors that are reported by the crypto engine support routines.
3756 @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}})
3757 The function @code{gpgme_op_export_ext_start} initiates a
3758 @code{gpgme_op_export_ext} operation. It can be completed by calling
3759 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3761 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3762 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3763 if @var{keydata} is not a valid empty data buffer.
3767 @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}})
3768 The function @code{gpgme_op_export_keys} extracts public keys and returns
3769 them in the data buffer @var{keydata}. The output format of the key
3770 data returned is determined by the @acronym{ASCII} armor attribute set
3771 for the context @var{ctx}, or, if that is not set, by the encoding
3772 specified for @var{keydata}.
3774 The keys to export are taken form the @code{NULL} terminated array
3775 @var{keys}. Only keys of the the currently selected protocol of
3776 @var{ctx} which do have a fingerprint set are considered for export.
3777 Other keys specified by the @var{keys} are ignored. In particular
3778 OpenPGP keys retrieved via an external key listing are not included.
3780 @var{mode} is usually 0; other values are described above.
3782 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3783 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3784 @var{keydata} is not a valid empty data buffer, @code{GPG_ERR_NO_DATA}
3785 if no useful keys are in @var{keys} and passes through any errors that
3786 are reported by the crypto engine support routines.
3789 @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}})
3790 The function @code{gpgme_op_export_keys_start} initiates a
3791 @code{gpgme_op_export_ext} operation. It can be completed by calling
3792 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3794 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3795 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3796 if @var{keydata} is not a valid empty data buffer, @code{GPG_ERR_NO_DATA}
3797 if no useful keys are in @var{keys} and passes through any errors that
3798 are reported by the crypto engine support routines.
3802 @node Importing Keys
3803 @subsection Importing Keys
3805 @cindex key ring, import to
3807 Importing keys means the same as running @command{gpg} with the command
3811 @deftypefun gpgme_error_t gpgme_op_import (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3812 The function @code{gpgme_op_import} adds the keys in the data buffer
3813 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
3814 The format of @var{keydata} can be @acronym{ASCII} armored, for example,
3815 but the details are specific to the crypto engine.
3817 After the operation completed successfully, the result can be
3818 retrieved with @code{gpgme_op_import_result}.
3820 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3821 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3822 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3823 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3826 @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3827 The function @code{gpgme_op_import_start} initiates a
3828 @code{gpgme_op_import} operation. It can be completed by calling
3829 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3831 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3832 import could be started successfully, @code{GPG_ERR_INV_VALUE} if
3833 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3834 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3837 @deftypefun gpgme_error_t gpgme_op_import_keys (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{keys}})
3838 The function @code{gpgme_op_import_keys} adds the keys described by the
3839 @code{NULL} terminated array @var{keys} to the key ring of the crypto
3840 engine used by @var{ctx}. This function is the general interface to
3841 move a key from one crypto engine to another as long as they are
3842 compatible. In particular it is used to actually import and make keys
3843 permanent which have been retrieved from an external source (i.e. using
3844 @code{GPGME_KEYLIST_MODE_EXTERN}). @footnote{Thus it is a replacement
3845 for the usual workaround of exporting and then importing a key to make
3846 an X.509 key permanent.}
3848 Only keys of the the currently selected protocol of @var{ctx} are
3849 considered for import. Other keys specified by the @var{keys} are
3850 ignored. As of now all considered keys must have been retrieved using
3851 the same method, that is the used key listing mode must be identical.
3853 After the operation completed successfully, the result can be
3854 retrieved with @code{gpgme_op_import_result}.
3856 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3857 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3858 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3859 @code{GPG_ERR_CONFLICT} if the key listing mode does not match, and
3860 @code{GPG_ERR_NO_DATA} if no keys are considered for export.
3863 @deftypefun gpgme_error_t gpgme_op_import_keys_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{keys}})
3864 The function @code{gpgme_op_import_keys_start} initiates a
3865 @code{gpgme_op_import_keys} operation. It can be completed by calling
3866 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3868 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3869 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3870 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3871 @code{GPG_ERR_CONFLICT} if the key listing mode does not match, and
3872 @code{GPG_ERR_NO_DATA} if no keys are considered for export.
3875 @deftp {Data type} {gpgme_import_status_t}
3876 This is a pointer to a structure used to store a part of the result of
3877 a @code{gpgme_op_import} operation. For each considered key one
3878 status is added that contains information about the result of the
3879 import. The structure contains the following members:
3882 @item gpgme_import_status_t next
3883 This is a pointer to the next status structure in the linked list, or
3884 @code{NULL} if this is the last element.
3887 This is the fingerprint of the key that was considered.
3889 @item gpgme_error_t result
3890 If the import was not successful, this is the error value that caused
3891 the import to fail. Otherwise the error code is
3892 @code{GPG_ERR_NO_ERROR}.
3894 @item unsigned int status
3895 This is a bit-wise OR of the following flags that give more
3896 information about what part of the key was imported. If the key was
3897 already known, this might be 0.
3900 @item GPGME_IMPORT_NEW
3903 @item GPGME_IMPORT_UID
3904 The key contained new user IDs.
3906 @item GPGME_IMPORT_SIG
3907 The key contained new signatures.
3909 @item GPGME_IMPORT_SUBKEY
3910 The key contained new sub keys.
3912 @item GPGME_IMPORT_SECRET
3913 The key contained a secret key.
3918 @deftp {Data type} {gpgme_import_result_t}
3919 This is a pointer to a structure used to store the result of a
3920 @code{gpgme_op_import} operation. After a successful import
3921 operation, you can retrieve the pointer to the result with
3922 @code{gpgme_op_import_result}. The structure contains the following
3926 @item int considered
3927 The total number of considered keys.
3929 @item int no_user_id
3930 The number of keys without user ID.
3933 The total number of imported keys.
3936 The number of imported RSA keys.
3939 The number of unchanged keys.
3942 The number of new user IDs.
3945 The number of new sub keys.
3947 @item new_signatures
3948 The number of new signatures.
3950 @item new_revocations
3951 The number of new revocations.
3954 The total number of secret keys read.
3956 @item secret_imported
3957 The number of imported secret keys.
3959 @item secret_unchanged
3960 The number of unchanged secret keys.
3963 The number of keys not imported.
3965 @item gpgme_import_status_t imports
3966 A list of gpgme_import_status_t objects which contain more information
3967 about the keys for which an import was attempted.
3971 @deftypefun gpgme_import_result_t gpgme_op_import_result (@w{gpgme_ctx_t @var{ctx}})
3972 The function @code{gpgme_op_import_result} returns a
3973 @code{gpgme_import_result_t} pointer to a structure holding the result
3974 of a @code{gpgme_op_import} operation. The pointer is only valid if
3975 the last operation on the context was a @code{gpgme_op_import} or
3976 @code{gpgme_op_import_start} operation, and if this operation finished
3977 successfully. The returned pointer is only valid until the next
3978 operation is started on the context.
3981 The following interface is deprecated and only provided for backward
3982 compatibility. Don't use it. It will be removed in a future version
3985 @deftypefun gpgme_error_t gpgme_op_import_ext (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}}, @w{int *@var{nr}})
3986 The function @code{gpgme_op_import_ext} is equivalent to:
3989 gpgme_error_t err = gpgme_op_import (ctx, keydata);
3992 gpgme_import_result_t result = gpgme_op_import_result (ctx);
3993 *nr = result->considered;
4000 @subsection Deleting Keys
4002 @cindex key ring, delete from
4004 @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}})
4005 The function @code{gpgme_op_delete} deletes the key @var{key} from the
4006 key ring of the crypto engine used by @var{ctx}. If
4007 @var{allow_secret} is @code{0}, only public keys are deleted,
4008 otherwise secret keys are deleted as well, if that is supported.
4010 The function returns the error code @code{GPG_ERR_NO_ERROR} if the key
4011 was deleted successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} or
4012 @var{key} is not a valid pointer, @code{GPG_ERR_NO_PUBKEY} if
4013 @var{key} could not be found in the keyring,
4014 @code{GPG_ERR_AMBIGUOUS_NAME} if the key was not specified
4015 unambiguously, and @code{GPG_ERR_CONFLICT} if the secret key for
4016 @var{key} is available, but @var{allow_secret} is zero.
4019 @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}})
4020 The function @code{gpgme_op_delete_start} initiates a
4021 @code{gpgme_op_delete} operation. It can be completed by calling
4022 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4024 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4025 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
4026 @var{ctx} or @var{key} is not a valid pointer.
4030 @node Changing Passphrases
4031 @subsection Changing Passphrases
4032 @cindex passphrase, change
4034 @deftypefun gpgme_error_t gpgme_op_passwd @
4035 (@w{gpgme_ctx_t @var{ctx}}, @
4036 @w{const gpgme_key_t @var{key}}, @
4037 @w{unsigned int @var{flags}})
4039 The function @code{gpgme_op_passwd} changes the passphrase of the
4040 private key associated with @var{key}. The only allowed value for
4041 @var{flags} is @code{0}. The backend engine will usually popup a window
4042 to ask for the old and the new passphrase. Thus this function is not
4043 useful in a server application (where passphrases are not required
4046 Note that old @code{gpg} engines (before version 2.0.15) do not support
4047 this command and will silently ignore it.
4050 @deftypefun gpgme_error_t gpgme_op_passwd_start @
4051 (@w{gpgme_ctx_t @var{ctx}}, @
4052 @w{const gpgme_key_t @var{key}}, @
4053 @w{unsigned int @var{flags}})
4055 The function @code{gpgme_op_passwd_start} initiates a
4056 @code{gpgme_op_passwd} operation. It can be completed by calling
4057 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4059 The function returns @code{0} if the operation was started successfully,
4060 and an error code if one of the arguments is not valid or the oepration
4061 could not be started.
4065 @node Advanced Key Editing
4066 @subsection Advanced Key Editing
4069 @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}})}
4070 @tindex gpgme_edit_cb_t
4071 The @code{gpgme_edit_cb_t} type is the type of functions which
4072 @acronym{GPGME} calls if it a key edit operation is on-going. The
4073 status code @var{status} and the argument line @var{args} are passed
4074 through by @acronym{GPGME} from the crypto engine. The file
4075 descriptor @var{fd} is -1 for normal status messages. If @var{status}
4076 indicates a command rather than a status message, the response to the
4077 command should be written to @var{fd}. The @var{handle} is provided
4078 by the user at start of operation.
4080 The function should return @code{GPG_ERR_NO_ERROR} or an error value.
4083 @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}})
4084 The function @code{gpgme_op_edit} processes the key @var{KEY}
4085 interactively, using the edit callback function @var{FNC} with the
4086 handle @var{HANDLE}. The callback is invoked for every status and
4087 command request from the crypto engine. The output of the crypto
4088 engine is written to the data object @var{out}.
4090 Note that the protocol between the callback function and the crypto
4091 engine is specific to the crypto engine and no further support in
4092 implementing this protocol correctly is provided by @acronym{GPGME}.
4094 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4095 edit operation completes successfully, @code{GPG_ERR_INV_VALUE} if
4096 @var{ctx} or @var{key} is not a valid pointer, and any error returned
4097 by the crypto engine or the edit callback handler.
4100 @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}})
4101 The function @code{gpgme_op_edit_start} initiates a
4102 @code{gpgme_op_edit} operation. It can be completed by calling
4103 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4105 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4106 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
4107 @var{ctx} or @var{key} is not a valid pointer.
4111 @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}})
4112 The function @code{gpgme_op_card_edit} is analogous to
4113 @code{gpgme_op_edit}, but should be used to process the smart card corresponding to the key @var{key}.
4116 @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}})
4117 The function @code{gpgme_op_card_edit_start} initiates a
4118 @code{gpgme_op_card_edit} operation. It can be completed by calling
4119 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4121 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4122 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
4123 @var{ctx} or @var{key} is not a valid pointer.
4127 @node Trust Item Management
4128 @section Trust Item Management
4131 @strong{Caution:} The trust items interface is experimental.
4133 @deftp {Data type} gpgme_trust_item_t
4134 The @code{gpgme_trust_item_t} type is a pointer to a trust item object.
4135 It has the following members:
4139 This is a string describing the key to which this trust items belongs.
4142 This is the type of the trust item. A value of 1 refers to a key, a
4143 value of 2 refers to a user ID.
4146 This is the trust level.
4148 @item char *owner_trust
4149 The owner trust if @code{type} is 1.
4151 @item char *validity
4152 The calculated validity.
4155 The user name if @code{type} is 2.
4160 * Listing Trust Items:: Browsing the list of available trust items.
4161 * Information About Trust Items:: Requesting information about trust items.
4162 * Manipulating Trust Items:: Operations on trust items.
4166 @node Listing Trust Items
4167 @subsection Listing Trust Items
4168 @cindex trust item list
4170 @deftypefun gpgme_error_t gpgme_op_trustlist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}})
4171 The function @code{gpgme_op_trustlist_start} initiates a trust item
4172 listing operation inside the context @var{ctx}. It sets everything up
4173 so that subsequent invocations of @code{gpgme_op_trustlist_next} return
4174 the trust items in the list.
4176 The string @var{pattern} contains an engine specific expression that
4177 is used to limit the list to all trust items matching the pattern. It
4178 can not be the empty string.
4180 The argument @var{max_level} is currently ignored.
4182 The context will be busy until either all trust items are received
4183 (and @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}), or
4184 @code{gpgme_op_trustlist_end} is called to finish the operation.
4186 The function returns the error code @code{GPG_ERR_INV_VALUE} if
4187 @var{ctx} is not a valid pointer, and passes through any errors that
4188 are reported by the crypto engine support routines.
4191 @deftypefun gpgme_error_t gpgme_op_trustlist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_trust_item_t *@var{r_item}})
4192 The function @code{gpgme_op_trustlist_next} returns the next trust
4193 item in the list created by a previous @code{gpgme_op_trustlist_start}
4194 operation in the context @var{ctx}. The trust item can be destroyed
4195 with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}.
4197 This is the only way to get at @code{gpgme_trust_item_t} objects in
4200 If the last trust item in the list has already been returned,
4201 @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}.
4203 The function returns the error code @code{GPG_ERR_INV_VALUE} if @var{ctx} or
4204 @var{r_item} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if
4205 there is not enough memory for the operation.
4208 @deftypefun gpgme_error_t gpgme_op_trustlist_end (@w{gpgme_ctx_t @var{ctx}})
4209 The function @code{gpgme_op_trustlist_end} ends a pending trust list
4210 operation in the context @var{ctx}.
4212 The function returns the error code @code{GPG_ERR_INV_VALUE} if
4213 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
4214 time during the operation there was not enough memory available.
4218 @node Information About Trust Items
4219 @subsection Information About Trust Items
4220 @cindex trust item, information about
4221 @cindex trust item, attributes
4222 @cindex attributes, of a trust item
4224 The following interfaces are deprecated and only provided for backward
4225 compatibility. Don't use them. They will be removed in a future
4226 version of @acronym{GPGME}.
4228 Trust items have attributes which can be queried using the interfaces
4229 below. The attribute identifiers are shared with those for key
4230 attributes. @xref{Information About Keys}.
4232 @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}})
4233 The function @code{gpgme_trust_item_get_string_attr} returns the value
4234 of the string-representable attribute @var{what} of trust item
4235 @var{item}. The arguments @var{idx} and @var{reserved} are reserved
4236 for later use and should be @code{0} and @code{NULL} respectively.
4238 The string returned is only valid as long as the key is valid.
4240 The function returns @code{0} if an attribute can't be returned as a
4241 string, @var{key} is not a valid pointer, @var{idx} out of range,
4242 or @var{reserved} not @code{NULL}.
4245 @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}})
4246 The function @code{gpgme_trust_item_get_int_attr} returns the value of
4247 the number-representable attribute @var{what} of trust item
4248 @var{item}. If the attribute occurs more than once in the trust item,
4249 the index is specified by @var{idx}. However, currently no such
4250 attribute exists, so @var{idx} should be @code{0}. The argument
4251 @var{reserved} is reserved for later use and should be @code{NULL}.
4253 The function returns @code{0} if the attribute can't be returned as a
4254 number, @var{key} is not a valid pointer, @var{idx} out of range,
4255 or @var{reserved} not @code{NULL}.
4259 @node Manipulating Trust Items
4260 @subsection Manipulating Trust Items
4261 @cindex trust item, manipulation
4263 @deftypefun void gpgme_trust_item_ref (@w{gpgme_trust_item_t @var{item}})
4264 The function @code{gpgme_trust_item_ref} acquires an additional
4265 reference for the trust item @var{item}.
4268 @deftypefun void gpgme_trust_item_unref (@w{gpgme_trust_item_t @var{item}})
4269 The function @code{gpgme_trust_item_unref} releases a reference for
4270 the trust item @var{item}. If this was the last reference, the trust
4271 item will be destroyed and all resources associated to it will be
4276 The following interface is deprecated and only provided for backward
4277 compatibility. Don't use it. It will be removed in a future version
4280 @deftypefun void gpgme_trust_item_release (@w{gpgme_trust_item_t @var{item}})
4281 The function @code{gpgme_trust_item_release} is an alias for
4282 @code{gpgme_trust_item_unref}.
4286 @node Crypto Operations
4287 @section Crypto Operations
4288 @cindex cryptographic operation
4290 Sometimes, the result of a crypto operation returns a list of invalid
4291 keys encountered in processing the request. The following structure
4292 is used to hold information about such a key.
4294 @deftp {Data type} {gpgme_invalid_key_t}
4295 This is a pointer to a structure used to store a part of the result of
4296 a crypto operation which takes user IDs as one input parameter. The
4297 structure contains the following members:
4300 @item gpgme_invalid_key_t next
4301 This is a pointer to the next invalid key structure in the linked
4302 list, or @code{NULL} if this is the last element.
4305 The fingerprint or key ID of the invalid key encountered.
4307 @item gpgme_error_t reason
4308 An error code describing the reason why the key was found invalid.
4314 * Decrypt:: Decrypting a ciphertext.
4315 * Verify:: Verifying a signature.
4316 * Decrypt and Verify:: Decrypting a signed ciphertext.
4317 * Sign:: Creating a signature.
4318 * Encrypt:: Encrypting a plaintext.
4325 @cindex cryptographic operation, decryption
4327 @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}})
4328 The function @code{gpgme_op_decrypt} decrypts the ciphertext in the
4329 data object @var{cipher} and stores it into the data object
4332 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4333 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
4334 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
4335 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
4336 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
4337 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
4338 secret key could not be retrieved, and passes through any errors that
4339 are reported by the crypto engine support routines.
4342 @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}})
4343 The function @code{gpgme_op_decrypt_start} initiates a
4344 @code{gpgme_op_decrypt} operation. It can be completed by calling
4345 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
4347 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4348 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
4349 if @var{cipher} or @var{plain} is not a valid pointer.