1 \input texinfo @c -*- Texinfo -*-
2 @setfilename gpgme.info
3 @settitle The `GnuPG Made Easy' Reference Manual
5 @dircategory GNU Libraries
7 * @acronym{GPGME}: (gpgme). Adding support for cryptography to your program.
12 @c Unify some of the indices.
17 This file documents the @acronym{GPGME} library.
19 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
20 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
23 @c NOTE: Don't forget to update the year for the TeX version, too.
24 Copyright @copyright{} 2002, 2003, 2004, 2005 g10 Code GmbH.
26 The GPGME reference manual is free software; you can redistribute it
27 and/or modify it under the terms of the GNU Lesser General Public
28 License as published by the Free Software Foundation; either version
29 2.1 of the License, or (at your option) any later version.
31 The GPGME reference manual is distributed in the hope that it will be
32 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34 Lesser General Public License for more details.
36 You should have received a copy of the GNU Lesser General Public
37 License along with this program; if not, write to the Free Software
38 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
43 @shorttitlepage The `GnuPG Made Easy' Reference Manual
46 @center @titlefont{The `GnuPG Made Easy'}
48 @center @titlefont{Reference Manual}
50 @center Edition @value{EDITION}
52 @center last updated @value{UPDATED}
54 @center for version @value{VERSION}
56 @vskip 0pt plus 1filll
57 Copyright @copyright{} 2002, 2003, 2004, 2005 g10 Code GmbH.
60 The GPGME reference manual is free software; you can redistribute it
61 and/or modify it under the terms of the GNU Lesser General Public
62 License as published by the Free Software Foundation; either version
63 2.1 of the License, or (at your option) any later version.
65 The GPGME reference manual is distributed in the hope that it will be
66 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
67 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
68 Lesser General Public License for more details.
70 You should have received a copy of the GNU Lesser General Public
71 License along with this program; if not, write to the Free Software
72 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
79 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
80 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
81 @value{VERSION} of the @acronym{GPGME} library.
85 * Introduction:: How to use this manual.
86 * Preparation:: What you should do before using the library.
87 * Protocols and Engines:: Supported crypto protocols.
88 * Algorithms:: Supported algorithms.
89 * Error Handling:: Error numbers and their meanings.
90 * Exchanging Data:: Passing data to and from @acronym{GPGME}.
91 * Contexts:: Handling @acronym{GPGME} contexts.
95 * Library Copying:: The GNU Lesser General Public License says
96 how you can copy and share `GnuPG Made Easy'.
100 * Concept Index:: Index of concepts and programs.
101 * Function and Data Index:: Index of functions, variables and data types.
105 --- The Detailed Node Listing ---
109 * Getting Started:: Purpose of the manual, and how to use it.
110 * Features:: Reasons to install and use @acronym{GPGME}.
111 * Overview:: Basic architecture of the @acronym{GPGME} library.
115 * Header:: What header file you need to include.
116 * Building the Source:: Compiler options to be used.
117 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
118 * Using Automake:: Compiler options to be used the easy way.
119 * Using Libtool:: Avoiding compiler options entirely.
120 * Library Version Check:: Getting and verifying the library version.
121 * Signal Handling:: How @acronym{GPGME} affects signal handling.
122 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
124 Protocols and Engines
126 * Engine Version Check:: Verifying the engine version.
127 * Engine Information:: Obtaining more information about the engines.
128 * Engine Configuration:: Changing the engine configuration.
129 * OpenPGP:: Support for the OpenPGP protocol.
130 * Cryptographic Message Syntax:: Support for the CMS.
134 * Public Key Algorithms:: A list of all public key algorithms.
135 * Hash Algorithms:: A list of all hash algorithms.
139 * Error Values:: The error value and what it means.
140 * Error Codes:: A list of important error codes.
141 * Error Sources:: A list of important error sources.
142 * Error Strings:: How to get a descriptive string from a value.
146 * Creating Data Buffers:: Creating new data buffers.
147 * Destroying Data Buffers:: Releasing data buffers.
148 * Manipulating Data Buffers:: Operations on data buffers.
150 Creating Data Buffers
152 * Memory Based Data Buffers:: Creating memory based data buffers.
153 * File Based Data Buffers:: Creating file based data buffers.
154 * Callback Based Data Buffers:: Creating callback based data buffers.
156 Manipulating Data Buffers
158 * Data Buffer I/O Operations:: I/O operations on data buffers.
159 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
163 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
164 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
165 * Context Attributes:: Setting properties of a context.
166 * Key Management:: Managing keys with @acronym{GPGME}.
167 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
168 * Crypto Operations:: Using a context for cryptography.
169 * Run Control:: Controlling how operations are run.
173 * Protocol Selection:: Selecting the protocol used by a context.
174 * Crypto Engine:: Configuring the crypto engine.
175 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
176 * Text Mode:: Choosing canonical text mode.
177 * Included Certificates:: Including a number of certificates.
178 * Key Listing Mode:: Selecting key listing mode.
179 * Passphrase Callback:: Getting the passphrase from the user.
180 * Progress Meter Callback:: Being informed about the progress.
181 * Locale:: Setting the locale of a context.
185 * Listing Keys:: Browsing the list of available keys.
186 * Information About Keys:: Requesting detailed information about keys.
187 * Key Signatures:: Listing the signatures on a key.
188 * Manipulating Keys:: Operations on keys.
189 * Generating Keys:: Creating new key pairs.
190 * Exporting Keys:: Retrieving key data from the key ring.
191 * Importing Keys:: Adding keys to the key ring.
192 * Deleting Keys:: Removing keys from the key ring.
194 Trust Item Management
196 * Listing Trust Items:: Browsing the list of available trust items.
197 * Information About Trust Items:: Requesting information about trust items.
198 * Manipulating Trust Items:: Operations on trust items.
202 * Decrypt:: Decrypting a ciphertext.
203 * Verify:: Verifying a signature.
204 * Decrypt and Verify:: Decrypting a signed ciphertext.
205 * Sign:: Creating a signature.
206 * Encrypt:: Encrypting a plaintext.
210 * Selecting Signers:: How to choose the keys to sign with.
211 * Creating a Signature:: How to create a signature.
212 * Signature Notation Data:: How to add notation data to a signature.
216 * Encrypting a Plaintext:: How to encrypt a plaintext.
220 * Waiting For Completion:: Waiting until an operation is completed.
221 * Using External Event Loops:: Advanced control over what happens when.
222 * Cancellation:: How to end pending operations prematurely.
224 Using External Event Loops
226 * I/O Callback Interface:: How I/O callbacks are registered.
227 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
228 * I/O Callback Example:: An example how to use I/O callbacks.
229 * I/O Callback Example GTK+:: How to integrate @acronym{GPGME} in GTK+.
230 * I/O Callback Example GDK:: How to integrate @acronym{GPGME} in GDK.
231 * I/O Callback Example Qt:: How to integrate @acronym{GPGME} in Qt.
237 @chapter Introduction
239 `GnuPG Made Easy' (@acronym{GPGME}) is a C language library that
240 allows to add support for cryptography to a program. It is designed
241 to make access to public key crypto engines like GnuPG or GpgSM easier
242 for applications. @acronym{GPGME} provides a high-level crypto API
243 for encryption, decryption, signing, signature verification and key
246 @acronym{GPGME} uses GnuPG and GpgSM as its backends to support
247 OpenPGP and the Cryptographic Message Syntax (CMS).
250 * Getting Started:: Purpose of the manual, and how to use it.
251 * Features:: Reasons to install and use @acronym{GPGME}.
252 * Overview:: Basic architecture of the @acronym{GPGME} library.
256 @node Getting Started
257 @section Getting Started
259 This manual documents the @acronym{GPGME} library programming
260 interface. All functions and data types provided by the library are
263 The reader is assumed to possess basic knowledge about cryptography in
264 general, and public key cryptography in particular. The underlying
265 cryptographic engines that are used by the library are not explained,
266 but where necessary, special features or requirements by an engine are
267 mentioned as far as they are relevant to @acronym{GPGME} or its users.
269 This manual can be used in several ways. If read from the beginning
270 to the end, it gives a good introduction into the library and how it
271 can be used in an application. Forward references are included where
272 necessary. Later on, the manual can be used as a reference manual to
273 get just the information needed about any particular interface of the
274 library. Experienced programmers might want to start looking at the
275 examples at the end of the manual, and then only read up those parts
276 of the interface which are unclear.
282 @acronym{GPGME} has a couple of advantages over other libraries doing
283 a similar job, and over implementing support for GnuPG or other crypto
284 engines into your application directly.
287 @item it's free software
288 Anybody can use, modify, and redistribute it under the terms of the GNU
289 Lesser General Public License (@pxref{Library Copying}).
292 @acronym{GPGME} provides transparent support for several cryptographic
293 protocols by different engines. Currently, @acronym{GPGME} supports
294 the OpenPGP protocol using GnuPG as the backend, and the Cryptographic
295 Message Syntax using GpgSM as the backend.
298 @acronym{GPGME} hides the differences between the protocols and
299 engines from the programmer behind an easy-to-use interface. This way
300 the programmer can focus on the other parts of the program, and still
301 integrate strong cryptography in his application. Once support for
302 @acronym{GPGME} has been added to a program, it is easy to add support
303 for other crypto protocols once @acronym{GPGME} backends provide them.
310 @acronym{GPGME} provides a data abstraction that is used to pass data
311 to the crypto engine, and receive returned data from it. Data can be
312 read from memory or from files, but it can also be provided by a
315 The actual cryptographic operations are always set within a context.
316 A context provides configuration parameters that define the behaviour
317 of all operations performed within it. Only one operation per context
318 is allowed at any time, but when one operation is finished, you can
319 run the next operation in the same context. There can be more than
320 one context, and all can run different operations at the same time.
322 Furthermore, @acronym{GPGME} has rich key management facilities
323 including listing keys, querying their attributes, generating,
324 importing, exporting and deleting keys, and acquiring information
325 about the trust path.
327 With some precautions, @acronym{GPGME} can be used in a multi-threaded
328 environment, although it is not completely thread safe and thus needs
329 the support of the application.
335 To use @acronym{GPGME}, you have to perform some changes to your
336 sources and the build system. The necessary changes are small and
337 explained in the following sections. At the end of this chapter, it
338 is described how the library is initialized, and how the requirements
339 of the library are verified.
342 * Header:: What header file you need to include.
343 * Building the Source:: Compiler options to be used.
344 * Largefile Support (LFS):: How to use @acronym{GPGME} with LFS.
345 * Using Automake:: Compiler options to be used the easy way.
346 * Using Libtool:: Avoiding compiler options entirely.
347 * Library Version Check:: Getting and verifying the library version.
348 * Signal Handling:: How @acronym{GPGME} affects signal handling.
349 * Multi Threading:: How @acronym{GPGME} can be used in an MT environment.
358 All interfaces (data types and functions) of the library are defined
359 in the header file `gpgme.h'. You must include this in all programs
360 using the library, either directly or through some other header file,
367 The name space of @acronym{GPGME} is @code{gpgme_*} for function names
368 and data types and @code{GPGME_*} for other symbols. Symbols internal
369 to @acronym{GPGME} take the form @code{_gpgme_*} and @code{_GPGME_*}.
371 Because @acronym{GPGME} makes use of the GPG Error library, using
372 @acronym{GPGME} will also use the @code{GPG_ERR_*} name space
373 directly, and the @code{gpg_err*} and @code{gpg_str*} name space
377 @node Building the Source
378 @section Building the Source
379 @cindex compiler options
380 @cindex compiler flags
382 If you want to compile a source file including the `gpgme.h' header
383 file, you must make sure that the compiler can find it in the
384 directory hierarchy. This is accomplished by adding the path to the
385 directory in which the header file is located to the compilers include
386 file search path (via the @option{-I} option).
388 However, the path to the include file is determined at the time the
389 source is configured. To solve this problem, gpgme ships with a small
390 helper program @command{gpgme-config} that knows about the path to the
391 include file and other configuration options. The options that need
392 to be added to the compiler invocation at compile time are output by
393 the @option{--cflags} option to @command{gpgme-config}. The following
394 example shows how it can be used at the command line:
397 gcc -c foo.c `gpgme-config --cflags`
400 Adding the output of @samp{gpgme-config --cflags} to the compiler
401 command line will ensure that the compiler can find the
402 @acronym{GPGME} header file.
404 A similar problem occurs when linking the program with the library.
405 Again, the compiler has to find the library files. For this to work,
406 the path to the library files has to be added to the library search
407 path (via the @option{-L} option). For this, the option
408 @option{--libs} to @command{gpgme-config} can be used. For
409 convenience, this option also outputs all other options that are
410 required to link the program with @acronym{GPGME} (in particular, the
411 @samp{-lgpgme} option). The example shows how to link @file{foo.o}
412 with the @acronym{GPGME} library to a program @command{foo}.
415 gcc -o foo foo.o `gpgme-config --libs`
418 Of course you can also combine both examples to a single command by
419 specifying both options to @command{gpgme-config}:
422 gcc -o foo foo.c `gpgme-config --cflags --libs`
425 If you want to link to one of the thread-safe versions of
426 @acronym{GPGME}, you must specify the @option{--thread} option before
427 any other option to select the thread package you want to link with.
428 Supported thread packages are @option{--thread=pth} and
429 @option{--thread=pthread}.
432 @node Largefile Support (LFS)
433 @section Largefile Support (LFS)
434 @cindex largefile support
437 @acronym{GPGME} is compiled with largefile support by default, if it
438 is available on the system. This means that GPGME supports files
439 larger than two gigabyte in size, if the underlying operating system
440 can. On some systems, largefile support is already the default. On
441 such systems, nothing special is required. However, some systems
442 provide only support for files up to two gigabyte in size by default.
443 Support for larger file sizes has to be specifically enabled.
445 To make a difficult situation even more complex, such systems provide
446 two different types of largefile support. You can either get all
447 relevant functions replaced with alternatives that are largefile
448 capable, or you can get new functions and data types for largefile
449 support added. Those new functions have the same name as their
450 smallfile counterparts, but with a suffix of 64.
452 An example: The data type @code{off_t} is 32 bit wide on GNU/Linux PC
453 systems. To address offsets in large files, you can either enable
454 largefile support add-on. Then a new data type @code{off64_t} is
455 provided, which is 64 bit wide. Or you can replace the existing
456 @code{off_t} data type with its 64 bit wide counterpart. All
457 occurences of @code{off_t} are then automagically replaced.
459 As if matters were not complex enough, there are also two different
460 types of file descriptors in such systems. This is important because
461 if file descriptors are exchanged between programs that use a
462 different maximum file size, certain errors must be produced on some
463 file descriptors to prevent subtle overflow bugs from occuring.
465 As you can see, supporting two different maximum file sizes at the
466 same time is not at all an easy task. However, the maximum file size
467 does matter for @acronym{GPGME}, because some data types it uses in
468 its interfaces are affected by that. For example, the @code{off_t}
469 data type is used in the @code{gpgme_data_seek} function, to match its
470 @acronym{POSIX} counterpart. This affects the call-frame of the
471 function, and thus the ABI of the library. Furthermore, file
472 descriptors can be exchanged between GPGME and the application.
474 For you as the user of the library, this means that your program must
475 be compiled in the same file size mode as the library. Luckily, there
476 is absolutely no valid reason for new programs to not enable largefile
477 support by default and just use that. The compatibility modes (small
478 file sizes or dual mode) can be considered an historic artefact, only
479 useful to allow for a transitional period.
481 @acronym{GPGME} is compiled using largefile support by default. This
482 means that your application must do the same, at least as far as it is
483 relevant for using the @file{gpgme.h} header file. All types in this
484 header files refer to their largefile counterparts, if they are
485 different from any default types on the system.
487 You can enable largefile support, if it is different from the default
488 on the system the application is compiled on, by using the Autoconf
489 macro @code{AC_SYS_LARGEFILE}. If you do this, then you don't need to
490 worry about anything else: It will just work. In this case you might
491 also want to use @code{AC_FUNC_FSEEKO} to take advantage of some new
492 interfaces, and @code{AC_TYPE_OFF_T} (just in case).
494 If you do not use Autoconf, you can define the preprocessor symbol
495 @code{_FILE_OFFSET_BITS} to 64 @emph{before} including any header
496 files, for example by specifying the option
497 @code{-D_FILE_OFFSET_BITS=64} on the compiler command line. You will
498 also want to define the preprocessor symbol @code{LARGEFILE_SOURCE} to
499 1 in this case, to take advantage of some new interfaces.
501 If you do not want to do either of the above, you probably know enough
502 about the issue to invent your own solution. Just keep in mind that
503 the @acronym{GPGME} header file expects that largefile support is
504 enabled, if it is available. In particular, we do not support dual
505 mode (@code{_LARGEFILE64_SOURCE}).
509 @section Using Automake
513 It is much easier if you use GNU Automake instead of writing your own
514 Makefiles. If you do that you do not have to worry about finding and
515 invoking the @command{gpgme-config} script at all. @acronym{GPGME}
516 provides an extension to Automake that does all the work for you.
518 @c A simple macro for optional variables.
520 @r{[}@var{\varname\}@r{]}
522 @defmac AM_PATH_GPGME (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
523 @defmacx AM_PATH_GPGME_PTH (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
524 @defmacx AM_PATH_GPGME_PTHREAD (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found})
525 Check whether @acronym{GPGME} (at least version @var{minimum-version},
526 if given) exists on the host system. If it is found, execute
527 @var{action-if-found}, otherwise do @var{action-if-not-found}, if
530 Additionally, the function defines @code{GPGME_CFLAGS} to the flags
531 needed for compilation of the program to find the @file{gpgme.h}
532 header file, and @code{GPGME_LIBS} to the linker flags needed to link
533 the program to the @acronym{GPGME} library.
535 @code{AM_PATH_GPGME_PTH} checks for the version of @acronym{GPGME}
536 that can be used with GNU Pth, and defines @code{GPGME_PTH_CFLAGS} and
537 @code{GPGME_PTH_LIBS}.
539 @code{AM_PATH_GPGME_PTHREAD} checks for the version of @acronym{GPGME}
540 that can be used with the native pthread implementation, and defines
541 @code{GPGME_PTHREAD_CFLAGS} and @code{GPGME_PTHREAD_LIBS}.
544 You can use the defined Autoconf variables like this in your
548 AM_CPPFLAGS = $(GPGME_CFLAGS)
549 LDADD = $(GPGME_LIBS)
554 @section Using Libtool
557 The easiest way is to just use GNU Libtool. If you use libtool, and
558 link to @code{libgpgme.la}, @code{libgpgme-pth.la} or
559 @code{libgpgme-pthread.la} respectively, everything will be done
560 automatically by Libtool.
563 @node Library Version Check
564 @section Library Version Check
565 @cindex version check, of the library
567 @deftypefun {const char *} gpgme_check_version (@w{const char *@var{required_version}})
568 The function @code{gpgme_check_version} has three purposes. It can be
569 used to retrieve the version number of the library. In addition it
570 can verify that the version number is higher than a certain required
571 version number. In either case, the function initializes some
572 sub-systems, and for this reason alone it must be invoked early in
573 your program, before you make use of the other functions in
576 If @var{required_version} is @code{NULL}, the function returns a
577 pointer to a statically allocated string containing the version number
580 If @var{required_version} is not @code{NULL}, it should point to a
581 string containing a version number, and the function checks that the
582 version of the library is at least as high as the version number
583 provided. In this case, the function returns a pointer to a
584 statically allocated string containing the version number of the
585 library. If @var{REQUIRED_VERSION} is not a valid version number, or
586 if the version requirement is not met, the function returns
589 If you use a version of a library that is backwards compatible with
590 older releases, but contains additional interfaces which your program
591 uses, this function provides a run-time check if the necessary
592 features are provided by the installed version of the library.
596 After initializing @acronym{GPGME}, you should set the locale
597 information to the locale required for your output terminal. This
598 locale information is needed for example for the curses and Gtk
599 pinentry. Here is an example of a complete initialization:
608 /* Initialize the locale environment. */
609 setlocale (LC_ALL, "");
610 gpgme_check_version (NULL);
611 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
613 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
618 Note that you are highly recommended to initialize the locale settings
619 like this. @acronym{GPGME} can not do this for you because it would
620 not be thread safe. The conditional on LC_MESSAGES is only necessary
621 for portability to W32 systems.
624 @node Signal Handling
625 @section Signal Handling
627 @cindex signal handling
629 The @acronym{GPGME} library communicates with child processes (the
630 crypto engines). If a child process dies unexpectedly, for example
631 due to a bug, or system problem, a @code{SIGPIPE} signal will be
632 delivered to the application. The default action is to abort the
633 program. To protect against this, @code{gpgme_check_version} sets the
634 @code{SIGPIPE} signal action to @code{SIG_IGN}, which means that the
635 signal will be ignored.
637 @acronym{GPGME} will only do that if the signal action for
638 @code{SIGPIPE} is @code{SIG_DEF} at the time
639 @code{gpgme_check_version} is called. If it is something different,
640 @code{GPGME} will take no action.
642 This means that if your application does not install any signal
643 handler for @code{SIGPIPE}, you don't need to take any precautions.
644 If you do install a signal handler for @code{SIGPIPE}, you must be
645 prepared to handle any @code{SIGPIPE} events that occur due to
646 @acronym{GPGME} writing to a defunct pipe. Furthermore, if your
647 application is multi-threaded, and you install a signal action for
648 @code{SIGPIPE}, you must make sure you do this either before
649 @code{gpgme_check_version} is called or afterwards.
652 @node Multi Threading
653 @section Multi Threading
654 @cindex thread-safeness
655 @cindex multi-threading
657 The @acronym{GPGME} library is not entirely thread-safe, but it can
658 still be used in a multi-threaded environment if some care is taken.
659 If the following requirements are met, there should be no race
660 conditions to worry about:
664 @acronym{GPGME} supports the thread libraries pthread and GNU Pth.
665 The support for this has to be enabled at compile time.
666 @acronym{GPGME} will automatically detect the location in which the
667 thread libraries are installed and activate the support for them at
670 Support for other thread libraries is very easy to add. Please
671 contact us if you have the need.
674 If you want to use @acronym{GPGME} with threads, you must link to the
675 right version of the library. The name of the right library is
676 @code{libgpgme-} followed by the name of the thread package you use.
677 For example, if you use GNU Pth, the right name is
678 @code{libgpgme-pth}. Use the Automake macros or
679 @command{gpgme-config} program for simplicity.
683 The function @code{gpgme_check_version} must be called before any
684 other function in the library, because it initializes the thread
685 support subsystem in @acronym{GPGME}. To achieve this in
686 multi-threaded programs, you must synchronize the memory with respect
687 to other threads that also want to use @acronym{GPGME}. For this, it
688 is sufficient to call @code{gpgme_check_version} before creating the
689 other threads using @acronym{GPGME}@footnote{At least this is true for
690 POSIX threads, as @code{pthread_create} is a function that
691 synchronizes memory with respects to other threads. There are many
692 functions which have this property, a complete list can be found in
693 POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in the
694 definition of the term ``Memory Synchronization''. For other thread
695 packages other, more relaxed or more strict rules may apply.}.
698 Any @code{gpgme_data_t} and @code{gpgme_ctx_t} object must only be
699 accessed by one thread at a time. If multiple threads want to deal
700 with the same object, the caller has to make sure that operations on
701 that object are fully synchronized.
704 Only one thread at any time is allowed to call @code{gpgme_wait}. If
705 multiple threads call this function, the caller must make sure that
706 all invocations are fully synchronized. It is safe to start
707 asynchronous operations while a thread is running in gpgme_wait.
710 The function @code{gpgme_strerror} is not thread safe. You have to
711 use @code{gpgme_strerror_r} instead.
715 @node Protocols and Engines
716 @chapter Protocols and Engines
719 @cindex crypto engine
721 @cindex crypto backend
723 @acronym{GPGME} supports several cryptographic protocols, however, it
724 does not implement them. Rather it uses backends (also called
725 engines) which implement the protocol. @acronym{GPGME} uses
726 inter-process communication to pass data back and forth between the
727 application and the backend, but the details of the communication
728 protocol and invocation of the backend is completely hidden by the
729 interface. All complexity is handled by @acronym{GPGME}. Where an
730 exchange of information between the application and the backend is
731 necessary, @acronym{GPGME} provides the necessary callback function
732 hooks and further interfaces.
734 @deftp {Data type} {enum gpgme_protocol_t}
735 @tindex gpgme_protocol_t
736 The @code{gpgme_protocol_t} type specifies the set of possible protocol
737 values that are supported by @acronym{GPGME}. The following protocols
741 @item GPGME_PROTOCOL_OpenPGP
742 This specifies the OpenPGP protocol.
744 @item GPGME_PROTOCOL_CMS
745 This specifies the Cryptographic Message Syntax.
750 @deftypefun {const char *} gpgme_get_protocol_name (@w{gpgme_protocol_t @var{protocol}})
751 The function @code{gpgme_get_protocol_name} returns a statically
752 allocated string describing the protocol @var{protocol}, or
753 @code{NULL} if the protocol number is not valid.
757 * Engine Version Check:: Verifying the engine version.
758 * Engine Information:: Obtaining more information about the engines.
759 * Engine Configuration:: Changing the engine configuration.
760 * OpenPGP:: Support for the OpenPGP protocol.
761 * Cryptographic Message Syntax:: Support for the CMS.
765 @node Engine Version Check
766 @section Engine Version Check
767 @cindex version check, of the engines
769 @deftypefun gpgme_error_t gpgme_engine_check_version (@w{gpgme_protocol_t @var{protocol}})
770 The function @code{gpgme_engine_check_version} verifies that the
771 engine implementing the protocol @var{PROTOCOL} is installed in the
772 expected path and meets the version requirement of @acronym{GPGME}.
774 This function returns the error code @code{GPG_ERR_NO_ERROR} if the
775 engine is available and @code{GPG_ERR_INV_ENGINE} if it is not.
779 @node Engine Information
780 @section Engine Information
781 @cindex engine, information about
783 @deftp {Data type} {gpgme_engine_info_t}
784 @tindex gpgme_protocol_t
785 The @code{gpgme_engine_info_t} type specifies a pointer to a structure
786 describing a crypto engine. The structure contains the following
790 @item gpgme_engine_info_t next
791 This is a pointer to the next engine info structure in the linked
792 list, or @code{NULL} if this is the last element.
794 @item gpgme_protocol_t protocol
795 This is the protocol for which the crypto engine is used. You can
796 convert this to a string with @code{gpgme_get_protocol_name} for
799 @item const char *file_name
800 This is a string holding the file name of the executable of the crypto
801 engine. Currently, it is never @code{NULL}, but using @code{NULL} is
802 reserved for future use, so always check before you use it.
804 @item const char *home_dir
805 This is a string holding the directory name of the crypto engine's
806 configuration directory. If it is @code{NULL}, then the default
809 @item const char *version
810 This is a string containing the version number of the crypto engine.
811 It might be @code{NULL} if the version number can not be determined,
812 for example because the executable doesn't exist or is invalid.
814 @item const char *req_version
815 This is a string containing the minimum required version number of the
816 crypto engine for @acronym{GPGME} to work correctly. This is the
817 version number that @code{gpgme_engine_check_version} verifies
818 against. Currently, it is never @code{NULL}, but using @code{NULL} is
819 reserved for future use, so always check before you use it.
823 @deftypefun gpgme_error_t gpgme_get_engine_info (@w{gpgme_engine_info_t *@var{info}})
824 The function @code{gpgme_get_engine_info} returns a linked list of
825 engine info structures in @var{info}. Each info structure describes
826 the defaults of one configured backend.
828 The memory for the info structures is allocated the first time this
829 function is invoked, and must not be freed by the caller.
831 This function returns the error code @code{GPG_ERR_NO_ERROR} if
832 successful, and a system error if the memory could not be allocated.
835 Here is an example how you can provide more diagnostics if you receive
836 an error message which indicates that the crypto engine is invalid.
844 if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
846 gpgme_engine_info_t info;
847 err = gpgme_get_engine_info (&info);
850 while (info && info->protocol != gpgme_get_protocol (ctx))
853 fprintf (stderr, "GPGME compiled without support for protocol %s",
854 gpgme_get_protocol_name (info->protocol));
855 else if (info->path && !info->version)
856 fprintf (stderr, "Engine %s not installed properly",
858 else if (info->path && info->version && info->req_version)
859 fprintf (stderr, "Engine %s version %s installed, "
860 "but at least version %s required", info->path,
861 info->version, info->req_version);
863 fprintf (stderr, "Unknown problem with engine for protocol %s",
864 gpgme_get_protocol_name (info->protocol));
870 @node Engine Configuration
871 @section Engine Configuration
872 @cindex engine, configuration of
873 @cindex configuration of crypto backend
875 You can change the configuration of a backend engine, and thus change
876 the executable program and configuration directory to be used. You
877 can make these changes the default or set them for some contexts
880 @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}})
881 The function @code{gpgme_set_engine_info} changes the default
882 configuration of the crypto engine implementing the protocol
885 @var{file_name} is the file name of the executable program
886 implementing this protocol, and @var{home_dir} is the directory name
887 of the configuration directory for this crypto engine. If
888 @var{home_dir} is @code{NULL}, the engine's default will be used.
890 The new defaults are not applied to already created GPGME contexts.
892 This function returns the error code @code{GPG_ERR_NO_ERROR} if
893 successful, or an eror code on failure.
896 The functions @code{gpgme_ctx_get_engine_info} and
897 @code{gpgme_ctx_set_engine_info} can be used to change the engine
898 configuration per context. @xref{Crypto Engine}.
905 @cindex protocol, GnuPG
906 @cindex engine, GnuPG
908 OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard.
909 This is the first protocol that was supported by @acronym{GPGME}.
911 The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}.
914 @node Cryptographic Message Syntax
915 @section Cryptographic Message Syntax
917 @cindex cryptographic message syntax
919 @cindex protocol, CMS
920 @cindex engine, GpgSM
922 @cindex protocol, S/MIME
924 @acronym{CMS} is implemented by GpgSM, the S/MIME implementation for
927 The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}.
934 The crypto backends support a variety of algorithms used in public key
935 cryptography. The following sections list the identifiers used to
936 denote such an algorithm.
939 * Public Key Algorithms:: A list of all public key algorithms.
940 * Hash Algorithms:: A list of all hash algorithms.
944 @node Public Key Algorithms
945 @section Public Key Algorithms
946 @cindex algorithms, public key
947 @cindex public key algorithms
949 Public key algorithms are used for encryption, decryption, signing and
950 verification of signatures.
952 @deftp {Data type} {enum gpgme_pubkey_algo_t}
953 @tindex gpgme_pubkey_algo_t
954 The @code{gpgme_pubkey_algo_t} type specifies the set of all public key
955 algorithms that are supported by @acronym{GPGME}. Possible values
960 This value indicates the RSA (Rivest, Shamir, Adleman) algorithm.
963 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
964 algorithm for encryption and decryption only.
967 Deprecated. This value indicates the RSA (Rivest, Shamir, Adleman)
968 algorithm for signing and verification only.
971 This value indicates DSA, the Digital Signature Algorithm.
974 This value indicates ElGamal.
977 This value also indicates ElGamal and is used specifically in GnuPG.
981 @deftypefun {const char *} gpgme_pubkey_algo_name (@w{gpgme_pubkey_algo_t @var{algo}})
982 The function @code{gpgme_pubkey_algo_name} returns a pointer to a
983 statically allocated string containing a description of the public key
984 algorithm @var{algo}. This string can be used to output the name of
985 the public key algorithm to the user.
987 If @var{algo} is not a valid public key algorithm, @code{NULL} is
992 @node Hash Algorithms
993 @section Hash Algorithms
994 @cindex algorithms, hash
995 @cindex algorithms, message digest
996 @cindex hash algorithms
997 @cindex message digest algorithms
999 Hash (message digest) algorithms are used to compress a long message
1000 to make it suitable for public key cryptography.
1002 @deftp {Data type} {enum gpgme_hash_algo_t}
1003 @tindex gpgme_hash_algo_t
1004 The @code{gpgme_hash_algo_t} type specifies the set of all hash algorithms
1005 that are supported by @acronym{GPGME}. Possible values are:
1010 @item GPGME_MD_RMD160
1012 @item GPGME_MD_TIGER
1013 @item GPGME_MD_HAVAL
1014 @item GPGME_MD_SHA256
1015 @item GPGME_MD_SHA384
1016 @item GPGME_MD_SHA512
1018 @item GPGME_MD_CRC32
1019 @item GPGME_MD_CRC32_RFC1510
1020 @item GPGME_MD_CRC24_RFC2440
1024 @deftypefun {const char *} gpgme_hash_algo_name (@w{gpgme_hash_algo_t @var{algo}})
1025 The function @code{gpgme_hash_algo_name} returns a pointer to a
1026 statically allocated string containing a description of the hash
1027 algorithm @var{algo}. This string can be used to output the name of
1028 the hash algorithm to the user.
1030 If @var{algo} is not a valid hash algorithm, @code{NULL} is returned.
1034 @node Error Handling
1035 @chapter Error Handling
1036 @cindex error handling
1038 Many functions in @acronym{GPGME} can return an error if they fail.
1039 For this reason, the application should always catch the error
1040 condition and take appropriate measures, for example by releasing the
1041 resources and passing the error up to the caller, or by displaying a
1042 descriptive message to the user and cancelling the operation.
1044 Some error values do not indicate a system error or an error in the
1045 operation, but the result of an operation that failed properly. For
1046 example, if you try to decrypt a tempered message, the decryption will
1047 fail. Another error value actually means that the end of a data
1048 buffer or list has been reached. The following descriptions explain
1049 for many error codes what they mean usually. Some error values have
1050 specific meanings if returned by a certain functions. Such cases are
1051 described in the documentation of those functions.
1053 @acronym{GPGME} uses the @code{libgpg-error} library. This allows to
1054 share the error codes with other components of the GnuPG system, and
1055 thus pass error values transparently from the crypto engine, or some
1056 helper application of the crypto engine, to the user. This way no
1057 information is lost. As a consequence, @acronym{GPGME} does not use
1058 its own identifiers for error codes, but uses those provided by
1059 @code{libgpg-error}. They usually start with @code{GPG_ERR_}.
1061 However, @acronym{GPGME} does provide aliases for the functions
1062 defined in libgpg-error, which might be preferred for name space
1066 * Error Values:: The error value and what it means.
1067 * Error Sources:: A list of important error sources.
1068 * Error Codes:: A list of important error codes.
1069 * Error Strings:: How to get a descriptive string from a value.
1074 @section Error Values
1075 @cindex error values
1077 @cindex error sources
1079 @deftp {Data type} {gpgme_err_code_t}
1080 The @code{gpgme_err_code_t} type is an alias for the @code{libgpg-error}
1081 type @code{gpg_err_code_t}. The error code indicates the type of an
1082 error, or the reason why an operation failed.
1084 A list of important error codes can be found in the next section.
1087 @deftp {Data type} {gpgme_err_source_t}
1088 The @code{gpgme_err_source_t} type is an alias for the
1089 @code{libgpg-error} type @code{gpg_err_source_t}. The error source
1090 has not a precisely defined meaning. Sometimes it is the place where
1091 the error happened, sometimes it is the place where an error was
1092 encoded into an error value. Usually the error source will give an
1093 indication to where to look for the problem. This is not always true,
1094 but it is attempted to achieve this goal.
1096 A list of important error sources can be found in the next section.
1099 @deftp {Data type} {gpgme_error_t}
1100 The @code{gpgme_error_t} type is an alias for the @code{libgpg-error}
1101 type @code{gpg_error_t}. An error value like this has always two
1102 components, an error code and an error source. Both together form the
1105 Thus, the error value can not be directly compared against an error
1106 code, but the accessor functions described below must be used.
1107 However, it is guaranteed that only 0 is used to indicate success
1108 (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of
1109 the error value are set to 0, too.
1111 Note that in @acronym{GPGME}, the error source is used purely for
1112 diagnostical purposes. Only the error code should be checked to test
1113 for a certain outcome of a function. The manual only documents the
1114 error code part of an error value. The error source is left
1115 unspecified and might be anything.
1118 @deftypefun {static inline gpgme_err_code_t} gpgme_err_code (@w{gpgme_error_t @var{err}})
1119 The static inline function @code{gpgme_err_code} returns the
1120 @code{gpgme_err_code_t} component of the error value @var{err}. This
1121 function must be used to extract the error code from an error value in
1122 order to compare it with the @code{GPG_ERR_*} error code macros.
1125 @deftypefun {static inline gpgme_err_source_t} gpgme_err_source (@w{gpgme_error_t @var{err}})
1126 The static inline function @code{gpgme_err_source} returns the
1127 @code{gpgme_err_source_t} component of the error value @var{err}. This
1128 function must be used to extract the error source from an error value in
1129 order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros.
1132 @deftypefun {static inline gpgme_error_t} gpgme_err_make (@w{gpgme_err_source_t @var{source}}, @w{gpgme_err_code_t @var{code}})
1133 The static inline function @code{gpgme_err_make} returns the error
1134 value consisting of the error source @var{source} and the error code
1137 This function can be used in callback functions to construct an error
1138 value to return it to the library.
1141 @deftypefun {static inline gpgme_error_t} gpgme_error (@w{gpgme_err_code_t @var{code}})
1142 The static inline function @code{gpgme_error} returns the error value
1143 consisting of the default error source and the error code @var{code}.
1145 For @acronym{GPGME} applications, the default error source is
1146 @code{GPG_ERR_SOURCE_USER_1}. You can define
1147 @code{GPGME_ERR_SOURCE_DEFAULT} before including @file{gpgme.h} to
1148 change this default.
1150 This function can be used in callback functions to construct an error
1151 value to return it to the library.
1154 The @code{libgpg-error} library provides error codes for all system
1155 error numbers it knows about. If @var{err} is an unknown error
1156 number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The
1157 following functions can be used to construct error values from system
1160 @deftypefun {gpgme_error_t} gpgme_err_make_from_errno (@w{gpgme_err_source_t @var{source}}, @w{int @var{err}})
1161 The function @code{gpgme_err_make_from_errno} is like
1162 @code{gpgme_err_make}, but it takes a system error like @code{errno}
1163 instead of a @code{gpgme_err_code_t} error code.
1166 @deftypefun {gpgme_error_t} gpgme_error_from_errno (@w{int @var{err}})
1167 The function @code{gpgme_error_from_errno} is like @code{gpgme_error},
1168 but it takes a system error like @code{errno} instead of a
1169 @code{gpgme_err_code_t} error code.
1172 Sometimes you might want to map system error numbers to error codes
1173 directly, or map an error code representing a system error back to the
1174 system error number. The following functions can be used to do that.
1176 @deftypefun {gpgme_err_code_t} gpgme_err_code_from_errno (@w{int @var{err}})
1177 The function @code{gpgme_err_code_from_errno} returns the error code
1178 for the system error @var{err}. If @var{err} is not a known system
1179 error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}.
1182 @deftypefun {int} gpgme_err_code_to_errno (@w{gpgme_err_code_t @var{err}})
1183 The function @code{gpgme_err_code_to_errno} returns the system error
1184 for the error code @var{err}. If @var{err} is not an error code
1185 representing a system error, or if this system error is not defined on
1186 this system, the function returns @code{0}.
1191 @section Error Sources
1192 @cindex error codes, list of
1194 The library @code{libgpg-error} defines an error source for every
1195 component of the GnuPG system. The error source part of an error
1196 value is not well defined. As such it is mainly useful to improve the
1197 diagnostic error message for the user.
1199 If the error code part of an error value is @code{0}, the whole error
1200 value will be @code{0}. In this case the error source part is of
1201 course @code{GPG_ERR_SOURCE_UNKNOWN}.
1203 The list of error sources that might occur in applications using
1207 @item GPG_ERR_SOURCE_UNKNOWN
1208 The error source is not known. The value of this error source is
1211 @item GPG_ERR_SOURCE_GPGME
1212 The error source is @acronym{GPGME} itself. This is the default for
1213 errors that occur in the @acronym{GPGME} library.
1215 @item GPG_ERR_SOURCE_GPG
1216 The error source is GnuPG, which is the crypto engine used for the
1219 @item GPG_ERR_SOURCE_GPGSM
1220 The error source is GPGSM, which is the crypto engine used for the
1223 @item GPG_ERR_SOURCE_GCRYPT
1224 The error source is @code{libgcrypt}, which is used by crypto engines
1225 to perform cryptographic operations.
1227 @item GPG_ERR_SOURCE_GPGAGENT
1228 The error source is @command{gpg-agent}, which is used by crypto
1229 engines to perform operations with the secret key.
1231 @item GPG_ERR_SOURCE_PINENTRY
1232 The error source is @command{pinentry}, which is used by
1233 @command{gpg-agent} to query the passphrase to unlock a secret key.
1235 @item GPG_ERR_SOURCE_SCD
1236 The error source is the SmartCard Daemon, which is used by
1237 @command{gpg-agent} to delegate operations with the secret key to a
1240 @item GPG_ERR_SOURCE_KEYBOX
1241 The error source is @code{libkbx}, a library used by the crypto
1242 engines to manage local keyrings.
1244 @item GPG_ERR_SOURCE_USER_1
1245 @item GPG_ERR_SOURCE_USER_2
1246 @item GPG_ERR_SOURCE_USER_3
1247 @item GPG_ERR_SOURCE_USER_4
1248 These error sources are not used by any GnuPG component and can be
1249 used by other software. For example, applications using
1250 @acronym{GPGME} can use them to mark error values coming from callback
1251 handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors
1252 created with @code{gpgme_error} and @code{gpgme_error_from_errno},
1253 unless you define @code{GPGME_ERR_SOURCE_DEFAULT} before including
1259 @section Error Codes
1260 @cindex error codes, list of
1262 The library @code{libgpg-error} defines many error values. Most of
1263 them are not used by @code{GPGME} directly, but might be returned by
1264 @acronym{GPGME} because it received them from the crypto engine. The
1265 below list only includes such error codes that have a specific meaning
1266 in @code{GPGME}, or which are so common that you should know about
1271 This value indicates the end of a list, buffer or file.
1273 @item GPG_ERR_NO_ERROR
1274 This value indicates success. The value of this error code is
1275 @code{0}. Also, it is guaranteed that an error value made from the
1276 error code @code{0} will be @code{0} itself (as a whole). This means
1277 that the error source information is lost for this error code,
1278 however, as this error code indicates that no error occured, this is
1279 generally not a problem.
1281 @item GPG_ERR_GENERAL
1282 This value means that something went wrong, but either there is not
1283 enough information about the problem to return a more useful error
1284 value, or there is no separate error value for this type of problem.
1286 @item GPG_ERR_ENOMEM
1287 This value means that an out-of-memory condition occurred.
1290 System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
1293 @item GPG_ERR_INV_VALUE
1294 This value means that some user provided data was out of range. This
1295 can also refer to objects. For example, if an empty
1296 @code{gpgme_data_t} object was expected, but one containing data was
1297 provided, this error value is returned.
1299 @item GPG_ERR_UNUSABLE_PUBKEY
1300 This value means that some recipients for a message were invalid.
1302 @item GPG_ERR_UNUSABLE_SECKEY
1303 This value means that some signers were invalid.
1305 @item GPG_ERR_NO_DATA
1306 This value means that a @code{gpgme_data_t} object which was expected
1307 to have content was found empty.
1309 @item GPG_ERR_CONFLICT
1310 This value means that a conflict of some sort occurred.
1312 @item GPG_ERR_NOT_IMPLEMENTED
1313 This value indicates that the specific function (or operation) is not
1314 implemented. This error should never happen. It can only occur if
1315 you use certain values or configuration options which do not work,
1316 but for which we think that they should work at some later time.
1318 @item GPG_ERR_DECRYPT_FAILED
1319 This value indicates that a decryption operation was unsuccessful.
1321 @item GPG_ERR_BAD_PASSPHRASE
1322 This value means that the user did not provide a correct passphrase
1325 @item GPG_ERR_CANCELED
1326 This value means that the operation was canceled.
1328 @item GPG_ERR_INV_ENGINE
1329 This value means that the engine that implements the desired protocol
1330 is currently not available. This can either be because the sources
1331 were configured to exclude support for this engine, or because the
1332 engine is not installed properly.
1334 @item GPG_ERR_AMBIGUOUS_NAME
1335 This value indicates that a user ID or other specifier did not specify
1338 @item GPG_ERR_WRONG_KEY_USAGE
1339 This value indicates that a key is not used appropriately.
1341 @item GPG_ERR_CERT_REVOKED
1342 This value indicates that a key signature was revoced.
1344 @item GPG_ERR_CERT_EXPIRED
1345 This value indicates that a key signature expired.
1347 @item GPG_ERR_NO_CRL_KNOWN
1348 This value indicates that no certificate revocation list is known for
1351 @item GPG_ERR_NO_POLICY_MATCH
1352 This value indicates that a policy issue occured.
1354 @item GPG_ERR_NO_SECKEY
1355 This value indicates that no secret key for the user ID is available.
1357 @item GPG_ERR_MISSING_CERT
1358 This value indicates that a key could not be imported because the
1359 issuer certificate is missing.
1361 @item GPG_ERR_BAD_CERT_CHAIN
1362 This value indicates that a key could not be imported because its
1363 certificate chain is not good, for example it could be too long.
1365 @item GPG_ERR_UNSUPPORTED_ALGORITHM
1366 This value means a verification failed because the cryptographic
1367 algorithm is not supported by the crypto backend.
1369 @item GPG_ERR_BAD_SIGNATURE
1370 This value means a verification failed because the signature is bad.
1372 @item GPG_ERR_NO_PUBKEY
1373 This value means a verification failed because the public key is not
1376 @item GPG_ERR_USER_1
1377 @item GPG_ERR_USER_2
1379 @item GPG_ERR_USER_16
1380 These error codes are not used by any GnuPG component and can be
1381 freely used by other software. Applications using @acronym{GPGME}
1382 might use them to mark specific errors returned by callback handlers
1383 if no suitable error codes (including the system errors) for
1384 these errors exist already.
1389 @section Error Strings
1390 @cindex error values, printing of
1391 @cindex error codes, printing of
1392 @cindex error sources, printing of
1393 @cindex error strings
1395 @deftypefun {const char *} gpgme_strerror (@w{gpgme_error_t @var{err}})
1396 The function @code{gpgme_strerror} returns a pointer to a statically
1397 allocated string containing a description of the error code contained
1398 in the error value @var{err}. This string can be used to output a
1399 diagnostic message to the user.
1401 This function is not thread safe. Use @code{gpgme_strerror_r} in
1402 multi-threaded programs.
1406 @deftypefun {char *} gpgme_strerror_r (@w{gpgme_error_t @var{err}})
1407 The function @code{gpgme_strerror_r} returns a pointer to a
1408 dynamically allocated string containing a description of the error
1409 code contained in the error value @var{err}. This string can be used
1410 to output a diagnostic message to the user. When it is not needed
1411 anymore, the user must deallocate it with @code{free}.
1415 @deftypefun {const char *} gpgme_strsource (@w{gpgme_error_t @var{err}})
1416 The function @code{gpgme_strerror} returns a pointer to a statically
1417 allocated string containing a description of the error source
1418 contained in the error value @var{err}. This string can be used to
1419 output a diagnostic message to the user.
1422 The following example illustrates the use of @code{gpgme_strerror}:
1426 gpgme_error_t err = gpgme_new (&ctx);
1429 fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
1430 argv[0], gpgme_strsource (err), gpgme_strerror (err));
1436 @node Exchanging Data
1437 @chapter Exchanging Data
1438 @cindex data, exchanging
1440 A lot of data has to be exchanged between the user and the crypto
1441 engine, like plaintext messages, ciphertext, signatures and
1442 information about the keys. The technical details about exchanging
1443 the data information are completely abstracted by @acronym{GPGME}.
1444 The user provides and receives the data via @code{gpgme_data_t} objects,
1445 regardless of the communication protocol between @acronym{GPGME} and
1446 the crypto engine in use.
1448 @deftp {Data type} {gpgme_data_t}
1449 The @code{gpgme_data_t} type is a handle for a container for generic
1450 data, which is used by @acronym{GPGME} to exchange data with the user.
1454 * Creating Data Buffers:: Creating new data buffers.
1455 * Destroying Data Buffers:: Releasing data buffers.
1456 * Manipulating Data Buffers:: Operations on data buffers.
1460 @node Creating Data Buffers
1461 @section Creating Data Buffers
1462 @cindex data buffer, creation
1464 Data objects can be based on memory, files, or callback functions
1465 provided by the user. Not all operations are supported by all
1470 * Memory Based Data Buffers:: Creating memory based data buffers.
1471 * File Based Data Buffers:: Creating file based data buffers.
1472 * Callback Based Data Buffers:: Creating callback based data buffers.
1476 @node Memory Based Data Buffers
1477 @subsection Memory Based Data Buffers
1479 Memory based data objects store all data in allocated memory. This is
1480 convenient, but only practical for an amount of data that is a
1481 fraction of the available physical memory. The data has to be copied
1482 from its source and to its destination, which can often be avoided by
1483 using one of the other data object
1485 @deftypefun gpgme_error_t gpgme_data_new (@w{gpgme_data_t *@var{dh}})
1486 The function @code{gpgme_data_new} creates a new @code{gpgme_data_t}
1487 object and returns a handle for it in @var{dh}. The data object is
1488 memory based and initially empty.
1490 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1491 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1492 @var{dh} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1493 enough memory is available.
1496 @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}})
1497 The function @code{gpgme_data_new_from_mem} creates a new
1498 @code{gpgme_data_t} object and fills it with @var{size} bytes starting
1501 If @var{copy} is not zero, a private copy of the data is made. If
1502 @var{copy} is zero, the data is taken from the specified buffer as
1503 needed, and the user has to ensure that the buffer remains valid for
1504 the whole life span of the data object.
1506 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1507 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1508 @var{dh} or @var{buffer} is not a valid pointer, and
1509 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1512 @deftypefun gpgme_error_t gpgme_data_new_from_file (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}})
1513 The function @code{gpgme_data_new_from_file} creates a new
1514 @code{gpgme_data_t} object and fills it with the content of the file
1517 If @var{copy} is not zero, the whole file is read in at initialization
1518 time and the file is not used anymore after that. This is the only
1519 mode supported currently. Later, a value of zero for @var{copy} might
1520 cause all reads to be delayed until the data is needed, but this is
1521 not yet implemented.
1523 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1524 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1525 @var{dh} or @var{filename} is not a valid pointer,
1526 @code{GPG_ERR_NOT_IMPLEMENTED} if @var{code} is zero, and
1527 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1530 @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}})
1531 The function @code{gpgme_data_new_from_filepart} creates a new
1532 @code{gpgme_data_t} object and fills it with a part of the file specified
1533 by @var{filename} or @var{fp}.
1535 Exactly one of @var{filename} and @var{fp} must be non-zero, the other
1536 must be zero. The argument that is not zero specifies the file from
1537 which @var{length} bytes are read into the data object, starting from
1540 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1541 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1542 @var{dh} and exactly one of @var{filename} and @var{fp} is not a valid
1543 pointer, and @code{GPG_ERR_ENOMEM} if not enough memory is available.
1547 @node File Based Data Buffers
1548 @subsection File Based Data Buffers
1550 File based data objects operate directly on file descriptors or
1551 streams. Only a small amount of data is stored in core at any time,
1552 so the size of the data objects is not limited by @acronym{GPGME}.
1554 @deftypefun gpgme_error_t gpgme_data_new_from_fd (@w{gpgme_data_t *@var{dh}}, @w{int @var{fd}})
1555 The function @code{gpgme_data_new_from_fd} creates a new
1556 @code{gpgme_data_t} object and uses the file descriptor @var{fd} to read
1557 from (if used as an input data object) and write to (if used as an
1558 output data object).
1560 When using the data object as an input buffer, the function might read
1561 a bit more from the file descriptor than is actually needed by the
1562 crypto engine in the desired operation because of internal buffering.
1564 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1565 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1566 enough memory is available.
1569 @deftypefun gpgme_error_t gpgme_data_new_from_stream (@w{gpgme_data_t *@var{dh}}, @w{FILE *@var{stream}})
1570 The function @code{gpgme_data_new_from_stream} creates a new
1571 @code{gpgme_data_t} object and uses the I/O stream @var{stream} to read
1572 from (if used as an input data object) and write to (if used as an
1573 output data object).
1575 When using the data object as an input buffer, the function might read
1576 a bit more from the stream than is actually needed by the crypto
1577 engine in the desired operation because of internal buffering.
1579 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1580 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1581 enough memory is available.
1585 @node Callback Based Data Buffers
1586 @subsection Callback Based Data Buffers
1588 If neither memory nor file based data objects are a good fit for your
1589 application, you can implement the functions a data object provides
1590 yourself and create a data object from these callback functions.
1592 @deftp {Data type} {ssize_t (*gpgme_data_read_cb_t) (@w{void *@var{handle}}, @w{void @var{*buffer}}, @w{size_t @var{size}})}
1593 @tindex gpgme_data_read_cb_t
1594 The @code{gpgme_data_read_cb_t} type is the type of functions which
1595 @acronym{GPGME} calls if it wants to read data from a user-implemented
1596 data object. The function should read up to @var{size} bytes from the
1597 current read position into the space starting at @var{buffer}. The
1598 @var{handle} is provided by the user at data object creation time.
1600 The function should return the number of bytes read, 0 on EOF, and -1
1601 on error. If an error occurs, @var{errno} should be set to describe
1602 the type of the error.
1605 @deftp {Data type} {ssize_t (*gpgme_data_write_cb_t) (@w{void *@var{handle}}, @w{const void @var{*buffer}}, @w{size_t @var{size}})}
1606 @tindex gpgme_data_write_cb_t
1607 The @code{gpgme_data_write_cb_t} type is the type of functions which
1608 @acronym{GPGME} calls if it wants to write data to a user-implemented
1609 data object. The function should write up to @var{size} bytes to the
1610 current write position from the space starting at @var{buffer}. The
1611 @var{handle} is provided by the user at data object creation time.
1613 The function should return the number of bytes written, and -1 on
1614 error. If an error occurs, @var{errno} should be set to describe the
1618 @deftp {Data type} {off_t (*gpgme_data_seek_cb_t) (@w{void *@var{handle}}, @w{off_t @var{offset}}, @w{int @var{whence}})}
1619 @tindex gpgme_data_seek_cb_t
1620 The @code{gpgme_data_seek_cb_t} type is the type of functions which
1621 @acronym{GPGME} calls if it wants to change the current read/write
1622 position in a user-implemented data object, just like the @code{lseek}
1625 The function should return the new read/write position, and -1 on
1626 error. If an error occurs, @var{errno} should be set to describe the
1630 @deftp {Data type} {void (*gpgme_data_release_cb_t) (@w{void *@var{handle}})}
1631 @tindex gpgme_data_release_cb_t
1632 The @code{gpgme_data_release_cb_t} type is the type of functions which
1633 @acronym{GPGME} calls if it wants to destroy a user-implemented data
1634 object. The @var{handle} is provided by the user at data object
1638 @deftp {Data type} {struct gpgme_data_cbs}
1639 This structure is used to store the data callback interface functions
1640 described above. It has the following members:
1643 @item gpgme_data_read_cb_t read
1644 This is the function called by @acronym{GPGME} to read data from the
1645 data object. It is only required for input data object.
1647 @item gpgme_data_write_cb_t write
1648 This is the function called by @acronym{GPGME} to write data to the
1649 data object. It is only required for output data object.
1651 @item gpgme_data_seek_cb_t seek
1652 This is the function called by @acronym{GPGME} to change the current
1653 read/write pointer in the data object (if available). It is optional.
1655 @item gpgme_data_release_cb_t release
1656 This is the function called by @acronym{GPGME} to release a data
1657 object. It is optional.
1661 @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}})
1662 The function @code{gpgme_data_new_from_cbs} creates a new
1663 @code{gpgme_data_t} object and uses the user-provided callback functions
1664 to operate on the data object.
1666 The handle @var{handle} is passed as first argument to the callback
1667 functions. This can be used to identify this data object.
1669 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1670 data object was successfully created, and @code{GPG_ERR_ENOMEM} if not
1671 enough memory is available.
1674 The following interface is deprecated and only provided for backward
1675 compatibility. Don't use it. It will be removed in a future version
1678 @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}})
1679 The function @code{gpgme_data_new_with_read_cb} creates a new
1680 @code{gpgme_data_t} object and uses the callback function @var{readfunc}
1681 to retrieve the data on demand. As the callback function can supply
1682 the data in any way it wants, this is the most flexible data type
1683 @acronym{GPGME} provides. However, it can not be used to write data.
1685 The callback function receives @var{hook_value} as its first argument
1686 whenever it is invoked. It should return up to @var{count} bytes in
1687 @var{buffer}, and return the number of bytes actually read in
1688 @var{nread}. It may return @code{0} in @var{nread} if no data is
1689 currently available. To indicate @code{EOF} the function should
1690 return with an error code of @code{-1} and set @var{nread} to
1691 @code{0}. The callback function may support to reset its internal
1692 read pointer if it is invoked with @var{buffer} and @var{nread} being
1693 @code{NULL} and @var{count} being @code{0}.
1695 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1696 data object was successfully created, @code{GPG_ERR_INV_VALUE} if
1697 @var{dh} or @var{readfunc} is not a valid pointer, and
1698 @code{GPG_ERR_ENOMEM} if not enough memory is available.
1702 @node Destroying Data Buffers
1703 @section Destroying Data Buffers
1704 @cindex data buffer, destruction
1706 @deftypefun void gpgme_data_release (@w{gpgme_data_t @var{dh}})
1707 The function @code{gpgme_data_release} destroys the data object with
1708 the handle @var{dh}. It releases all associated resources that were
1709 not provided by the user in the first place.
1712 @deftypefun {char *} gpgme_data_release_and_get_mem (@w{gpgme_data_t @var{dh}}, @w{size_t *@var{length}})
1713 The function @code{gpgme_data_release_and_get_mem} is like
1714 @code{gpgme_data_release}, except that it returns the data buffer and
1715 its length that was provided by the object.
1717 The user has to release the buffer with @code{gpgme_free}. In case
1718 the user provided the data buffer in non-copy mode, a copy will be
1719 made for this purpose.
1721 In case an error returns, or there is no suitable data buffer that can
1722 be returned to the user, the function will return @code{NULL}. In any
1723 case, the data object @var{dh} is destroyed.
1727 @deftypefun void gpgme_free (@w{void *@var{buffer}})
1728 The function @code{gpgme_free} releases the memory returned by
1729 @code{gpgme_data_release_and_get_mem}. It should be used instead of
1730 the system libraries @code{free} function in case different allocators
1731 are used in a single program.
1735 @node Manipulating Data Buffers
1736 @section Manipulating Data Buffers
1737 @cindex data buffer, manipulation
1739 Data buffers contain data and meta-data. The following operations can
1740 be used to manipulate both.
1744 * Data Buffer I/O Operations:: I/O operations on data buffers.
1745 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
1749 @node Data Buffer I/O Operations
1750 @subsection Data Buffer I/O Operations
1751 @cindex data buffer, I/O operations
1752 @cindex data buffer, read
1753 @cindex data buffer, write
1754 @cindex data buffer, seek
1756 @deftypefun ssize_t gpgme_data_read (@w{gpgme_data_t @var{dh}}, @w{void *@var{buffer}}, @w{size_t @var{length}})
1757 The function @code{gpgme_data_read} reads up to @var{length} bytes
1758 from the data object with the handle @var{dh} into the space starting
1761 If no error occurs, the actual amount read is returned. If the end of
1762 the data object is reached, the function returns 0.
1764 In all other cases, the function returns -1 and sets @var{errno}.
1767 @deftypefun ssize_t gpgme_data_write (@w{gpgme_data_t @var{dh}}, @w{const void *@var{buffer}}, @w{size_t @var{size}})
1768 The function @code{gpgme_data_write} writes up to @var{size} bytes
1769 starting from @var{buffer} into the data object with the handle
1770 @var{dh} at the current write position.
1772 The function returns the number of bytes actually written, or -1 if an
1773 error occurs. If an error occurs, @var{errno} is set.
1776 @deftypefun off_t gpgme_data_seek (@w{gpgme_data_t @var{dh}}, @w{off_t @var{offset}}, @w{int @var{whence}})
1777 The function @code{gpgme_data_seek} changes the current read/write
1780 The @var{whence} argument specifies how the @var{offset} should be
1781 interpreted. It must be one of the following symbolic constants:
1785 Specifies that @var{offset} is a count of characters from the
1786 beginning of the data object.
1789 Specifies that @var{offset} is a count of characters from the current
1790 file position. This count may be positive or negative.
1793 Specifies that @var{offset} is a count of characters from the end of
1794 the data object. A negative count specifies a position within the
1795 current extent of the data object; a positive count specifies a
1796 position past the current end. If you set the position past the
1797 current end, and actually write data, you will extend the data object
1798 with zeros up to that position.
1801 If successful, the function returns the resulting file position,
1802 measured in bytes from the beginning of the data object. You can use
1803 this feature together with @code{SEEK_CUR} to read the current
1804 read/write position.
1806 If the function fails, -1 is returned and @var{errno} is set.
1809 The following function is deprecated and should not be used. It will
1810 be removed in a future version of @acronym{GPGME}.
1812 @deftypefun gpgme_error_t gpgme_data_rewind (@w{gpgme_data_t @var{dh}})
1813 The function @code{gpgme_data_rewind} is equivalent to:
1816 return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
1817 ? gpgme_error_from_errno (errno) : 0;
1824 @node Data Buffer Meta-Data
1825 @subsection Data Buffer Meta-Data
1826 @cindex data buffer, meta-data
1827 @cindex data buffer, file name
1828 @cindex data buffer, encoding
1830 @deftypefun {char *} gpgme_data_get_file_name (@w{gpgme_data_t @var{dh}})
1831 The function @code{gpgme_data_get_file_name} returns a pointer to a
1832 string containing the file name associated with the data object. The
1833 file name will be stored in the output when encrypting or signing the
1834 data and will be returned to the user when decrypting or verifying the
1837 If no error occurs, the string containing the file name is returned.
1838 Otherwise, @code{NULL} will be returned.
1842 @deftypefun gpgme_error_t gpgme_data_set_file_name (@w{gpgme_data_t @var{dh}}, @w{const char *@var{file_name}})
1843 The function @code{gpgme_data_set_file_name} sets the file name
1844 associated with the data object. The file name will be stored in the
1845 output when encrypting or signing the data and will be returned to the
1846 user when decrypting or verifying the output data.
1848 The function returns the error code @code{GPG_ERR_INV_VALUE} if
1849 @var{dh} is not a valid pointer and @code{GPG_ERR_ENOMEM} if not
1850 enough memory is available.
1854 @deftp {Data type} {enum gpgme_data_encoding_t}
1855 @tindex gpgme_data_encoding_t
1856 The @code{gpgme_data_encoding_t} type specifies the encoding of a
1857 @code{gpgme_data_t} object. This encoding is useful to give the backend
1858 a hint on the type of data. The following data types are available:
1861 @item GPGME_DATA_ENCODING_NONE
1862 This specifies that the encoding is not known. This is the default
1863 for a new data object. The backend will try its best to detect the
1864 encoding automatically.
1866 @item GPGME_DATA_ENCODING_BINARY
1867 This specifies that the data is encoding in binary form; i.e. there is
1868 no special encoding.
1870 @item GPGME_DATA_ENCODING_BASE64
1871 This specifies that the data is encoded using the Base-64 encoding
1872 scheme as used by @acronym{MIME} and other protocols.
1874 @item GPGME_DATA_ENCODING_ARMOR
1875 This specifies that the data is encoded in an armored form as used by
1880 @deftypefun gpgme_data_encoding_t gpgme_data_get_encoding (@w{gpgme_data_t @var{dh}})
1881 The function @code{gpgme_data_get_encoding} returns the encoding of
1882 the data object with the handle @var{dh}. If @var{dh} is not a valid
1883 pointer (e.g. @code{NULL}) @code{GPGME_DATA_ENCODING_NONE} is
1887 @deftypefun gpgme_error_t gpgme_data_set_encoding (@w{gpgme_data_t @var{dh}, gpgme_data_encoding_t @var{enc}})
1888 The function @code{gpgme_data_set_encoding} changes the encoding of
1889 the data object with the handle @var{dh} to @var{enc}.
1900 All cryptographic operations in @acronym{GPGME} are performed within a
1901 context, which contains the internal state of the operation as well as
1902 configuration parameters. By using several contexts you can run
1903 several cryptographic operations in parallel, with different
1906 @deftp {Data type} {gpgme_ctx_t}
1907 The @code{gpgme_ctx_t} type is a handle for a @acronym{GPGME} context,
1908 which is used to hold the configuration, status and result of
1909 cryptographic operations.
1913 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
1914 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
1915 * Context Attributes:: Setting properties of a context.
1916 * Key Management:: Managing keys with @acronym{GPGME}.
1917 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
1918 * Crypto Operations:: Using a context for cryptography.
1919 * Run Control:: Controlling how operations are run.
1923 @node Creating Contexts
1924 @section Creating Contexts
1925 @cindex context, creation
1927 @deftypefun gpgme_error_t gpgme_new (@w{gpgme_ctx_t *@var{ctx}})
1928 The function @code{gpgme_new} creates a new @code{gpgme_ctx_t} object
1929 and returns a handle for it in @var{ctx}.
1931 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1932 context was successfully created, @code{GPG_ERR_INV_VALUE} if
1933 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not
1934 enough memory is available.
1938 @node Destroying Contexts
1939 @section Destroying Contexts
1940 @cindex context, destruction
1942 @deftypefun void gpgme_release (@w{gpgme_ctx_t @var{ctx}})
1943 The function @code{gpgme_release} destroys the context with the handle
1944 @var{ctx} and releases all associated resources.
1948 @node Context Attributes
1949 @section Context Attributes
1950 @cindex context, attributes
1953 * Protocol Selection:: Selecting the protocol used by a context.
1954 * Crypto Engine:: Configuring the crypto engine.
1955 * ASCII Armor:: Requesting @acronym{ASCII} armored output.
1956 * Text Mode:: Choosing canonical text mode.
1957 * Included Certificates:: Including a number of certificates.
1958 * Key Listing Mode:: Selecting key listing mode.
1959 * Passphrase Callback:: Getting the passphrase from the user.
1960 * Progress Meter Callback:: Being informed about the progress.
1961 * Locale:: Setting the locale of a context.
1965 @node Protocol Selection
1966 @subsection Protocol Selection
1967 @cindex context, selecting protocol
1968 @cindex protocol, selecting
1970 @deftypefun gpgme_error_t gpgme_set_protocol (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_protocol_t @var{proto}})
1971 The function @code{gpgme_set_protocol} sets the protocol used within
1972 the context @var{ctx} to @var{proto}. All crypto operations will be
1973 performed by the crypto engine configured for that protocol.
1974 @xref{Protocols and Engines}.
1976 Setting the protocol with @code{gpgme_set_protocol} does not check if
1977 the crypto engine for that protocol is available and installed
1978 correctly. @xref{Engine Version Check}.
1980 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
1981 protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if
1982 @var{protocol} is not a valid protocol.
1985 @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}})
1986 The function @code{gpgme_get_protocol} retrieves the protocol currently
1987 use with the context @var{ctx}.
1992 @subsection Crypto Engine
1993 @cindex context, configuring engine
1994 @cindex engine, configuration per context
1996 The following functions can be used to set and retrieve the
1997 configuration of the crypto engines of a specific context. The
1998 default can also be retrieved without any particular context.
1999 @xref{Engine Information}. The default can also be changed globally.
2000 @xref{Engine Configuration}.
2002 @deftypefun gpgme_engine_info_t gpgme_ctx_get_engine_info (@w{gpgme_ctx_t @var{ctx}})
2003 The function @code{gpgme_ctx_get_engine_info} returns a linked list of
2004 engine info structures. Each info structure describes the
2005 configuration of one configured backend, as used by the context
2008 The result is valid until the next invocation of
2009 @code{gpgme_ctx_set_engine_info} for this particular context.
2011 This function can not fail.
2014 @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}})
2015 The function @code{gpgme_ctx_set_engine_info} changes the
2016 configuration of the crypto engine implementing the protocol
2017 @var{proto} for the context @var{ctx}.
2019 @var{file_name} is the file name of the executable program
2020 implementing this protocol, and @var{home_dir} is the directory name
2021 of the configuration directory for this crypto engine. If
2022 @var{home_dir} is @code{NULL}, the engine's default will be used.
2024 Currently this function must be used before starting the first crypto
2025 operation. It is unspecified if and when the changes will take effect
2026 if the function is called after starting the first operation on the
2029 This function returns the error code @code{GPG_ERR_NO_ERROR} if
2030 successful, or an eror code on failure.
2034 @c FIXME: Unfortunately, using @acronym here breaks texi2dvi.
2036 @subsection @acronym{ASCII} Armor
2037 @cindex context, armor mode
2038 @cindex @acronym{ASCII} armor
2041 @deftypefun void gpgme_set_armor (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2042 The function @code{gpgme_set_armor} specifies if the output should be
2043 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
2046 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
2050 @deftypefun int gpgme_get_armor (@w{gpgme_ctx_t @var{ctx}})
2051 The function @code{gpgme_get_armor} returns 1 if the output is
2052 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
2053 not a valid pointer.
2058 @subsection Text Mode
2059 @cindex context, text mode
2061 @cindex canonical text mode
2063 @deftypefun void gpgme_set_textmode (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{yes}})
2064 The function @code{gpgme_set_textmode} specifies if canonical text mode
2065 should be used. By default, text mode is not used.
2067 Text mode is for example used for the RFC2015 signatures; note that
2068 the updated RFC 3156 mandates that the mail user agent does some
2069 preparations so that text mode is not needed anymore.
2071 This option is only relevant to the OpenPGP crypto engine, and ignored
2072 by all other engines.
2074 Canonical text mode is disabled if @var{yes} is zero, and enabled
2078 @deftypefun int gpgme_get_textmode (@w{gpgme_ctx_t @var{ctx}})
2079 The function @code{gpgme_get_textmode} returns 1 if canonical text
2080 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
2085 @node Included Certificates
2086 @subsection Included Certificates
2087 @cindex certificates, included
2089 @deftypefun void gpgme_set_include_certs (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{nr_of_certs}})
2090 The function @code{gpgme_set_include_certs} specifies how many
2091 certificates should be included in an S/MIME signed message. By
2092 default, only the sender's certificate is included. The possible
2093 values of @var{nr_of_certs} are:
2096 @item GPGME_INCLUDE_CERTS_DEFAULT
2097 Fall back to the default of the crypto backend. This is the default
2100 Include all certificates except the root certificate.
2102 Include all certificates.
2104 Include no certificates.
2106 Include the sender's certificate only.
2108 Include the first n certificates of the certificates path, starting
2109 from the sender's certificate. The number @code{n} must be positive.
2112 Values of @var{nr_of_certs} smaller than -2 are undefined.
2114 This option is only relevant to the CMS crypto engine, and ignored by
2118 @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}})
2119 The function @code{gpgme_get_include_certs} returns the number of
2120 certificates to include into an S/MIME signed message.
2124 @node Key Listing Mode
2125 @subsection Key Listing Mode
2126 @cindex key listing mode
2127 @cindex key listing, mode of
2129 @deftypefun gpgme_error_t gpgme_set_keylist_mode (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_keylist_mode_t @var{mode}})
2130 The function @code{gpgme_set_keylist_mode} changes the default
2131 behaviour of the key listing functions. The value in @var{mode} is a
2132 bitwise-or combination of one or multiple of the following bit values:
2135 @item GPGME_KEYLIST_MODE_LOCAL
2136 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
2137 keyring should be searched for keys in the keylisting operation. This
2140 @item GPGME_KEYLIST_MODE_EXTERN
2141 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
2142 source should be searched for keys in the keylisting
2143 operation. The type of external source is dependant on the crypto
2144 engine used. For example, it can be a remote keyserver or LDAP
2147 @item GPGME_KEYLIST_MODE_SIGS
2148 The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key
2149 signatures should be included in the listed keys.
2151 @item GPGME_KEYLIST_MODE_SIG_NOTATIONS
2152 The @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} symbol specifies that the
2153 signature notations on key signatures should be included in the listed
2154 keys. This only works if @code{GPGME_KEYLIST_MODE_SIGS} is also
2157 @item GPGME_KEYLIST_MODE_VALIDATE
2158 The @code{GPGME_KEYLIST_MODE_VALIDATE} symbol specifies that the
2159 backend should do key or certificate validation and not just get the
2160 validity information from an internal cache. This might be an
2161 expensive operation and is in general not useful. Currently only
2162 implemented for the S/MIME backend and ignored for other backends.
2166 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
2167 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
2168 compatibility, you should get the current mode with
2169 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
2170 appropriate bits, and then using that calulcated value in the
2171 @code{gpgme_set_keylisting_mode} operation. This will leave all other
2172 bits in the mode value intact (in particular those that are not used
2173 in the current version of the library).
2175 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
2176 mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx}
2177 is not a valid pointer or @var{mode} is not a valid mode.
2181 @deftypefun gpgme_keylist_mode_t gpgme_get_keylist_mode (@w{gpgme_ctx_t @var{ctx}})
2182 The function @code{gpgme_get_keylist_mode} returns the current key
2183 listing mode of the context @var{ctx}. This value can then be
2184 modified and used in a subsequent @code{gpgme_set_keylist_mode}
2185 operation to only affect the desired bits (and leave all others
2188 The function returns 0 if @var{ctx} is not a valid pointer, and the
2189 current mode otherwise. Note that 0 is not a valid mode value.
2193 @node Passphrase Callback
2194 @subsection Passphrase Callback
2195 @cindex callback, passphrase
2196 @cindex passphrase callback
2198 @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}})}
2199 @tindex gpgme_passphrase_cb_t
2200 The @code{gpgme_passphrase_cb_t} type is the type of functions usable as
2201 passphrase callback function.
2203 The argument @var{uid_hint} might contain a string that gives an
2204 indication for which user ID the passphrase is required. If this is
2205 not available, or not applicable (in the case of symmetric encryption,
2206 for example), @var{uid_hint} will be @code{NULL}.
2208 The argument @var{passphrase_info}, if not @code{NULL}, will give
2209 further information about the context in which the passphrase is
2210 required. This information is engine and operation specific.
2212 If this is the repeated attempt to get the passphrase, because
2213 previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
2216 The user must write the passphrase, followed by a newline character,
2217 to the file descriptor @var{fd}. If the user returns 0 indicating
2218 success, the user must at least write a newline character before
2219 returning from the callback.
2221 If an error occurs, return the corresponding @code{gpgme_error_t}
2222 value. You can use the error code @code{GPG_ERR_CANCELED} to abort
2223 the operation. Otherwise, return @code{0}.
2226 @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}})
2227 The function @code{gpgme_set_passphrase_cb} sets the function that is
2228 used when a passphrase needs to be provided by the user to
2229 @var{passfunc}. The function @var{passfunc} needs to implemented by
2230 the user, and whenever it is called, it is called with its first
2231 argument being @var{hook_value}. By default, no passphrase callback
2234 Not all crypto engines require this callback to retrieve the
2235 passphrase. It is better if the engine retrieves the passphrase from
2236 a trusted agent (a daemon process), rather than having each user to
2237 implement their own passphrase query. Some engines do not even
2238 support an external passphrase callback at all, in this case the error
2239 code @code{GPG_ERR_NOT_SUPPORTED} is returned.
2241 The user can disable the use of a passphrase callback function by
2242 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
2246 @deftypefun void gpgme_get_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t *@var{passfunc}}, @w{void **@var{hook_value}})
2247 The function @code{gpgme_get_passphrase_cb} returns the function that
2248 is used when a passphrase needs to be provided by the user in
2249 @var{*passfunc}, and the first argument for this function in
2250 @var{*hook_value}. If no passphrase callback is set, or @var{ctx} is
2251 not a valid pointer, @code{NULL} is returned in both variables.
2253 @var{passfunc} or @var{hook_value} can be @code{NULL}. In this case,
2254 the corresponding value will not be returned.
2258 @node Progress Meter Callback
2259 @subsection Progress Meter Callback
2260 @cindex callback, progress meter
2261 @cindex progress meter callback
2263 @deftp {Data type} {void (*gpgme_progress_cb_t)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
2264 @tindex gpgme_progress_cb_t
2265 The @code{gpgme_progress_cb_t} type is the type of functions usable as
2266 progress callback function.
2268 The arguments are specific to the crypto engine. More information
2269 about the progress information returned from the GnuPG engine can be
2270 found in the GnuPG source code in the file @file{doc/DETAILS} in the
2274 @deftypefun void gpgme_set_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t @var{progfunc}}, @w{void *@var{hook_value}})
2275 The function @code{gpgme_set_progress_cb} sets the function that is
2276 used when progress information about a cryptographic operation is
2277 available. The function @var{progfunc} needs to implemented by the
2278 user, and whenever it is called, it is called with its first argument
2279 being @var{hook_value}. By default, no progress callback function
2282 Setting a callback function allows an interactive program to display
2283 progress information about a long operation to the user.
2285 The user can disable the use of a progress callback function by
2286 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
2290 @deftypefun void gpgme_get_progress_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_progress_cb_t *@var{progfunc}}, @w{void **@var{hook_value}})
2291 The function @code{gpgme_get_progress_cb} returns the function that is
2292 used to inform the user about the progress made in @var{*progfunc},
2293 and the first argument for this function in @var{*hook_value}. If no
2294 progress callback is set, or @var{ctx} is not a valid pointer,
2295 @code{NULL} is returned in both variables.
2297 @var{progfunc} or @var{hook_value} can be @code{NULL}. In this case,
2298 the corresponding value will not be returned.
2304 @cindex locale, default
2305 @cindex locale, of a context
2307 A locale setting can be associated with a context. This locale is
2308 passed to the crypto engine, and used for applications like the PIN
2309 entry, which is displayed to the user when entering a passphrase is
2312 The default locale is used to initialize the locale setting of all
2313 contexts created afterwards.
2315 @deftypefun gpgme_error_t gpgme_set_locale (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{category}}, @w{const char *@var{value}})
2316 The function @code{gpgme_set_locale} sets the locale of the context
2317 @var{ctx}, or the default locale if @var{ctx} is a null pointer.
2319 The locale settings that should be changed are specified by
2320 @var{category}. Supported categories are @code{LC_CTYPE},
2321 @code{LC_MESSAGES}, and @code{LC_ALL}, which is a wildcard you can use
2322 if you want to change all the categories at once.
2324 The value to be used for the locale setting is @var{value}, which will
2325 be copied to @acronym{GPGME}'s internal data structures. @var{value}
2326 can be a null pointer, which disables setting the locale, and will
2327 make PIN entry and other applications use their default setting, which
2328 is usually not what you want.
2330 Note that the settings are only used if the application runs on a text
2331 terminal, and that the settings should fit the configuration of the
2332 output terminal. Normally, it is sufficient to initialize the default
2335 The function returns an error if not enough memory is available.
2339 @node Key Management
2340 @section Key Management
2341 @cindex key management
2343 Some of the cryptographic operations require that recipients or
2344 signers are specified. This is always done by specifying the
2345 respective keys that should be used for the operation. The following
2346 section describes how such keys can be selected and manipulated.
2348 @deftp {Data type} gpgme_sub_key_t
2349 The @code{gpgme_sub_key_t} type is a pointer to a subkey structure.
2350 Sub keys are one component of a @code{gpgme_key_t} object. In fact,
2351 subkeys are those parts that contains the real information about the
2352 individual cryptographic keys that belong to the same key object. One
2353 @code{gpgme_key_t} can contain several subkeys. The first subkey in
2354 the linked list is also called the primary key.
2356 The subkey structure has the following members:
2359 @item gpgme_sub_key_t next
2360 This is a pointer to the next subkey structure in the linked list, or
2361 @code{NULL} if this is the last element.
2363 @item unsigned int revoked : 1
2364 This is true if the subkey is revoked.
2366 @item unsigned int expired : 1
2367 This is true if the subkey is expired.
2369 @item unsigned int disabled : 1
2370 This is true if the subkey is disabled.
2372 @item unsigned int invalid : 1
2373 This is true if the subkey is invalid.
2375 @item unsigned int can_encrypt : 1
2376 This is true if the subkey can be used for encryption.
2378 @item unsigned int can_sign : 1
2379 This is true if the subkey can be used to create data signatures.
2381 @item unsigned int can_certify : 1
2382 This is true if the subkey can be used to create key certificates.
2384 @item unsigned int can_authenticate : 1
2385 This is true if the subkey can be used for authentication.
2387 @item unsigned int is_qualified : 1
2388 This is true if the subkey can be used for qualified signatures
2389 according to local government regulations.
2391 @item unsigned int secret : 1
2392 This is true if the subkey is a secret key. Note that it will be false
2393 if the key is actually a stub key; i.e. a secret key operation is
2394 currently not possible (offline-key).
2396 @item gpgme_pubkey_algo_t pubkey_algo
2397 This is the public key algorithm supported by this subkey.
2399 @item unsigned int length
2400 This is the length of the subkey (in bits).
2403 This is the key ID of the subkey in hexadecimal digits.
2406 This is the fingerprint of the subkey in hexadecimal digits, if
2409 @item long int timestamp
2410 This is the creation timestamp of the subkey. This is -1 if the
2411 timestamp is invalid, and 0 if it is not available.
2413 @item long int expires
2414 This is the expiration timestamp of the subkey, or 0 if the subkey
2419 @deftp {Data type} gpgme_key_sig_t
2420 The @code{gpgme_key_sig_t} type is a pointer to a key signature structure.
2421 Key signatures are one component of a @code{gpgme_key_t} object, and
2422 validate user IDs on the key.
2424 The signatures on a key are only available if the key was retrieved
2425 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
2426 enabled, because it can be expensive to retrieve all signatures of a
2429 The signature notations on a key signature are only available if the
2430 key was retrieved via a listing operation with the
2431 @code{GPGME_KEYLIST_MODE_SIG_NOTATIONS} mode enabled, because it can
2432 be expensive to retrieve all signature notations.
2434 The key signature structure has the following members:
2437 @item gpgme_key_sig_t next
2438 This is a pointer to the next key signature structure in the linked
2439 list, or @code{NULL} if this is the last element.
2441 @item unsigned int revoked : 1
2442 This is true if the key signature is a revocation signature.
2444 @item unsigned int expired : 1
2445 This is true if the key signature is expired.
2447 @item unsigned int invalid : 1
2448 This is true if the key signature is invalid.
2450 @item unsigned int exportable : 1
2451 This is true if the key signature is exportable.
2453 @item gpgme_pubkey_algo_t pubkey_algo
2454 This is the public key algorithm used to create the signature.
2457 This is the key ID of the key (in hexadecimal digits) used to create
2460 @item long int timestamp
2461 This is the creation timestamp of the key signature. This is -1 if
2462 the timestamp is invalid, and 0 if it is not available.
2464 @item long int expires
2465 This is the expiration timestamp of the key signature, or 0 if the key
2466 signature does not expire.
2468 @item gpgme_error_t status
2469 This is the status of the signature and has the same meaning as the
2470 member of the same name in a @code{gpgme_signature_t} object.
2472 @item unsigned int sig_class
2473 This specifies the signature class of the key signature. The meaning
2474 is specific to the crypto engine.
2477 This is the main user ID of the key used to create the signature.
2480 This is the name component of @code{uid}, if available.
2483 This is the comment component of @code{uid}, if available.
2486 This is the email component of @code{uid}, if available.
2488 @item gpgme_sig_notation_t notations
2489 This is a linked list with the notation data and policy URLs.
2493 @deftp {Data type} gpgme_user_id_t
2494 A user ID is a component of a @code{gpgme_key_t} object. One key can
2495 have many user IDs. The first one in the list is the main (or
2498 The user ID structure has the following members.
2501 @item gpgme_user_id_t next
2502 This is a pointer to the next user ID structure in the linked list, or
2503 @code{NULL} if this is the last element.
2505 @item unsigned int revoked : 1
2506 This is true if the user ID is revoked.
2508 @item unsigned int invalid : 1
2509 This is true if the user ID is invalid.
2511 @item gpgme_validity_t validity
2512 This specifies the validity of the user ID.
2515 This is the user ID string.
2518 This is the name component of @code{uid}, if available.
2521 This is the comment component of @code{uid}, if available.
2524 This is the email component of @code{uid}, if available.
2526 @item gpgme_key_sig_t signatures
2527 This is a linked list with the signatures on this user ID.
2531 @deftp {Data type} gpgme_key_t
2532 The @code{gpgme_key_t} type is a pointer to a key object. It has the
2536 @item gpgme_keylist_mode_t keylist_mode
2537 The keylist mode that was active when the key was retrieved.
2539 @item unsigned int revoked : 1
2540 This is true if the key is revoked.
2542 @item unsigned int expired : 1
2543 This is true if the key is expired.
2545 @item unsigned int disabled : 1
2546 This is true if the key is disabled.
2548 @item unsigned int invalid : 1
2549 This is true if the key is invalid. This might have several reasons,
2550 for a example for the S/MIME backend, it will be set in during key
2551 listsing if the key could not be validated due to a missing
2552 certificates or unmatched policies.
2554 @item unsigned int can_encrypt : 1
2555 This is true if the key (ie one of its subkeys) can be used for
2558 @item unsigned int can_sign : 1
2559 This is true if the key (ie one of its subkeys) can be used to create
2562 @item unsigned int can_certify : 1
2563 This is true if the key (ie one of its subkeys) can be used to create
2566 @item unsigned int can_authenticate : 1
2567 This is true if the key (ie one of its subkeys) can be used for
2570 @item unsigned int is_qualified : 1
2571 This is true if the key can be used for qualified signatures according
2572 to local government regulations.
2574 @item unsigned int secret : 1
2575 This is true if the key is a secret key. Note, that this will always be
2576 true even if the corresponding subkey flag may be false (offline/stub
2579 @item gpgme_protocol_t protocol
2580 This is the protocol supported by this key.
2582 @item char *issuer_serial
2583 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2586 @item char *issuer_name
2587 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2590 @item char *chain_id
2591 If @code{protocol} is @code{GPGME_PROTOCOL_CMS}, then this is the
2592 chain ID, which can be used to built the certificate chain.
2594 @item gpgme_validity_t owner_trust
2595 If @code{protocol} is @code{GPGME_PROTOCOL_OpenPGP}, then this is the
2598 @item gpgme_sub_key_t subkeys
2599 This is a linked list with the subkeys of the key. The first subkey
2600 in the list is the primary key and usually available.
2602 @item gpgme_user_id_t uids
2603 This is a linked list with the user IDs of the key. The first user ID
2604 in the list is the main (or primary) user ID.
2609 * Listing Keys:: Browsing the list of available keys.
2610 * Information About Keys:: Requesting detailed information about keys.
2611 * Key Signatures:: Listing the signatures on a key.
2612 * Manipulating Keys:: Operations on keys.
2613 * Generating Keys:: Creating new key pairs.
2614 * Exporting Keys:: Retrieving key data from the key ring.
2615 * Importing Keys:: Adding keys to the key ring.
2616 * Deleting Keys:: Removing keys from the key ring.
2621 @subsection Listing Keys
2622 @cindex listing keys
2624 @cindex key listing, start
2625 @cindex key ring, list
2626 @cindex key ring, search
2628 @deftypefun gpgme_error_t gpgme_op_keylist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
2629 The function @code{gpgme_op_keylist_start} initiates a key listing
2630 operation inside the context @var{ctx}. It sets everything up so that
2631 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
2634 If @var{pattern} is @code{NULL}, all available keys are returned.
2635 Otherwise, @var{pattern} contains an engine specific expression that
2636 is used to limit the list to all keys matching the pattern. Note that
2637 the total length of the pattern is restricted to an engine-specific
2638 maximum (a couple of hundred characters are usually accepted). The
2639 pattern should be used to restrict the search to a certain common name
2640 or user, not to list many specific keys at once by listing their
2641 fingerprints or key IDs.
2643 If @var{secret_only} is not @code{0}, the list is restricted to secret
2646 The context will be busy until either all keys are received (and
2647 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2648 @code{gpgme_op_keylist_end} is called to finish the operation.
2650 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2651 @var{ctx} is not a valid pointer, and passes through any errors that
2652 are reported by the crypto engine support routines.
2655 @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}})
2656 The function @code{gpgme_op_keylist_ext_start} initiates an extended
2657 key listing operation inside the context @var{ctx}. It sets
2658 everything up so that subsequent invocations of
2659 @code{gpgme_op_keylist_next} return the keys in the list.
2661 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
2662 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
2663 array of strings that are used to limit the list to all keys matching
2664 at least one of the patterns verbatim. Note that the total length of
2665 all patterns is restricted to an engine-specific maximum (the exact
2666 limit also depends on the number of patterns and amount of quoting
2667 required, but a couple of hundred characters are usually accepted).
2668 Patterns should be used to restrict the search to a certain common
2669 name or user, not to list many specific keys at once by listing their
2670 fingerprints or key IDs.
2672 If @var{secret_only} is not @code{0}, the list is restricted to secret
2675 The value of @var{reserved} must be @code{0}.
2677 The context will be busy until either all keys are received (and
2678 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or
2679 @code{gpgme_op_keylist_end} is called to finish the operation.
2681 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2682 @var{ctx} is not a valid pointer, and passes through any errors that
2683 are reported by the crypto engine support routines.
2686 @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}})
2687 The function @code{gpgme_op_keylist_next} returns the next key in the
2688 list created by a previous @code{gpgme_op_keylist_start} operation in
2689 the context @var{ctx}. The key will have one reference for the user.
2690 @xref{Manipulating Keys}.
2692 This is the only way to get at @code{gpgme_key_t} objects in
2695 If the last key in the list has already been returned,
2696 @code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}.
2698 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2699 @var{ctx} or @var{r_key} is not a valid pointer, and
2700 @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation.
2703 @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}})
2704 The function @code{gpgme_op_keylist_next} ends a pending key list
2705 operation in the context @var{ctx}.
2707 After the operation completed successfully, the result of the key
2708 listing operation can be retrieved with
2709 @code{gpgme_op_keylist_result}.
2711 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2712 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
2713 time during the operation there was not enough memory available.
2716 The following example illustrates how all keys containing a certain
2717 string (@code{g10code}) can be listed with their key ID and the name
2718 and e-mail address of the main user ID:
2722 gpgme_error_t err = gpgme_new (&ctx);
2726 err = gpgme_op_keylist_start (ctx, "g10code", 0);
2729 err = gpgme_op_keylist_next (ctx, &key);
2732 printf ("%s: %s <%s>\n", key->keyid, key->name, key->email);
2733 gpgme_key_release (key);
2735 gpgme_release (ctx);
2737 if (gpg_err_code (err) != GPG_ERR_EOF)
2739 fprintf (stderr, "%s: can not list keys: %s\n",
2740 argv[0], gpgme_strerror (err));
2745 @deftp {Data type} {gpgme_keylist_result_t}
2746 This is a pointer to a structure used to store the result of a
2747 @code{gpgme_op_keylist_*} operation. After successfully ending a key
2748 listing operation, you can retrieve the pointer to the result with
2749 @code{gpgme_op_keylist_result}. The structure contains the following
2753 @item unsigned int truncated : 1
2754 This is true if the crypto backend had to truncate the result, and
2755 less than the desired keys could be listed.
2759 @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}})
2760 The function @code{gpgme_op_keylist_result} returns a
2761 @code{gpgme_keylist_result_t} pointer to a structure holding the
2762 result of a @code{gpgme_op_keylist_*} operation. The pointer is only
2763 valid if the last operation on the context was a key listing
2764 operation, and if this operation finished successfully. The returned
2765 pointer is only valid until the next operation is started on the
2769 In a simple program, for which a blocking operation is acceptable, the
2770 following function can be used to retrieve a single key.
2772 @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}})
2773 The function @code{gpgme_get_key} gets the key with the fingerprint
2774 (or key ID) @var{fpr} from the crypto backend and return it in
2775 @var{r_key}. If @var{secret} is true, get the secret key. The
2776 currently active keylist mode is used to retrieve the key. The key
2777 will have one reference for the user.
2779 If the key is not found in the keyring, @code{gpgme_get_key} returns
2780 the error code @code{GPG_ERR_NO_ERROR} and *@var{r_key} will be set to
2783 The function returns the error code @code{GPG_ERR_INV_VALUE} if
2784 @var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a
2785 fingerprint or key ID, @code{GPG_ERR_AMBIGUOUS_NAME} if the key ID was
2786 not a unique specifier for a key, and @code{GPG_ERR_ENOMEM} if at some
2787 time during the operation there was not enough memory available.
2791 @node Information About Keys
2792 @subsection Information About Keys
2793 @cindex key, information about
2794 @cindex key, attributes
2795 @cindex attributes, of a key
2797 Please see the beginning of this section for more information about
2798 @code{gpgme_key_t} objects.
2800 @deftp {Data type} gpgme_validity_t
2801 The @code{gpgme_validity_t} type is used to specify the validity of a user ID
2802 in a key. The following validities are defined:
2805 @item GPGME_VALIDITY_UNKNOWN
2806 The user ID is of unknown validity. The string representation of this
2809 @item GPGME_VALIDITY_UNDEFINED
2810 The validity of the user ID is undefined. The string representation of this
2813 @item GPGME_VALIDITY_NEVER
2814 The user ID is never valid. The string representation of this
2817 @item GPGME_VALIDITY_MARGINAL
2818 The user ID is marginally valid. The string representation of this
2821 @item GPGME_VALIDITY_FULL
2822 The user ID is fully valid. The string representation of this
2825 @item GPGME_VALIDITY_ULTIMATE
2826 The user ID is ultimately valid. The string representation of this
2832 The following interfaces are deprecated and only provided for backward
2833 compatibility. Don't use them. They will be removed in a future
2834 version of @acronym{GPGME}.
2836 @deftp {Data type} gpgme_attr_t
2837 The @code{gpgme_attr_t} type is used to specify a key or trust item
2838 attribute. The following attributes are defined:
2841 @item GPGME_ATTR_KEYID
2842 This is the key ID of a sub key. It is representable as a string.
2844 For trust items, the trust item refers to the key with this ID.
2846 @item GPGME_ATTR_FPR
2847 This is the fingerprint of a sub key. It is representable as a
2850 @item GPGME_ATTR_ALGO
2851 This is the crypto algorithm for which the sub key can be used. It
2852 is representable as a string and as a number. The numbers correspond
2853 to the @code{enum gcry_pk_algos} values in the gcrypt library.
2855 @item GPGME_ATTR_LEN
2856 This is the key length of a sub key. It is representable as a
2859 @item GPGME_ATTR_CREATED
2860 This is the timestamp at creation time of a sub key. It is
2861 representable as a number.
2863 @item GPGME_ATTR_EXPIRE
2864 This is the expiration time of a sub key. It is representable as a
2867 @item GPGME_ATTR_OTRUST
2868 XXX FIXME (also for trust items)
2870 @item GPGME_ATTR_USERID
2871 This is a user ID. There can be more than one user IDs in a
2872 @var{gpgme_key_t} object. The first one (with index 0) is the primary
2873 user ID. The user ID is representable as a number.
2875 For trust items, this is the user ID associated with this trust item.
2877 @item GPGME_ATTR_NAME
2878 This is the name belonging to a user ID. It is representable as a string.
2880 @item GPGME_ATTR_EMAIL
2881 This is the email address belonging to a user ID. It is representable
2884 @item GPGME_ATTR_COMMENT
2885 This is the comment belonging to a user ID. It is representable as a
2888 @item GPGME_ATTR_VALIDITY
2889 This is the validity belonging to a user ID. It is representable as a
2890 string and as a number. See below for a list of available validities.
2892 For trust items, this is the validity that is associated with this
2895 @item GPGME_ATTR_UID_REVOKED
2896 This specifies if a user ID is revoked. It is representable as a
2897 number, and is @code{1} if the user ID is revoked, and @code{0}
2900 @item GPGME_ATTR_UID_INVALID
2901 This specifies if a user ID is invalid. It is representable as a
2902 number, and is @code{1} if the user ID is invalid, and @code{0}
2905 @item GPGME_ATTR_LEVEL
2906 This is the trust level of a trust item.
2908 @item GPGME_ATTR_TYPE
2909 This returns information about the type of key. For the string function
2910 this will eother be "PGP" or "X.509". The integer function returns 0
2911 for PGP and 1 for X.509. It is also used for the type of a trust item.
2913 @item GPGME_ATTR_IS_SECRET
2914 This specifies if the key is a secret key. It is representable as a
2915 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
2917 @item GPGME_ATTR_KEY_REVOKED
2918 This specifies if a sub key is revoked. It is representable as a
2919 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
2921 @item GPGME_ATTR_KEY_INVALID
2922 This specifies if a sub key is invalid. It is representable as a
2923 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
2925 @item GPGME_ATTR_KEY_EXPIRED
2926 This specifies if a sub key is expired. It is representable as a
2927 number, and is @code{1} if the key is expired, and @code{0} otherwise.
2929 @item GPGME_ATTR_KEY_DISABLED
2930 This specifies if a sub key is disabled. It is representable as a
2931 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
2933 @item GPGME_ATTR_KEY_CAPS
2934 This is a description of the capabilities of a sub key. It is
2935 representable as a string. The string contains the letter ``e'' if
2936 the key can be used for encryption, ``s'' if the key can be used for
2937 signatures, and ``c'' if the key can be used for certifications.
2939 @item GPGME_ATTR_CAN_ENCRYPT
2940 This specifies if a sub key can be used for encryption. It is
2941 representable as a number, and is @code{1} if the sub key can be used
2942 for encryption, and @code{0} otherwise.
2944 @item GPGME_ATTR_CAN_SIGN
2945 This specifies if a sub key can be used to create data signatures. It
2946 is representable as a number, and is @code{1} if the sub key can be
2947 used for signatures, and @code{0} otherwise.
2949 @item GPGME_ATTR_CAN_CERTIFY
2950 This specifies if a sub key can be used to create key certificates.
2951 It is representable as a number, and is @code{1} if the sub key can be
2952 used for certifications, and @code{0} otherwise.
2954 @item GPGME_ATTR_SERIAL
2955 The X.509 issuer serial attribute of the key. It is representable as
2958 @item GPGME_ATTR_ISSUE
2959 The X.509 issuer name attribute of the key. It is representable as a
2962 @item GPGME_ATTR_CHAINID
2963 The X.509 chain ID can be used to build the certification chain. It
2964 is representable as a string.
2968 @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}})
2969 The function @code{gpgme_key_get_string_attr} returns the value of the
2970 string-representable attribute @var{what} of key @var{key}. If the
2971 attribute is an attribute of a sub key or an user ID, @var{idx}
2972 specifies the sub key or user ID of which the attribute value is
2973 returned. The argument @var{reserved} is reserved for later use and
2974 should be @code{NULL}.
2976 The string returned is only valid as long as the key is valid.
2978 The function returns @code{0} if an attribute can't be returned as a
2979 string, @var{key} is not a valid pointer, @var{idx} out of range,
2980 or @var{reserved} not @code{NULL}.
2983 @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}})
2984 The function @code{gpgme_key_get_ulong_attr} returns the value of the
2985 number-representable attribute @var{what} of key @var{key}. If the
2986 attribute is an attribute of a sub key or an user ID, @var{idx}
2987 specifies the sub key or user ID of which the attribute value is
2988 returned. The argument @var{reserved} is reserved for later use and
2989 should be @code{NULL}.
2991 The function returns @code{0} if the attribute can't be returned as a
2992 number, @var{key} is not a valid pointer, @var{idx} out of range, or
2993 @var{reserved} not @code{NULL}.
2997 @node Key Signatures
2998 @subsection Key Signatures
2999 @cindex key, signatures
3000 @cindex signatures, on a key
3002 The following interfaces are deprecated and only provided for backward
3003 compatibility. Don't use them. They will be removed in a future
3004 version of @acronym{GPGME}.
3006 The signatures on a key are only available if the key was retrieved
3007 via a listing operation with the @code{GPGME_KEYLIST_MODE_SIGS} mode
3008 enabled, because it is expensive to retrieve all signatures of a key.
3010 So, before using the below interfaces to retrieve the signatures on a
3011 key, you have to make sure that the key was listed with signatures
3012 enabled. One convenient, but blocking, way to do this is to use the
3013 function @code{gpgme_get_key}.
3015 @deftp {Data type} gpgme_attr_t
3016 The @code{gpgme_attr_t} type is used to specify a key signature
3017 attribute. The following attributes are defined:
3020 @item GPGME_ATTR_KEYID
3021 This is the key ID of the key which was used for the signature. It is
3022 representable as a string.
3024 @item GPGME_ATTR_ALGO
3025 This is the crypto algorithm used to create the signature. It is
3026 representable as a string and as a number. The numbers correspond to
3027 the @code{enum gcry_pk_algos} values in the gcrypt library.
3029 @item GPGME_ATTR_CREATED
3030 This is the timestamp at creation time of the signature. It is
3031 representable as a number.
3033 @item GPGME_ATTR_EXPIRE
3034 This is the expiration time of the signature. It is representable as
3037 @item GPGME_ATTR_USERID
3038 This is the user ID associated with the signing key. The user ID is
3039 representable as a number.
3041 @item GPGME_ATTR_NAME
3042 This is the name belonging to a user ID. It is representable as a string.
3044 @item GPGME_ATTR_EMAIL
3045 This is the email address belonging to a user ID. It is representable
3048 @item GPGME_ATTR_COMMENT
3049 This is the comment belonging to a user ID. It is representable as a
3052 @item GPGME_ATTR_KEY_REVOKED
3053 This specifies if a key signature is a revocation signature. It is
3054 representable as a number, and is @code{1} if the key is revoked, and
3057 @c @item GPGME_ATTR_KEY_EXPIRED
3058 @c This specifies if a key signature is expired. It is representable as
3059 @c a number, and is @code{1} if the key is revoked, and @code{0}
3062 @item GPGME_ATTR_SIG_CLASS
3063 This specifies the signature class of a key signature. It is
3064 representable as a number. The meaning is specific to the crypto
3067 @item GPGME_ATTR_SIG_CLASS
3068 This specifies the signature class of a key signature. It is
3069 representable as a number. The meaning is specific to the crypto
3072 @item GPGME_ATTR_SIG_STATUS
3073 This is the same value as returned by @code{gpgme_get_sig_status}.
3077 @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}})
3078 The function @code{gpgme_key_sig_get_string_attr} returns the value of
3079 the string-representable attribute @var{what} of the signature
3080 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3081 argument @var{reserved} is reserved for later use and should be
3084 The string returned is only valid as long as the key is valid.
3086 The function returns @code{0} if an attribute can't be returned as a
3087 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3088 out of range, or @var{reserved} not @code{NULL}.
3091 @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}})
3092 The function @code{gpgme_key_sig_get_ulong_attr} returns the value of
3093 the number-representable attribute @var{what} of the signature
3094 @var{idx} on the user ID @var{uid_idx} in the key @var{key}. The
3095 argument @var{reserved} is reserved for later use and should be
3098 The function returns @code{0} if an attribute can't be returned as a
3099 string, @var{key} is not a valid pointer, @var{uid_idx} or @var{idx}
3100 out of range, or @var{reserved} not @code{NULL}.
3104 @node Manipulating Keys
3105 @subsection Manipulating Keys
3106 @cindex key, manipulation
3108 @deftypefun void gpgme_key_ref (@w{gpgme_key_t @var{key}})
3109 The function @code{gpgme_key_ref} acquires an additional reference for
3113 @deftypefun void gpgme_key_unref (@w{gpgme_key_t @var{key}})
3114 The function @code{gpgme_key_unref} releases a reference for the key
3115 @var{key}. If this was the last reference, the key will be destroyed
3116 and all resources associated to it will be released.
3120 The following interface is deprecated and only provided for backward
3121 compatibility. Don't use it. It will be removed in a future version
3124 @deftypefun void gpgme_key_release (@w{gpgme_key_t @var{key}})
3125 The function @code{gpgme_key_release} is equivalent to
3126 @code{gpgme_key_unref}.
3130 @node Generating Keys
3131 @subsection Generating Keys
3132 @cindex key, creation
3133 @cindex key ring, add
3135 @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}})
3136 The function @code{gpgme_op_genkey} generates a new key pair in the
3137 context @var{ctx}. The meaning of @var{public} and @var{secret}
3138 depends on the crypto backend.
3140 GnuPG does not support @var{public} and @var{secret}, they should be
3141 @code{NULL}. GnuPG will generate a key pair and add it to the
3142 standard key ring. The fingerprint of the generated key is available
3143 with @code{gpgme_op_genkey_result}.
3145 GpgSM requires @var{public} to be a writable data object. GpgSM will
3146 generate a secret key (which will be stored by @command{gpg-agent},
3147 and return a certificate request in @var{public}, which then needs to
3148 be signed by the certification authority and imported before it can be
3149 used. GpgSM does not make the fingerprint available.
3151 The argument @var{parms} specifies parameters for the key in an XML
3152 string. The details about the format of @var{parms} are specific to
3153 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
3157 <GnupgKeyParms format="internal">
3162 Name-Real: Joe Tester
3163 Name-Comment: with stupid passphrase
3164 Name-Email: joe@@foo.bar
3170 Here is an example for GpgSM as the crypto engine:
3173 <GnupgKeyParms format="internal">
3176 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3177 Name-Email: joe@@foo.bar
3181 Strings should be given in UTF-8 encoding. The only format supported
3182 for now is ``internal''. The content of the @code{GnupgKeyParms}
3183 container is passed verbatim to the crypto backend. Control
3184 statements are not allowed.
3186 After the operation completed successfully, the result can be
3187 retrieved with @code{gpgme_op_genkey_result}.
3189 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3190 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3191 @var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if
3192 @var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL}
3193 if no key was created by the backend.
3196 @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}})
3197 The function @code{gpgme_op_genkey_start} initiates a
3198 @code{gpgme_op_genkey} operation. It can be completed by calling
3199 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3201 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3202 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3203 @var{parms} is not a valid XML string, and
3204 @code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not
3208 @deftp {Data type} {gpgme_genkey_result_t}
3209 This is a pointer to a structure used to store the result of a
3210 @code{gpgme_op_genkey} operation. After successfully generating a
3211 key, you can retrieve the pointer to the result with
3212 @code{gpgme_op_genkey_result}. The structure contains the following
3216 @item unsigned int primary : 1
3217 This is a flag that is set to 1 if a primary key was created and to 0
3220 @item unsigned int sub : 1
3221 This is a flag that is set to 1 if a subkey was created and to 0
3225 This is the fingerprint of the key that was created. If both a
3226 primary and a sub key were generated, the fingerprint of the primary
3227 key will be returned. If the crypto engine does not provide the
3228 fingerprint, @code{fpr} will be a null pointer.
3232 @deftypefun gpgme_genkey_result_t gpgme_op_genkey_result (@w{gpgme_ctx_t @var{ctx}})
3233 The function @code{gpgme_op_genkey_result} returns a
3234 @code{gpgme_genkey_result_t} pointer to a structure holding the result of
3235 a @code{gpgme_op_genkey} operation. The pointer is only valid if the
3236 last operation on the context was a @code{gpgme_op_genkey} or
3237 @code{gpgme_op_genkey_start} operation, and if this operation finished
3238 successfully. The returned pointer is only valid until the next
3239 operation is started on the context.
3243 @node Exporting Keys
3244 @subsection Exporting Keys
3246 @cindex key ring, export from
3248 @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}})
3249 The function @code{gpgme_op_export} extracts public keys and returns
3250 them in the data buffer @var{keydata}. The output format of the key
3251 data returned is determined by the @acronym{ASCII} armor attribute set
3252 for the context @var{ctx}.
3254 If @var{pattern} is @code{NULL}, all available keys are returned.
3255 Otherwise, @var{pattern} contains an engine specific expression that
3256 is used to limit the list to all keys matching the pattern.
3258 @var{reserved} is reserved for future use and must be @code{0}.
3260 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3261 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3262 @var{keydata} is not a valid empty data buffer, and passes through any
3263 errors that are reported by the crypto engine support routines.
3266 @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}})
3267 The function @code{gpgme_op_export_start} initiates a
3268 @code{gpgme_op_export} operation. It can be completed by calling
3269 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3271 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3272 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3273 if @var{keydata} is not a valid empty data buffer.
3276 @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}})
3277 The function @code{gpgme_op_export} extracts public keys and returns
3278 them in the data buffer @var{keydata}. The output format of the key
3279 data returned is determined by the @acronym{ASCII} armor attribute set
3280 for the context @var{ctx}.
3282 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
3283 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
3284 array of strings that are used to limit the list to all keys matching
3285 at least one of the patterns verbatim.
3287 @var{reserved} is reserved for future use and must be @code{0}.
3289 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3290 operation completed successfully, @code{GPG_ERR_INV_VALUE} if
3291 @var{keydata} is not a valid empty data buffer, and passes through any
3292 errors that are reported by the crypto engine support routines.
3295 @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}})
3296 The function @code{gpgme_op_export_ext_start} initiates a
3297 @code{gpgme_op_export_ext} operation. It can be completed by calling
3298 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3300 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3301 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3302 if @var{keydata} is not a valid empty data buffer.
3306 @node Importing Keys
3307 @subsection Importing Keys
3309 @cindex key ring, import to
3311 @deftypefun gpgme_error_t gpgme_op_import (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3312 The function @code{gpgme_op_import} adds the keys in the data buffer
3313 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
3314 The format of @var{keydata} can be @acronym{ASCII} armored, for example,
3315 but the details are specific to the crypto engine.
3317 After the operation completed successfully, the result can be
3318 retrieved with @code{gpgme_op_import_result}.
3320 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3321 import was completed successfully, @code{GPG_ERR_INV_VALUE} if
3322 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3323 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3326 @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}})
3327 The function @code{gpgme_op_import_start} initiates a
3328 @code{gpgme_op_import} operation. It can be completed by calling
3329 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3331 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3332 import could be started successfully, @code{GPG_ERR_INV_VALUE} if
3333 @var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer,
3334 and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer.
3337 @deftp {Data type} {gpgme_import_status_t}
3338 This is a pointer to a structure used to store a part of the result of
3339 a @code{gpgme_op_import} operation. For each considered key one
3340 status is added that contains information about the result of the
3341 import. The structure contains the following members:
3344 @item gpgme_import_status_t next
3345 This is a pointer to the next status structure in the linked list, or
3346 @code{NULL} if this is the last element.
3349 This is the fingerprint of the key that was considered.
3351 @item gpgme_error_t result
3352 If the import was not successful, this is the error value that caused
3353 the import to fail. Otherwise the error code is
3354 @code{GPG_ERR_NO_ERROR}.
3356 @item unsigned int status
3357 This is a bit-wise OR of the following flags that give more
3358 information about what part of the key was imported. If the key was
3359 already known, this might be 0.
3362 @item GPGME_IMPORT_NEW
3365 @item GPGME_IMPORT_UID
3366 The key contained new user IDs.
3368 @item GPGME_IMPORT_SIG
3369 The key contained new signatures.
3371 @item GPGME_IMPORT_SUBKEY
3372 The key contained new sub keys.
3374 @item GPGME_IMPORT_SECRET
3375 The key contained a secret key.
3380 @deftp {Data type} {gpgme_import_result_t}
3381 This is a pointer to a structure used to store the result of a
3382 @code{gpgme_op_import} operation. After a successful import
3383 operation, you can retrieve the pointer to the result with
3384 @code{gpgme_op_import_result}. The structure contains the following
3388 @item int considered
3389 The total number of considered keys.
3391 @item int no_user_id
3392 The number of keys without user ID.
3395 The total number of imported keys.
3398 The number of imported RSA keys.
3401 The number of unchanged keys.
3404 The number of new user IDs.
3407 The number of new sub keys.
3409 @item new_signatures
3410 The number of new signatures.
3412 @item new_revocations
3413 The number of new revocations.
3416 The total number of secret keys read.
3418 @item secret_imported
3419 The number of imported secret keys.
3421 @item secret_unchanged
3422 The number of unchanged secret keys.
3425 The number of keys not imported.
3427 @item gpgme_import_status_t imports
3428 A list of gpgme_import_status_t objects which contain more information
3429 about the keys for which an import was attempted.
3433 @deftypefun gpgme_import_result_t gpgme_op_import_result (@w{gpgme_ctx_t @var{ctx}})
3434 The function @code{gpgme_op_import_result} returns a
3435 @code{gpgme_import_result_t} pointer to a structure holding the result
3436 of a @code{gpgme_op_import} operation. The pointer is only valid if
3437 the last operation on the context was a @code{gpgme_op_import} or
3438 @code{gpgme_op_import_start} operation, and if this operation finished
3439 successfully. The returned pointer is only valid until the next
3440 operation is started on the context.
3443 The following interface is deprecated and only provided for backward
3444 compatibility. Don't use it. It will be removed in a future version
3447 @deftypefun gpgme_error_t gpgme_op_import_ext (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}}, @w{int *@var{nr}})
3448 The function @code{gpgme_op_import_ext} is equivalent to:
3451 gpgme_error_t err = gpgme_op_import (ctx, keydata);
3454 gpgme_import_result_t result = gpgme_op_import_result (ctx);
3455 *nr = result->considered;
3462 @subsection Deleting Keys
3464 @cindex key ring, delete from
3466 @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}})
3467 The function @code{gpgme_op_delete} deletes the key @var{key} from the
3468 key ring of the crypto engine used by @var{ctx}. If
3469 @var{allow_secret} is @code{0}, only public keys are deleted,
3470 otherwise secret keys are deleted as well, if that is supported.
3472 The function returns the error code @code{GPG_ERR_NO_ERROR} if the key
3473 was deleted successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3474 @var{key} is not a valid pointer, @code{GPG_ERR_NO_PUBKEY} if
3475 @var{key} could not be found in the keyring,
3476 @code{GPG_ERR_AMBIGUOUS_NAME} if the key was not specified
3477 unambiguously, and @code{GPG_ERR_CONFLICT} if the secret key for
3478 @var{key} is available, but @var{allow_secret} is zero.
3481 @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}})
3482 The function @code{gpgme_op_delete_start} initiates a
3483 @code{gpgme_op_delete} operation. It can be completed by calling
3484 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3486 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3487 operation was started successfully, and @code{GPG_ERR_INV_VALUE} if
3488 @var{ctx} or @var{key} is not a valid pointer.
3492 @node Trust Item Management
3493 @section Trust Item Management
3496 @strong{Caution:} The trust items interface is experimental.
3498 @deftp {Data type} gpgme_trust_item_t
3499 The @code{gpgme_trust_item_t} type is a pointer to a trust item object.
3500 It has the following members:
3504 This is a string describing the key to which this trust items belongs.
3507 This is the type of the trust item. A value of 1 refers to a key, a
3508 value of 2 refers to a user ID.
3511 This is the trust level.
3513 @item char *owner_trust
3514 The owner trust if @code{type} is 1.
3516 @item char *validity
3517 The calculated validity.
3520 The user name if @code{type} is 2.
3525 * Listing Trust Items:: Browsing the list of available trust items.
3526 * Information About Trust Items:: Requesting information about trust items.
3527 * Manipulating Trust Items:: Operations on trust items.
3531 @node Listing Trust Items
3532 @subsection Listing Trust Items
3533 @cindex trust item list
3535 @deftypefun gpgme_error_t gpgme_op_trustlist_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}})
3536 The function @code{gpgme_op_trustlist_start} initiates a trust item
3537 listing operation inside the context @var{ctx}. It sets everything up
3538 so that subsequent invocations of @code{gpgme_op_trustlist_next} return
3539 the trust items in the list.
3541 The string @var{pattern} contains an engine specific expression that
3542 is used to limit the list to all trust items matching the pattern. It
3543 can not be the empty string.
3545 The argument @var{max_level} is currently ignored.
3547 The context will be busy until either all trust items are received
3548 (and @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}), or
3549 @code{gpgme_op_trustlist_end} is called to finish the operation.
3551 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3552 @var{ctx} is not a valid pointer, and passes through any errors that
3553 are reported by the crypto engine support routines.
3556 @deftypefun gpgme_error_t gpgme_op_trustlist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_trust_item_t *@var{r_item}})
3557 The function @code{gpgme_op_trustlist_next} returns the next trust
3558 item in the list created by a previous @code{gpgme_op_trustlist_start}
3559 operation in the context @var{ctx}. The trust item can be destroyed
3560 with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}.
3562 This is the only way to get at @code{gpgme_trust_item_t} objects in
3565 If the last trust item in the list has already been returned,
3566 @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}.
3568 The function returns the error code @code{GPG_ERR_INV_VALUE} if @var{ctx} or
3569 @var{r_item} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if
3570 there is not enough memory for the operation.
3573 @deftypefun gpgme_error_t gpgme_op_trustlist_end (@w{gpgme_ctx_t @var{ctx}})
3574 The function @code{gpgme_op_trustlist_next} ends a pending key list
3575 operation in the context @var{ctx}.
3577 The function returns the error code @code{GPG_ERR_INV_VALUE} if
3578 @var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some
3579 time during the operation there was not enough memory available.
3583 @node Information About Trust Items
3584 @subsection Information About Trust Items
3585 @cindex trust item, information about
3586 @cindex trust item, attributes
3587 @cindex attributes, of a trust item
3589 The following interfaces are deprecated and only provided for backward
3590 compatibility. Don't use them. They will be removed in a future
3591 version of @acronym{GPGME}.
3593 Trust items have attributes which can be queried using the interfaces
3594 below. The attribute identifiers are shared with those for key
3595 attributes. @xref{Information About Keys}.
3597 @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}})
3598 The function @code{gpgme_trust_item_get_string_attr} returns the value
3599 of the string-representable attribute @var{what} of trust item
3600 @var{item}. The arguments @var{idx} and @var{reserved} are reserved
3601 for later use and should be @code{0} and @code{NULL} respectively.
3603 The string returned is only valid as long as the key is valid.
3605 The function returns @code{0} if an attribute can't be returned as a
3606 string, @var{key} is not a valid pointer, @var{idx} out of range,
3607 or @var{reserved} not @code{NULL}.
3610 @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}})
3611 The function @code{gpgme_trust_item_get_int_attr} returns the value of
3612 the number-representable attribute @var{what} of trust item
3613 @var{item}. If the attribute occurs more than once in the trust item,
3614 the index is specified by @var{idx}. However, currently no such
3615 attribute exists, so @var{idx} should be @code{0}. The argument
3616 @var{reserved} is reserved for later use and should be @code{NULL}.
3618 The function returns @code{0} if the attribute can't be returned as a
3619 number, @var{key} is not a valid pointer, @var{idx} out of range,
3620 or @var{reserved} not @code{NULL}.
3624 @node Manipulating Trust Items
3625 @subsection Manipulating Trust Items
3626 @cindex trust item, manipulation
3628 @deftypefun void gpgme_trust_item_ref (@w{gpgme_trust_item_t @var{item}})
3629 The function @code{gpgme_trust_item_ref} acquires an additional
3630 reference for the trust item @var{item}.
3633 @deftypefun void gpgme_trust_item_unref (@w{gpgme_trust_item_t @var{item}})
3634 The function @code{gpgme_trust_item_unref} releases a reference for
3635 the trust item @var{item}. If this was the last reference, the trust
3636 item will be destroyed and all resources associated to it will be
3641 The following interface is deprecated and only provided for backward
3642 compatibility. Don't use it. It will be removed in a future version
3645 @deftypefun void gpgme_trust_item_release (@w{gpgme_trust_item_t @var{item}})
3646 The function @code{gpgme_trust_item_release} is an alias for
3647 @code{gpgme_trust_item_unref}.
3651 @node Crypto Operations
3652 @section Crypto Operations
3653 @cindex cryptographic operation
3655 Sometimes, the result of a crypto operation returns a list of invalid
3656 keys encountered in processing the request. The following structure
3657 is used to hold information about such a key.
3659 @deftp {Data type} {gpgme_invalid_key_t}
3660 This is a pointer to a structure used to store a part of the result of
3661 a crypto operation which takes user IDs as one input parameter. The
3662 structure contains the following members:
3665 @item gpgme_invalid_key_t next
3666 This is a pointer to the next invalid key structure in the linked
3667 list, or @code{NULL} if this is the last element.
3670 The fingerprint or key ID of the invalid key encountered.
3672 @item gpgme_error_t reason
3673 An error code describing the reason why the key was found invalid.
3679 * Decrypt:: Decrypting a ciphertext.
3680 * Verify:: Verifying a signature.
3681 * Decrypt and Verify:: Decrypting a signed ciphertext.
3682 * Sign:: Creating a signature.
3683 * Encrypt:: Encrypting a plaintext.
3690 @cindex cryptographic operation, decryption
3692 @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}})
3693 The function @code{gpgme_op_decrypt} decrypts the ciphertext in the
3694 data object @var{cipher} and stores it into the data object
3697 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3698 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
3699 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
3700 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
3701 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
3702 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
3703 secret key could not be retrieved, and passes through any errors that
3704 are reported by the crypto engine support routines.
3707 @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}})
3708 The function @code{gpgme_op_decrypt_start} initiates a
3709 @code{gpgme_op_decrypt} operation. It can be completed by calling
3710 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3712 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3713 operation could be started successfully, and @code{GPG_ERR_INV_VALUE}
3714 if @var{cipher} or @var{plain} is not a valid pointer.
3717 @deftp {Data type} {gpgme_recipient_t}
3718 This is a pointer to a structure used to store information about the
3719 recipient of an encrypted text which is decrypted in a
3720 @code{gpgme_op_decrypt} operation. This information (except for the
3721 status field) is even available before the operation finished
3722 successfully, for example in a passphrase callback. The structure
3723 contains the following members:
3726 @item gpgme_recipient_t next
3727 This is a pointer to the next recipient structure in the linked list,
3728 or @code{NULL} if this is the last element.
3730 @item gpgme_pubkey_algo_t
3731 The public key algorithm used in the encryption.
3733 @item unsigned int wrong_key_usage : 1
3734 This is true if the key was not used according to its policy.
3737 This is the key ID of the key (in hexadecimal digits) used as
3740 @item gpgme_error_t status
3741 This is an error number with the error code GPG_ERR_NO_SECKEY if the
3742 secret key for this recipient is not available, and 0 otherwise.
3746 @deftp {Data type} {gpgme_decrypt_result_t}
3747 This is a pointer to a structure used to store the result of a
3748 @code{gpgme_op_decrypt} operation. After successfully decrypting
3749 data, you can retrieve the pointer to the result with
3750 @code{gpgme_op_decrypt_result}. The structure contains the following
3754 @item char *unsupported_algorithm
3755 If an unsupported algorithm was encountered, this string describes the
3756 algorithm that is not supported.
3758 @item unsigned int wrong_key_usage : 1
3759 This is true if the key was not used according to its policy.
3761 @item gpgme_recipient_t recipient
3762 This is a linked list of recipients to which this message was encrypted.
3764 @item char *file_name
3765 This is the filename of the original plaintext message file if it is
3766 known, otherwise this is a null pointer.
3770 @deftypefun gpgme_decrypt_result_t gpgme_op_decrypt_result (@w{gpgme_ctx_t @var{ctx}})
3771 The function @code{gpgme_op_decrypt_result} returns a
3772 @code{gpgme_decrypt_result_t} pointer to a structure holding the
3773 result of a @code{gpgme_op_decrypt} operation. The pointer is only
3774 valid if the last operation on the context was a
3775 @code{gpgme_op_decrypt} or @code{gpgme_op_decrypt_start} operation.
3776 If the operation failed this might be a @code{NULL} pointer. The
3777 returned pointer is only valid until the next operation is started on
3784 @cindex verification
3785 @cindex signature, verification
3786 @cindex cryptographic operation, verification
3787 @cindex cryptographic operation, signature check
3788 @cindex signature notation data
3789 @cindex notation data
3791 @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}})
3792 The function @code{gpgme_op_verify} verifies that the signature in the
3793 data object @var{sig} is a valid signature. If @var{sig} is a
3794 detached signature, then the signed text should be provided in
3795 @var{signed_text} and @var{plain} should be a null pointer.
3796 Otherwise, if @var{sig} is a normal (or cleartext) signature,
3797 @var{signed_text} should be a null pointer and @var{plain} should be a
3798 writable data object that will contain the plaintext after successful
3801 The results of the individual signature verifications can be retrieved
3802 with @code{gpgme_op_verify_result}.
3804 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3805 operation could be completed successfully, @code{GPG_ERR_INV_VALUE} if
3806 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer,
3807 @code{GPG_ERR_NO_DATA} if @var{sig} does not contain any data to
3808 verify, and passes through any errors that are reported by the crypto
3809 engine support routines.
3812 @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}})
3813 The function @code{gpgme_op_verify_start} initiates a
3814 @code{gpgme_op_verify} operation. It can be completed by calling
3815 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
3817 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
3818 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
3819 @var{ctx}, @var{sig} or @var{plain} is not a valid pointer, and
3820 @code{GPG_ERR_NO_DATA} if @var{sig} or @var{plain} does not contain
3824 @deftp {Data type} {gpgme_sig_notation_t}
3825 This is a pointer to a structure used to store a part of the result of
3826 a @code{gpgme_op_verify} operation. The structure contains the
3830 @item gpgme_sig_notation_t next
3831 This is a pointer to the next new signature notation structure in the
3832 linked list, or @code{NULL} if this is the last element.
3835 The name of the notation field. If this is @code{NULL}, then the
3836 member @code{value} will contain a policy URL.
3839 The length of the @code{name} field. For strings the length is
3840 counted without the trailing binary zero.
3843 The value of the notation field. If @code{name} is @code{NULL}, then
3844 this is a policy URL.
3847 The length of the @code{value} field. For strings the length is
3848 counted without the trailing binary zero.
3850 @item gpgme_sig_notation_flags_t flags
3851 The accumulated flags field. This field contains the flags associated
3852 with the notation data in an accumulated form which can be used as an
3853 argument to the function @code{gpgme_sig_notation_add}. The value
3854 @code{flags} is a bitwise-or combination of one or multiple of the
3855 following bit values:
3858 @item GPGME_SIG_NOTATION_HUMAN_READABLE
3859 The @code{GPGME_SIG_NOTATION_HUMAN_READABLE} symbol specifies that the
3860 notation data is in human readable form
3862 @item GPGME_SIG_NOTATION_CRITICAL
3863 The @code{GPGME_SIG_NOTATION_CRITICAL} symbol specifies that the
3864 notation data is critical.
3868 @item unsigned int human_readable : 1
3869 This is true if the @code{GPGME_SIG_NOTATION_HUMAN_READABLE} flag is
3870 set and false otherwise. This flag is only valid for notation data,
3871 not for policy URLs.
3873 @item unsigned int critical : 1
3874 This is true if the @code{GPGME_SIG_NOTATION_CRITICAL} flag is set and
3875 false otherwise. This flag is valid for notation data and policy URLs.
3880 @deftp {Data type} {gpgme_signature_t}
3881 This is a pointer to a structure used to store a part of the result of
3882 a @code{gpgme_op_verify} operation. The structure contains the
3886 @item gpgme_signature_t next
3887 This is a pointer to the next new signature structure in the linked
3888 list, or @code{NULL} if this is the last element.
3890 @item gpgme_sigsum_t summary
3891 This is a bit vector giving a summary of the signature status. It
3892 provides an easy interface to a defined semantic of the signature
3893 status. Checking just one bit is sufficient to see whether a
3894 signature is valid without any restrictions.
3896 The defined bits are:
3898 @item GPGME_SIGSUM_VALID
3899 The signature is fully valid.
3901 @item GPGME_SIGSUM_GREEN
3902 The signature is good but one might want to display some extra
3903 information. Check the other bits.
3905 @item GPGME_SIGSUM_RED
3906 The signature is bad. It might be useful to check other bits and
3907 display more information, i.e. a revoked certificate might not render a
3908 signature invalid when the message was received prior to the cause for
3911 @item GPGME_SIGSUM_KEY_REVOKED
3912 The key or at least one certificate has been revoked.
3914 @item GPGME_SIGSUM_KEY_EXPIRED
3915 The key or one of the certificates has expired. It is probably a good
3916 idea to display the date of the expiration.
3918 @item GPGME_SIGSUM_SIG_EXPIRED
3919 The signature has expired.
3921 @item GPGME_SIGSUM_KEY_MISSING
3922 Can't verify due to a missing key or certificate.
3924 @item GPGME_SIGSUM_CRL_MISSING
3925 The CRL (or an equivalent mechanism) is not available.
3927 @item GPGME_SIGSUM_CRL_TOO_OLD
3928 Available CRL is too old.
3930 @item GPGME_SIGSUM_BAD_POLICY
3931 A policy requirement was not met.
3933 @item GPGME_SIGSUM_SYS_ERROR
3934 A system error occured.
3938 This is the fingerprint or key ID of the signature.
3940 @item gpgme_error_t status
3941 This is the status of the signature. In particular, the following
3942 status codes are of interest:
3945 @item GPG_ERR_NO_ERROR
3946 This status indicates that the signature is valid. For the combined
3947 result this status means that all signatures are valid.
3949 @item GPG_ERR_SIG_EXPIRED
3950 This status indicates that the signature is valid but expired. For
3951 the combined result this status means that all signatures are valid
3954 @item GPG_ERR_KEY_EXPIRED
3955 This status indicates that the signature is valid but the key used to
3956 verify the signature has expired. For the combined result this status
3957 means that all signatures are valid and all keys are expired.
3959 @item GPG_ERR_CERT_REVOKED
3960 This status indicates that the signature is valid but the key used
3961 to verify the signature has been revoked. For the combined result
3962 this status means that all signatures are valid and all keys are
3965 @item GPG_ERR_BAD_SIGNATURE
3966 This status indicates that the signature is invalid. For the combined
3967 result this status means that all signatures are invalid.
3969 @item GPG_ERR_NO_PUBKEY
3970 This status indicates that the signature could not be verified due to
3971 a missing key. For the combined result this status means that all
3972 signatures could not be checked due to missing keys.
3974 @item GPG_ERR_GENERAL
3975 This status indicates that there was some other error which prevented
3976 the signature verification.
3979 @item gpgme_sig_notation_t notations
3980 This is a linked list with the notation data and policy URLs.
3982 @item unsigned long timestamp
3983 The creation timestamp of this signature.
3985 @item unsigned long exp_timestamp
3986 The expiration timestamp of this signature, or 0 if the signature does
3989 @item unsigned int wrong_key_usage : 1
3990 This is true if the key was not used according to its policy.
3992 @item unsigned int pka_trust : 2
3993 This is set to the trust information gained by means of the PKA system.
3997 No PKA information available or verification not possible.
3999 PKA verification failed.
4001 PKA verification succeeded.
4003 Reserved for future use.
4005 Depending on the configuration of the engine, this metric may also be
4006 reflected by the validity of the signature.
4008 @item gpgme_validity_t validity
4009 The validity of the signature.
4011 @item gpgme_error_t validity_reason
4012 If a signature is not valid, this provides a reason why.
4014 @item gpgme_pubkey_algo_t
4015 The public key algorithm used to create this signature.
4017 @item gpgme_hash_algo_t
4018 The hash algorithm used to create this signature.
4022 @deftp {Data type} {gpgme_verify_result_t}
4023 This is a pointer to a structure used to store the result of a
4024 @code{gpgme_op_verify} operation. After verifying a signature, you
4025 can retrieve the pointer to the result with
4026 @code{gpgme_op_verify_result}. If the operation failed this might be
4027 a @code{NULL} pointer. The structure contains the following member:
4030 @item gpgme_signature_t signatures
4031 A linked list with information about all signatures for which a
4032 verification was attempted.
4034 @item char *file_name
4035 This is the filename of the original plaintext message file if it is
4036 known, otherwise this is a null pointer.
4040 @deftypefun gpgme_verify_result_t gpgme_op_verify_result (@w{gpgme_ctx_t @var{ctx}})
4041 The function @code{gpgme_op_verify_result} returns a
4042 @code{gpgme_verify_result_t} pointer to a structure holding the result
4043 of a @code{gpgme_op_verify} operation. The pointer is only valid if
4044 the last operation on the context was a @code{gpgme_op_verify},
4045 @code{gpgme_op_verify_start}, @code{gpgme_op_decrypt_verify} or
4046 @code{gpgme_op_decrypt_verify_start} operation, and if this operation
4047 finished successfully (for @code{gpgme_op_decrypt_verify} and
4048 @code{gpgme_op_decrypt_verify_start}, the error code
4049 @code{GPG_ERR_NO_DATA} counts as successful in this context). The
4050 returned pointer is only valid until the next operation is started on
4055 The following interfaces are deprecated and only provided for backward
4056 compatibility. Don't use them. They will be removed in a future
4057 version of @acronym{GPGME}.
4059 @deftp {Data type} {enum gpgme_sig_stat_t}
4060 @tindex gpgme_sig_stat_t
4061 The @code{gpgme_sig_stat_t} type holds the result of a signature check, or
4062 the combined result of all signatures. The following results are
4066 @item GPGME_SIG_STAT_NONE
4067 This status should not occur in normal operation.
4069 @item GPGME_SIG_STAT_GOOD
4070 This status indicates that the signature is valid. For the combined
4071 result this status means that all signatures are valid.
4073 @item GPGME_SIG_STAT_GOOD_EXP
4074 This status indicates that the signature is valid but expired. For
4075 the combined result this status means that all signatures are valid
4078 @item GPGME_SIG_STAT_GOOD_EXPKEY
4079 This status indicates that the signature is valid but the key used to
4080 verify the signature has expired. For the combined result this status
4081 means that all signatures are valid and all keys are expired.
4083 @item GPGME_SIG_STAT_BAD
4084 This status indicates that the signature is invalid. For the combined
4085 result this status means that all signatures are invalid.
4087 @item GPGME_SIG_STAT_NOKEY
4088 This status indicates that the signature could not be verified due to
4089 a missing key. For the combined result this status means that all
4090 signatures could not be checked due to missing keys.
4092 @item GPGME_SIG_STAT_NOSIG
4093 This status indicates that the signature data provided was not a real
4096 @item GPGME_SIG_STAT_ERROR
4097 This status indicates that there was some other error which prevented
4098 the signature verification.
4100 @item GPGME_SIG_STAT_DIFF
4101 For the combined result this status means that at least two signatures
4102 have a different status. You can get each key's status with
4103 @code{gpgme_get_sig_status}.
4107 @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}})
4108 The function @code{gpgme_get_sig_status} is equivalent to:
4111 gpgme_verify_result_t result;
4112 gpgme_signature_t sig;
4114 result = gpgme_op_verify_result (ctx);
4115 sig = result->signatures;
4127 switch (gpg_err_code (sig->status))
4129 case GPG_ERR_NO_ERROR:
4130 *r_stat = GPGME_SIG_STAT_GOOD;
4133 case GPG_ERR_BAD_SIGNATURE:
4134 *r_stat = GPGME_SIG_STAT_BAD;
4137 case GPG_ERR_NO_PUBKEY:
4138 *r_stat = GPGME_SIG_STAT_NOKEY;
4141 case GPG_ERR_NO_DATA:
4142 *r_stat = GPGME_SIG_STAT_NOSIG;
4145 case GPG_ERR_SIG_EXPIRED:
4146 *r_stat = GPGME_SIG_STAT_GOOD_EXP;
4149 case GPG_ERR_KEY_EXPIRED:
4150 *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY;
4154 *r_stat = GPGME_SIG_STAT_ERROR;
4159 *r_created = sig->timestamp;
4164 @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}})
4165 The function @code{gpgme_get_sig_string_attr} is equivalent to:
4168 gpgme_verify_result_t result;
4169 gpgme_signature_t sig;
4171 result = gpgme_op_verify_result (ctx);
4172 sig = result->signatures;
4184 case GPGME_ATTR_FPR:
4187 case GPGME_ATTR_ERRTOK:
4189 return sig->wrong_key_usage ? "Wrong_Key_Usage" : "";
4200 @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}})
4201 The function @code{gpgme_get_sig_ulong_attr} is equivalent to:
4204 gpgme_verify_result_t result;
4205 gpgme_signature_t sig;
4207 result = gpgme_op_verify_result (ctx);
4208 sig = result->signatures;
4220 case GPGME_ATTR_CREATED:
4221 return sig->timestamp;
4223 case GPGME_ATTR_EXPIRE:
4224 return sig->exp_timestamp;
4226 case GPGME_ATTR_VALIDITY:
4227 return (unsigned long) sig->validity;
4229 case GPGME_ATTR_SIG_STATUS:
4230 switch (sig->status)
4232 case GPG_ERR_NO_ERROR:
4233 return GPGME_SIG_STAT_GOOD;
4235 case GPG_ERR_BAD_SIGNATURE:
4236 return GPGME_SIG_STAT_BAD;
4238 case GPG_ERR_NO_PUBKEY:
4239 return GPGME_SIG_STAT_NOKEY;
4241 case GPG_ERR_NO_DATA:
4242 return GPGME_SIG_STAT_NOSIG;
4244 case GPG_ERR_SIG_EXPIRED:
4245 return GPGME_SIG_STAT_GOOD_EXP;
4247 case GPG_ERR_KEY_EXPIRED:
4248 return GPGME_SIG_STAT_GOOD_EXPKEY;
4251 return GPGME_SIG_STAT_ERROR;
4254 case GPGME_ATTR_SIG_SUMMARY:
4255 return sig->summary;
4264 @deftypefun {const char *} gpgme_get_sig_key (@w{gpgme_ctx_t @var{ctx}}, @w{int @var{idx}}, @w{gpgme_key_t *@var{r_key}})
4265 The function @code{gpgme_get_sig_key} is equivalent to:
4268 gpgme_verify_result_t result;
4269 gpgme_signature_t sig;
4271 result = gpgme_op_verify_result (ctx);
4272 sig = result->signatures;
4280 return gpg_error (GPG_ERR_EOF);
4282 return gpgme_get_key (ctx, sig->fpr, r_key, 0);
4287 @node Decrypt and Verify
4288 @subsection Decrypt and Verify
4289 @cindex decryption and verification
4290 @cindex verification and decryption
4291 @cindex signature check
4292 @cindex cryptographic operation, decryption and verification
4294 @deftypefun gpgme_error_t gpgme_op_decrypt_verify (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{cipher}}, @w{gpgme_data_t @var{plain}})
4295 The function @code{gpgme_op_decrypt_verify} decrypts the ciphertext in
4296 the data object @var{cipher} and stores it into the data object
4297 @var{plain}. If @var{cipher} contains signatures, they will be
4300 After the operation completed, @code{gpgme_op_decrypt_result} and
4301 @code{gpgme_op_verify_result} can be used to retrieve more information
4302 about the signatures.
4304 If the error code @code{GPG_ERR_NO_DATA} is returned, @var{cipher}
4305 does not contain any data to decrypt. However, it might still be
4306 signed. The information about detected signatures is available with
4307 @code{gpgme_op_verify_result} in this case.
4309 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4310 ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE}
4311 if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
4312 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
4313 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
4314 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
4315 secret key could not be retrieved, and passes through any errors that
4316 are reported by the crypto engine support routines.
4319 @deftypefun gpgme_error_t gpgme_op_decrypt_verify (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{cipher}}, @w{gpgme_data_t @var{plain}})
4320 The function @code{gpgme_op_decrypt_verify_start} initiates a
4321 @code{gpgme_op_decrypt_verify} operation. It can be completed by
4322 calling @code{gpgme_wait} on the context. @xref{Waiting For
4325 The function returns the error code @code{GPG_ERR_NO_ERROR} if the
4326 operation could be started successfully, @code{GPG_ERR_INV_VALUE} if
4327 @var{ctx}, @var{cipher}, @var{plain} or @var{r_stat} is not a valid
4328 pointer, and @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain
4329 any data to decrypt.
4335 @cindex signature, creation
4337 @cindex cryptographic operation, signing
4339 A signature can contain signatures by one or more keys. The set of
4340 keys used to create a signatures is contained in a context, and is
4341 applied to all following signing operations in this context (until the
4345 * Selecting Signers:: How to choose the keys to sign with.
4346 * Creating a Signature:: How to create a signature.
4347 * Signature Notation Data:: How to add notation data to a signature.
4351 @node Selecting Signers
4352 @subsubsection Selecting Signers
4353 @cindex signature, selecting signers
4354 @cindex signers, selecting
4356 @deftypefun void gpgme_signers_clear (@w{gpgme_ctx_t @var{ctx}})
4357 The function @code{gpgme_signers_clear} releases a reference for each
4358 key on the signers list and removes the list of signers from the
4361 Every context starts with an empty list.
4364 @deftypefun gpgme_error_t gpgme_signers_add (@w{gpgme_ctx_t @var{ctx}}, @w{const gpgme_key_t @var{key}})
4365 The function @code{gpgme_signers_add} adds the key @var{key} to the
4366 list of signers in the context @var{ctx}.
4368 Calling this function acquires an additional reference for the key.
4371 @deftypefun gpgme_key_t gpgme_signers_enum (@w{const gpgme_ctx_t @var{ctx}}, @w{int @var{seq}})
4372 The function @code{gpgme_signers_enum} returns the @var{seq}th key in
4373 the list of signers in the context @var{ctx}. An additional reference
4374 is acquired for the user.
4376 If @var{seq} is out of range, @code{NULL} is returned.
4380 @node Creating a Signature
4381 @subsubsection Creating a Signature
4383 @deftp {Data type} {enum gpgme_sig_mode_t}
4384 @tindex gpgme_sig_mode_t
4385 The @code{gpgme_sig_mode_t} type is used to specify the desired type of a
4386 signature. The following modes are available:
4389 @item GPGME_SIG_MODE_NORMAL
4390 A normal signature is made, the output includes the plaintext and the