1 \input texinfo @c -*- mode: texinfo; coding: latin-1; -*-
2 @documentencoding ISO-8859-1
3 @setfilename gpgme.info
4 @settitle The `GnuPG Made Easy' Reference Manual
6 @dircategory GNU Libraries
8 * @acronym{GPGME}: (gpgme). Adding support for cryptography to your program.
11 @c Unify some of the indices.
16 Copyright @copyright{} 2002, 2003, 2004, 2005, 2006, 2007, 2008 g10 Code GmbH.
19 Permission is granted to copy, distribute and/or modify this document
20 under the terms of the GNU General Public License as published by the
21 Free Software Foundation; either version 3 of the License, or (at your
22 option) any later version. The text of the license can be found in the
23 section entitled ``Copying''.
26 This document is distributed in the hope that it will be useful, but
27 WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 General Public License for more details.
34 @c Macros used by the description of the UI server protocol
47 This file documents the @acronym{GPGME} library.
49 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
50 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
53 @c NOTE: Don't forget to update the year for the TeX version, too.
58 @c We do not want that bastard short titlepage.
60 @c @shorttitlepage The `GnuPG Made Easy' Reference Manual
63 @center @titlefont{The `GnuPG Made Easy'}
65 @center @titlefont{Reference Manual}
67 @center Edition @value{EDITION}
69 @center last updated @value{UPDATED}
71 @center for version @value{VERSION}
73 @vskip 0pt plus 1filll
74 Published by g10 Code GmbH@* Hüttenstr. 61@* 40699 Erkrath, Germany
86 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
87 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
88 @value{VERSION} of the @acronym{GPGME} library.
92 * Introduction:: How to use this manual.
93 * Preparation:: What you should do before using the library.
94 * Protocols and Engines:: Supported crypto protocols.
95 * Algorithms:: Supported algorithms.
96 * Error Handling:: Error numbers and their meanings.
97 * Exchanging Data:: Passing data to and from @acronym{GPGME}.
98 * Contexts:: Handling @acronym{GPGME} contexts.
102 * UI Server Protocol:: The GnuPG UI Server Protocol.
104 * Library Copying:: The GNU Lesser General Public License says
105 how you can copy and share `GnuPG Made Easy'.
106 * Copying:: The GNU General Public License says how you
107 can copy and share this manual.
111 * Concept Index:: Index of concepts and programs.
112 * Function and Data Index:: Index of functions, variables and data types.
116 --- The Detailed Node Listing ---
120 * Getting Started:: Purpose of the manual, and how to use it.
121 * Features:: Reasons to install and use @acronym{GPGME}.
122 * Overview:: Basic architecture of the @acronym{GPGME} library.
126 * Header:: What header file you need to include.
127 * Building the Source:: Compiler options to be used.
128 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
129 * Using Automake:: Compiler options to be used the easy way.
130 * Using Libtool:: Avoiding compiler options entirely.
131 * Library Version Check:: Getting and verifying the library version.
132 * Signal Handling:: How @acronym{GPGME} affects signal handling.
133 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
135 Protocols and Engines
137 * Engine Version Check:: Verifying the engine version.
138 * Engine Information:: Obtaining more information about the engines.
139 * Engine Configuration:: Changing the engine configuration.
140 * OpenPGP:: Support for the OpenPGP protocol.
141 * Cryptographic Message Syntax:: Support for the CMS.
145 * Public Key Algorithms:: A list of all public key algorithms.
146 * Hash Algorithms:: A list of all hash algorithms.
150 * Error Values:: The error value and what it means.
151 * Error Codes:: A list of important error codes.
152 * Error Sources:: A list of important error sources.
153 * Error Strings:: How to get a descriptive string from a value.
157 * Creating Data Buffers:: Creating new data buffers.
158 * Destroying Data Buffers:: Releasing data buffers.
159 * Manipulating Data Buffers:: Operations on data buffers.
161 Creating Data Buffers
163 * Memory Based Data Buffers:: Creating memory based data buffers.
164 * File Based Data Buffers:: Creating file based data buffers.
165 * Callback Based Data Buffers:: Creating callback based data buffers.
167 Manipulating Data Buffers
169 * Data Buffer I/O Operations:: I/O operations on data buffers.
170 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
174 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
175 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
176 * Context Attributes:: Setting properties of a context.
177 * Key Management:: Managing keys with @acronym{GPGME}.
178 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
179 * Crypto Operations:: Using a context for cryptography.
180 * Run Control:: Controlling how operations are run.
184 * Protocol Selection:: Selecting the protocol used by a context.
185 * Crypto Engine:: Configuring the crypto engine.
186 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
187 * Text Mode:: Choosing canonical text mode.
188 * Included Certificates:: Including a number of certificates.
189 * Key Listing Mode:: Selecting key listing mode.
190 * Passphrase Callback:: Getting the passphrase from the user.
191 * Progress Meter Callback:: Being informed about the progress.
192 * Locale:: Setting the locale of a context.
196 * Listing Keys:: Browsing the list of available keys.
197 * Information About Keys:: Requesting detailed information about keys.
198 * Key Signatures:: Listing the signatures on a key.
199 * Manipulating Keys:: Operations on keys.
200 * Generating Keys:: Creating new key pairs.
201 * Exporting Keys:: Retrieving key data from the key ring.
202 * Importing Keys:: Adding keys to the key ring.
203 * Deleting Keys:: Removing keys from the key ring.
204 * Advanced Key Editing:: Advanced key edit operation.
206 Trust Item Management
208 * Listing Trust Items:: Browsing the list of available trust items.
209 * Information About Trust Items:: Requesting information about trust items.
210 * Manipulating Trust Items:: Operations on trust items.
214 * Decrypt:: Decrypting a ciphertext.
215 * Verify:: Verifying a signature.
216 * Decrypt and Verify:: Decrypting a signed ciphertext.
217 * Sign:: Creating a signature.
218 * Encrypt:: Encrypting a plaintext.
222 * Selecting Signers:: How to choose the keys to sign with.
223 * Creating a Signature:: How to create a signature.
224 * Signature Notation Data:: How to add notation data to a signature.
228 * Encrypting a Plaintext:: How to encrypt a plaintext.
232 * Waiting For Completion:: Waiting until an operation is completed.
233 * Using External Event Loops:: Advanced control over what happens when.
234 * Cancellation:: How to end pending operations prematurely.
236 Using External Event Loops
238 * I/O Callback Interface:: How I/O callbacks are registered.
239 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
240 * I/O Callback Example:: An example how to use I/O callbacks.
241 * I/O Callback Example GTK+:: How to integrate @acronym{GPGME} in GTK+.
242 * I/O Callback Example GDK:: How to integrate @acronym{GPGME} in GDK.
243 * I/O Callback Example Qt:: How to integrate @acronym{GPGME} in Qt.
249 @chapter Introduction
251 `GnuPG Made Easy' (@acronym{GPGME}) is a C language library that
252 allows to add support for cryptography to a program. It is designed
253 to make access to public key crypto engines like GnuPG or GpgSM easier
254 for applications. @acronym{GPGME} provides a high-level crypto API
255 for encryption, decryption, signing, signature verification and key
258 @acronym{GPGME} uses GnuPG and GpgSM as its backends to support
259 OpenPGP and the Cryptographic Message Syntax (CMS).
262 * Getting Started:: Purpose of the manual, and how to use it.
263 * Features:: Reasons to install and use @acronym{GPGME}.
264 * Overview:: Basic architecture of the @acronym{GPGME} library.
268 @node Getting Started
269 @section Getting Started
271 This manual documents the @acronym{GPGME} library programming
272 interface. All functions and data types provided by the library are
275 The reader is assumed to possess basic knowledge about cryptography in
276 general, and public key cryptography in particular. The underlying
277 cryptographic engines that are used by the library are not explained,
278 but where necessary, special features or requirements by an engine are
279 mentioned as far as they are relevant to @acronym{GPGME} or its users.
281 This manual can be used in several ways. If read from the beginning
282 to the end, it gives a good introduction into the library and how it
283 can be used in an application. Forward references are included where
284 necessary. Later on, the manual can be used as a reference manual to
285 get just the information needed about any particular interface of the
286 library. Experienced programmers might want to start looking at the
287 examples at the end of the manual, and then only read up those parts
288 of the interface which are unclear.
294 @acronym{GPGME} has a couple of advantages over other libraries doing
295 a similar job, and over implementing support for GnuPG or other crypto
296 engines into your application directly.
299 @item it's free software
300 Anybody can use, modify, and redistribute it under the terms of the GNU
301 Lesser General Public License (@pxref{Library Copying}).
304 @acronym{GPGME} provides transparent support for several cryptographic
305 protocols by different engines. Currently, @acronym{GPGME} supports
306 the OpenPGP protocol using GnuPG as the backend, and the Cryptographic
307 Message Syntax using GpgSM as the backend.
310 @acronym{GPGME} hides the differences between the protocols and
311 engines from the programmer behind an easy-to-use interface. This way
312 the programmer can focus on the other parts of the program, and still
313 integrate strong cryptography in his application. Once support for
314 @acronym{GPGME} has been added to a program, it is easy to add support
315 for other crypto protocols once @acronym{GPGME} backends provide them.
322 @acronym{GPGME} provides a data abstraction that is used to pass data
323 to the crypto engine, and receive returned data from it. Data can be
324 read from memory or from files, but it can also be provided by a
327 The actual cryptographic operations are always set within a context.
328 A context provides configuration parameters that define the behaviour
329 of all operations performed within it. Only one operation per context
330 is allowed at any time, but when one operation is finished, you can
331 run the next operation in the same context. There can be more than
332 one context, and all can run different operations at the same time.
334 Furthermore, @acronym{GPGME} has rich key management facilities
335 including listing keys, querying their attributes, generating,
336 importing, exporting and deleting keys, and acquiring information
337 about the trust path.
339 With some precautions, @acronym{GPGME} can be used in a multi-threaded
340 environment, although it is not completely thread safe and thus needs
341 the support of the application.
347 To use @acronym{GPGME}, you have to perform some changes to your
348 sources and the build system. The necessary changes are small and
349 explained in the following sections. At the end of this chapter, it
350 is described how the library is initialized, and how the requirements
351 of the library are verified.
354 * Header:: What header file you need to include.
355 * Building the Source:: Compiler options to be used.
356 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
357 * Using Automake:: Compiler options to be used the easy way.
358 * Using Libtool:: Avoiding compiler options entirely.
359 * Library Version Check:: Getting and verifying the library version.
360 * Signal Handling:: How @acronym{GPGME} affects signal handling.
361 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
370 All interfaces (data types and functions) of the library are defined
371 in the header file `gpgme.h'. You must include this in all programs
372 using the library, either directly or through some other header file,
379 The name space of @acronym{GPGME} is @code{gpgme_*} for function names
380 and data types and @code{GPGME_*} for other symbols. Symbols internal
381 to @acronym{GPGME} take the form @code{_gpgme_*} and @code{_GPGME_*}.
383 Because @acronym{GPGME} makes use of the GPG Error library, using
384 @acronym{GPGME} will also use the @code{GPG_ERR_*} name space
385 directly, and the @code{gpg_err*} and @code{gpg_str*} name space
389 @node Building the Source
390 @section Building the Source
391 @cindex compiler options
392 @cindex compiler flags
394 If you want to compile a source file including the `gpgme.h' header
395 file, you must make sure that the compiler can find it in the
396 directory hierarchy. This is accomplished by adding the path to the
397 directory in which the header file is located to the compilers include
398 file search path (via the @option{-I} option).
400 However, the path to the include file is determined at the time the
401 source is configured. To solve this problem, gpgme ships with a small
402 helper program @command{gpgme-config} that knows about the path to the
403 include file and other configuration options. The options that need
404 to be added to the compiler invocation at compile time are output by
405 the @option{--cflags} option to @command{gpgme-config}. The following
406 example shows how it can be used at the command line:
409 gcc -c foo.c `gpgme-config --cflags`
412 Adding the output of @samp{gpgme-config --cflags} to the compiler
413 command line will ensure that the compiler can find the
414 @acronym{GPGME} header file.
416 A similar problem occurs when linking the program with the library.
417 Again, the compiler has to find the library files. For this to work,
418 the path to the library files has to be added to the library search
419 path (via the @option{-L} option). For this, the option
420 @option{--libs} to @command{gpgme-config} can be used. For
421 convenience, this option also outputs all other options that are
422 required to link the program with @acronym{GPGME} (in particular, the
423 @samp{-lgpgme} option). The example shows how to link @file{foo.o}
424 with the @acronym{GPGME} library to a program @command{foo}.
427 gcc -o foo foo.o `gpgme-config --libs`
430 Of course you can also combine both examples to a single command by
431 specifying both options to @command{gpgme-config}:
434 gcc -o foo foo.c `gpgme-config --cflags --libs`
437 If you want to link to one of the thread-safe versions of
438 @acronym{GPGME}, you must specify the @option{--thread} option before
439 any other option to select the thread package you want to link with.
440 Supported thread packages are @option{--thread=pth} and
441 @option{--thread=pthread}.
444 @node Largefile Support (LFS)
445 @section Largefile Support (LFS)
446 @cindex largefile support
449 @acronym{GPGME} is compiled with largefile support by default, if it
450 is available on the system. This means that GPGME supports files
451 larger than two gigabyte in size, if the underlying operating system
452 can. On some systems, largefile support is already the default. On
453 such systems, nothing special is required. However, some systems
454 provide only support for files up to two gigabyte in size by default.
455 Support for larger file sizes has to be specifically enabled.
457 To make a difficult situation even more complex, such systems provide
458 two different types of largefile support. You can either get all
459 relevant functions replaced with alternatives that are largefile
460 capable, or you can get new functions and data types for largefile
461 support added. Those new functions have the same name as their
462 smallfile counterparts, but with a suffix of 64.
464 An example: The data type @code{off_t} is 32 bit wide on GNU/Linux PC
465 systems. To address offsets in large files, you can either enable
466 largefile support add-on. Then a new data type @code{off64_t} is
467 provided, which is 64 bit wide. Or you can replace the existing
468 @code{off_t} data type with its 64 bit wide counterpart. All
469 occurences of @code{off_t} are then automagically replaced.
471 As if matters were not complex enough, there are also two different
472 types of file descriptors in such systems. This is important because
473 if file descriptors are exchanged between programs that use a
474 different maximum file size, certain errors must be produced on some
475 file descriptors to prevent subtle overflow bugs from occuring.
477 As you can see, supporting two different maximum file sizes at the
478 same time is not at all an easy task. However, the maximum file size
479 does matter for @acronym{GPGME}, because some data types it uses in
480 its interfaces are affected by that. For example, the @code{off_t}
481 data type is used in the @code{gpgme_data_seek} function, to match its
482 @acronym{POSIX} counterpart. This affects the call-frame of the
483 function, and thus the ABI of the library. Furthermore, file
484 descriptors can be exchanged between GPGME and the application.
486 For you as the user of the library, this means that your program must
487 be compiled in the same file size mode as the library. Luckily, there
488 is absolutely no valid reason for new programs to not enable largefile
489 support by default and just use that. The compatibility modes (small
490 file sizes or dual mode) can be considered an historic artefact, only
491 useful to allow for a transitional period.
493 @acronym{GPGME} is compiled using largefile support by default. This
494 means that your application must do the same, at least as far as it is
495 relevant for using the @file{gpgme.h} header file. All types in this
496 header files refer to their largefile counterparts, if they are
497 different from any default types on the system.
499 You can enable largefile support, if it is different from the default
500 on the system the application is compiled on, by using the Autoconf
501 macro @code{AC_SYS_LARGEFILE}. If you do this, then you don't need to
502 worry about anything else: It will just work. In this case you might
503 also want to use @code{AC_FUNC_FSEEKO} to take advantage of some new
504 interfaces, and @code{AC_TYPE_OFF_T} (just in case).
506 If you do not use Autoconf, you can define the preprocessor symbol
507 @code{_FILE_OFFSET_BITS} to 64 @emph{before} including any header
508 files, for example by specifying the option
509 @code{-D_FILE_OFFSET_BITS=64} on the compiler command line. You will
510 also want to define the preprocessor symbol @code{LARGEFILE_SOURCE} to
511 1 in this case, to take advantage of some new interfaces.
513 If you do not want to do either of the above, you probably know enough
514 about the issue to invent your own solution. Just keep in mind that
515 the @acronym{GPGME} header file expects that largefile support is
516 enabled, if it is available. In particular, we do not support dual
517 mode (@code{_LARGEFILE64_SOURCE}).
521 @section Using Automake
525 It is much easier if you use GNU Automake instead of writing your own
526 Makefiles. If you do that you do not have to worry about finding and
527 invoking the @command{gpgme-config} script at all. @acronym{GPGME}
528 provides an extension to Automake that does all the work for you.
530 @c A simple macro for optional variables.
532 @r{[}@var{\varname\}@r{]}
534 @defmac AM_PATH_GPGME (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
535 @defmacx AM_PATH_GPGME_PTH (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
536 @defmacx AM_PATH_GPGME_PTHREAD (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
537 Check whether @acronym{GPGME} (at least version @var{minimum-version},
538 if given) exists on the host system. If it is found, execute
539 @var{action-if-found}, otherwise do @var{action-if-not-found}, if
542 Additionally, the function defines @code{GPGME_CFLAGS} to the flags
543 needed for compilation of the program to find the @file{gpgme.h}
544 header file, and @code{GPGME_LIBS} to the linker flags needed to link
545 the program to the @acronym{GPGME} library.
547 @code{AM_PATH_GPGME_PTH} checks for the version of @acronym{GPGME}
548 that can be used with GNU Pth, and defines @code{GPGME_PTH_CFLAGS} and
549 @code{GPGME_PTH_LIBS}.
551 @code{AM_PATH_GPGME_PTHREAD} checks for the version of @acronym{GPGME}
552 that can be used with the native pthread implementation, and defines
553 @code{GPGME_PTHREAD_CFLAGS} and @code{GPGME_PTHREAD_LIBS}.
556 You can use the defined Autoconf variables like this in your
560 AM_CPPFLAGS = $(GPGME_CFLAGS)
561 LDADD = $(GPGME_LIBS)
566 @section Using Libtool
569 The easiest way is to just use GNU Libtool. If you use libtool, and
570 link to @code{libgpgme.la}, @code{libgpgme-pth.la} or
571 @code{libgpgme-pthread.la} respectively, everything will be done
572 automatically by Libtool.
575 @node Library Version Check
576 @section Library Version Check
577 @cindex version check, of the library
579 @deftypefun {const char *} gpgme_check_version (@w{const char *@var{required_version}})
580 The function @code{gpgme_check_version} has four purposes. It can be
581 used to retrieve the version number of the library. In addition it
582 can verify that the version number is higher than a certain required
583 version number. In either case, the function initializes some
584 sub-systems, and for this reason alone it must be invoked early in
585 your program, before you make use of the other functions in
586 @acronym{GPGME}. The last purpose is to run selftests.
588 As a side effect for W32 based systems, the socket layer will get
592 If @var{required_version} is @code{NULL}, the function returns a
593 pointer to a statically allocated string containing the version number
596 If @var{required_version} is not @code{NULL}, it should point to a
597 string containing a version number, and the function checks that the
598 version of the library is at least as high as the version number
599 provided. In this case, the function returns a pointer to a
600 statically allocated string containing the version number of the
601 library. If @var{REQUIRED_VERSION} is not a valid version number, or
602 if the version requirement is not met, the function returns
605 If you use a version of a library that is backwards compatible with
606 older releases, but contains additional interfaces which your program
607 uses, this function provides a run-time check if the necessary
608 features are provided by the installed version of the library.
610 If a selftest fails, the function may still succeed. Selftest errors
611 are returned later when invoking @code{gpgme_new}, so that a detailed
612 error code can be returned (historically, @code{gpgme_check_version}
613 does not return a detailed error code).
617 After initializing @acronym{GPGME}, you should set the locale
618 information to the locale required for your output terminal. This
619 locale information is needed for example for the curses and Gtk
620 pinentry. Here is an example of a complete initialization:
629 /* Initialize the locale environment. */
630 setlocale (LC_ALL, "");
631 gpgme_check_version (NULL);
632 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
634 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
639 Note that you are highly recommended to initialize the locale settings
640 like this. @acronym{GPGME} can not do this for you because it would
641 not be thread safe. The conditional on LC_MESSAGES is only necessary
642 for portability to W32 systems.
645 @node Signal Handling
646 @section Signal Handling
648 @cindex signal handling
650 The @acronym{GPGME} library communicates with child processes (the
651 crypto engines). If a child process dies unexpectedly, for example
652 due to a bug, or system problem, a @code{SIGPIPE} signal will be
653 delivered to the application. The default action is to abort the
654 program. To protect against this, @code{gpgme_check_version} sets the
655 @code{SIGPIPE} signal action to @code{SIG_IGN}, which means that the
656 signal will be ignored.
658 @acronym{GPGME} will only do that if the signal action for
659 @code{SIGPIPE} is @code{SIG_DEF} at the time
660 @code{gpgme_check_version} is called. If it is something different,
661 @code{GPGME} will take no action.
663 This means that if your application does not install any signal
664 handler for @code{SIGPIPE}, you don't need to take any precautions.
665 If you do install a signal handler for @code{SIGPIPE}, you must be
666 prepared to handle any @code{SIGPIPE} events that occur due to
667 @acronym{GPGME} writing to a defunct pipe. Furthermore, if your
668 application is multi-threaded, and you install a signal action for
669 @code{SIGPIPE}, you must make sure you do this either before
670 @code{gpgme_check_version} is called or afterwards.
673 @node Multi Threading
674 @section Multi Threading
675 @cindex thread-safeness
676 @cindex multi-threading
678 The @acronym{GPGME} library is not entirely thread-safe, but it can
679 still be used in a multi-threaded environment if some care is taken.
680 If the following requirements are met, there should be no race
681 conditions to worry about:
685 @acronym{GPGME} supports the thread libraries pthread and GNU Pth.
686 The support for this has to be enabled at compile time.
687 @acronym{GPGME} will automatically detect the location in which the
688 thread libraries are installed and activate the support for them at
691 Support for other thread libraries is very easy to add. Please
692 contact us if you have the need.
695 If you want to use @acronym{GPGME} with threads, you must link to the
696 right version of the library. The name of the right library is
697 @code{libgpgme-} followed by the name of the thread package you use.
698 For example, if you use GNU Pth, the right name is
699 @code{libgpgme-pth}. Use the Automake macros or
700 @command{gpgme-config} program for simplicity.
704 The function @code{gpgme_check_version} must be called before any
705 other function in the library, because it initializes the thread
706 support subsystem in @acronym{GPGME}. To achieve this in
707 multi-threaded programs, you must synchronize the memory with respect
708 to other threads that also want to use @acronym{GPGME}. For this, it
709 is sufficient to call @code{gpgme_check_version} before creating the
710 other threads using @acronym{GPGME}@footnote{At least this is true for
711 POSIX threads, as @code{pthread_create} is a function that
712 synchronizes memory with respects to other threads. There are many
713 functions which have this property, a complete list can be found in
714 POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the
715 definition of the term ``Memory Synchronization''. For other thread
716 packages other, more relaxed or more strict rules may apply.}.
719 Any @code{gpgme_data_t} and @code{gpgme_ctx_t} object must only be
720 accessed by one thread at a time. If multiple threads want to deal
721 with the same object, the caller has to make sure that operations on
722 that object are fully synchronized.
725 Only one thread at any time is allowed to call @code{gpgme_wait}. If
726 multiple threads call this function, the caller must make sure that
727 all invocations are fully synchronized. It is safe to start
728 asynchronous operations while a thread is running in gpgme_wait.
731 The function @code{gpgme_strerror} is not thread safe. You have to
732 use @code{gpgme_strerror_r} instead.
736 @node Protocols and Engines
737 @chapter Protocols and Engines
740 @cindex crypto engine
742 @cindex crypto backend
744 @acronym{GPGME} supports several cryptographic protocols, however, it
745 does not implement them. Rather it uses backends (also called
746 engines) which implement the protocol. @acronym{GPGME} uses
747 inter-process communication to pass data back and forth between the
748 application and the backend, but the details of the communication
749 protocol and invocation of the backend is completely hidden by the
750 interface. All complexity is handled by @acronym{GPGME}. Where an
751 exchange of information between the application and the backend is
752 necessary, @acronym{GPGME} provides the necessary callback function
753 hooks and further interfaces.
755 @deftp {Data type} {enum gpgme_protocol_t}
756 @tindex gpgme_protocol_t
757 The @code{gpgme_protocol_t} type specifies the set of possible protocol
758 values that are supported by @acronym{GPGME}. The following protocols
762 @item GPGME_PROTOCOL_OpenPGP
763 This specifies the OpenPGP protocol.
765 @item GPGME_PROTOCOL_CMS
766 This specifies the Cryptographic Message Syntax.
768 @item GPGME_PROTOCOL_UNKNOWN
769 Reserved for future extension. You may use this to indicate that the
770 used protocol is not known to the application. Currently,
771 @acronym{GPGME} does not accept this value in any operation, though,
772 except for @code{gpgme_get_protocol_name}.
777 @deftypefun {const char *} gpgme_get_protocol_name (@w{gpgme_protocol_t @var{protocol}})
778 The function @code{gpgme_get_protocol_name} returns a statically
779 allocated string describing the protocol @var{protocol}, or
780 @code{NULL} if the protocol number is not valid.
784 * Engine Version Check:: Verifying the engine version.
785 * Engine Information:: Obtaining more information about the engines.
786 * Engine Configuration:: Changing the engine configuration.
787 * OpenPGP:: Support for the OpenPGP protocol.
788 * Cryptographic Message Syntax:: Support for the CMS.
792 @node Engine Version Check
793 @section Engine Version Check
794 @cindex version check, of the engines
796 @deftypefun gpgme_error_t gpgme_engine_check_version (@w{gpgme_protocol_t @var{protocol}})
797 The function @code{gpgme_engine_check_version} verifies that the
798 engine implementing the protocol @var{PROTOCOL} is installed in the
799 expected path and meets the version requirement of @acronym{GPGME}.
801 This function returns the error code @code{GPG_ERR_NO_ERROR} if the
802 engine is available and @code{GPG_ERR_INV_ENGINE} if it is not.
806 @node Engine Information
807 @section Engine Information
808 @cindex engine, information about
810 @deftp {Data type} {gpgme_engine_info_t}
811 @tindex gpgme_protocol_t
812 The @code{gpgme_engine_info_t} type specifies a pointer to a structure
813 describing a crypto engine. The structure contains the following
817 @item gpgme_engine_info_t next
818 This is a pointer to the next engine info structure in the linked
819 list, or @code{NULL} if this is the last element.
821 @item gpgme_protocol_t protocol
822 This is the protocol for which the crypto engine is used. You can
823 convert this to a string with @code{gpgme_get_protocol_name} for
826 @item const char *file_name
827 This is a string holding the file name of the executable of the crypto
828 engine. Currently, it is never @code{NULL}, but using @code{NULL} is
829 reserved for future use, so always check before you use it.
831 @item const char *home_dir
832 This is a string holding the directory name of the crypto engine's
833 configuration directory. If it is @code{NULL}, then the default
836 @item const char *version
837 This is a string containing the version number of the crypto engine.
838 It might be @code{NULL} if the version number can not be determined,
839 for example because the executable doesn't exist or is invalid.
841 @item const char *req_version
842 This is a string containing the minimum required version number of the
843 crypto engine for @acronym{GPGME} to work correctly. This is the
844 version number that @code{gpgme_engine_check_version} verifies
845 against. Currently, it is never @code{NULL}, but using @code{NULL} is
846 reserved for future use, so always check before you use it.
850 @deftypefun gpgme_error_t gpgme_get_engine_info (@w{gpgme_engine_info_t *@var{info}})
851 The function @code{gpgme_get_engine_info} returns a linked list of
852 engine info structures in @var{info}. Each info structure describes
853 the defaults of one configured backend.
855 The memory for the info structures is allocated the first time this
856 function is invoked, and must not be freed by the caller.
858 This function returns the error code @code{GPG_ERR_NO_ERROR} if
859 successful, and a system error if the memory could not be allocated.
862 Here is an example how you can provide more diagnostics if you receive
863 an error message which indicates that the crypto engine is invalid.
871 if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
873 gpgme_engine_info_t info;
874 err = gpgme_get_engine_info (&info);
877 while (info && info->protocol != gpgme_get_protocol (ctx))
880 fprintf (stderr, "GPGME compiled without support for protocol %s",
881 gpgme_get_protocol_name (info->protocol));
882 else if (info->file_name && !info->version)
883 fprintf (stderr, "Engine %s not installed properly",
885 else if (info->file_name && info->version && info->req_version)
886 fprintf (stderr, "Engine %s version %s installed, "
887 "but at least version %s required", info->file_name,
888 info->version, info->req_version);
890 fprintf (stderr, "Unknown problem with engine for protocol %s",
891 gpgme_get_protocol_name (info->protocol));
897 @node Engine Configuration
898 @section Engine Configuration
899 @cindex engine, configuration of
900 @cindex configuration of crypto backend
902 You can change the configuration of a backend engine, and thus change
903 the executable program and configuration directory to be used. You
904 can make these changes the default or set them for some contexts
907 @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}})
908 The function @code{gpgme_set_engine_info} changes the default
909 configuration of the crypto engine implementing the protocol
912 @var{file_name} is the file name of the executable program
913 implementing this protocol, and @var{home_dir} is the directory name
914 of the configuration directory for this crypto engine. If
915 @var{home_dir} is @code{NULL}, the engine's default will be used.
917 The new defaults are not applied to already created GPGME contexts.
919 This function returns the error code @code{GPG_ERR_NO_ERROR} if
920 successful, or an eror code on failure.
923 The functions @code{gpgme_ctx_get_engine_info} and
924 @code{gpgme_ctx_set_engine_info} can be used to change the engine
925 configuration per context. @xref{Crypto Engine}.
932 @cindex protocol, GnuPG
933 @cindex engine, GnuPG
935 OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard.
936 This is the first protocol that was supported by @acronym{GPGME}.
938 The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}.
941 @node Cryptographic Message Syntax
942 @section Cryptographic Message Syntax
944 @cindex cryptographic message syntax
946 @cindex protocol, CMS
947 @cindex engine, GpgSM
949 @cindex protocol, S/MIME
951 @acronym{CMS} is implemented by GpgSM, the S/MIME implementation for
954 The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}.
961 The crypto backends support a variety of algorithms used in public key
962 cryptography.@footnote{Some engines also provide symmetric only
963 encryption; see the description of the encryption function on how to use
964 this.} The following sections list the identifiers used to denote such
968 * Public Key Algorithms:: A list of all public key algorithms.
969 * Hash Algorithms:: A list of all hash algorithms.
973 @node Public Key Algorithms
974 @section Public Key Algorithms
975 @cindex algorithms, public key
976 @cindex public key algorithms
978 Public key algorithms are used for encryption, decryption, signing and
979 verification of signatures.
981 @deftp {Data type} {enum gpgme_pubkey_algo_t}
982 @tindex gpgme_pubkey_algo_t
983 The @code{gpgme_pubkey_algo_t} type specifies the set of all public key
984 algorithms that are supported by @acronym{GPGME}. Possible values
989 This value indicates the RSA (Rivest, Shamir, Adleman) algorithm.
992 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
993 algorithm for encryption and decryption only.
996 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
997 algorithm for signing and verification only.
1000 This value indicates DSA, the Digital Signature Algorithm.
1003 This value indicates ElGamal.
1005 @item GPGME_PK_ELG_E
1006 This value also indicates ElGamal and is used specifically in GnuPG.
1010 @deftypefun {const char *} gpgme_pubkey_algo_name (@w{gpgme_pubkey_algo_t @var{algo}})
1011 The function @code{gpgme_pubkey_algo_name} returns a pointer to a
1012 statically allocated string containing a description of the public key
1013 algorithm @var{algo}. This string can be used to output the name of
1014 the public key algorithm to the user.
1016 If @var{algo} is not a valid public key algorithm, @code{NULL} is
1021 @node Hash Algorithms
1022 @section Hash Algorithms
1023 @cindex algorithms, hash
1024 @cindex algorithms, message digest
1025 @cindex hash algorithms
1026 @cindex message digest algorithms
1028 Hash (message digest) algorithms are used to compress a long message
1029 to make it suitable for public key cryptography.
1031 @deftp {Data type} {enum gpgme_hash_algo_t}
1032 @tindex gpgme_hash_algo_t
1033 The @code{gpgme_hash_algo_t} type specifies the set of all hash algorithms
1034 that are supported by @acronym{GPGME}. Possible values are:
1039 @item GPGME_MD_RMD160
1041 @item GPGME_MD_TIGER
1042 @item GPGME_MD_HAVAL
1043 @item GPGME_MD_SHA256
1044 @item GPGME_MD_SHA384
1045 @item GPGME_MD_SHA512
1047 @item GPGME_MD_CRC32
1048 @item GPGME_MD_CRC32_RFC1510
1049 @item GPGME_MD_CRC24_RFC2440
1053 @deftypefun {const char *} gpgme_hash_algo_name (@w{gpgme_hash_algo_t @var{algo}})
1054 The function @code{gpgme_hash_algo_name} returns a pointer to a
1055 statically allocated string containing a description of the hash
1056 algorithm @var{algo}. This string can be used to output the name of
1057 the hash algorithm to the user.
1059 If @var{algo} is not a valid hash algorithm, @code{NULL} is returned.
1063 @node Error Handling
1064 @chapter Error Handling
1065 @cindex error handling
1067 Many functions in @acronym{GPGME} can return an error if they fail.
1068 For this reason, the application should always catch the error
1069 condition and take appropriate measures, for example by releasing the
1070 resources and passing the error up to the caller, or by displaying a
1071 descriptive message to the user and cancelling the operation.
1073 Some error values do not indicate a system error or an error in the
1074 operation, but the result of an operation that failed properly. For
1075 example, if you try to decrypt a tempered message, the decryption will
1076 fail. Another error value actually means that the end of a data
1077 buffer or list has been reached. The following descriptions explain
1078 for many error codes what they mean usually. Some error values have
1079 specific meanings if returned by a certain functions. Such cases are
1080 described in the documentation of those functions.
1082 @acronym{GPGME} uses the @code{libgpg-error} library. This allows to
1083 share the error codes with other components of the GnuPG system, and
1084 thus pass error values transparently from the crypto engine, or some
1085 helper application of the crypto engine, to the user. This way no
1086 information is lost. As a consequence, @acronym{GPGME} does not use
1087 its own identifiers for error codes, but uses those provided by
1088 @code{libgpg-error}. They usually start with @code{GPG_ERR_}.
1090 However, @acronym{GPGME} does provide aliases for the functions
1091 defined in libgpg-error, which might be preferred for name space
1095 * Error Values:: The error value and what it means.
1096 * Error Sources:: A list of important error sources.
1097 * Error Codes:: A list of important error codes.
1098 * Error Strings:: How to get a descriptive string from a value.
1103 @section Error Values
1104 @cindex error values
1106 @cindex error sources
1108 @deftp {Data type} {gpgme_err_code_t}
1109 The @code{gpgme_err_code_t} type is an alias for the @code{libgpg-error}
1110 type @code{gpg_err_code_t}. The error code indicates the type of an
1111 error, or the reason why an operation failed.
1113 A list of important error codes can be found in the next section.
1116 @deftp {Data type} {gpgme_err_source_t}
1117 The @code{gpgme_err_source_t} type is an alias for the
1118 @code{libgpg-error} type @code{gpg_err_source_t}. The error source
1119 has not a precisely defined meaning. Sometimes it is the place where
1120 the error happened, sometimes it is the place where an error was
1121 encoded into an error value. Usually the error source will give an
1122 indication to where to look for the problem. This is not always true,
1123 but it is attempted to achieve this goal.
1125 A list of important error sources can be found in the next section.
1128 @deftp {Data type} {gpgme_error_t}
1129 The @code{gpgme_error_t} type is an alias for the @code{libgpg-error}
1130 type @code{gpg_error_t}. An error value like this has always two
1131 components, an error code and an error source. Both together form the
1134 Thus, the error value can not be directly compared against an error
1135 code, but the accessor functions described below must be used.
1136 However, it is guaranteed that only 0 is used to indicate success
1137 (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of
1138 the error value are set to 0, too.
1140 Note that in @acronym{GPGME}, the error source is used purely for
1141 diagnostical purposes. Only the error code should be checked to test
1142 for a certain outcome of a function. The manual only documents the
1143 error code part of an error value. The error source is left
1144 unspecified and might be anything.
1147 @deftypefun {static inline gpgme_err_code_t} gpgme_err_code (@w{gpgme_error_t @var{err}})
1148 The static inline function @code{gpgme_err_code} returns the
1149 @code{gpgme_err_code_t} component of the error value @var{err}. This
1150 function must be used to extract the error code from an error value in
1151 order to compare it with the @code{GPG_ERR_*} error code macros.
1154 @deftypefun {static inline gpgme_err_source_t} gpgme_err_source (@w{gpgme_error_t @var{err}})
1155 The static inline function @code{gpgme_err_source} returns the
1156 @code{gpgme_err_source_t} component of the error value @var{err}. This
1157 function must be used to extract the error source from an error value in
1158 order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros.
1161 @deftypefun {static inline gpgme_error_t} gpgme_err_make (@w{gpgme_err_source_t @var{source}}, @w{gpgme_err_code_t @var{code}})
1162 The static inline function @code{gpgme_err_make} returns the error
1163 value consisting of the error source @var{source} and the error code
1166 This function can be used in callback functions to construct an error
1167 value to return it to the library.
1170 @deftypefun {static inline gpgme_error_t} gpgme_error (@w{gpgme_err_code_t @var{code}})
1171 The static inline function @code{gpgme_error} returns the error value
1172 consisting of the default error source and the error code @var{code}.
1174 For @acronym{GPGME} applications, the default error source is
1175 @code{GPG_ERR_SOURCE_USER_1}. You can define
1176 @code{GPGME_ERR_SOURCE_DEFAULT} before including @file{gpgme.h} to
1177 change this default.
1179 This function can be used in callback functions to construct an error
1180 value to return it to the library.
1183 The @code{libgpg-error} library provides error codes for all system
1184 error numbers it knows about. If @var{err} is an unknown error
1185 number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The
1186 following functions can be used to construct error values from system
1189 @deftypefun {gpgme_error_t} gpgme_err_make_from_errno (@w{gpgme_err_source_t @var{source}}, @w{int @var{err}})
1190 The function @code{gpgme_err_make_from_errno} is like
1191 @code{gpgme_err_make}, but it takes a system error like @code{errno}
1192 instead of a @code{gpgme_err_code_t} error code.
1195 @deftypefun {gpgme_error_t} gpgme_error_from_errno (@w{int @var{err}})
1196 The function @code{gpgme_error_from_errno} is like @code{gpgme_error},
1197 but it takes a system error like @code{errno} instead of a
1198 @code{gpgme_err_code_t} error code.
1201 Sometimes you might want to map system error numbers to error codes
1202 directly, or map an error code representing a system error back to the
1203 system error number. The following functions can be used to do that.
1205 @deftypefun {gpgme_err_code_t} gpgme_err_code_from_errno (@w{int @var{err}})
1206 The function @code{gpgme_err_code_from_errno} returns the error code
1207 for the system error @var{err}. If @var{err} is not a known system
1208 error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}.
1211 @deftypefun {int} gpgme_err_code_to_errno (@w{gpgme_err_code_t @var{err}})
1212 The function @code{gpgme_err_code_to_errno} returns the system error
1213 for the error code @var{err}. If @var{err} is not an error code
1214 representing a system error, or if this system error is not defined on
1215 this system, the function returns @code{0}.
1220 @section Error Sources
1221 @cindex error codes, list of
1223 The library @code{libgpg-error} defines an error source for every
1224 component of the GnuPG system. The error source part of an error
1225 value is not well defined. As such it is mainly useful to improve the
1226 diagnostic error message for the user.
1228 If the error code part of an error value is @code{0}, the whole error
1229 value will be @code{0}. In this case the error source part is of
1230 course @code{GPG_ERR_SOURCE_UNKNOWN}.
1232 The list of error sources that might occur in applications using
1236 @item GPG_ERR_SOURCE_UNKNOWN
1237 The error source is not known. The value of this error source is
1240 @item GPG_ERR_SOURCE_GPGME
1241 The error source is @acronym{GPGME} itself. This is the default for
1242 errors that occur in the @acronym{GPGME} library.
1244 @item GPG_ERR_SOURCE_GPG
1245 The error source is GnuPG, which is the crypto engine used for the
1248 @item GPG_ERR_SOURCE_GPGSM
1249 The error source is GPGSM, which is the crypto engine used for the
1252 @item GPG_ERR_SOURCE_GCRYPT
1253 The error source is @code{libgcrypt}, which is used by crypto engines
1254 to perform cryptographic operations.
1256 @item GPG_ERR_SOURCE_GPGAGENT
1257 The error source is @command{gpg-agent}, which is used by crypto
1258 engines to perform operations with the secret key.
1260 @item GPG_ERR_SOURCE_PINENTRY
1261 The error source is @command{pinentry}, which is used by
1262 @command{gpg-agent} to query the passphrase to unlock a secret key.
1264 @item GPG_ERR_SOURCE_SCD
1265 The error source is the SmartCard Daemon, which is used by
1266 @command{gpg-agent} to delegate operations with the secret key to a
1269 @item GPG_ERR_SOURCE_KEYBOX
1270 The error source is @code{libkbx}, a library used by the crypto
1271 engines to manage local keyrings.
1273 @item GPG_ERR_SOURCE_USER_1
1274 @item GPG_ERR_SOURCE_USER_2
1275 @item GPG_ERR_SOURCE_USER_3
1276 @item GPG_ERR_SOURCE_USER_4
1277 These error sources are not used by any GnuPG component and can be
1278 used by other software. For example, applications using
1279 @acronym{GPGME} can use them to mark error values coming from callback
1280 handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors
1281 created with @code{gpgme_error} and @code{gpgme_error_from_errno},
1282 unless you define @code{GPGME_ERR_SOURCE_DEFAULT} before including
1288 @section Error Codes
1289 @cindex error codes, list of
1291 The library @code{libgpg-error} defines many error values. Most of
1292 them are not used by @code{GPGME} directly, but might be returned by
1293 @acronym{GPGME} because it received them from the crypto engine. The
1294 below list only includes such error codes that have a specific meaning
1295 in @code{GPGME}, or which are so common that you should know about
1300 This value indicates the end of a list, buffer or file.
1302 @item GPG_ERR_NO_ERROR
1303 This value indicates success. The value of this error code is
1304 @code{0}. Also, it is guaranteed that an error value made from the
1305 error code @code{0} will be @code{0} itself (as a whole). This means
1306 that the error source information is lost for this error code,
1307 however, as this error code indicates that no error occured, this is
1308 generally not a problem.
1310 @item GPG_ERR_GENERAL
1311 This value means that something went wrong, but either there is not
1312 enough information about the problem to return a more useful error
1313 value, or there is no separate error value for this type of problem.
1315 @item GPG_ERR_ENOMEM
1316 This value means that an out-of-memory condition occurred.
1319 System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
1322 @item GPG_ERR_INV_VALUE
1323 This value means that some user provided data was out of range. This
1324 can also refer to objects. For example, if an empty
1325 @code{gpgme_data_t} object was expected, but one containing data was
1326 provided, this error value is returned.
1328 @item GPG_ERR_UNUSABLE_PUBKEY
1329 This value means that some recipients for a message were invalid.
1331 @item GPG_ERR_UNUSABLE_SECKEY
1332 This value means that some signers were invalid.
1334 @item GPG_ERR_NO_DATA
1335 This value means that a @code{gpgme_data_t} object which was expected
1336 to have content was found empty.
1338 @item GPG_ERR_CONFLICT
1339 This value means that a conflict of some sort occurred.
1341 @item GPG_ERR_NOT_IMPLEMENTED
1342 This value indicates that the specific function (or operation) is not
1343 implemented. This error should never happen. It can only occur if
1344 you use certain values or configuration options which do not work,
1345 but for which we think that they should work at some later time.
1347 @item GPG_ERR_DECRYPT_FAILED
1348 This value indicates that a decryption operation was unsuccessful.
1350 @item GPG_ERR_BAD_PASSPHRASE
1351 This value means that the user did not provide a correct passphrase
1354 @item GPG_ERR_CANCELED
1355 This value means that the operation was canceled.
1357 @item GPG_ERR_INV_ENGINE
1358 This value means that the engine that implements the desired protocol
1359 is currently not available. This can either be because the sources
1360 were configured to exclude support for this engine, or because the
1361 engine is not installed properly.
1363 @item GPG_ERR_AMBIGUOUS_NAME
1364 This value indicates that a user ID or other specifier did not specify
1367 @item GPG_ERR_WRONG_KEY_USAGE
1368 This value indicates that a key is not used appropriately.
1370 @item GPG_ERR_CERT_REVOKED
1371 This value indicates that a key signature was revoced.
1373 @item GPG_ERR_CERT_EXPIRED
1374 This value indicates that a key signature expired.
1376 @item GPG_ERR_NO_CRL_KNOWN
1377 This value indicates that no certificate revocation list is known for
1380 @item GPG_ERR_NO_POLICY_MATCH
1381 This value indicates that a policy issue occured.
1383 @item GPG_ERR_NO_SECKEY
1384 This value indicates that no secret key for the user ID is available.
1386 @item GPG_ERR_MISSING_CERT
1387 This value indicates that a key could not be imported because the
1388 issuer certificate is missing.
1390 @item GPG_ERR_BAD_CERT_CHAIN
1391 This value indicates that a key could not be imported because its
1392 certificate chain is not good, for example it could be too long.
1394 @item GPG_ERR_UNSUPPORTED_ALGORITHM
1395 This value means a verification failed because the cryptographic
1396 algorithm is not supported by the crypto backend.
1398 @item GPG_ERR_BAD_SIGNATURE
1399 This value means a verification failed because the signature is bad.
1401 @item GPG_ERR_NO_PUBKEY
1402 This value means a verification failed because the public key is not
1405 @item GPG_ERR_USER_1
1406 @item GPG_ERR_USER_2
1408 @item GPG_ERR_USER_16
1409 These error codes are not used by any GnuPG component and can be
1410 freely used by other software. Applications using @acronym{GPGME}
1411 might use them to mark specific errors returned by callback handlers
1412 if no suitable error codes (including the system errors) for
1413 these errors exist already.
1418 @section Error Strings
1419 @cindex error values, printing of
1420 @cindex error codes, printing of
1421 @cindex error sources, printing of
1422 @cindex error strings
1424 @deftypefun {const char *} gpgme_strerror (@w{gpgme_error_t @var{err}})
1425 The function @code{gpgme_strerror} returns a pointer to a statically
1426 allocated string containing a description of the error code contained
1427 in the error value @var{err}. This string can be used to output a
1428 diagnostic message to the user.
1430 This function is not thread safe. Use @code{gpgme_strerror_r} in
1431 multi-threaded programs.
1435 @deftypefun {int} gpgme_strerror_r (@w{gpgme_error_t @var{err}}, @w{char *@var{buf}}, @w{size_t @var{buflen}})
1436 The function @code{gpgme_strerror_r} returns the error string for
1437 @var{err} in the user-supplied buffer @var{buf} of size @var{buflen}.
1438 This function is, in contrast to @code{gpgme_strerror}, thread-safe if
1439 a thread-safe @code{strerror_r} function is provided by the system.
1440 If the function succeeds, 0 is returned and @var{buf} contains the
1441 string describing the error. If the buffer was not large enough,
1442 ERANGE is returned and @var{buf} contains as much of the beginning of
1443 the error string as fits into the buffer.
1447 @deftypefun {const char *} gpgme_strsource (@w{gpgme_error_t @var{err}})
1448 The function @code{gpgme_strerror} returns a pointer to a statically
1449 allocated string containing a description of the error source
1450 contained in the error value @var{err}. This string can be used to
1451 output a diagnostic message to the user.
1454 The following example illustrates the use of @code{gpgme_strerror}:
1458 gpgme_error_t err = gpgme_new (&ctx);
1461 fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
1462 argv[0], gpgme_strsource (err), gpgme_strerror (err));
1468 @node Exchanging Data
1469 @chapter Exchanging Data
1470 @cindex data, exchanging
1472 A lot of data has to be exchanged between the user and the crypto
1473 engine, like plaintext messages, ciphertext, signatures and
1474 information about the keys. The technical details about exchanging
1475 the data information are completely abstracted by @acronym{GPGME}.
1476 The user provides and receives the data via @code{gpgme_data_t} objects,
1477 regardless of the communication protocol between @acronym{GPGME} and
1478 the crypto engine in use.
1480 @deftp {Data type} {gpgme_data_t}
1481 The @code{gpgme_data_t} type is a handle for a container for generic
1482 data, which is used by @acronym{GPGME} to exchange data with the user.
1485 @code{gpgme_data_t} objects do not provide notifications on events.
1486 It is assumed that read and write operations are blocking until data
1487 is available. If this is undesirable, the application must ensure
1488 that all GPGME data operations always have data available, for example
1489 by using memory buffers or files rather than pipes or sockets. This
1490 might be relevant, for example, if the external event loop mechanism
1494 * Creating Data Buffers:: Creating new data buffers.
1495 * Destroying Data Buffers:: Releasing data buffers.
1496 * Manipulating Data Buffers:: Operations on data buffers.
1500 @node Creating Data Buffers
1501 @section Creating Data Buffers
1502 @cindex data buffer, creation
1504 Data objects can be based on memory, files, or callback functions
1505 provided by the user. Not all operations are supported by all
1510 * Memory Based Data Buffers:: Creating memory based data buffers.
1511 * File Based Data Buffers:: Creating file based data buffers.
1512 * Callback Based Data Buffers:: Creating callback based data buffers.
1516 @node Memory Based Data Buffers
1517 @subsection Memory Based Data Buffers
1519 Memory based data objects store all data in allocated memory. This is
1520 convenient, but only practical for an amount of data that is a
1521 fraction of the available physical memory. The data has to be copied
1522 from its source and to its destination, which can often be avoided by
1523 using one of the other data object
1525 @deftypefun gpgme_error_t gpgme_data_new (@w{gpgme_data_t *@var{dh}})
1526 The function @code{gpgme_data_new} creates a new @code{gpgme_data_t}
1527 object and returns a handle for it in @var{dh}. The data object is
1528 memory based and initially empty.
1530 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1531 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1532 @var{dh} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1533 enough memory is available.
1536 @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}})
1537 The function @code{gpgme_data_new_from_mem} creates a new
1538 @code{gpgme_data_t} object and fills it with @var{size} bytes starting
1541 If @var{copy} is not zero, a private copy of the data is made. If
1542 @var{copy} is zero, the data is taken from the specified buffer as
1543 needed, and the user has to ensure that the buffer remains valid for
1544 the whole life span of the data object.
1546 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1547 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1548 @var{dh} or @var{buffer} is not a valid pointer, and
1549 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1552 @deftypefun gpgme_error_t gpgme_data_new_from_file (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}})
1553 The function @code{gpgme_data_new_from_file} creates a new
1554 @code{gpgme_data_t} object and fills it with the content of the file
1557 If @var{copy} is not zero, the whole file is read in at initialization
1558 time and the file is not used anymore after that. This is the only
1559 mode supported currently. Later, a value of zero for @var{copy} might
1560 cause all reads to be delayed until the data is needed, but this is
1561 not yet implemented.
1563 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1564 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1565 @var{dh} or @var{filename} is not a valid pointer,
1566 @code{GPG_ERR_NOT_IMPLEMENTED} if @var{code} is zero, and
1567 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1570 @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}})
1571 The function @code{gpgme_data_new_from_filepart} creates a new
1572 @code{gpgme_data_t} object and fills it with a part of the file specified
1573 by @var{filename} or @var{fp}.
1575 Exactly one of @var{filename} and @var{fp} must be non-zero, the other
1576 must be zero. The argument that is not zero specifies the file from
1577 which @var{length} bytes are read into the data object, starting from
1580 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1581 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1582 @var{dh} and exactly one of @var{filename} and @var{fp} is not a valid
1583 pointer, and @code{GPG_ERR_ENOMEM} if not enough memory is available.
1587 @node File Based Data Buffers
1588 @subsection File Based Data Buffers
1590 File based data objects operate directly on file descriptors or
1591 streams. Only a small amount of data is stored in core at any time,
1592 so the size of the data objects is not limited by @acronym{GPGME}.
1594 @deftypefun gpgme_error_t gpgme_data_new_from_fd (@w{gpgme_data_t *@var{dh}}, @w{int @var{fd}})
1595 The function @code{gpgme_data_new_from_fd} creates a new
1596 @code{gpgme_data_t} object and uses the file descriptor @var{fd} to read
1597 from (if used as an input data object) and write to (if used as an
1598 output data object).
1600 When using the data object as an input buffer, the function might read
1601 a bit more from the file descriptor than is actually needed by the
1602 crypto engine in the desired operation because of internal buffering.
1604 Note that GPGME assumes that the file descriptor is set to blocking
1605 mode. Errors during I/O operations, except for EINTR, are usually
1606 fatal for crypto operations.
1608 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1609 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1610 enough memory is available.
1613 @deftypefun gpgme_error_t gpgme_data_new_from_stream (@w{gpgme_data_t *@var{dh}}, @w{FILE *@var{stream}})
1614 The function @code{gpgme_data_new_from_stream} creates a new
1615 @code{gpgme_data_t} object and uses the I/O stream @var{stream} to read
1616 from (if used as an input data object) and write to (if used as an
1617 output data object).
1619 When using the data object as an input buffer, the function might read
1620 a bit more from the stream than is actually needed by the crypto
1621 engine in the desired operation because of internal buffering.
1623 Note that GPGME assumes that the stream is in blocking mode. Errors
1624 during I/O operations, except for EINTR, are usually fatal for crypto
1627 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1628 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1629 enough memory is available.
1633 @node Callback Based Data Buffers
1634 @subsection Callback Based Data Buffers
1636 If neither memory nor file based data objects are a good fit for your
1637 application, you can implement the functions a data object provides
1638 yourself and create a data object from these callback functions.
1640 @deftp {Data type} {ssize_t (*gpgme_data_read_cb_t) (@w{void *@var{handle}}, @w{void @var{*buffer}}, @w{size_t @var{size}})}
1641 @tindex gpgme_data_read_cb_t
1642 The @code{gpgme_data_read_cb_t} type is the type of functions which
1643 @acronym{GPGME} calls if it wants to read data from a user-implemented
1644 data object. The function should read up to @var{size} bytes from the
1645 current read position into the space starting at @var{buffer}. The
1646 @var{handle} is provided by the user at data object creation time.
1648 Note that GPGME assumes that the read blocks until data is available.
1649 Errors during I/O operations, except for EINTR, are usually fatal for
1652 The function should return the number of bytes read, 0 on EOF, and -1
1653 on error. If an error occurs, @var{errno} should be set to describe
1654 the type of the error.
1657 @deftp {Data type} {ssize_t (*gpgme_data_write_cb_t) (@w{void *@var{handle}}, @w{const void @var{*buffer}}, @w{size_t @var{size}})}
1658 @tindex gpgme_data_write_cb_t
1659 The @code{gpgme_data_write_cb_t} type is the type of functions which
1660 @acronym{GPGME} calls if it wants to write data to a user-implemented
1661 data object. The function should write up to @var{size} bytes to the
1662 current write position from the space starting at @var{buffer}. The
1663 @var{handle} is provided by the user at data object creation time.
1665 Note that GPGME assumes that the write blocks until data is available.
1666 Errors during I/O operations, except for EINTR, are usually fatal for
1669 The function should return the number of bytes written, and -1 on
1670 error. If an error occurs, @var{errno} should be set to describe the
1674 @deftp {Data type} {off_t (*gpgme_data_seek_cb_t) (@w{void *@var{handle}}, @w{off_t @var{offset}}, @w{int @var{whence}})}
1675 @tindex gpgme_data_seek_cb_t
1676 The @code{gpgme_data_seek_cb_t} type is the type of functions which
1677 @acronym{GPGME} calls if it wants to change the current read/write
1678 position in a user-implemented data object, just like the @code{lseek}
1681 The function should return the new read/write position, and -1 on
1682 error. If an error occurs, @var{errno} should be set to describe the
1686 @deftp {Data type} {void (*gpgme_data_release_cb_t) (@w{void *@var{handle}})}
1687 @tindex gpgme_data_release_cb_t
1688 The @code{gpgme_data_release_cb_t} type is the type of functions which
1689 @acronym{GPGME} calls if it wants to destroy a user-implemented data
1690 object. The @var{handle} is provided by the user at data object
1694 @deftp {Data type} {struct gpgme_data_cbs}
1695 This structure is used to store the data callback interface functions
1696 described above. It has the following members:
1699 @item gpgme_data_read_cb_t read
1700 This is the function called by @acronym{GPGME} to read data from the
1701 data object. It is only required for input data object.
1703 @item gpgme_data_write_cb_t write
1704 This is the function called by @acronym{GPGME} to write data to the
1705 data object. It is only required for output data object.
1707 @item gpgme_data_seek_cb_t seek
1708 This is the function called by @acronym{GPGME} to change the current
1709 read/write pointer in the data object (if available). It is optional.
1711 @item gpgme_data_release_cb_t release
1712 This is the function called by @acronym{GPGME} to release a data
1713 object. It is optional.
1717 @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}})
1718 The function @code{gpgme_data_new_from_cbs} creates a new
1719 @code{gpgme_data_t} object and uses the user-provided callback functions
1720 to operate on the data object.
1722 The handle @var{handle} is passed as first argument to the callback
1723 functions. This can be used to identify this data object.
1725 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1726 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1727 enough memory is available.
1730 The following interface is deprecated and only provided for backward
1731 compatibility. Don't use it. It will be removed in a future version
1734 @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}})
1735 The function @code{gpgme_data_new_with_read_cb} creates a new
1736 @code{gpgme_data_t} object and uses the callback function @var{readfunc}
1737 to retrieve the data on demand. As the callback function can supply
1738 the data in any way it wants, this is the most flexible data type
1739 @acronym{GPGME} provides. However, it can not be used to write data.
1741 The callback function receives @var{hook_value} as its first argument
1742 whenever it is invoked. It should return up to @var{count} bytes in
1743 @var{buffer}, and return the number of bytes actually read in
1744 @var{nread}. It may return @code{0} in @var{nread} if no data is
1745 currently available. To indicate @code{EOF} the function should
1746 return with an error code of @code{-1} and set @var{nread} to
1747 @code{0}. The callback function may support to reset its internal
1748 read pointer if it is invoked with @var{buffer} and @var{nread} being
1749 @code{NULL} and @var{count} being @code{0}.
1751 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1752 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1753 @var{dh} or @var{readfunc} is not a valid pointer, and
1754 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1758 @node Destroying Data Buffers
1759 @section Destroying Data Buffers
1760 @cindex data buffer, destruction
1762 @deftypefun void gpgme_data_release (@w{gpgme_data_t @var{dh}})
1763 The function @code{gpgme_data_release} destroys the data object with
1764 the handle @var{dh}. It releases all associated resources that were
1765 not provided by the user in the first place.
1768 @deftypefun {char *} gpgme_data_release_and_get_mem (@w{gpgme_data_t @var{dh}}, @w{size_t *@var{length}})
1769 The function @code{gpgme_data_release_and_get_mem} is like
1770 @code{gpgme_data_release}, except that it returns the data buffer and
1771 its length that was provided by the object.
1773 The user has to release the buffer with @code{gpgme_free}. In case
1774 the user provided the data buffer in non-copy mode, a copy will be
1775 made for this purpose.
1777 In case an error returns, or there is no suitable data buffer that can
1778 be returned to the user, the function will return @code{NULL}. In any
1779 case, the data object @var{dh} is destroyed.
1783 @deftypefun void gpgme_free (@w{void *@var{buffer}})
1784 The function @code{gpgme_free} releases the memory returned by
1785 @code{gpgme_data_release_and_get_mem}. It should be used instead of
1786 the system libraries @code{free} function in case different allocators
1787 are used in a single program.
1791 @node Manipulating Data Buffers
1792 @section Manipulating Data Buffers
1793 @cindex data buffer, manipulation
1795 Data buffers contain data and meta-data. The following operations can
1796 be used to manipulate both.
1800 * Data Buffer I/O Operations:: I/O operations on data buffers.
1801 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
1805 @node Data Buffer I/O Operations
1806 @subsection Data Buffer I/O Operations
1807 @cindex data buffer, I/O operations
1808 @cindex data buffer, read
1809 @cindex data buffer, write
1810 @cindex data buffer, seek
1812 @deftypefun ssize_t gpgme_data_read (@w{gpgme_data_t @var{dh}}, @w{void *@var{buffer}}, @w{size_t @var{length}})
1813 The function @code{gpgme_data_read} reads up to @var{length} bytes
1814 from the data object with the handle @var{dh} into the space starting
1817 If no error occurs, the actual amount read is returned. If the end of
1818 the data object is reached, the function returns 0.
1820 In all other cases, the function returns -1 and sets @var{errno}.
1823 @deftypefun ssize_t gpgme_data_write (@w{gpgme_data_t @var{dh}}, @w{const void *@var{buffer}}, @w{size_t @var{size}})
1824 The function @code{gpgme_data_write} writes up to @var{size} bytes
1825 starting from @var{buffer} into the data object with the handle
1826 @var{dh} at the current write position.
1828 The function returns the number of bytes actually written, or -1 if an
1829 error occurs. If an error occurs, @var{errno} is set.
1832 @deftypefun off_t gpgme_data_seek (@w{gpgme_data_t @var{dh}}, @w{off_t @var{offset}}, @w{int @var{whence}})
1833 The function @code{gpgme_data_seek} changes the current read/write
1836 The @var{whence} argument specifies how the @var{offset} should be
1837 interpreted. It must be one of the following symbolic constants:
1841 Specifies that @var{offset} is a count of characters from the
1842 beginning of the data object.
1845 Specifies that @var{offset} is a count of characters from the current
1846 file position. This count may be positive or negative.
1849 Specifies that @var{offset} is a count of characters from the end of
1850 the data object. A negative count specifies a position within the
1851 current extent of the data object; a positive count specifies a
1852 position past the current end. If you set the position past the
1853 current end, and actually write data, you will extend the data object
1854 with zeros up to that position.
1857 If successful, the function returns the resulting file position,
1858 measured in bytes from the beginning of the data object. You can use
1859 this feature together with @code{SEEK_CUR} to read the current
1860 read/write position.
1862 If the function fails, -1 is returned and @var{errno} is set.
1865 The following function is deprecated and should not be used. It will
1866 be removed in a future version of @acronym{GPGME}.
1868 @deftypefun gpgme_error_t gpgme_data_rewind (@w{gpgme_data_t @var{dh}})
1869 The function @code{gpgme_data_rewind} is equivalent to:
1872 return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
1873 ? gpgme_error_from_errno (errno) : 0;
1880 @node Data Buffer Meta-Data
1881 @subsection Data Buffer Meta-Data
1882 @cindex data buffer, meta-data
1883 @cindex data buffer, file name
1884 @cindex data buffer, encoding
1886 @deftypefun {char *} gpgme_data_get_file_name (@w{gpgme_data_t @var{dh}})
1887 The function @code{gpgme_data_get_file_name} returns a pointer to a
1888 string containing the file name associated with the data object. The
1889 file name will be stored in the output when encrypting or signing the
1890 data and will be returned to the user when decrypting or verifying the
1893 If no error occurs, the string containing the file name is returned.
1894 Otherwise, @code{NULL} will be returned.
1898 @deftypefun gpgme_error_t gpgme_data_set_file_name (@w{gpgme_data_t @var{dh}}, @w{const char *@var{file_name}})
1899 The function @code{gpgme_data_set_file_name} sets the file name
1900 associated with the data object. The file name will be stored in the
1901 output when encrypting or signing the data and will be returned to the
1902 user when decrypting or verifying the output data.
1904 The function returns the error code @code{GPG_ERR_INV_VALUE} if
1905 @var{dh} is not a valid pointer and @code{GPG_ERR_ENOMEM} if not
1906 enough memory is available.
1910 @deftp {Data type} {enum gpgme_data_encoding_t}
1911 @tindex gpgme_data_encoding_t
1912 The @code{gpgme_data_encoding_t} type specifies the encoding of a
1913 @code{gpgme_data_t} object. For input data objects, the encoding is
1914 useful to give the backend a hint on the type of data. For output
1915 data objects, the encoding can specify the output data format on
1916 certain operations. Please note that not all backends support all
1917 encodings on all operations. The following data types are available:
1920 @item GPGME_DATA_ENCODING_NONE
1921 This specifies that the encoding is not known. This is the default
1922 for a new data object. The backend will try its best to detect the
1923 encoding automatically.
1925 @item GPGME_DATA_ENCODING_BINARY
1926 This specifies that the data is encoding in binary form; i.e. there is
1927 no special encoding.
1929 @item GPGME_DATA_ENCODING_BASE64
1930 This specifies that the data is encoded using the Base-64 encoding
1931 scheme as used by @acronym{MIME} and other protocols.
1933 @item GPGME_DATA_ENCODING_ARMOR
1934 This specifies that the data is encoded in an armored form as used by
1939 @deftypefun gpgme_data_encoding_t gpgme_data_get_encoding (@w{gpgme_data_t @var{dh}})
1940 The function @code{gpgme_data_get_encoding} returns the encoding of
1941 the data object with the handle @var{dh}. If @var{dh} is not a valid
1942 pointer (e.g. @code{NULL}) @code{GPGME_DATA_ENCODING_NONE} is
1946 @deftypefun gpgme_error_t gpgme_data_set_encoding (@w{gpgme_data_t @var{dh}, gpgme_data_encoding_t @var{enc}})
1947 The function @code{gpgme_data_set_encoding} changes the encoding of
1948 the data object with the handle @var{dh} to @var{enc}.
1959 All cryptographic operations in @acronym{GPGME} are performed within a
1960 context, which contains the internal state of the operation as well as
1961 configuration parameters. By using several contexts you can run
1962 several cryptographic operations in parallel, with different
1965 @deftp {Data type} {gpgme_ctx_t}
1966 The @code{gpgme_ctx_t} type is a handle for a @acronym{GPGME} context,
1967 which is used to hold the configuration, status and result of
1968 cryptographic operations.
1972 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
1973 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
1974 * Context Attributes:: Setting properties of a context.
1975 * Key Management:: Managing keys with @acronym{GPGME}.
1976 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
1977 * Crypto Operations:: Using a context for cryptography.
1978 * Run Control:: Controlling how operations are run.
1982 @node Creating Contexts
1983 @section Creating Contexts
1984 @cindex context, creation
1986 @deftypefun gpgme_error_t gpgme_new (@w{gpgme_ctx_t *@var{ctx}})
1987 The function @code{gpgme_new} creates a new @code{gpgme_ctx_t} object
1988 and returns a handle for it in @var{ctx}.
1990 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1991 context was successfully created, @code{GPG_ERR_INV_VALUE} if
1992 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1993 enough memory is available. Also, it returns
1994 @code{GPG_ERR_NOT_OPERATIONAL} if @code{gpgme_check_version} was not
1995 called to initialize GPGME, and @code{GPG_ERR_SELFTEST_FAILED} if a
1996 selftest failed. Currently, the only selftest is for Windows MingW32
1997 targets to see if @code{-mms-bitfields} was used (as required).
2001 @node Destroying Contexts
2002 @section Destroying Contexts
2003 @cindex context, destruction
2005 @deftypefun void gpgme_release (@w{gpgme_ctx_t @var{ctx}})
2006 The function @code{gpgme_release} destroys the context with the handle
2007 @var{ctx} and releases all associated resources.
2011 @node Context Attributes
2012 @section Context Attributes
2013 @cindex context, attributes
2016 * Protocol Selection:: Selecting the protocol used by a context.
2017 * Crypto Engine:: Configuring the crypto engine.
2018 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
2019 * Text Mode:: Choosing canonical text mode.
2020 * Included Certificates:: Including a number of certificates.
2021 * Key Listing Mode:: Selecting key listing mode.
2022 * Passphrase Callback:: Getting the passphrase from the user.
2023 * Progress Meter Callback:: Being informed about the progress.
2024 * Locale:: Setting the locale of a context.
2028 @node Protocol Selection
2029 @subsection Protocol Selection
2030 @cindex context, selecting protocol
2031 @cindex protocol, selecting
2033 @deftypefun gpgme_error_t gpgme_set_protocol (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}})
2034 The function @code{gpgme_set_protocol} sets the protocol used within
2035 the context @var{ctx} to @var{proto}. All crypto operations will be
2036 performed by the crypto engine configured for that protocol.
2037 @xref{Protocols and Engines}.
2039 Setting the protocol with @code{gpgme_set_protocol} does not check if
2040 the crypto engine for that protocol is available and installed
2041 correctly. @xref{Engine Version Check}.
2043 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2044 protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if
2045 @var{protocol} is not a valid protocol.
2048 @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}})
2049 The function @code{gpgme_get_protocol} retrieves the protocol currently
2050 use with the context @var{ctx}.
2055 @subsection Crypto Engine
2056 @cindex context, configuring engine
2057 @cindex engine, configuration per context
2059 The following functions can be used to set and retrieve the
2060 configuration of the crypto engines of a specific context. The
2061 default can also be retrieved without any particular context.
2062 @xref{Engine Information}. The default can also be changed globally.
2063 @xref{Engine Configuration}.
2065 @deftypefun gpgme_engine_info_t gpgme_ctx_get_engine_info (@w{gpgme_ctx_t @var{ctx}})
2066 The function @code{gpgme_ctx_get_engine_info} returns a linked list of
2067 engine info structures. Each info structure describes the
2068 configuration of one configured backend, as used by the context
2071 The result is valid until the next invocation of
2072 @code{gpgme_ctx_set_engine_info} for this particular context.
2074 This function can not fail.
2077 @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}})
2078 The function @code{gpgme_ctx_set_engine_info} changes the
2079 configuration of the crypto engine implementing the protocol
2080 @var{proto} for the context @var{ctx}.
2082 @var{file_name} is the file name of the executable program
2083 implementing this protocol, and @var{home_dir} is the directory name
2084 of the configuration directory for this crypto engine. If
2085 @var{home_dir} is @code{NULL}, the engine's default will be used.
2087 Currently this function must be used before starting the first crypto
2088 operation. It is unspecified if and when the changes will take effect
2089 if the function is called after starting the first operation on the
2092 This function returns the error code @code{GPG_ERR_NO_ERROR} if
2093 successful, or an eror code on failure.
2097 @c FIXME: Unfortunately, using @acronym here breaks texi2dvi.
2099 @subsection @acronym{ASCII} Armor
2100 @cindex context, armor mode
2101 @cindex @acronym{ASCII} armor
2104 @deftypefun void gpgme_set_armor (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2105 The function @code{gpgme_set_armor} specifies if the output should be
2106 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
2109 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
2113 @deftypefun int gpgme_get_armor (@w{gpgme_ctx_t @var{ctx}})
2114 The function @code{gpgme_get_armor} returns 1 if the output is
2115 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
2116 not a valid pointer.
2121 @subsection Text Mode
2122 @cindex context, text mode
2124 @cindex canonical text mode
2126 @deftypefun void gpgme_set_textmode (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2127 The function @code{gpgme_set_textmode} specifies if canonical text mode
2128 should be used. By default, text mode is not used.
2130 Text mode is for example used for the RFC2015 signatures; note that
2131 the updated RFC 3156 mandates that the mail user agent does some
2132 preparations so that text mode is not needed anymore.
2134 This option is only relevant to the OpenPGP crypto engine, and ignored
2135 by all other engines.
2137 Canonical text mode is disabled if @var{yes} is zero, and enabled
2141 @deftypefun int gpgme_get_textmode (@w{gpgme_ctx_t @var{ctx}})
2142 The function @code{gpgme_get_textmode} returns 1 if canonical text
2143 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2148 @node Included Certificates
2149 @subsection Included Certificates
2150 @cindex certificates, included
2152 @deftypefun void gpgme_set_include_certs (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{nr_of_certs}})
2153 The function @code{gpgme_set_include_certs} specifies how many
2154 certificates should be included in an S/MIME signed message. By
2155 default, only the sender's certificate is included. The possible
2156 values of @var{nr_of_certs} are:
2159 @item GPGME_INCLUDE_CERTS_DEFAULT
2160 Fall back to the default of the crypto backend. This is the default
2163 Include all certificates except the root certificate.
2165 Include all certificates.
2167 Include no certificates.
2169 Include the sender's certificate only.
2171 Include the first n certificates of the certificates path, starting
2172 from the sender's certificate. The number @code{n} must be positive.
2175 Values of @var{nr_of_certs} smaller than -2 are undefined.
2177 This option is only relevant to the CMS crypto engine, and ignored by
2181 @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}})
2182 The function @code{gpgme_get_include_certs} returns the number of
2183 certificates to include into an S/MIME signed message.
2187 @node Key Listing Mode
2188 @subsection Key Listing Mode
2189 @cindex key listing mode
2190 @cindex key listing, mode of
2192 @deftypefun gpgme_error_t gpgme_set_keylist_mode (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_keylist_mode_t @var{mode}})
2193 The function @code{gpgme_set_keylist_mode} changes the default
2194 behaviour of the key listing functions. The value in @var{mode} is a
2195 bitwise-or combination of one or multiple of the following bit values:
2198 @item GPGME_KEYLIST_MODE_LOCAL
2199 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
2200 keyring should be searched for keys in the keylisting operation. This
2203 @item GPGME_KEYLIST_MODE_EXTERN
2204 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
2205 source should be searched for keys in the keylisting operation. The
2206 type of external source is dependant on the crypto engine used and
2207 whether it is combined with @code{GPGME_KEYLIST_MODE_LOCAL}. For
2208 example, it can be a remote keyserver or LDAP certificate server.
2210 @item GPGME_KEYLIST_MODE_SIGS
2211 The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key
2212 signatures should be included in the listed keys.
2214 @item GPGME_KEYLIST_MODE_SIG_NOTATIONS
2215 The @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} symbol specifies that the
2216 signature notations on key signatures should be included in the listed
2217 keys. This only works if @code{GPGME_KEYLIST_MODE_SIGS} is also
2220 @item GPGME_KEYLIST_MODE_EPHEMERAL
2221 The @code{GPGME_KEYLIST_MODE_EPHEMERAL} symbol specifies that keys
2222 flagged as ephemeral are included in the listing.
2224 @item GPGME_KEYLIST_MODE_VALIDATE
2225 The @code{GPGME_KEYLIST_MODE_VALIDATE} symbol specifies that the
2226 backend should do key or certificate validation and not just get the
2227 validity information from an internal cache. This might be an
2228 expensive operation and is in general not useful. Currently only
2229 implemented for the S/MIME backend and ignored for other backends.
2233 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
2234 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
2235 compatibility, you should get the current mode with
2236 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
2237 appropriate bits, and then using that calculated value in the
2238 @code{gpgme_set_keylisting_mode} operation. This will leave all other
2239 bits in the mode value intact (in particular those that are not used
2240 in the current version of the library).
2242 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2243 mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx}
2244 is not a valid pointer or @var{mode} is not a valid mode.
2248 @deftypefun gpgme_keylist_mode_t gpgme_get_keylist_mode (@w{gpgme_ctx_t @var{ctx}})
2249 The function @code{gpgme_get_keylist_mode} returns the current key
2250 listing mode of the context @var{ctx}. This value can then be
2251 modified and used in a subsequent @code{gpgme_set_keylist_mode}
2252 operation to only affect the desired bits (and leave all others
2255 The function returns 0 if @var{ctx} is not a valid pointer, and the
2256 current mode otherwise. Note that 0 is not a valid mode value.
2260 @node Passphrase Callback
2261 @subsection Passphrase Callback
2262 @cindex callback, passphrase
2263 @cindex passphrase callback
2265 @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}})}
2266 @tindex gpgme_passphrase_cb_t
2267 The @code{gpgme_passphrase_cb_t} type is the type of functions usable as
2268 passphrase callback function.
2270 The argument @var{uid_hint} might contain a string that gives an
2271 indication for which user ID the passphrase is required. If this is
2272 not available, or not applicable (in the case of symmetric encryption,
2273 for example), @var{uid_hint} will be @code{NULL}.
2275 The argument @var{passphrase_info}, if not @code{NULL}, will give
2276 further information about the context in which the passphrase is
2277 required. This information is engine and operation specific.
2279 If this is the repeated attempt to get the passphrase, because
2280 previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
2283 The user must write the passphrase, followed by a newline character,
2284 to the file descriptor @var{fd}. If the user returns 0 indicating
2285 success, the user must at least write a newline character before
2286 returning from the callback.
2288 If an error occurs, return the corresponding @code{gpgme_error_t}
2289 value. You can use the error code @code{GPG_ERR_CANCELED} to abort
2290 the operation. Otherwise, return @code{0}.
2293 @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}})
2294 The function @code{gpgme_set_passphrase_cb} sets the function that is
2295 used when a passphrase needs to be provided by the user to
2296 @var{passfunc}. The function @var{passfunc} needs to implemented by
2297 the user, and whenever it is called, it is called with its first
2298 argument being @var{hook_value}. By default, no passphrase callback
2301 Not all crypto engines require this callback to retrieve the
2302 passphrase. It is better if the engine retrieves the passphrase from
2303 a trusted agent (a daemon process), rather than having each user to
2304 implement their own passphrase query. Some engines do not even
2305 support an external passphrase callback at all, in this case the error
2306 code @code{GPG_ERR_NOT_SUPPORTED} is returned.
2308 The user can disable the use of a passphrase callback function by
2309 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
2313 @deftypefun void gpgme_get_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t *@var{passfunc}}, @w{void **@var{hook_value}})
2314 The function @code{gpgme_get_passphrase_cb} returns the function that
2315 is used when a passphrase needs to be provided by the user in
2316 @var{*passfunc}, and the first argument for this function in
2317 @var{*hook_value}. If no passphrase callback is set, or @var{ctx} is
2318 not a valid pointer, @code{NULL} is returned in both variables.
2320 @var{passfunc} or @var{hook_value} can be @code{NULL}. In this case,
2321 the corresponding value will not be returned.
2325 @node Progress Meter Callback
2326 @subsection Progress Meter Callback
2327 @cindex callback, progress meter
2328 @cindex progress meter callback
2330 @deftp {Data type} {void (*gpgme_progress_cb_t)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
2331 @tindex gpgme_progress_cb_t
2332 The @code{gpgme_progress_cb_t} type is the type of functions usable as
2333 progress callback function.
2335 The arguments are specific to the crypto engine. More information
2336 about the progress information returned from the GnuPG engine can be
2337 found in the GnuPG source code in the file @file{doc/DETAILS} in the
2341 @deftypefun void gpgme_set_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t @var{progfunc}}, @w{void *@var{hook_value}})
2342 The function @code{gpgme_set_progress_cb} sets the function that is
2343 used when progress information about a cryptographic operation is
2344 available. The function @var{progfunc} needs to implemented by the
2345 user, and whenever it is called, it is called with its first argument
2346 being @var{hook_value}. By default, no progress callback function
2349 Setting a callback function allows an interactive program to display
2350 progress information about a long operation to the user.
2352 The user can disable the use of a progress callback function by
2353 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
2357 @deftypefun void gpgme_get_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t *@var{progfunc}}, @w{void **@var{hook_value}})
2358 The function @code{gpgme_get_progress_cb} returns the function that is
2359 used to inform the user about the progress made in @var{*progfunc},
2360 and the first argument for this function in @var{*hook_value}. If no
2361 progress callback is set, or @var{ctx} is not a valid pointer,
2362 @code{NULL} is returned in both variables.
2364 @var{progfunc} or @var{hook_value} can be @code{NULL}. In this case,
2365 the corresponding value will not be returned.
2371 @cindex locale, default
2372 @cindex locale, of a context
2374 A locale setting can be associated with a context. This locale is
2375 passed to the crypto engine, and used for applications like the PIN
2376 entry, which is displayed to the user when entering a passphrase is
2379 The default locale is used to initialize the locale setting of all
2380 contexts created afterwards.
2382 @deftypefun gpgme_error_t gpgme_set_locale (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{category}}, @w{const char *@var{value}})
2383 The function @code{gpgme_set_locale} sets the locale of the context
2384 @var{ctx}, or the default locale if @var{ctx} is a null pointer.
2386 The locale settings that should be changed are specified by
2387 @var{category}. Supported categories are @code{LC_CTYPE},
2388 @code{LC_MESSAGES}, and @code{LC_ALL}, which is a wildcard you can use
2389 if you want to change all the categories at once.
2391 The value to be used for the locale setting is @var{value}, which will
2392 be copied to @acronym{GPGME}'s internal data structures. @var{value}
2393 can be a null pointer, which disables setting the locale, and will
2394 make PIN entry and other applications use their default setting, which
2395 is usually not what you want.
2397 Note that the settings are only used if the application runs on a text
2398 terminal, and that the settings should fit the configuration of the
2399 output terminal. Normally, it is sufficient to initialize the default
2402 The function returns an error if not enough memory is available.
2406 @node Key Management
2407 @section Key Management
2408 @cindex key management
2410 Some of the cryptographic operations require that recipients or
2411 signers are specified. This is always done by specifying the
2412 respective keys that should be used for the operation. The following
2413 section describes how such keys can be selected and manipulated.
2415 @deftp {Data type} gpgme_sub_key_t
2416 The @code{gpgme_sub_key_t} type is a pointer to a subkey structure.
2417 Sub keys are one component of a @code{gpgme_key_t} object. In fact,
2418 subkeys are those parts that contains the real information about the
2419 individual cryptographic keys that belong to the same key object. One
2420 @code{gpgme_key_t} can contain several subkeys. The first subkey in
2421 the linked list is also called the primary key.
2423 The subkey structure has the following members:
2426 @item gpgme_sub_key_t next
2427 This is a pointer to the next subkey structure in the linked list, or
2428 @code{NULL} if this is the last element.
2430 @item unsigned int revoked : 1
2431 This is true if the subkey is revoked.
2433 @item unsigned int expired : 1
2434 This is true if the subkey is expired.
2436 @item unsigned int disabled : 1
2437 This is true if the subkey is disabled.
2439 @item unsigned int invalid : 1
2440 This is true if the subkey is invalid.
2442 @item unsigned int can_encrypt : 1
2443 This is true if the subkey can be used for encryption.
2445 @item unsigned int can_sign : 1
2446 This is true if the subkey can be used to create data signatures.
2448 @item unsigned int can_certify : 1
2449 This is true if the subkey can be used to create key certificates.
2451 @item unsigned int can_authenticate : 1
2452 This is true if the subkey can be used for authentication.
2454 @item unsigned int is_qualified : 1
2455 This is true if the subkey can be used for qualified signatures
2456 according to local government regulations.
2458 @item unsigned int secret : 1
2459 This is true if the subkey is a secret key. Note that it will be false
2460 if the key is actually a stub key; i.e. a secret key operation is
2461 currently not possible (offline-key).
2463 @item gpgme_pubkey_algo_t pubkey_algo
2464 This is the public key algorithm supported by this subkey.
2466 @item unsigned int length
2467 This is the length of the subkey (in bits).
2470 This is the key ID of the subkey in hexadecimal digits.
2473 This is the fingerprint of the subkey in hexadecimal digits, if
2476 @item long int timestamp
2477 This is the creation timestamp of the subkey. This is -1 if the
2478 timestamp is invalid, and 0 if it is not available.
2480 @item long int expires
2481 This is the expiration timestamp of the subkey, or 0 if the subkey
2486 @deftp {Data type} gpgme_key_sig_t
2487 The @code{gpgme_key_sig_t} type is a pointer to a key signature structure.
2488 Key signatures are one component of a @code{gpgme_key_t} object, and
2489 validate user IDs on the key.
2491 The signatures on a key are only available if the key was retrieved
2492 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
2493 enabled, because it can be expensive to retrieve all signatures of a
2496 The signature notations on a key signature are only available if the
2497 key was retrieved via a listing operation with the
2498 @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} mode enabled, because it can
2499 be expensive to retrieve all signature notations.
2501 The key signature structure has the following members:
2504 @item gpgme_key_sig_t next
2505 This is a pointer to the next key signature structure in the linked
2506 list, or @code{NULL} if this is the last element.
2508 @item unsigned int revoked : 1
2509 This is true if the key signature is a revocation signature.
2511 @item unsigned int expired : 1
2512 This is true if the key signature is expired.
2514 @item unsigned int invalid : 1
2515 This is true if the key signature is invalid.
2517 @item unsigned int exportable : 1
2518 This is true if the key signature is exportable.
2520 @item gpgme_pubkey_algo_t pubkey_algo
2521 This is the public key algorithm used to create the signature.
2524 This is the key ID of the key (in hexadecimal digits) used to create
2527 @item long int timestamp
2528 This is the creation timestamp of the key signature. This is -1 if
2529 the timestamp is invalid, and 0 if it is not available.
2531 @item long int expires
2532 This is the expiration timestamp of the key signature, or 0 if the key
2533 signature does not expire.
2535 @item gpgme_error_t status
2536 This is the status of the signature and has the same meaning as the
2537 member of the same name in a @code{gpgme_signature_t} object.
2539 @item unsigned int sig_class
2540 This specifies the signature class of the key signature. The meaning
2541 is specific to the crypto engine.
2544 This is the main user ID of the key used to create the signature.
2547 This is the name component of @code{uid}, if available.
2550 This is the comment component of @code{uid}, if available.
2553 This is the email component of @code{uid}, if available.
2555 @item gpgme_sig_notation_t notations
2556 This is a linked list with the notation data and policy URLs.
2560 @deftp {Data type} gpgme_user_id_t
2561 A user ID is a component of a @code{gpgme_key_t} object. One key can
2562 have many user IDs. The first one in the list is the main (or
2565 The user ID structure has the following members.
2568 @item gpgme_user_id_t next
2569 This is a pointer to the next user ID structure in the linked list, or
2570 @code{NULL} if this is the last element.
2572 @item unsigned int revoked : 1
2573 This is true if the user ID is revoked.
2575 @item unsigned int invalid : 1
2576 This is true if the user ID is invalid.
2578 @item gpgme_validity_t validity
2579 This specifies the validity of the user ID.
2582 This is the user ID string.
2585 This is the name component of @code{uid}, if available.
2588 This is the comment component of @code{uid}, if available.
2591 This is the email component of @code{uid}, if available.
2593 @item gpgme_key_sig_t signatures
2594 This is a linked list with the signatures on this user ID.
2598 @deftp {Data type} gpgme_key_t
2599 The @code{gpgme_key_t} type is a pointer to a key object. It has the
2603 @item gpgme_keylist_mode_t keylist_mode
2604 The keylist mode that was active when the key was retrieved.
2606 @item unsigned int revoked : 1
2607 This is true if the key is revoked.
2609 @item unsigned int expired : 1
2610 This is true if the key is expired.
2612 @item unsigned int disabled : 1
2613 This is true if the key is disabled.
2615 @item unsigned int invalid : 1
2616 This is true if the key is invalid. This might have several reasons,
2617 for a example for the S/MIME backend, it will be set in during key
2618 listsing if the key could not be validated due to a missing
2619 certificates or unmatched policies.
2621 @item unsigned int can_encrypt : 1
2622 This is true if the key (ie one of its subkeys) can be used for
2625 @item unsigned int can_sign : 1
2626 This is true if the key (ie one of its subkeys) can be used to create
2629 @item unsigned int can_certify : 1
2630 This is true if the key (ie one of its subkeys) can be used to create
2633 @item unsigned int can_authenticate : 1
2634 This is true if the key (ie one of its subkeys) can be used for
2637 @item unsigned int is_qualified : 1
2638 This is true if the key can be used for qualified signatures according
2639 to local government regulations.
2641 @item unsigned int secret : 1
2642 This is true if the key is a secret key. Note, that this will always be
2643 true even if the corresponding subkey flag may be false (offline/stub
2646 @item gpgme_protocol_t protocol
2647 This is the protocol supported by this key.
2649 @item char *issuer_serial
2650 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2653 @item char *issuer_name
2654 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2657 @item char *chain_id
2658 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2659 chain ID, which can be used to built the certificate chain.
2661 @item gpgme_validity_t owner_trust
2662 If @code{protocol} is @code{GPGME_PROTOCOL_OpenPGP}, then this is the
2665 @item gpgme_sub_key_t subkeys
2666 This is a linked list with the subkeys of the key. The first subkey
2667 in the list is the primary key and usually available.
2669 @item gpgme_user_id_t uids
2670 This is a linked list with the user IDs of the key. The first user ID
2671 in the list is the main (or primary) user ID.
2676 * Listing Keys:: Browsing the list of available keys.
2677 * Information About Keys:: Requesting detailed information about keys.
2678 * Key Signatures:: Listing the signatures on a key.
2679 * Manipulating Keys:: Operations on keys.
2680 * Generating Keys:: Creating new key pairs.
2681 * Exporting Keys:: Retrieving key data from the key ring.
2682 * Importing Keys:: Adding keys to the key ring.
2683 * Deleting Keys:: Removing keys from the key ring.
2684 * Advanced Key Editing:: Advanced key edit operation.
2689 @subsection Listing Keys
2690 @cindex listing keys
2692 @cindex key listing, start
2693 @cindex key ring, list
2694 @cindex key ring, search
2696 @deftypefun gpgme_error_t gpgme_op_keylist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
2697 The function @code{gpgme_op_keylist_start} initiates a key listing
2698 operation inside the context @var{ctx}. It sets everything up so that
2699 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
2702 If @var{pattern} is @code{NULL}, all available keys are returned.
2703 Otherwise, @var{pattern} contains an engine specific expression that
2704 is used to limit the list to all keys matching the pattern. Note that
2705 the total length of the pattern is restricted to an engine-specific
2706 maximum (a couple of hundred characters are usually accepted). The
2707 pattern should be used to restrict the search to a certain common name
2708 or user, not to list many specific keys at once by listing their
2709 fingerprints or key IDs.
2711 If @var{secret_only} is not @code{0}, the list is restricted to secret
2714 The context will be busy until either all keys are received (and
2715 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2716 @code{gpgme_op_keylist_end} is called to finish the operation.
2718 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2719 @var{ctx} is not a valid pointer, and passes through any errors that
2720 are reported by the crypto engine support routines.
2723 @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}})
2724 The function @code{gpgme_op_keylist_ext_start} initiates an extended
2725 key listing operation inside the context @var{ctx}. It sets
2726 everything up so that subsequent invocations of
2727 @code{gpgme_op_keylist_next} return the keys in the list.
2729 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
2730 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
2731 array of strings that are used to limit the list to all keys matching
2732 at least one of the patterns verbatim. Note that the total length of
2733 all patterns is restricted to an engine-specific maximum (the exact
2734 limit also depends on the number of patterns and amount of quoting
2735 required, but a couple of hundred characters are usually accepted).
2736 Patterns should be used to restrict the search to a certain common
2737 name or user, not to list many specific keys at once by listing their
2738 fingerprints or key IDs.
2740 If @var{secret_only} is not @code{0}, the list is restricted to secret
2743 The value of @var{reserved} must be @code{0}.
2745 The context will be busy until either all keys are received (and
2746 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2747 @code{gpgme_op_keylist_end} is called to finish the operation.
2749 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2750 @var{ctx} is not a valid pointer, and passes through any errors that
2751 are reported by the crypto engine support routines.
2754 @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}})
2755 The function @code{gpgme_op_keylist_next} returns the next key in the
2756 list created by a previous @code{gpgme_op_keylist_start} operation in
2757 the context @var{ctx}. The key will have one reference for the user.
2758 @xref{Manipulating Keys}.
2760 This is the only way to get at @code{gpgme_key_t} objects in
2763 If the last key in the list has already been returned,
2764 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}.
2766 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2767 @var{ctx} or @var{r_key} is not a valid pointer, and
2768 @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation.
2771 @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}})
2772 The function @code{gpgme_op_keylist_next} ends a pending key list
2773 operation in the context @var{ctx}.
2775 After the operation completed successfully, the result of the key
2776 listing operation can be retrieved with
2777 @code{gpgme_op_keylist_result}.
2779 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2780 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
2781 time during the operation there was not enough memory available.
2784 The following example illustrates how all keys containing a certain
2785 string (@code{g10code}) can be listed with their key ID and the name
2786 and e-mail address of the main user ID:
2791 gpgme_error_t err = gpgme_new (&ctx);
2795 err = gpgme_op_keylist_start (ctx, "g10code", 0);
2798 err = gpgme_op_keylist_next (ctx, &key);
2801 printf ("%s:", key->subkeys->keyid);
2802 if (key->uids && key->uids->name)
2803 printf (" %s", key->uids->name);
2804 if (key->uids && key->uids->email)
2805 printf (" <%s>", key->uids->email);
2807 gpgme_key_release (key);
2809 gpgme_release (ctx);
2811 if (gpg_err_code (err) != GPG_ERR_EOF)
2813 fprintf (stderr, "can not list keys: %s\n", gpgme_strerror (err));
2818 @deftp {Data type} {gpgme_keylist_result_t}
2819 This is a pointer to a structure used to store the result of a
2820 @code{gpgme_op_keylist_*} operation. After successfully ending a key
2821 listing operation, you can retrieve the pointer to the result with
2822 @code{gpgme_op_keylist_result}. The structure contains the following
2826 @item unsigned int truncated : 1
2827 This is true if the crypto backend had to truncate the result, and
2828 less than the desired keys could be listed.
2832 @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}})
2833 The function @code{gpgme_op_keylist_result} returns a
2834 @code{gpgme_keylist_result_t} pointer to a structure holding the
2835 result of a @code{gpgme_op_keylist_*} operation. The pointer is only
2836 valid if the last operation on the context was a key listing
2837 operation, and if this operation finished successfully. The returned
2838 pointer is only valid until the next operation is started on the
2842 In a simple program, for which a blocking operation is acceptable, the
2843 following function can be used to retrieve a single key.
2845 @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}})
2846 The function @code{gpgme_get_key} gets the key with the fingerprint
2847 (or key ID) @var{fpr} from the crypto backend and return it in
2848 @var{r_key}. If @var{secret} is true, get the secret key. The
2849 currently active keylist mode is used to retrieve the key. The key
2850 will have one reference for the user.
2852 If the key is not found in the keyring, @code{gpgme_get_key} returns
2853 the error code @code{GPG_ERR_EOF} and *@var{r_key} will be set to
2856 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2857 @var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a
2858 fingerprint or key ID, @code{GPG_ERR_AMBIGUOUS_NAME} if the key ID was
2859 not a unique specifier for a key, and @code{GPG_ERR_ENOMEM} if at some
2860 time during the operation there was not enough memory available.
2864 @node Information About Keys
2865 @subsection Information About Keys
2866 @cindex key, information about
2867 @cindex key, attributes
2868 @cindex attributes, of a key
2870 Please see the beginning of this section for more information about
2871 @code{gpgme_key_t} objects.
2873 @deftp {Data type} gpgme_validity_t
2874 The @code{gpgme_validity_t} type is used to specify the validity of a user ID
2875 in a key. The following validities are defined:
2878 @item GPGME_VALIDITY_UNKNOWN
2879 The user ID is of unknown validity. The string representation of this
2882 @item GPGME_VALIDITY_UNDEFINED
2883 The validity of the user ID is undefined. The string representation of this
2886 @item GPGME_VALIDITY_NEVER
2887 The user ID is never valid. The string representation of this
2890 @item GPGME_VALIDITY_MARGINAL
2891 The user ID is marginally valid. The string representation of this
2894 @item GPGME_VALIDITY_FULL
2895 The user ID is fully valid. The string representation of this
2898 @item GPGME_VALIDITY_ULTIMATE
2899 The user ID is ultimately valid. The string representation of this
2905 The following interfaces are deprecated and only provided for backward
2906 compatibility. Don't use them. They will be removed in a future
2907 version of @acronym{GPGME}.
2909 @deftp {Data type} gpgme_attr_t
2910 The @code{gpgme_attr_t} type is used to specify a key or trust item
2911 attribute. The following attributes are defined:
2914 @item GPGME_ATTR_KEYID
2915 This is the key ID of a sub key. It is representable as a string.
2917 For trust items, the trust item refers to the key with this ID.
2919 @item GPGME_ATTR_FPR
2920 This is the fingerprint of a sub key. It is representable as a
2923 @item GPGME_ATTR_ALGO
2924 This is the crypto algorithm for which the sub key can be used. It
2925 is representable as a string and as a number. The numbers correspond
2926 to the @code{enum gcry_pk_algos} values in the gcrypt library.
2928 @item GPGME_ATTR_LEN
2929 This is the key length of a sub key. It is representable as a
2932 @item GPGME_ATTR_CREATED
2933 This is the timestamp at creation time of a sub key. It is
2934 representable as a number.
2936 @item GPGME_ATTR_EXPIRE
2937 This is the expiration time of a sub key. It is representable as a
2940 @item GPGME_ATTR_OTRUST
2941 XXX FIXME (also for trust items)
2943 @item GPGME_ATTR_USERID
2944 This is a user ID. There can be more than one user IDs in a
2945 @var{gpgme_key_t} object. The first one (with index 0) is the primary
2946 user ID. The user ID is representable as a number.
2948 For trust items, this is the user ID associated with this trust item.
2950 @item GPGME_ATTR_NAME
2951 This is the name belonging to a user ID. It is representable as a string.
2953 @item GPGME_ATTR_EMAIL
2954 This is the email address belonging to a user ID. It is representable
2957 @item GPGME_ATTR_COMMENT
2958 This is the comment belonging to a user ID. It is representable as a
2961 @item GPGME_ATTR_VALIDITY
2962 This is the validity belonging to a user ID. It is representable as a
2963 string and as a number. See below for a list of available validities.
2965 For trust items, this is the validity that is associated with this
2968 @item GPGME_ATTR_UID_REVOKED
2969 This specifies if a user ID is revoked. It is representable as a
2970 number, and is @code{1} if the user ID is revoked, and @code{0}
2973 @item GPGME_ATTR_UID_INVALID
2974 This specifies if a user ID is invalid. It is representable as a
2975 number, and is @code{1} if the user ID is invalid, and @code{0}
2978 @item GPGME_ATTR_LEVEL
2979 This is the trust level of a trust item.
2981 @item GPGME_ATTR_TYPE
2982 This returns information about the type of key. For the string function
2983 this will eother be "PGP" or "X.509". The integer function returns 0
2984 for PGP and 1 for X.509. It is also used for the type of a trust item.
2986 @item GPGME_ATTR_IS_SECRET
2987 This specifies if the key is a secret key. It is representable as a
2988 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
2990 @item GPGME_ATTR_KEY_REVOKED
2991 This specifies if a sub key is revoked. It is representable as a
2992 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
2994 @item GPGME_ATTR_KEY_INVALID
2995 This specifies if a sub key is invalid. It is representable as a
2996 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
2998 @item GPGME_ATTR_KEY_EXPIRED
2999 This specifies if a sub key is expired. It is representable as a
3000 number, and is @code{1} if the key is expired, and @code{0} otherwise.
3002 @item GPGME_ATTR_KEY_DISABLED
3003 This specifies if a sub key is disabled. It is representable as a
3004 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
3006 @item GPGME_ATTR_KEY_CAPS
3007 This is a description of the capabilities of a sub key. It is
3008 representable as a string. The string contains the letter ``e'' if
3009 the key can be used for encryption, ``s'' if the key can be used for
3010 signatures, and ``c'' if the key can be used for certifications.
3012 @item GPGME_ATTR_CAN_ENCRYPT
3013 This specifies if a sub key can be used for encryption. It is
3014 representable as a number, and is @code{1} if the sub key can be used
3015 for encryption, and @code{0} otherwise.
3017 @item GPGME_ATTR_CAN_SIGN
3018 This specifies if a sub key can be used to create data signatures. It
3019 is representable as a number, and is @code{1} if the sub key can be
3020 used for signatures, and @code{0} otherwise.
3022 @item GPGME_ATTR_CAN_CERTIFY
3023 This specifies if a sub key can be used to create key certificates.
3024 It is representable as a number, and is @code{1} if the sub key can be
3025 used for certifications, and @code{0} otherwise.
3027 @item GPGME_ATTR_SERIAL
3028 The X.509 issuer serial attribute of the key. It is representable as
3031 @item GPGME_ATTR_ISSUE
3032 The X.509 issuer name attribute of the key. It is representable as a
3035 @item GPGME_ATTR_CHAINID
3036 The X.509 chain ID can be used to build the certification chain. It
3037 is representable as a string.
3041 @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}})
3042 The function @code{gpgme_key_get_string_attr} returns the value of the
3043 string-representable attribute @var{what} of key @var{key}. If the
3044 attribute is an attribute of a sub key or an user ID, @var{idx}
3045 specifies the sub key or user ID of which the attribute value is
3046 returned. The argument @var{reserved} is reserved for later use and
3047 should be @code{NULL}.
3049 The string returned is only valid as long as the key is valid.
3051 The function returns @code{0} if an attribute can't be returned as a
3052 string, @var{key} is not a valid pointer, @var{idx} out of range,
3053 or @var{reserved} not @code{NULL}.
3056 @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}})
3057 The function @code{gpgme_key_get_ulong_attr} returns the value of the
3058 number-representable attribute @var{what} of key @var{key}. If the
3059 attribute is an attribute of a sub key or an user ID, @var{idx}
3060 specifies the sub key or user ID of which the attribute value is
3061 returned. The argument @var{reserved} is reserved for later use and
3062 should be @code{NULL}.
3064 The function returns @code{0} if the attribute can't be returned as a
3065 number, @var{key} is not a valid pointer, @var{idx} out of range, or
3066 @var{reserved} not @code{NULL}.
3070 @node Key Signatures
3071 @subsection Key Signatures
3072 @cindex key, signatures
3073 @cindex signatures, on a key
3075 The following interfaces are deprecated and only provided for backward
3076 compatibility. Don't use them. They will be removed in a future
3077 version of @acronym{GPGME}.
3079 The signatures on a key are only available if the key was retrieved
3080 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
3081 enabled, because it is expensive to retrieve all signatures of a key.
3083 So, before using the below interfaces to retrieve the signatures on a
3084 key, you have to make sure that the key was listed with signatures
3085 enabled. One convenient, but blocking, way to do this is to use the
3086 function @code{gpgme_get_key}.
3088 @deftp {Data type} gpgme_attr_t
3089 The @code{gpgme_attr_t} type is used to specify a key signature
3090 attribute. The following attributes are defined:
3093 @item GPGME_ATTR_KEYID
3094 This is the key ID of the key which was used for the signature. It is
3095 representable as a string.
3097 @item GPGME_ATTR_ALGO
3098 This is the crypto algorithm used to create the signature. It is
3099 representable as a string and as a number. The numbers correspond to
3100 the @code{enum gcry_pk_algos} values in the gcrypt library.
3102 @item GPGME_ATTR_CREATED
3103 This is the timestamp at creation time of the signature. It is
3104 representable as a number.
3106 @item GPGME_ATTR_EXPIRE
3107 This is the expiration time of the signature. It is representable as
3110 @item GPGME_ATTR_USERID
3111 This is the user ID associated with the signing key. The user ID is
3112 representable as a number.
3114 @item GPGME_ATTR_NAME
3115 This is the name belonging to a user ID. It is representable as a string.
3117 @item GPGME_ATTR_EMAIL
3118 This is the email address belonging to a user ID. It is representable
3121 @item GPGME_ATTR_COMMENT
3122 This is the comment belonging to a user ID. It is representable as a
3125 @item GPGME_ATTR_KEY_REVOKED
3126 This specifies if a key signature is a revocation signature. It is
3127 representable as a number, and is @code{1} if the key is revoked, and
3130 @c @item GPGME_ATTR_KEY_EXPIRED
3131 @c This specifies if a key signature is expired. It is representable as
3132 @c a number, and is @code{1} if the key is revoked, and @code{0}
3135 @item GPGME_ATTR_SIG_CLASS
3136 This specifies the signature class of a key signature. It is
3137 representable as a number. The meaning is specific to the crypto
3140 @item GPGME_ATTR_SIG_CLASS
3141 This specifies the signature class of a key signature. It is
3142 representable as a number. The meaning is specific to the crypto
3145 @item GPGME_ATTR_SIG_STATUS
3146 This is the same value as returned by @code{gpgme_get_sig_status}.
3150 @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}})
3151 The function @code{gpgme_key_sig_get_string_attr} returns the value of
3152 the string-representable attribute @var{what} of the signature
3153 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3154 argument @var{reserved} is reserved for later use and should be
3157 The string returned is only valid as long as the key is valid.
3159 The function returns @code{0} if an attribute can't be returned as a
3160 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3161 out of range, or @var{reserved} not @code{NULL}.
3164 @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}})
3165 The function @code{gpgme_key_sig_get_ulong_attr} returns the value of
3166 the number-representable attribute @var{what} of the signature
3167 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3168 argument @var{reserved} is reserved for later use and should be
3171 The function returns @code{0} if an attribute can't be returned as a
3172 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3173 out of range, or @var{reserved} not @code{NULL}.
3177 @node Manipulating Keys
3178 @subsection Manipulating Keys
3179 @cindex key, manipulation
3181 @deftypefun void gpgme_key_ref (@w{gpgme_key_t @var{key}})
3182 The function @code{gpgme_key_ref} acquires an additional reference for
3186 @deftypefun void gpgme_key_unref (@w{gpgme_key_t @var{key}})
3187 The function @code{gpgme_key_unref} releases a reference for the key
3188 @var{key}. If this was the last reference, the key will be destroyed
3189 and all resources associated to it will be released.
3193 The following interface is deprecated and only provided for backward
3194 compatibility. Don't use it. It will be removed in a future version
3197 @deftypefun void gpgme_key_release (@w{gpgme_key_t @var{key}})
3198 The function @code{gpgme_key_release} is equivalent to
3199 @code{gpgme_key_unref}.
3203 @node Generating Keys
3204 @subsection Generating Keys
3205 @cindex key, creation
3206 @cindex key ring, add
3208 @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}})
3209 The function @code{gpgme_op_genkey} generates a new key pair in the
3210 context @var{ctx}. The meaning of @var{public} and @var{secret}
3211 depends on the crypto backend.
3213 GnuPG does not support @var{public} and @var{secret}, they should be
3214 @code{NULL}. GnuPG will generate a key pair and add it to the
3215 standard key ring. The fingerprint of the generated key is available
3216 with @code{gpgme_op_genkey_result}.
3218 GpgSM requires @var{public} to be a writable data object. GpgSM will
3219 generate a secret key (which will be stored by @command{gpg-agent},
3220 and return a certificate request in @var{public}, which then needs to
3221 be signed by the certification authority and imported before it can be
3222 used. GpgSM does not make the fingerprint available.
3224 The argument @var{parms} specifies parameters for the key in an XML
3225 string. The details about the format of @var{parms} are specific to
3226 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
3230 <GnupgKeyParms format="internal">
3235 Name-Real: Joe Tester
3236 Name-Comment: with stupid passphrase
3237 Name-Email: joe@@foo.bar
3243 Here is an example for GpgSM as the crypto engine:
3246 <GnupgKeyParms format="internal">
3249 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3250 Name-Email: joe@@foo.bar
3254 Strings should be given in UTF-8 encoding. The only format supported
3255 for now is ``internal''. The content of the @code{GnupgKeyParms}
3256 container is passed verbatim to the crypto backend. Control
3257 statements are not allowed.
3259 After the operation completed successfully, the result can be
3260 retrieved with @code{gpgme_op_genkey_result}.
3262 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3263 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3264 @var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if
3265 @var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL}
3266 if no key was created by the backend.
3269 @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}})
3270 The function @code{gpgme_op_genkey_start} initiates a
3271 @code{gpgme_op_genkey} operation. It can be completed by calling
3272 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3274 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3275 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3276 @var{parms} is not a valid XML string, and
3277 @code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not
3281 @deftp {Data type} {gpgme_genkey_result_t}
3282 This is a pointer to a structure used to store the result of a
3283 @code{gpgme_op_genkey} operation. After successfully generating a
3284 key, you can retrieve the pointer to the result with
3285 @code{gpgme_op_genkey_result}. The structure contains the following
3289 @item unsigned int primary : 1
3290 This is a flag that is set to 1 if a primary key was created and to 0
3293 @item unsigned int sub : 1
3294 This is a flag that is set to 1 if a subkey was created and to 0
3298 This is the fingerprint of the key that was created. If both a
3299 primary and a sub key were generated, the fingerprint of the primary
3300 key will be returned. If the crypto engine does not provide the
3301 fingerprint, @code{fpr} will be a null pointer.
3305 @deftypefun gpgme_genkey_result_t gpgme_op_genkey_result (@w{gpgme_ctx_t @var{ctx}})
3306 The function @code{gpgme_op_genkey_result} returns a
3307 @code{gpgme_genkey_result_t} pointer to a structure holding the result of
3308 a @code{gpgme_op_genkey} operation. The pointer is only valid if the
3309 last operation on the context was a @code{gpgme_op_genkey} or
3310 @code{gpgme_op_genkey_start} operation, and if this operation finished
3311 successfully. The returned pointer is only valid until the next
3312 operation is started on the context.
3316 @node Exporting Keys
3317 @subsection Exporting Keys
3319 @cindex key ring, export from
3321 @deftypefun gpgme_error_t gpgme_op_export (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}})
3322 The function @code{gpgme_op_export} extracts public keys and returns
3323 them in the data buffer @var{keydata}. The output format of the key
3324 data returned is determined by the @acronym{ASCII} armor attribute set
3325 for the context @var{ctx}, or, if that is not set, by the encoding
3326 specified for @var{keydata}.
3328 If @var{pattern} is @code{NULL}, all available keys are returned.
3329 Otherwise, @var{pattern} contains an engine specific expression that
3330 is used to limit the list to all keys matching the pattern.
3332 @var{reserved} is reserved for future use and must be @code{0}.
3334 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3335 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3336 @var{keydata} is not a valid empty data buffer, and passes through any
3337 errors that are reported by the crypto engine support routines.
3340 @deftypefun gpgme_error_t gpgme_op_export_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}})
3341 The function @code{gpgme_op_export_start} initiates a
3342 @code{gpgme_op_export} operation. It can be completed by calling
3343 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3345 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3346 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3347 if @var{keydata} is not a valid empty data buffer.
3350 @deftypefun gpgme_error_t gpgme_op_export_ext (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}})
3351 The function @code{gpgme_op_export} extracts public keys and returns
3352 them in the data buffer @var{keydata}. The output format of the key
3353 data returned is determined by the @acronym{ASCII} armor attribute set
3354 for the context @var{ctx}, or, if that is not set, by the encoding
3355 specified for @var{keydata}.
3357 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3358 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3359 array of strings that are used to limit the list to all keys matching
3360 at least one of the patterns verbatim.
3362 @var{reserved} is reserved for future use and must be @code{0}.
3364 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3365 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3366 @var{keydata} is not a valid empty data buffer, and passes through any
3367 errors that are reported by the crypto engine support routines.
3370 @deftypefun gpgme_error_t gpgme_op_export_ext_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}})
3371 The function @code{gpgme_op_export_ext_start} initiates a
3372 @code{gpgme_op_export_ext} operation. It can be completed by calling
3373 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3375 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3376 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3377 if @var{keydata} is not a valid empty data buffer.
3381 @node Importing Keys
3382 @subsection Importing Keys
3384 @cindex key ring, import to
3386 @deftypefun gpgme_error_t gpgme_op_import (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3387 The function @code{gpgme_op_import} adds the keys in the data buffer
3388 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
3389 The format of @var{keydata} can be @acronym{ASCII} armored, for example,
3390 but the details are specific to the crypto engine.
3392 After the operation completed successfully, the result can be
3393 retrieved with @code{gpgme_op_import_result}.
3395 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3396 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3397 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3398 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3401 @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3402 The function @code{gpgme_op_import_start} initiates a
3403 @code{gpgme_op_import} operation. It can be completed by calling
3404 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3406 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3407 import could be started successfully, @code{GPG_ERR_INV_VALUE} if
3408 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3409 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3412 @deftp {Data type} {gpgme_import_status_t}
3413 This is a pointer to a structure used to store a part of the result of
3414 a @code{gpgme_op_import} operation. For each considered key one
3415 status is added that contains information about the result of the
3416 import. The structure contains the following members:
3419 @item gpgme_import_status_t next
3420 This is a pointer to the next status structure in the linked list, or
3421 @code{NULL} if this is the last element.
3424 This is the fingerprint of the key that was considered.
3426 @item gpgme_error_t result
3427 If the import was not successful, this is the error value that caused
3428 the import to fail. Otherwise the error code is
3429 @code{GPG_ERR_NO_ERROR}.
3431 @item unsigned int status
3432 This is a bit-wise OR of the following flags that give more
3433 information about what part of the key was imported. If the key was
3434 already known, this might be 0.
3437 @item GPGME_IMPORT_NEW
3440 @item GPGME_IMPORT_UID
3441 The key contained new user IDs.
3443 @item GPGME_IMPORT_SIG
3444 The key contained new signatures.
3446 @item GPGME_IMPORT_SUBKEY
3447 The key contained new sub keys.
3449 @item GPGME_IMPORT_SECRET
3450 The key contained a secret key.
3455 @deftp {Data type} {gpgme_import_result_t}
3456 This is a pointer to a structure used to store the result of a
3457 @code{gpgme_op_import} operation. After a successful import
3458 operation, you can retrieve the pointer to the result with
3459 @code{gpgme_op_import_result}. The structure contains the following
3463 @item int considered
3464 The total number of considered keys.
3466 @item int no_user_id
3467 The number of keys without user ID.
3470 The total number of imported keys.
3473 The number of imported RSA keys.
3476 The number of unchanged keys.
3479 The number of new user IDs.
3482 The number of new sub keys.
3484 @item new_signatures
3485 The number of new signatures.
3487 @item new_revocations
3488 The number of new revocations.
3491 The total number of secret keys read.
3493 @item secret_imported
3494 The number of imported secret keys.
3496 @item secret_unchanged
3497 The number of unchanged secret keys.
3500 The number of keys not imported.
3502 @item gpgme_import_status_t imports
3503 A list of gpgme_import_status_t objects which contain more information
3504 about the keys for which an import was attempted.
3508 @deftypefun gpgme_import_result_t gpgme_op_import_result (@w{gpgme_ctx_t @var{ctx}})
3509 The function @code{gpgme_op_import_result} returns a
3510 @code{gpgme_import_result_t} pointer to a structure holding the result
3511 of a @code{gpgme_op_import} operation. The pointer is only valid if
3512 the last operation on the context was a @code{gpgme_op_import} or
3513 @code{gpgme_op_import_start} operation, and if this operation finished
3514 successfully. The returned pointer is only valid until the next
3515 operation is started on the context.
3518 The following interface is deprecated and only provided for backward
3519 compatibility. Don't use it. It will be removed in a future version
3522 @deftypefun gpgme_error_t gpgme_op_import_ext (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}}, @w{int *@var{nr}})
3523 The function @code{gpgme_op_import_ext} is equivalent to:
3526 gpgme_error_t err = gpgme_op_import (ctx, keydata);
3529 gpgme_import_result_t result = gpgme_op_import_result (ctx);
3530 *nr = result->considered;
3537 @subsection Deleting Keys
3539 @cindex key ring, delete from
3541 @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}})
3542 The function @code{gpgme_op_delete} deletes the key @var{key} from the
3543 key ring of the crypto engine used by @var{ctx}. If
3544 @var{allow_secret} is @code{0}, only public keys are deleted,
3545 otherwise secret keys are deleted as well, if that is supported.
3547 The function returns the error code @code{GPG_ERR_NO_ERROR} if the key
3548 was deleted successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3549 @var{key} is not a valid pointer, @code{GPG_ERR_NO_PUBKEY} if
3550 @var{key} could not be found in the keyring,
3551 @code{GPG_ERR_AMBIGUOUS_NAME} if the key was not specified
3552 unambiguously, and @code{GPG_ERR_CONFLICT} if the secret key for
3553 @var{key} is available, but @var{allow_secret} is zero.
3556 @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}})
3557 The function @code{gpgme_op_delete_start} initiates a
3558 @code{gpgme_op_delete} operation. It can be completed by calling
3559 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3561 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3562 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3563 @var{ctx} or @var{key} is not a valid pointer.
3567 @node Advanced Key Editing
3568 @subsection Advanced Key Editing
3571 @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}})}
3572 @tindex gpgme_edit_cb_t
3573 The @code{gpgme_edit_cb_t} type is the type of functions which
3574 @acronym{GPGME} calls if it a key edit operation is on-going. The
3575 status code @var{status} and the argument line @var{args} are passed
3576 through by @acronym{GPGME} from the crypto engine. The file
3577 descriptor @var{fd} is -1 for normal status messages. If @var{status}
3578 indicates a command rather than a status message, the response to the
3579 command should be written to @var{fd}. The @var{handle} is provided
3580 by the user at start of operation.
3582 The function should return @code{GPG_ERR_NO_ERROR} or an error value.
3585 @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}})
3586 The function @code{gpgme_op_edit} processes the key @var{KEY}
3587 interactively, using the edit callback function @var{FNC} with the
3588 handle @var{HANDLE}. The callback is invoked for every status and
3589 command request from the crypto engine. The output of the crypto
3590 engine is written to the data object @var{out}.
3592 Note that the protocol between the callback function and the crypto
3593 engine is specific to the crypto engine and no further support in
3594 implementing this protocol correctly is provided by @acronym{GPGME}.
3596 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3597 edit operation completes successfully, @code{GPG_ERR_INV_VALUE} if
3598 @var{ctx} or @var{key} is not a valid pointer, and any error returned
3599 by the crypto engine or the edit callback handler.
3602 @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}})
3603 The function @code{gpgme_op_edit_start} initiates a
3604 @code{gpgme_op_edit} operation. It can be completed by calling
3605 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3607 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3608 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3609 @var{ctx} or @var{key} is not a valid pointer.
3613 @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}})
3614 The function @code{gpgme_op_card_edit} is analogous to
3615 @code{gpgme_op_edit}, but should be used to process the smart card corresponding to the key @var{key}.
3618 @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}})
3619 The function @code{gpgme_op_card_edit_start} initiates a
3620 @code{gpgme_op_card_edit} operation. It can be completed by calling
3621 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3623 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3624 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3625 @var{ctx} or @var{key} is not a valid pointer.
3629 @node Trust Item Management
3630 @section Trust Item Management
3633 @strong{Caution:} The trust items interface is experimental.
3635 @deftp {Data type} gpgme_trust_item_t
3636 The @code{gpgme_trust_item_t} type is a pointer to a trust item object.
3637 It has the following members:
3641 This is a string describing the key to which this trust items belongs.
3644 This is the type of the trust item. A value of 1 refers to a key, a
3645 value of 2 refers to a user ID.
3648 This is the trust level.
3650 @item char *owner_trust
3651 The owner trust if @code{type} is 1.
3653 @item char *validity
3654 The calculated validity.
3657 The user name if @code{type} is 2.
3662 * Listing Trust Items:: Browsing the list of available trust items.
3663 * Information About Trust Items:: Requesting information about trust items.
3664 * Manipulating Trust Items:: Operations on trust items.
3668 @node Listing Trust Items
3669 @subsection Listing Trust Items
3670 @cindex trust item list
3672 @deftypefun gpgme_error_t gpgme_op_trustlist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}})
3673 The function @code{gpgme_op_trustlist_start} initiates a trust item
3674 listing operation inside the context @var{ctx}. It sets everything up
3675 so that subsequent invocations of @code{gpgme_op_trustlist_next} return
3676 the trust items in the list.
3678 The string @var{pattern} contains an engine specific expression that
3679 is used to limit the list to all trust items matching the pattern. It
3680 can not be the empty string.
3682 The argument @var{max_level} is currently ignored.
3684 The context will be busy until either all trust items are received
3685 (and @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}), or
3686 @code{gpgme_op_trustlist_end} is called to finish the operation.
3688 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3689 @var{ctx} is not a valid pointer, and passes through any errors that
3690 are reported by the crypto engine support routines.
3693 @deftypefun gpgme_error_t gpgme_op_trustlist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_trust_item_t *@var{r_item}})
3694 The function @code{gpgme_op_trustlist_next} returns the next trust
3695 item in the list created by a previous @code{gpgme_op_trustlist_start}
3696 operation in the context @var{ctx}. The trust item can be destroyed
3697 with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}.
3699 This is the only way to get at @code{gpgme_trust_item_t} objects in
3702 If the last trust item in the list has already been returned,
3703 @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}.
3705 The function returns the error code @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3706 @var{r_item} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if
3707 there is not enough memory for the operation.
3710 @deftypefun gpgme_error_t gpgme_op_trustlist_end (@w{gpgme_ctx_t @var{ctx}})
3711 The function @code{gpgme_op_trustlist_next} ends a pending key list
3712 operation in the context @var{ctx}.
3714 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3715 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
3716 time during the operation there was not enough memory available.
3720 @node Information About Trust Items
3721 @subsection Information About Trust Items
3722 @cindex trust item, information about
3723 @cindex trust item, attributes
3724 @cindex attributes, of a trust item
3726 The following interfaces are deprecated and only provided for backward
3727 compatibility. Don't use them. They will be removed in a future
3728 version of @acronym{GPGME}.
3730 Trust items have attributes which can be queried using the interfaces
3731 below. The attribute identifiers are shared with those for key
3732 attributes. @xref{Information About Keys}.
3734 @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}})
3735 The function @code{gpgme_trust_item_get_string_attr} returns the value
3736 of the string-representable attribute @var{what} of trust item
3737 @var{item}. The arguments @var{idx} and @var{reserved} are reserved
3738 for later use and should be @code{0} and @code{NULL} respectively.
3740 The string returned is only valid as long as the key is valid.
3742 The function returns @code{0} if an attribute can't be returned as a
3743 string, @var{key} is not a valid pointer, @var{idx} out of range,
3744 or @var{reserved} not @code{NULL}.
3747 @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}})
3748 The function @code{gpgme_trust_item_get_int_attr} returns the value of
3749 the number-representable attribute @var{what} of trust item
3750 @var{item}. If the attribute occurs more than once in the trust item,
3751 the index is specified by @var{idx}. However, currently no such
3752 attribute exists, so @var{idx} should be @code{0}. The argument
3753 @var{reserved} is reserved for later use and should be @code{NULL}.
3755 The function returns @code{0} if the attribute can't be returned as a
3756 number, @var{key} is not a valid pointer, @var{idx} out of range,
3757 or @var{reserved} not @code{NULL}.
3761 @node Manipulating Trust Items
3762 @subsection Manipulating Trust Items
3763 @cindex trust item, manipulation
3765 @deftypefun void gpgme_trust_item_ref (@w{gpgme_trust_item_t @var{item}})
3766 The function @code{gpgme_trust_item_ref} acquires an additional
3767 reference for the trust item @var{item}.
3770 @deftypefun void gpgme_trust_item_unref (@w{gpgme_trust_item_t @var{item}})
3771 The function @code{gpgme_trust_item_unref} releases a reference for
3772 the trust item @var{item}. If this was the last reference, the trust
3773 item will be destroyed and all resources associated to it will be
3778 The following interface is deprecated and only provided for backward
3779 compatibility. Don't use it. It will be removed in a future version
3782 @deftypefun void gpgme_trust_item_release (@w{gpgme_trust_item_t @var{item}})
3783 The function @code{gpgme_trust_item_release} is an alias for
3784 @code{gpgme_trust_item_unref}.
3788 @node Crypto Operations
3789 @section Crypto Operations
3790 @cindex cryptographic operation
3792 Sometimes, the result of a crypto operation returns a list of invalid
3793 keys encountered in processing the request. The following structure
3794 is used to hold information about such a key.
3796 @deftp {Data type} {gpgme_invalid_key_t}
3797 This is a pointer to a structure used to store a part of the result of
3798 a crypto operation which takes user IDs as one input parameter. The
3799 structure contains the following members:
3802 @item gpgme_invalid_key_t next
3803 This is a pointer to the next invalid key structure in the linked
3804 list, or @code{NULL} if this is the last element.
3807 The fingerprint or key ID of the invalid key encountered.
3809 @item gpgme_error_t reason
3810 An error code describing the reason why the key was found invalid.
3816 * Decrypt:: Decrypting a ciphertext.
3817 * Verify:: Verifying a signature.
3818 * Decrypt and Verify:: Decrypting a signed ciphertext.
3819 * Sign:: Creating a signature.
3820 * Encrypt:: Encrypting a plaintext.
3827 @cindex cryptographic operation, decryption
3829 @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}})
3830 The function @code{gpgme_op_decrypt} decrypts the ciphertext in the
3831 data object @var{cipher} and stores it into the data object
3834 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3835 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
3836 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
3837 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
3838 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
3839 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
3840 secret key could not be retrieved, and passes through any errors that
3841 are reported by the crypto engine support routines.
3844 @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}})
3845 The function @code{gpgme_op_decrypt_start} initiates a
3846 @code{gpgme_op_decrypt} operation. It can be completed by calling
3847 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3849 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3850 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3851 if @var{cipher} or @var{plain} is not a valid pointer.
3854 @deftp {Data type} {gpgme_recipient_t}
3855 This is a pointer to a structure used to store information about the
3856 recipient of an encrypted text which is decrypted in a
3857 @code{gpgme_op_decrypt} operation. This information (except for the
3858 status field) is even available before the operation finished
3859 successfully, for example in a passphrase callback. The structure
3860 contains the following members:
3863 @item gpgme_recipient_t next
3864 This is a pointer to the next recipient structure in the linked list,
3865 or @code{NULL} if this is the last element.
3867 @item gpgme_pubkey_algo_t
3868 The public key algorithm used in the encryption.
3870 @item unsigned int wrong_key_usage : 1
3871 This is true if the key was not used according to its policy.
3874 This is the key ID of the key (in hexadecimal digits) used as
3877 @item gpgme_error_t status
3878 This is an error number with the error code GPG_ERR_NO_SECKEY if the
3879 secret key for this recipient is not available, and 0 otherwise.
3883 @deftp {Data type} {gpgme_decrypt_result_t}
3884 This is a pointer to a structure used to store the result of a
3885 @code{gpgme_op_decrypt} operation. After successfully decrypting
3886 data, you can retrieve the pointer to the result with
3887 @code{gpgme_op_decrypt_result}. The structure contains the following
3891 @item char *unsupported_algorithm
3892 If an unsupported algorithm was encountered, this string describes the
3893 algorithm that is not supported.
3895 @item unsigned int wrong_key_usage : 1
3896 This is true if the key was not used according to its policy.
3898 @item gpgme_recipient_t recipient
3899 This is a linked list of recipients to which this message was encrypted.
3901 @item char *file_name
3902 This is the filename of the original plaintext message file if it is
3903 known, otherwise this is a null pointer.
3907 @deftypefun gpgme_decrypt_result_t gpgme_op_decrypt_result (@w{gpgme_ctx_t @var{ctx}})
3908 The function @code{gpgme_op_decrypt_result} returns a
3909 @code{gpgme_decrypt_result_t} pointer to a structure holding the
3910 result of a @code{gpgme_op_decrypt} operation. The pointer is only
3911 valid if the last operation on the context was a
3912 @code{gpgme_op_decrypt} or @code{gpgme_op_decrypt_start} operation.
3913 If the operation failed this might be a @code{NULL} pointer. The
3914 returned pointer is only valid until the next operation is started on
3921 @cindex verification
3922 @cindex signature, verification
3923 @cindex cryptographic operation, verification
3924 @cindex cryptographic operation, signature check
3925 @cindex signature notation data
3926 @cindex notation data
3928 @deftypefun gpgme_error_t gpgme_op_verify (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{sig}}, @w{gpgme_data_t @var{signed_text}}, @w{gpgme_data_t @var{plain}})
3929 The function @code{gpgme_op_verify} verifies that the signature in the
3930 data object @var{sig} is a valid signature. If @var{sig} is a
3931 detached signature, then the signed text should be provided in
3932 @var{signed_text} and @var{plain} should be a null pointer.
3933 Otherwise, if @var{sig} is a normal (or cleartext) signature,
3934 @var{signed_text} should be a null pointer and @var{plain} should be a
3935 writable data object that will contain the plaintext after successful
3938 The results of the individual signature verifications can be retrieved
3939 with @code{gpgme_op_verify_result}.
3941 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3942 operation could be completed successfully, @code{GPG_ERR_INV_VALUE} if
3943 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer,
3944 @code{GPG_ERR_NO_DATA} if @var{sig} does not contain any data to
3945 verify, and passes through any errors that are reported by the crypto
3946 engine support routines.
3949 @deftypefun gpgme_error_t gpgme_op_verify_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{sig}}, @w{gpgme_data_t @var{signed_text}}, @w{gpgme_data_t @var{plain}})
3950 The function @code{gpgme_op_verify_start} initiates a
3951 @code{gpgme_op_verify} operation. It can be completed by calling
3952 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3954 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3955 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3956 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer, and
3957 @code{GPG_ERR_NO_DATA} if @var{sig} or @var{plain} does not contain
3961 @deftp {Data type} {gpgme_sig_notation_t}
3962 This is a pointer to a structure used to store a part of the result of
3963 a @code{gpgme_op_verify} operation. The structure contains the
3967 @item gpgme_sig_notation_t next
3968 This is a pointer to the next new signature notation structure in the
3969 linked list, or @code{NULL} if this is the last element.
3972 The name of the notation field. If this is @code{NULL}, then the
3973 member @code{value} will contain a policy URL.
3976 The length of the @code{name} field. For strings the length is
3977 counted without the trailing binary zero.
3980 The value of the notation field. If @code{name} is @code{NULL}, then
3981 this is a policy URL.
3984 The length of the @code{value} field. For strings the length is
3985 counted without the trailing binary zero.
3987 @item gpgme_sig_notation_flags_t flags
3988 The accumulated flags field. This field contains the flags associated
3989 with the notation data in an accumulated form which can be used as an
3990 argument to the function @code{gpgme_sig_notation_add}. The value
3991 @code{flags} is a bitwise-or combination of one or multiple of the
3992 following bit values:
3995 @item GPGME_SIG_NOTATION_HUMAN_READABLE
3996 The @code{GPGME_SIG_NOTATION_HUMAN_READABLE} symbol specifies that the
3997 notation data is in human readable form
3999 @item GPGME_SIG_NOTATION_CRITICAL
4000 The @code{GPGME_SIG_NOTATION_CRITICAL} symbol specifies that the
4001 notation data is critical.
4005 @item unsigned int human_readable : 1
4006 This is true if the @code{GPGME_SIG_NOTATION_HUMAN_READABLE} flag is
4007 set and false otherwise. This flag is only valid for notation data,
4008 not for policy URLs.
4010 @item unsigned int critical : 1
4011 This is true if the @code{GPGME_SIG_NOTATION_CRITICAL} flag is set and
4012 false otherwise. This flag is valid for notation data and policy URLs.
4017 @deftp {Data type} {gpgme_signature_t}
4018 This is a pointer to a structure used to store a part of the result of
4019 a @code{gpgme_op_verify} operation. The structure contains the
4023 @item gpgme_signature_t next
4024 This is a pointer to the next new signature structure in the linked
4025 list, or @code{NULL} if this is the last element.
4027 @item gpgme_sigsum_t summary
4028 This is a bit vector giving a summary of the signature status. It
4029 provides an easy interface to a defined semantic of the signature
4030 status. Checking just one bit is sufficient to see whether a
4031 signature is valid without any restrictions.
4033 The defined bits are:
4035 @item GPGME_SIGSUM_VALID
4036 The signature is fully valid.
4038 @item GPGME_SIGSUM_GREEN
4039 The signature is good but one might want to display some extra
4040 information. Check the other bits.
4042 @item GPGME_SIGSUM_RED
4043 The signature is bad. It might be useful to check other bits and
4044 display more information, i.e. a revoked certificate might not render a
4045 signature invalid when the message was received prior to the cause for
4048 @item GPGME_SIGSUM_KEY_REVOKED
4049 The key or at least one certificate has been revoked.
4051 @item GPGME_SIGSUM_KEY_EXPIRED
4052 The key or one of the certificates has expired. It is probably a good
4053 idea to display the date of the expiration.
4055 @item GPGME_SIGSUM_SIG_EXPIRED
4056 The signature has expired.
4058 @item GPGME_SIGSUM_KEY_MISSING
4059 Can't verify due to a missing key or certificate.
4061 @item GPGME_SIGSUM_CRL_MISSING
4062 The CRL (or an equivalent mechanism) is not available.
4064 @item GPGME_SIGSUM_CRL_TOO_OLD
4065 Available CRL is too old.
4067 @item GPGME_SIGSUM_BAD_POLICY
4068 A policy requirement was not met.
4070 @item GPGME_SIGSUM_SYS_ERROR
4071 A system error occured.
4075 This is the fingerprint or key ID of the signature.
4077 @item gpgme_error_t status
4078 This is the status of the signature. In particular, the following
4079 status codes are of interest:
4082 @item GPG_ERR_NO_ERROR
4083 This status indicates that the signature is valid. For the combined
4084 result this status means that all signatures are valid.
4086 @item GPG_ERR_SIG_EXPIRED
4087 This status indicates that the signature is valid but expired. For
4088 the combined result this status means that all signatures are valid
4091 @item GPG_ERR_KEY_EXPIRED
4092 This status indicates that the signature is valid but the key used to
4093 verify the signature has expired. For the combined result this status
4094 means that all signatures are valid and all keys are expired.
4096 @item GPG_ERR_CERT_REVOKED
4097 This status indicates that the signature is valid but the key used
4098 to verify the signature has been revoked. For the combined result
4099 this status means that all signatures are valid and all keys are
4102 @item GPG_ERR_BAD_SIGNATURE
4103 This status indicates that the signature is invalid. For the combined
4104 result this status means that all signatures are invalid.
4106 @item GPG_ERR_NO_PUBKEY
4107 This status indicates that the signature could not be verified due to
4108 a missing key. For the combined result this status means that all
4109 signatures could not be checked due to missing keys.
4111 @item GPG_ERR_GENERAL
4112 This status indicates that there was some other error which prevented
4113 the signature verification.
4116 @item gpgme_sig_notation_t notations
4117 This is a linked list with the notation data and policy URLs.
4119 @item unsigned long timestamp
4120 The creation timestamp of this signature.
4122 @item unsigned long exp_timestamp
4123 The expiration timestamp of this signature, or 0 if the signature does
4126 @item unsigned int wrong_key_usage : 1
4127 This is true if the key was not used according to its policy.
4129 @item unsigned int pka_trust : 2
4130 This is set to the trust information gained by means of the PKA system.
4134 No PKA information available or verification not possible.
4136 PKA verification failed.
4138 PKA verification succeeded.
4140 Reserved for future use.
4142 Depending on the configuration of the engine, this metric may also be
4143 reflected by the validity of the signature.
4145 @item unsigned int chain_model : 1
4146 This is true if the validity of the signature has been checked using the
4147 chain model. In the chain model the time the signature has been created
4148 must be within the validity period of the certificate and the time the
4149 certificate itself has been created must be within the validity period
4150 of the issuing certificate. In contrast the default validation model
4151 checks the validity of signature as well at the entire certificate chain
4152 at the current time.
4155 @item gpgme_validity_t validity
4156 The validity of the signature.
4158 @item gpgme_error_t validity_reason
4159 If a signature is not valid, this provides a reason why.
4161 @item gpgme_pubkey_algo_t
4162 The public key algorithm used to create this signature.
4164 @item gpgme_hash_algo_t
4165 The hash algorithm used to create this signature.
4169 @deftp {Data type} {gpgme_verify_result_t}
4170 This is a pointer to a structure used to store the result of a
4171 @code{gpgme_op_verify} operation. After verifying a signature, you
4172 can retrieve the pointer to the result with
4173 @code{gpgme_op_verify_result}. If the operation failed this might be
4174 a @code{NULL} pointer. The structure contains the following member:
4177 @item gpgme_signature_t signatures
4178 A linked list with information about all signatures for which a
4179 verification was attempted.
4181 @item char *file_name
4182 This is the filename of the original plaintext message file if it is
4183 known, otherwise this is a null pointer.
4187 @deftypefun gpgme_verify_result_t gpgme_op_verify_result (@w{gpgme_ctx_t @var{ctx}})
4188 The function @code{gpgme_op_verify_result} returns a
4189 @code{gpgme_verify_result_t} pointer to a structure holding the result
4190 of a @code{gpgme_op_verify} operation. The pointer is only valid if
4191 the last operation on the context was a @code{gpgme_op_verify},
4192 @code{gpgme_op_verify_start}, @code{gpgme_op_decrypt_verify} or
4193 @code{gpgme_op_decrypt_verify_start} operation, and if this operation
4194 finished successfully (for @code{gpgme_op_decrypt_verify} and
4195 @code{gpgme_op_decrypt_verify_start}, the error code
4196 @code{GPG_ERR_NO_DATA} counts as successful in this context). The
4197 returned pointer is only valid until the next operation is started on
4202 The following interfaces are deprecated and only provided for backward
4203 compatibility. Don't use them. They will be removed in a future
4204 version of @acronym{GPGME}.
4206 @deftp {Data type} {enum gpgme_sig_stat_t}
4207 @tindex gpgme_sig_stat_t
4208 The @code{gpgme_sig_stat_t} type holds the result of a signature check, or
4209 the combined result of all signatures. The following results are
4213 @item GPGME_SIG_STAT_NONE
4214 This status should not occur in normal operation.
4216 @item GPGME_SIG_STAT_GOOD
4217 This status indicates that the signature is valid. For the combined
4218 result this status means that all signatures are valid.
4220 @item GPGME_SIG_STAT_GOOD_EXP
4221 This status indicates that the signature is valid but expired. For
4222 the combined result this status means that all signatures are valid
4225 @item GPGME_SIG_STAT_GOOD_EXPKEY
4226 This status indicates that the signature is valid but the key used to
4227 verify the signature has expired. For the combined result this status
4228 means that all signatures are valid and all keys are expired.
4230 @item GPGME_SIG_STAT_BAD
4231 This status indicates that the signature is invalid. For the combined
4232 result this status means that all signatures are invalid.
4234 @item GPGME_SIG_STAT_NOKEY
4235 This status indicates that the signature could not be verified due to
4236 a missing key. For the combined result this status means that all
4237 signatures could not be checked due to missing keys.
4239 @item GPGME_SIG_STAT_NOSIG
4240 This status indicates that the signature data provided was not a real
4243 @item GPGME_SIG_STAT_ERROR
4244 This status indicates that there was some other error which prevented
4245 the signature verification.
4247 @item GPGME_SIG_STAT_DIFF
4248 For the combined result this status means that at least two signatures
4249 have a different status. You can get each key's status with
4250 @code{gpgme_get_sig_status}.
4254 @deftypefun {const char *} gpgme_get_sig_status (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_sig_stat_t *@var{r_stat}}, @w{time_t *@var{r_created}})
4255 The function @code{gpgme_get_sig_status} is equivalent to:
4258 gpgme_verify_result_t result;
4259 gpgme_signature_t sig;
4261 result = gpgme_op_verify_result (ctx);
4262 sig = result->signatures;
4274 switch (gpg_err_code (sig->status))
4276 case GPG_ERR_NO_ERROR:
4277 *r_stat = GPGME_SIG_STAT_GOOD;
4280 case GPG_ERR_BAD_SIGNATURE:
4281 *r_stat = GPGME_SIG_STAT_BAD;
4284 case GPG_ERR_NO_PUBKEY:
4285 *r_stat = GPGME_SIG_STAT_NOKEY;
4288 case GPG_ERR_NO_DATA:
4289 *r_stat = GPGME_SIG_STAT_NOSIG;
4292 case GPG_ERR_SIG_EXPIRED:
4293 *r_stat = GPGME_SIG_STAT_GOOD_EXP;
4296 case GPG_ERR_KEY_EXPIRED:
4297 *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY;
4301 *r_stat = GPGME_SIG_STAT_ERROR;
4306 *r_created = sig->timestamp;
4311 @deftypefun {const char *} gpgme_get_sig_string_attr (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_attr_t @var{what}}, @w{int @var{whatidx}})
4312 The function @code{gpgme_get_sig_string_attr} is equivalent to:
4315 gpgme_verify_result_t result;
4316 gpgme_signature_t sig;
4318 result = gpgme_op_verify_result (ctx);
4319 sig = result->signatures;
4331 case GPGME_ATTR_FPR:
4334 case GPGME_ATTR_ERRTOK:
4336 return sig->wrong_key_usage ? "Wrong_Key_Usage" : "";
4347 @deftypefun {const char *} gpgme_get_sig_ulong_attr (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_attr_t @var{waht}}, @w{int @var{whatidx}})
4348 The function @code{gpgme_get_sig_ulong_attr} is equivalent to:
4351 gpgme_verify_result_t result;
4352 gpgme_signature_t sig;
4354 result = gpgme_op_verify_result (ctx);
4355 sig = result->signatures;
4367 case GPGME_ATTR_CREATED:
4368 return sig->timestamp;
4370 case GPGME_ATTR_EXPIRE:
4371 return sig->exp_timestamp;
4373 case GPGME_ATTR_VALIDITY:
4374 return (unsigned long) sig->validity;
4376 case GPGME_ATTR_SIG_STATUS:
4377 switch (sig->status)
4379 case GPG_ERR_NO_ERROR:
4380 return GPGME_SIG_STAT_GOOD;
4382 case GPG_ERR_BAD_SIGNATURE:
4383 return GPGME_SIG_STAT_BAD;
4385 case GPG_ERR_NO_PUBKEY:
4386 return GPGME_SIG_STAT_NOKEY;
4388 case GPG_ERR_NO_DATA:
4389 return GPGME_SIG_STAT_NOSIG;
4391 case GPG_ERR_SIG_EXPIRED:
4392 return GPGME_SIG_STAT_GOOD_EXP;
4394 case GPG_ERR_KEY_EXPIRED:
4395 return GPGME_SIG_STAT_GOOD_EXPKEY;
4398 return GPGME_SIG_STAT_ERROR;
4401 case GPGME_ATTR_SIG_SUMMARY:
4402 return sig->summary;