1 This is /home/wk/w/gpgme/doc/gpgme.info, produced by makeinfo version
2 4.13 from /home/wk/w/gpgme/doc/gpgme.texi.
4 INFO-DIR-SECTION GNU Libraries
6 * GPGME: (gpgme). Adding support for cryptography to your program.
9 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2012,
12 Permission is granted to copy, distribute and/or modify this
13 document under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 3 of the
15 License, or (at your option) any later version. The text of the
16 license can be found in the section entitled "Copying".
18 This document is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 This file documents the GPGME library.
25 This is Edition 1.4.0, last updated 26 February 2013, of `The `GnuPG
26 Made Easy' Reference Manual', for Version 1.4.0.
28 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2012,
31 Permission is granted to copy, distribute and/or modify this
32 document under the terms of the GNU General Public License as
33 published by the Free Software Foundation; either version 3 of the
34 License, or (at your option) any later version. The text of the
35 license can be found in the section entitled "Copying".
37 This document is distributed in the hope that it will be useful, but
38 WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40 General Public License for more details.
43 File: gpgme.info, Node: Top, Next: Introduction, Up: (dir)
48 This is Edition 1.4.0, last updated 26 February 2013, of `The `GnuPG
49 Made Easy' Reference Manual', for Version 1.4.0 of the GPGME library.
53 * Introduction:: How to use this manual.
54 * Preparation:: What you should do before using the library.
55 * Protocols and Engines:: Supported crypto protocols.
56 * Algorithms:: Supported algorithms.
57 * Error Handling:: Error numbers and their meanings.
58 * Exchanging Data:: Passing data to and from GPGME.
59 * Contexts:: Handling GPGME contexts.
63 * UI Server Protocol:: The GnuPG UI Server Protocol.
65 * Library Copying:: The GNU Lesser General Public License says
66 how you can copy and share `GnuPG Made Easy'.
67 * Copying:: The GNU General Public License says how you
68 can copy and share this manual.
72 * Concept Index:: Index of concepts and programs.
73 * Function and Data Index:: Index of functions, variables and data types.
76 --- The Detailed Node Listing ---
80 * Getting Started:: Purpose of the manual, and how to use it.
81 * Features:: Reasons to install and use GPGME.
82 * Overview:: Basic architecture of the GPGME library.
86 * Header:: What header file you need to include.
87 * Building the Source:: Compiler options to be used.
88 * Largefile Support (LFS):: How to use GPGME with LFS.
89 * Using Automake:: Compiler options to be used the easy way.
90 * Using Libtool:: Avoiding compiler options entirely.
91 * Library Version Check:: Getting and verifying the library version.
92 * Signal Handling:: How GPGME affects signal handling.
93 * Multi Threading:: How GPGME can be used in an MT environment.
97 * Engine Version Check:: Verifying the engine version.
98 * Engine Information:: Obtaining more information about the engines.
99 * Engine Configuration:: Changing the engine configuration.
100 * OpenPGP:: Support for the OpenPGP protocol.
101 * Cryptographic Message Syntax:: Support for the CMS.
105 * Public Key Algorithms:: A list of all public key algorithms.
106 * Hash Algorithms:: A list of all hash algorithms.
110 * Error Values:: The error value and what it means.
111 * Error Codes:: A list of important error codes.
112 * Error Sources:: A list of important error sources.
113 * Error Strings:: How to get a descriptive string from a value.
117 * Creating Data Buffers:: Creating new data buffers.
118 * Destroying Data Buffers:: Releasing data buffers.
119 * Manipulating Data Buffers:: Operations on data buffers.
121 Creating Data Buffers
123 * Memory Based Data Buffers:: Creating memory based data buffers.
124 * File Based Data Buffers:: Creating file based data buffers.
125 * Callback Based Data Buffers:: Creating callback based data buffers.
127 Manipulating Data Buffers
129 * Data Buffer I/O Operations:: I/O operations on data buffers.
130 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
134 * Creating Contexts:: Creating new GPGME contexts.
135 * Destroying Contexts:: Releasing GPGME contexts.
136 * Result Management:: Managing the result of crypto operations.
137 * Context Attributes:: Setting properties of a context.
138 * Key Management:: Managing keys with GPGME.
139 * Trust Item Management:: Managing trust items with GPGME.
140 * Crypto Operations:: Using a context for cryptography.
141 * Run Control:: Controlling how operations are run.
145 * Protocol Selection:: Selecting the protocol used by a context.
146 * Crypto Engine:: Configuring the crypto engine.
147 * ASCII Armor:: Requesting ASCII armored output.
148 * Text Mode:: Choosing canonical text mode.
149 * Included Certificates:: Including a number of certificates.
150 * Key Listing Mode:: Selecting key listing mode.
151 * Passphrase Callback:: Getting the passphrase from the user.
152 * Progress Meter Callback:: Being informed about the progress.
153 * Locale:: Setting the locale of a context.
157 * Listing Keys:: Browsing the list of available keys.
158 * Information About Keys:: Requesting detailed information about keys.
159 * Key Signatures:: Listing the signatures on a key.
160 * Manipulating Keys:: Operations on keys.
161 * Generating Keys:: Creating new key pairs.
162 * Exporting Keys:: Retrieving key data from the key ring.
163 * Importing Keys:: Adding keys to the key ring.
164 * Deleting Keys:: Removing keys from the key ring.
165 * Advanced Key Editing:: Advanced key edit operation.
167 Trust Item Management
169 * Listing Trust Items:: Browsing the list of available trust items.
170 * Information About Trust Items:: Requesting information about trust items.
171 * Manipulating Trust Items:: Operations on trust items.
175 * Decrypt:: Decrypting a ciphertext.
176 * Verify:: Verifying a signature.
177 * Decrypt and Verify:: Decrypting a signed ciphertext.
178 * Sign:: Creating a signature.
179 * Encrypt:: Encrypting a plaintext.
183 * Selecting Signers:: How to choose the keys to sign with.
184 * Creating a Signature:: How to create a signature.
185 * Signature Notation Data:: How to add notation data to a signature.
189 * Encrypting a Plaintext:: How to encrypt a plaintext.
193 * Waiting For Completion:: Waiting until an operation is completed.
194 * Using External Event Loops:: Advanced control over what happens when.
195 * Cancellation:: How to end pending operations prematurely.
197 Using External Event Loops
199 * I/O Callback Interface:: How I/O callbacks are registered.
200 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
201 * I/O Callback Example:: An example how to use I/O callbacks.
202 * I/O Callback Example GTK+:: How to integrate GPGME in GTK+.
203 * I/O Callback Example GDK:: How to integrate GPGME in GDK.
204 * I/O Callback Example Qt:: How to integrate GPGME in Qt.
207 File: gpgme.info, Node: Introduction, Next: Preparation, Prev: Top, Up: Top
212 `GnuPG Made Easy' (GPGME) is a C language library that allows to add
213 support for cryptography to a program. It is designed to make access
214 to public key crypto engines like GnuPG or GpgSM easier for
215 applications. GPGME provides a high-level crypto API for encryption,
216 decryption, signing, signature verification and key management.
218 GPGME uses GnuPG and GpgSM as its backends to support OpenPGP and
219 the Cryptographic Message Syntax (CMS).
223 * Getting Started:: Purpose of the manual, and how to use it.
224 * Features:: Reasons to install and use GPGME.
225 * Overview:: Basic architecture of the GPGME library.
228 File: gpgme.info, Node: Getting Started, Next: Features, Up: Introduction
233 This manual documents the GPGME library programming interface. All
234 functions and data types provided by the library are explained.
236 The reader is assumed to possess basic knowledge about cryptography
237 in general, and public key cryptography in particular. The underlying
238 cryptographic engines that are used by the library are not explained,
239 but where necessary, special features or requirements by an engine are
240 mentioned as far as they are relevant to GPGME or its users.
242 This manual can be used in several ways. If read from the beginning
243 to the end, it gives a good introduction into the library and how it
244 can be used in an application. Forward references are included where
245 necessary. Later on, the manual can be used as a reference manual to
246 get just the information needed about any particular interface of the
247 library. Experienced programmers might want to start looking at the
248 examples at the end of the manual, and then only read up those parts of
249 the interface which are unclear.
252 File: gpgme.info, Node: Features, Next: Overview, Prev: Getting Started, Up: Introduction
257 GPGME has a couple of advantages over other libraries doing a similar
258 job, and over implementing support for GnuPG or other crypto engines
259 into your application directly.
262 Anybody can use, modify, and redistribute it under the terms of
263 the GNU Lesser General Public License (*note Library Copying::).
266 GPGME provides transparent support for several cryptographic
267 protocols by different engines. Currently, GPGME supports the
268 OpenPGP protocol using GnuPG as the backend, and the Cryptographic
269 Message Syntax using GpgSM as the backend.
272 GPGME hides the differences between the protocols and engines from
273 the programmer behind an easy-to-use interface. This way the
274 programmer can focus on the other parts of the program, and still
275 integrate strong cryptography in his application. Once support for
276 GPGME has been added to a program, it is easy to add support for
277 other crypto protocols once GPGME backends provide them.
280 File: gpgme.info, Node: Overview, Prev: Features, Up: Introduction
285 GPGME provides a data abstraction that is used to pass data to the
286 crypto engine, and receive returned data from it. Data can be read
287 from memory or from files, but it can also be provided by a callback
290 The actual cryptographic operations are always set within a context.
291 A context provides configuration parameters that define the behaviour
292 of all operations performed within it. Only one operation per context
293 is allowed at any time, but when one operation is finished, you can run
294 the next operation in the same context. There can be more than one
295 context, and all can run different operations at the same time.
297 Furthermore, GPGME has rich key management facilities including
298 listing keys, querying their attributes, generating, importing,
299 exporting and deleting keys, and acquiring information about the trust
302 With some precautions, GPGME can be used in a multi-threaded
303 environment, although it is not completely thread safe and thus needs
304 the support of the application.
307 File: gpgme.info, Node: Preparation, Next: Protocols and Engines, Prev: Introduction, Up: Top
312 To use GPGME, you have to perform some changes to your sources and the
313 build system. The necessary changes are small and explained in the
314 following sections. At the end of this chapter, it is described how
315 the library is initialized, and how the requirements of the library are
320 * Header:: What header file you need to include.
321 * Building the Source:: Compiler options to be used.
322 * Largefile Support (LFS):: How to use GPGME with LFS.
323 * Using Automake:: Compiler options to be used the easy way.
324 * Using Libtool:: Avoiding compiler options entirely.
325 * Library Version Check:: Getting and verifying the library version.
326 * Signal Handling:: How GPGME affects signal handling.
327 * Multi Threading:: How GPGME can be used in an MT environment.
330 File: gpgme.info, Node: Header, Next: Building the Source, Up: Preparation
335 All interfaces (data types and functions) of the library are defined in
336 the header file `gpgme.h'. You must include this in all programs using
337 the library, either directly or through some other header file, like
342 The name space of GPGME is `gpgme_*' for function names and data
343 types and `GPGME_*' for other symbols. Symbols internal to GPGME take
344 the form `_gpgme_*' and `_GPGME_*'.
346 Because GPGME makes use of the GPG Error library, using GPGME will
347 also use the `GPG_ERR_*' name space directly, and the `gpg_err*' and
348 `gpg_str*' name space indirectly.
351 File: gpgme.info, Node: Building the Source, Next: Largefile Support (LFS), Prev: Header, Up: Preparation
353 2.2 Building the Source
354 =======================
356 If you want to compile a source file including the `gpgme.h' header
357 file, you must make sure that the compiler can find it in the directory
358 hierarchy. This is accomplished by adding the path to the directory in
359 which the header file is located to the compilers include file search
360 path (via the `-I' option).
362 However, the path to the include file is determined at the time the
363 source is configured. To solve this problem, gpgme ships with a small
364 helper program `gpgme-config' that knows about the path to the include
365 file and other configuration options. The options that need to be
366 added to the compiler invocation at compile time are output by the
367 `--cflags' option to `gpgme-config'. The following example shows how
368 it can be used at the command line:
370 gcc -c foo.c `gpgme-config --cflags`
372 Adding the output of `gpgme-config --cflags' to the compiler command
373 line will ensure that the compiler can find the GPGME header file.
375 A similar problem occurs when linking the program with the library.
376 Again, the compiler has to find the library files. For this to work,
377 the path to the library files has to be added to the library search
378 path (via the `-L' option). For this, the option `--libs' to
379 `gpgme-config' can be used. For convenience, this option also outputs
380 all other options that are required to link the program with GPGME (in
381 particular, the `-lgpgme' option). The example shows how to link
382 `foo.o' with the GPGME library to a program `foo'.
384 gcc -o foo foo.o `gpgme-config --libs`
386 Of course you can also combine both examples to a single command by
387 specifying both options to `gpgme-config':
389 gcc -o foo foo.c `gpgme-config --cflags --libs`
391 If you want to link to one of the thread-safe versions of GPGME, you
392 must specify the `--thread' option before any other option to select
393 the thread package you want to link with. Supported thread packages
394 are `--thread=pth' and `--thread=pthread'.
397 File: gpgme.info, Node: Largefile Support (LFS), Next: Using Automake, Prev: Building the Source, Up: Preparation
399 2.3 Largefile Support (LFS)
400 ===========================
402 GPGME is compiled with largefile support by default, if it is available
403 on the system. This means that GPGME supports files larger than two
404 gigabyte in size, if the underlying operating system can. On some
405 systems, largefile support is already the default. On such systems,
406 nothing special is required. However, some systems provide only
407 support for files up to two gigabyte in size by default. Support for
408 larger file sizes has to be specifically enabled.
410 To make a difficult situation even more complex, such systems provide
411 two different types of largefile support. You can either get all
412 relevant functions replaced with alternatives that are largefile
413 capable, or you can get new functions and data types for largefile
414 support added. Those new functions have the same name as their
415 smallfile counterparts, but with a suffix of 64.
417 An example: The data type `off_t' is 32 bit wide on GNU/Linux PC
418 systems. To address offsets in large files, you can either enable
419 largefile support add-on. Then a new data type `off64_t' is provided,
420 which is 64 bit wide. Or you can replace the existing `off_t' data
421 type with its 64 bit wide counterpart. All occurences of `off_t' are
422 then automagically replaced.
424 As if matters were not complex enough, there are also two different
425 types of file descriptors in such systems. This is important because
426 if file descriptors are exchanged between programs that use a different
427 maximum file size, certain errors must be produced on some file
428 descriptors to prevent subtle overflow bugs from occuring.
430 As you can see, supporting two different maximum file sizes at the
431 same time is not at all an easy task. However, the maximum file size
432 does matter for GPGME, because some data types it uses in its
433 interfaces are affected by that. For example, the `off_t' data type is
434 used in the `gpgme_data_seek' function, to match its POSIX counterpart.
435 This affects the call-frame of the function, and thus the ABI of the
436 library. Furthermore, file descriptors can be exchanged between GPGME
439 For you as the user of the library, this means that your program must
440 be compiled in the same file size mode as the library. Luckily, there
441 is absolutely no valid reason for new programs to not enable largefile
442 support by default and just use that. The compatibility modes (small
443 file sizes or dual mode) can be considered an historic artefact, only
444 useful to allow for a transitional period.
446 GPGME is compiled using largefile support by default. This means
447 that your application must do the same, at least as far as it is
448 relevant for using the `gpgme.h' header file. All types in this header
449 files refer to their largefile counterparts, if they are different from
450 any default types on the system.
452 You can enable largefile support, if it is different from the default
453 on the system the application is compiled on, by using the Autoconf
454 macro `AC_SYS_LARGEFILE'. If you do this, then you don't need to worry
455 about anything else: It will just work. In this case you might also
456 want to use `AC_FUNC_FSEEKO' to take advantage of some new interfaces,
457 and `AC_TYPE_OFF_T' (just in case).
459 If you do not use Autoconf, you can define the preprocessor symbol
460 `_FILE_OFFSET_BITS' to 64 _before_ including any header files, for
461 example by specifying the option `-D_FILE_OFFSET_BITS=64' on the
462 compiler command line. You will also want to define the preprocessor
463 symbol `LARGEFILE_SOURCE' to 1 in this case, to take advantage of some
466 If you do not want to do either of the above, you probably know
467 enough about the issue to invent your own solution. Just keep in mind
468 that the GPGME header file expects that largefile support is enabled,
469 if it is available. In particular, we do not support dual mode
470 (`_LARGEFILE64_SOURCE').
473 File: gpgme.info, Node: Using Automake, Next: Using Libtool, Prev: Largefile Support (LFS), Up: Preparation
478 It is much easier if you use GNU Automake instead of writing your own
479 Makefiles. If you do that you do not have to worry about finding and
480 invoking the `gpgme-config' script at all. GPGME provides an extension
481 to Automake that does all the work for you.
483 -- Macro: AM_PATH_GPGME ([MINIMUM-VERSION], [ACTION-IF-FOUND],
484 [ACTION-IF-NOT-FOUND])
485 -- Macro: AM_PATH_GPGME_PTH ([MINIMUM-VERSION], [ACTION-IF-FOUND],
486 [ACTION-IF-NOT-FOUND])
487 -- Macro: AM_PATH_GPGME_PTHREAD ([MINIMUM-VERSION], [ACTION-IF-FOUND],
488 [ACTION-IF-NOT-FOUND])
489 Check whether GPGME (at least version MINIMUM-VERSION, if given)
490 exists on the host system. If it is found, execute
491 ACTION-IF-FOUND, otherwise do ACTION-IF-NOT-FOUND, if given.
493 Additionally, the function defines `GPGME_CFLAGS' to the flags
494 needed for compilation of the program to find the `gpgme.h' header
495 file, and `GPGME_LIBS' to the linker flags needed to link the
496 program to the GPGME library.
498 `AM_PATH_GPGME_PTH' checks for the version of GPGME that can be
499 used with GNU Pth, and defines `GPGME_PTH_CFLAGS' and
502 `AM_PATH_GPGME_PTHREAD' checks for the version of GPGME that can
503 be used with the native pthread implementation, and defines
504 `GPGME_PTHREAD_CFLAGS' and `GPGME_PTHREAD_LIBS'.
506 You can use the defined Autoconf variables like this in your
509 AM_CPPFLAGS = $(GPGME_CFLAGS)
510 LDADD = $(GPGME_LIBS)
513 File: gpgme.info, Node: Using Libtool, Next: Library Version Check, Prev: Using Automake, Up: Preparation
518 The easiest way is to just use GNU Libtool. If you use libtool, and
519 link to `libgpgme.la', `libgpgme-pth.la' or `libgpgme-pthread.la'
520 respectively, everything will be done automatically by Libtool.
523 File: gpgme.info, Node: Library Version Check, Next: Signal Handling, Prev: Using Libtool, Up: Preparation
525 2.6 Library Version Check
526 =========================
528 -- Function: const char * gpgme_check_version
529 (const char *REQUIRED_VERSION)
530 The function `gpgme_check_version' has four purposes. It can be
531 used to retrieve the version number of the library. In addition it
532 can verify that the version number is higher than a certain
533 required version number. In either case, the function initializes
534 some sub-systems, and for this reason alone it must be invoked
535 early in your program, before you make use of the other functions
536 in GPGME. The last purpose is to run selftests.
538 As a side effect for W32 based systems, the socket layer will get
541 If REQUIRED_VERSION is `NULL', the function returns a pointer to a
542 statically allocated string containing the version number of the
545 If REQUIRED_VERSION is not `NULL', it should point to a string
546 containing a version number, and the function checks that the
547 version of the library is at least as high as the version number
548 provided. In this case, the function returns a pointer to a
549 statically allocated string containing the version number of the
550 library. If REQUIRED_VERSION is not a valid version number, or if
551 the version requirement is not met, the function returns `NULL'.
553 If you use a version of a library that is backwards compatible with
554 older releases, but contains additional interfaces which your
555 program uses, this function provides a run-time check if the
556 necessary features are provided by the installed version of the
559 If a selftest fails, the function may still succeed. Selftest
560 errors are returned later when invoking `gpgme_new', so that a
561 detailed error code can be returned (historically,
562 `gpgme_check_version' does not return a detailed error code).
564 -- Function: int gpgme_set_global_flag (const char *NAME,
566 On some systems it is not easy to set environment variables and
567 thus hard to use GPGME's internal trace facility for debugging.
568 This function has been introduced as an alternative way to enable
569 debugging. It is important to assure that only one thread accesses
570 GPGME functions between a call to this function and after the
571 return from the call to `gpgme_check_version'.
573 To enable debugging, you need to call this function as early as
574 possible -- even before `gpgme_check_version' -- with the string
575 "debug" for NAME and VALUE identical to the value used with the
576 environment variable `GPGME_DEBUG'.
578 This function returns `0' on success. In contrast to other
579 functions the non-zero return value on failure does not convey any
580 error code. For setting "debug" the only possible error cause is
581 an out of memory condition; which would exhibit itself later
582 anyway. Thus the return value may be ignored.
584 After initializing GPGME, you should set the locale information to
585 the locale required for your output terminal. This locale information
586 is needed for example for the curses and Gtk pinentry. Here is an
587 example of a complete initialization:
595 /* Initialize the locale environment. */
596 setlocale (LC_ALL, "");
597 gpgme_check_version (NULL);
598 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
600 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
604 Note that you are highly recommended to initialize the locale
605 settings like this. GPGME can not do this for you because it would not
606 be thread safe. The conditional on LC_MESSAGES is only necessary for
607 portability to W32 systems.
610 File: gpgme.info, Node: Signal Handling, Next: Multi Threading, Prev: Library Version Check, Up: Preparation
615 The GPGME library communicates with child processes (the crypto
616 engines). If a child process dies unexpectedly, for example due to a
617 bug, or system problem, a `SIGPIPE' signal will be delivered to the
618 application. The default action is to abort the program. To protect
619 against this, `gpgme_check_version' sets the `SIGPIPE' signal action to
620 `SIG_IGN', which means that the signal will be ignored.
622 GPGME will only do that if the signal action for `SIGPIPE' is
623 `SIG_DEF' at the time `gpgme_check_version' is called. If it is
624 something different, `GPGME' will take no action.
626 This means that if your application does not install any signal
627 handler for `SIGPIPE', you don't need to take any precautions. If you
628 do install a signal handler for `SIGPIPE', you must be prepared to
629 handle any `SIGPIPE' events that occur due to GPGME writing to a
630 defunct pipe. Furthermore, if your application is multi-threaded, and
631 you install a signal action for `SIGPIPE', you must make sure you do
632 this either before `gpgme_check_version' is called or afterwards.
635 File: gpgme.info, Node: Multi Threading, Prev: Signal Handling, Up: Preparation
640 The GPGME library is not entirely thread-safe, but it can still be used
641 in a multi-threaded environment if some care is taken. If the
642 following requirements are met, there should be no race conditions to
645 * GPGME supports the thread libraries pthread and GNU Pth. The
646 support for this has to be enabled at compile time. GPGME will
647 automatically detect the location in which the thread libraries
648 are installed and activate the support for them at build time.
650 Support for other thread libraries is very easy to add. Please
651 contact us if you have the need.
653 * If you want to use GPGME with threads, you must link to the right
654 version of the library. The name of the right library is
655 `libgpgme-' followed by the name of the thread package you use.
656 For example, if you use GNU Pth, the right name is `libgpgme-pth'.
657 Use the Automake macros or `gpgme-config' program for simplicity.
659 * The function `gpgme_check_version' must be called before any other
660 function in the library, because it initializes the thread support
661 subsystem in GPGME. To achieve this in multi-threaded programs,
662 you must synchronize the memory with respect to other threads that
663 also want to use GPGME. For this, it is sufficient to call
664 `gpgme_check_version' before creating the other threads using
667 * Any `gpgme_data_t' and `gpgme_ctx_t' object must only be accessed
668 by one thread at a time. If multiple threads want to deal with
669 the same object, the caller has to make sure that operations on
670 that object are fully synchronized.
672 * Only one thread at any time is allowed to call `gpgme_wait'. If
673 multiple threads call this function, the caller must make sure that
674 all invocations are fully synchronized. It is safe to start
675 asynchronous operations while a thread is running in gpgme_wait.
677 * The function `gpgme_strerror' is not thread safe. You have to use
678 `gpgme_strerror_r' instead.
680 ---------- Footnotes ----------
682 (1) At least this is true for POSIX threads, as `pthread_create' is
683 a function that synchronizes memory with respects to other threads.
684 There are many functions which have this property, a complete list can
685 be found in POSIX, IEEE Std 1003.1-2003, Base Definitions, Issue 6, in
686 the definition of the term "Memory Synchronization". For other thread
687 packages other, more relaxed or more strict rules may apply.
690 File: gpgme.info, Node: Protocols and Engines, Next: Algorithms, Prev: Preparation, Up: Top
692 3 Protocols and Engines
693 ***********************
695 GPGME supports several cryptographic protocols, however, it does not
696 implement them. Rather it uses backends (also called engines) which
697 implement the protocol. GPGME uses inter-process communication to pass
698 data back and forth between the application and the backend, but the
699 details of the communication protocol and invocation of the backend is
700 completely hidden by the interface. All complexity is handled by
701 GPGME. Where an exchange of information between the application and
702 the backend is necessary, GPGME provides the necessary callback function
703 hooks and further interfaces.
705 -- Data type: enum gpgme_protocol_t
706 The `gpgme_protocol_t' type specifies the set of possible protocol
707 values that are supported by GPGME. The following protocols are
710 `GPGME_PROTOCOL_OpenPGP'
711 This specifies the OpenPGP protocol.
714 This specifies the Cryptographic Message Syntax.
716 `GPGME_PROTOCOL_ASSUAN'
717 Under development. Please ask on <gnupg-devel@gnupg.org> for
721 Under development. Please ask on <gnupg-devel@gnupg.org> for
724 `GPGME_PROTOCOL_UISERVER'
725 Under development. Please ask on <gnupg-devel@gnupg.org> for
728 `GPGME_PROTOCOL_UNKNOWN'
729 Reserved for future extension. You may use this to indicate
730 that the used protocol is not known to the application.
731 Currently, GPGME does not accept this value in any operation,
732 though, except for `gpgme_get_protocol_name'.
734 -- Function: const char * gpgme_get_protocol_name
735 (gpgme_protocol_t PROTOCOL)
736 The function `gpgme_get_protocol_name' returns a statically
737 allocated string describing the protocol PROTOCOL, or `NULL' if
738 the protocol number is not valid.
742 * Engine Version Check:: Verifying the engine version.
743 * Engine Information:: Obtaining more information about the engines.
744 * Engine Configuration:: Changing the engine configuration.
745 * OpenPGP:: Support for the OpenPGP protocol.
746 * Cryptographic Message Syntax:: Support for the CMS.
749 File: gpgme.info, Node: Engine Version Check, Next: Engine Information, Up: Protocols and Engines
751 3.1 Engine Version Check
752 ========================
754 -- Function: gpgme_error_t gpgme_engine_check_version
755 (gpgme_protocol_t PROTOCOL)
756 The function `gpgme_engine_check_version' verifies that the engine
757 implementing the protocol PROTOCOL is installed in the expected
758 path and meets the version requirement of GPGME.
760 This function returns the error code `GPG_ERR_NO_ERROR' if the
761 engine is available and `GPG_ERR_INV_ENGINE' if it is not.
764 File: gpgme.info, Node: Engine Information, Next: Engine Configuration, Prev: Engine Version Check, Up: Protocols and Engines
766 3.2 Engine Information
767 ======================
769 -- Data type: gpgme_engine_info_t
770 The `gpgme_engine_info_t' type specifies a pointer to a structure
771 describing a crypto engine. The structure contains the following
774 `gpgme_engine_info_t next'
775 This is a pointer to the next engine info structure in the
776 linked list, or `NULL' if this is the last element.
778 `gpgme_protocol_t protocol'
779 This is the protocol for which the crypto engine is used.
780 You can convert this to a string with
781 `gpgme_get_protocol_name' for printing.
783 `const char *file_name'
784 This is a string holding the file name of the executable of
785 the crypto engine. Currently, it is never `NULL', but using
786 `NULL' is reserved for future use, so always check before you
789 `const char *home_dir'
790 This is a string holding the directory name of the crypto
791 engine's configuration directory. If it is `NULL', then the
792 default directory is used.
794 `const char *version'
795 This is a string containing the version number of the crypto
796 engine. It might be `NULL' if the version number can not be
797 determined, for example because the executable doesn't exist
800 `const char *req_version'
801 This is a string containing the minimum required version
802 number of the crypto engine for GPGME to work correctly.
803 This is the version number that `gpgme_engine_check_version'
804 verifies against. Currently, it is never `NULL', but using
805 `NULL' is reserved for future use, so always check before you
808 -- Function: gpgme_error_t gpgme_get_engine_info
809 (gpgme_engine_info_t *INFO)
810 The function `gpgme_get_engine_info' returns a linked list of
811 engine info structures in INFO. Each info structure describes the
812 defaults of one configured backend.
814 The memory for the info structures is allocated the first time this
815 function is invoked, and must not be freed by the caller.
817 This function returns the error code `GPG_ERR_NO_ERROR' if
818 successful, and a system error if the memory could not be
821 Here is an example how you can provide more diagnostics if you
822 receive an error message which indicates that the crypto engine is
830 if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE)
832 gpgme_engine_info_t info;
833 err = gpgme_get_engine_info (&info);
836 while (info && info->protocol != gpgme_get_protocol (ctx))
839 fprintf (stderr, "GPGME compiled without support for protocol %s",
840 gpgme_get_protocol_name (info->protocol));
841 else if (info->file_name && !info->version)
842 fprintf (stderr, "Engine %s not installed properly",
844 else if (info->file_name && info->version && info->req_version)
845 fprintf (stderr, "Engine %s version %s installed, "
846 "but at least version %s required", info->file_name,
847 info->version, info->req_version);
849 fprintf (stderr, "Unknown problem with engine for protocol %s",
850 gpgme_get_protocol_name (info->protocol));
855 File: gpgme.info, Node: Engine Configuration, Next: OpenPGP, Prev: Engine Information, Up: Protocols and Engines
857 3.3 Engine Configuration
858 ========================
860 You can change the configuration of a backend engine, and thus change
861 the executable program and configuration directory to be used. You can
862 make these changes the default or set them for some contexts
865 -- Function: gpgme_error_t gpgme_set_engine_info
866 (gpgme_protocol_t PROTO, const char *FILE_NAME,
867 const char *HOME_DIR)
868 The function `gpgme_set_engine_info' changes the default
869 configuration of the crypto engine implementing the protocol PROTO.
871 FILE_NAME is the file name of the executable program implementing
872 this protocol, and HOME_DIR is the directory name of the
873 configuration directory for this crypto engine. If HOME_DIR is
874 `NULL', the engine's default will be used.
876 The new defaults are not applied to already created GPGME contexts.
878 This function returns the error code `GPG_ERR_NO_ERROR' if
879 successful, or an eror code on failure.
881 The functions `gpgme_ctx_get_engine_info' and
882 `gpgme_ctx_set_engine_info' can be used to change the engine
883 configuration per context. *Note Crypto Engine::.
886 File: gpgme.info, Node: OpenPGP, Next: Cryptographic Message Syntax, Prev: Engine Configuration, Up: Protocols and Engines
891 OpenPGP is implemented by GnuPG, the GNU Privacy Guard. This is the
892 first protocol that was supported by GPGME.
894 The OpenPGP protocol is specified by `GPGME_PROTOCOL_OpenPGP'.
897 File: gpgme.info, Node: Cryptographic Message Syntax, Prev: OpenPGP, Up: Protocols and Engines
899 3.5 Cryptographic Message Syntax
900 ================================
902 CMS is implemented by GpgSM, the S/MIME implementation for GnuPG.
904 The CMS protocol is specified by `GPGME_PROTOCOL_CMS'.
907 File: gpgme.info, Node: Algorithms, Next: Error Handling, Prev: Protocols and Engines, Up: Top
912 The crypto backends support a variety of algorithms used in public key
913 cryptography.(1) The following sections list the identifiers used to
914 denote such an algorithm.
918 * Public Key Algorithms:: A list of all public key algorithms.
919 * Hash Algorithms:: A list of all hash algorithms.
921 ---------- Footnotes ----------
923 (1) Some engines also provide symmetric only encryption; see the
924 description of the encryption function on how to use this.
927 File: gpgme.info, Node: Public Key Algorithms, Next: Hash Algorithms, Up: Algorithms
929 4.1 Public Key Algorithms
930 =========================
932 Public key algorithms are used for encryption, decryption, signing and
933 verification of signatures.
935 -- Data type: enum gpgme_pubkey_algo_t
936 The `gpgme_pubkey_algo_t' type specifies the set of all public key
937 algorithms that are supported by GPGME. Possible values are:
940 This value indicates the RSA (Rivest, Shamir, Adleman)
944 Deprecated. This value indicates the RSA (Rivest, Shamir,
945 Adleman) algorithm for encryption and decryption only.
948 Deprecated. This value indicates the RSA (Rivest, Shamir,
949 Adleman) algorithm for signing and verification only.
952 This value indicates DSA, the Digital Signature Algorithm.
955 This value indicates ElGamal.
958 This value also indicates ElGamal and is used specifically in
962 This value also indicates ElGamal and is used specifically in
966 This value indicates ECDSA, the Elliptic Curve Digital
967 Signature Algorithm as defined by FIPS 186-2.
970 This value indicates ECDH, the Eliptic Curve Diffie-Hellmann
971 encryption algorithm as defined by the ECC in OpenPGP draft.
974 -- Function: const char * gpgme_pubkey_algo_name
975 (gpgme_pubkey_algo_t ALGO)
976 The function `gpgme_pubkey_algo_name' returns a pointer to a
977 statically allocated string containing a description of the public
978 key algorithm ALGO. This string can be used to output the name of
979 the public key algorithm to the user.
981 If ALGO is not a valid public key algorithm, `NULL' is returned.
984 File: gpgme.info, Node: Hash Algorithms, Prev: Public Key Algorithms, Up: Algorithms
989 Hash (message digest) algorithms are used to compress a long message to
990 make it suitable for public key cryptography.
992 -- Data type: enum gpgme_hash_algo_t
993 The `gpgme_hash_algo_t' type specifies the set of all hash
994 algorithms that are supported by GPGME. Possible values are:
1018 `GPGME_MD_CRC32_RFC1510'
1020 `GPGME_MD_CRC24_RFC2440'
1022 -- Function: const char * gpgme_hash_algo_name (gpgme_hash_algo_t ALGO)
1023 The function `gpgme_hash_algo_name' returns a pointer to a
1024 statically allocated string containing a description of the hash
1025 algorithm ALGO. This string can be used to output the name of the
1026 hash algorithm to the user.
1028 If ALGO is not a valid hash algorithm, `NULL' is returned.
1031 File: gpgme.info, Node: Error Handling, Next: Exchanging Data, Prev: Algorithms, Up: Top
1036 Many functions in GPGME can return an error if they fail. For this
1037 reason, the application should always catch the error condition and
1038 take appropriate measures, for example by releasing the resources and
1039 passing the error up to the caller, or by displaying a descriptive
1040 message to the user and cancelling the operation.
1042 Some error values do not indicate a system error or an error in the
1043 operation, but the result of an operation that failed properly. For
1044 example, if you try to decrypt a tempered message, the decryption will
1045 fail. Another error value actually means that the end of a data buffer
1046 or list has been reached. The following descriptions explain for many
1047 error codes what they mean usually. Some error values have specific
1048 meanings if returned by a certain functions. Such cases are described
1049 in the documentation of those functions.
1051 GPGME uses the `libgpg-error' library. This allows to share the
1052 error codes with other components of the GnuPG system, and thus pass
1053 error values transparently from the crypto engine, or some helper
1054 application of the crypto engine, to the user. This way no information
1055 is lost. As a consequence, GPGME does not use its own identifiers for
1056 error codes, but uses those provided by `libgpg-error'. They usually
1057 start with `GPG_ERR_'.
1059 However, GPGME does provide aliases for the functions defined in
1060 libgpg-error, which might be preferred for name space consistency.
1064 * Error Values:: The error value and what it means.
1065 * Error Sources:: A list of important error sources.
1066 * Error Codes:: A list of important error codes.
1067 * Error Strings:: How to get a descriptive string from a value.
1070 File: gpgme.info, Node: Error Values, Next: Error Sources, Up: Error Handling
1075 -- Data type: gpgme_err_code_t
1076 The `gpgme_err_code_t' type is an alias for the `libgpg-error'
1077 type `gpg_err_code_t'. The error code indicates the type of an
1078 error, or the reason why an operation failed.
1080 A list of important error codes can be found in the next section.
1082 -- Data type: gpgme_err_source_t
1083 The `gpgme_err_source_t' type is an alias for the `libgpg-error'
1084 type `gpg_err_source_t'. The error source has not a precisely
1085 defined meaning. Sometimes it is the place where the error
1086 happened, sometimes it is the place where an error was encoded
1087 into an error value. Usually the error source will give an
1088 indication to where to look for the problem. This is not always
1089 true, but it is attempted to achieve this goal.
1091 A list of important error sources can be found in the next section.
1093 -- Data type: gpgme_error_t
1094 The `gpgme_error_t' type is an alias for the `libgpg-error' type
1095 `gpg_error_t'. An error value like this has always two
1096 components, an error code and an error source. Both together form
1099 Thus, the error value can not be directly compared against an error
1100 code, but the accessor functions described below must be used.
1101 However, it is guaranteed that only 0 is used to indicate success
1102 (`GPG_ERR_NO_ERROR'), and that in this case all other parts of the
1103 error value are set to 0, too.
1105 Note that in GPGME, the error source is used purely for
1106 diagnostical purposes. Only the error code should be checked to
1107 test for a certain outcome of a function. The manual only
1108 documents the error code part of an error value. The error source
1109 is left unspecified and might be anything.
1111 -- Function: static inline gpgme_err_code_t gpgme_err_code
1113 The static inline function `gpgme_err_code' returns the
1114 `gpgme_err_code_t' component of the error value ERR. This
1115 function must be used to extract the error code from an error
1116 value in order to compare it with the `GPG_ERR_*' error code
1119 -- Function: static inline gpgme_err_source_t gpgme_err_source
1121 The static inline function `gpgme_err_source' returns the
1122 `gpgme_err_source_t' component of the error value ERR. This
1123 function must be used to extract the error source from an error
1124 value in order to compare it with the `GPG_ERR_SOURCE_*' error
1127 -- Function: static inline gpgme_error_t gpgme_err_make
1128 (gpgme_err_source_t SOURCE, gpgme_err_code_t CODE)
1129 The static inline function `gpgme_err_make' returns the error
1130 value consisting of the error source SOURCE and the error code
1133 This function can be used in callback functions to construct an
1134 error value to return it to the library.
1136 -- Function: static inline gpgme_error_t gpgme_error
1137 (gpgme_err_code_t CODE)
1138 The static inline function `gpgme_error' returns the error value
1139 consisting of the default error source and the error code CODE.
1141 For GPGME applications, the default error source is
1142 `GPG_ERR_SOURCE_USER_1'. You can define
1143 `GPGME_ERR_SOURCE_DEFAULT' before including `gpgme.h' to change
1146 This function can be used in callback functions to construct an
1147 error value to return it to the library.
1149 The `libgpg-error' library provides error codes for all system error
1150 numbers it knows about. If ERR is an unknown error number, the error
1151 code `GPG_ERR_UNKNOWN_ERRNO' is used. The following functions can be
1152 used to construct error values from system errnor numbers.
1154 -- Function: gpgme_error_t gpgme_err_make_from_errno
1155 (gpgme_err_source_t SOURCE, int ERR)
1156 The function `gpgme_err_make_from_errno' is like `gpgme_err_make',
1157 but it takes a system error like `errno' instead of a
1158 `gpgme_err_code_t' error code.
1160 -- Function: gpgme_error_t gpgme_error_from_errno (int ERR)
1161 The function `gpgme_error_from_errno' is like `gpgme_error', but
1162 it takes a system error like `errno' instead of a
1163 `gpgme_err_code_t' error code.
1165 Sometimes you might want to map system error numbers to error codes
1166 directly, or map an error code representing a system error back to the
1167 system error number. The following functions can be used to do that.
1169 -- Function: gpgme_err_code_t gpgme_err_code_from_errno (int ERR)
1170 The function `gpgme_err_code_from_errno' returns the error code
1171 for the system error ERR. If ERR is not a known system error, the
1172 function returns `GPG_ERR_UNKNOWN_ERRNO'.
1174 -- Function: int gpgme_err_code_to_errno (gpgme_err_code_t ERR)
1175 The function `gpgme_err_code_to_errno' returns the system error
1176 for the error code ERR. If ERR is not an error code representing
1177 a system error, or if this system error is not defined on this
1178 system, the function returns `0'.
1181 File: gpgme.info, Node: Error Sources, Next: Error Codes, Prev: Error Values, Up: Error Handling
1186 The library `libgpg-error' defines an error source for every component
1187 of the GnuPG system. The error source part of an error value is not
1188 well defined. As such it is mainly useful to improve the diagnostic
1189 error message for the user.
1191 If the error code part of an error value is `0', the whole error
1192 value will be `0'. In this case the error source part is of course
1193 `GPG_ERR_SOURCE_UNKNOWN'.
1195 The list of error sources that might occur in applications using
1198 `GPG_ERR_SOURCE_UNKNOWN'
1199 The error source is not known. The value of this error source is
1202 `GPG_ERR_SOURCE_GPGME'
1203 The error source is GPGME itself. This is the default for errors
1204 that occur in the GPGME library.
1206 `GPG_ERR_SOURCE_GPG'
1207 The error source is GnuPG, which is the crypto engine used for the
1210 `GPG_ERR_SOURCE_GPGSM'
1211 The error source is GPGSM, which is the crypto engine used for the
1214 `GPG_ERR_SOURCE_GCRYPT'
1215 The error source is `libgcrypt', which is used by crypto engines
1216 to perform cryptographic operations.
1218 `GPG_ERR_SOURCE_GPGAGENT'
1219 The error source is `gpg-agent', which is used by crypto engines
1220 to perform operations with the secret key.
1222 `GPG_ERR_SOURCE_PINENTRY'
1223 The error source is `pinentry', which is used by `gpg-agent' to
1224 query the passphrase to unlock a secret key.
1226 `GPG_ERR_SOURCE_SCD'
1227 The error source is the SmartCard Daemon, which is used by
1228 `gpg-agent' to delegate operations with the secret key to a
1231 `GPG_ERR_SOURCE_KEYBOX'
1232 The error source is `libkbx', a library used by the crypto engines
1233 to manage local keyrings.
1235 `GPG_ERR_SOURCE_USER_1'
1237 `GPG_ERR_SOURCE_USER_2'
1239 `GPG_ERR_SOURCE_USER_3'
1241 `GPG_ERR_SOURCE_USER_4'
1242 These error sources are not used by any GnuPG component and can be
1243 used by other software. For example, applications using GPGME can
1244 use them to mark error values coming from callback handlers. Thus
1245 `GPG_ERR_SOURCE_USER_1' is the default for errors created with
1246 `gpgme_error' and `gpgme_error_from_errno', unless you define
1247 `GPGME_ERR_SOURCE_DEFAULT' before including `gpgme.h'.
1250 File: gpgme.info, Node: Error Codes, Next: Error Strings, Prev: Error Sources, Up: Error Handling
1255 The library `libgpg-error' defines many error values. Most of them are
1256 not used by `GPGME' directly, but might be returned by GPGME because it
1257 received them from the crypto engine. The below list only includes
1258 such error codes that have a specific meaning in `GPGME', or which are
1259 so common that you should know about them.
1262 This value indicates the end of a list, buffer or file.
1265 This value indicates success. The value of this error code is
1266 `0'. Also, it is guaranteed that an error value made from the
1267 error code `0' will be `0' itself (as a whole). This means that
1268 the error source information is lost for this error code, however,
1269 as this error code indicates that no error occured, this is
1270 generally not a problem.
1273 This value means that something went wrong, but either there is not
1274 enough information about the problem to return a more useful error
1275 value, or there is no separate error value for this type of
1279 This value means that an out-of-memory condition occurred.
1282 System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
1286 This value means that some user provided data was out of range.
1287 This can also refer to objects. For example, if an empty
1288 `gpgme_data_t' object was expected, but one containing data was
1289 provided, this error value is returned.
1291 `GPG_ERR_UNUSABLE_PUBKEY'
1292 This value means that some recipients for a message were invalid.
1294 `GPG_ERR_UNUSABLE_SECKEY'
1295 This value means that some signers were invalid.
1298 This value means that a `gpgme_data_t' object which was expected
1299 to have content was found empty.
1302 This value means that a conflict of some sort occurred.
1304 `GPG_ERR_NOT_IMPLEMENTED'
1305 This value indicates that the specific function (or operation) is
1306 not implemented. This error should never happen. It can only
1307 occur if you use certain values or configuration options which do
1308 not work, but for which we think that they should work at some
1311 `GPG_ERR_DECRYPT_FAILED'
1312 This value indicates that a decryption operation was unsuccessful.
1314 `GPG_ERR_BAD_PASSPHRASE'
1315 This value means that the user did not provide a correct passphrase
1319 This value means that the operation was canceled.
1321 `GPG_ERR_INV_ENGINE'
1322 This value means that the engine that implements the desired
1323 protocol is currently not available. This can either be because
1324 the sources were configured to exclude support for this engine, or
1325 because the engine is not installed properly.
1327 `GPG_ERR_AMBIGUOUS_NAME'
1328 This value indicates that a user ID or other specifier did not
1329 specify a unique key.
1331 `GPG_ERR_WRONG_KEY_USAGE'
1332 This value indicates that a key is not used appropriately.
1334 `GPG_ERR_CERT_REVOKED'
1335 This value indicates that a key signature was revoced.
1337 `GPG_ERR_CERT_EXPIRED'
1338 This value indicates that a key signature expired.
1340 `GPG_ERR_NO_CRL_KNOWN'
1341 This value indicates that no certificate revocation list is known
1342 for the certificate.
1344 `GPG_ERR_NO_POLICY_MATCH'
1345 This value indicates that a policy issue occured.
1348 This value indicates that no secret key for the user ID is
1351 `GPG_ERR_MISSING_CERT'
1352 This value indicates that a key could not be imported because the
1353 issuer certificate is missing.
1355 `GPG_ERR_BAD_CERT_CHAIN'
1356 This value indicates that a key could not be imported because its
1357 certificate chain is not good, for example it could be too long.
1359 `GPG_ERR_UNSUPPORTED_ALGORITHM'
1360 This value means a verification failed because the cryptographic
1361 algorithm is not supported by the crypto backend.
1363 `GPG_ERR_BAD_SIGNATURE'
1364 This value means a verification failed because the signature is
1368 This value means a verification failed because the public key is
1378 These error codes are not used by any GnuPG component and can be
1379 freely used by other software. Applications using GPGME might use
1380 them to mark specific errors returned by callback handlers if no
1381 suitable error codes (including the system errors) for these
1382 errors exist already.
1385 File: gpgme.info, Node: Error Strings, Prev: Error Codes, Up: Error Handling
1390 -- Function: const char * gpgme_strerror (gpgme_error_t ERR)
1391 The function `gpgme_strerror' returns a pointer to a statically
1392 allocated string containing a description of the error code
1393 contained in the error value ERR. This string can be used to
1394 output a diagnostic message to the user.
1396 This function is not thread safe. Use `gpgme_strerror_r' in
1397 multi-threaded programs.
1399 -- Function: int gpgme_strerror_r (gpgme_error_t ERR, char *BUF,
1401 The function `gpgme_strerror_r' returns the error string for ERR
1402 in the user-supplied buffer BUF of size BUFLEN. This function is,
1403 in contrast to `gpgme_strerror', thread-safe if a thread-safe
1404 `strerror_r' function is provided by the system. If the function
1405 succeeds, 0 is returned and BUF contains the string describing the
1406 error. If the buffer was not large enough, ERANGE is returned and
1407 BUF contains as much of the beginning of the error string as fits
1410 -- Function: const char * gpgme_strsource (gpgme_error_t ERR)
1411 The function `gpgme_strerror' returns a pointer to a statically
1412 allocated string containing a description of the error source
1413 contained in the error value ERR. This string can be used to
1414 output a diagnostic message to the user.
1416 The following example illustrates the use of `gpgme_strerror':
1419 gpgme_error_t err = gpgme_new (&ctx);
1422 fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n",
1423 argv[0], gpgme_strsource (err), gpgme_strerror (err));
1428 File: gpgme.info, Node: Exchanging Data, Next: Contexts, Prev: Error Handling, Up: Top
1433 A lot of data has to be exchanged between the user and the crypto
1434 engine, like plaintext messages, ciphertext, signatures and information
1435 about the keys. The technical details about exchanging the data
1436 information are completely abstracted by GPGME. The user provides and
1437 receives the data via `gpgme_data_t' objects, regardless of the
1438 communication protocol between GPGME and the crypto engine in use.
1440 -- Data type: gpgme_data_t
1441 The `gpgme_data_t' type is a handle for a container for generic
1442 data, which is used by GPGME to exchange data with the user.
1444 `gpgme_data_t' objects do not provide notifications on events. It
1445 is assumed that read and write operations are blocking until data is
1446 available. If this is undesirable, the application must ensure that
1447 all GPGME data operations always have data available, for example by
1448 using memory buffers or files rather than pipes or sockets. This might
1449 be relevant, for example, if the external event loop mechanism is used.
1453 * Creating Data Buffers:: Creating new data buffers.
1454 * Destroying Data Buffers:: Releasing data buffers.
1455 * Manipulating Data Buffers:: Operations on data buffers.
1458 File: gpgme.info, Node: Creating Data Buffers, Next: Destroying Data Buffers, Up: Exchanging Data
1460 6.1 Creating Data Buffers
1461 =========================
1463 Data objects can be based on memory, files, or callback functions
1464 provided by the user. Not all operations are supported by all objects.
1468 * Memory Based Data Buffers:: Creating memory based data buffers.
1469 * File Based Data Buffers:: Creating file based data buffers.
1470 * Callback Based Data Buffers:: Creating callback based data buffers.
1473 File: gpgme.info, Node: Memory Based Data Buffers, Next: File Based Data Buffers, Up: Creating Data Buffers
1475 6.1.1 Memory Based Data Buffers
1476 -------------------------------
1478 Memory based data objects store all data in allocated memory. This is
1479 convenient, but only practical for an amount of data that is a fraction
1480 of the available physical memory. The data has to be copied from its
1481 source and to its destination, which can often be avoided by using one
1482 of the other data object
1484 -- Function: gpgme_error_t gpgme_data_new (gpgme_data_t *DH)
1485 The function `gpgme_data_new' creates a new `gpgme_data_t' object
1486 and returns a handle for it in DH. The data object is memory
1487 based and initially empty.
1489 The function returns the error code `GPG_ERR_NO_ERROR' if the data
1490 object was successfully created, `GPG_ERR_INV_VALUE' if DH is not
1491 a valid pointer, and `GPG_ERR_ENOMEM' if not enough memory is
1494 -- Function: gpgme_error_t gpgme_data_new_from_mem (gpgme_data_t *DH,
1495 const char *BUFFER, size_t SIZE, int COPY)
1496 The function `gpgme_data_new_from_mem' creates a new
1497 `gpgme_data_t' object and fills it with SIZE bytes starting from
1500 If COPY is not zero, a private copy of the data is made. If COPY
1501 is zero, the data is taken from the specified buffer as needed,
1502 and the user has to ensure that the buffer remains valid for the
1503 whole life span of the data object.
1505 The function returns the error code `GPG_ERR_NO_ERROR' if the data
1506 object was successfully created, `GPG_ERR_INV_VALUE' if DH or
1507 BUFFER is not a valid pointer, and `GPG_ERR_ENOMEM' if not enough
1508 memory is available.
1510 -- Function: gpgme_error_t gpgme_data_new_from_file (gpgme_data_t *DH,
1511 const char *FILENAME, int COPY)
1512 The function `gpgme_data_new_from_file' creates a new
1513 `gpgme_data_t' object and fills it with the content of the file
1516 If COPY is not zero, the whole file is read in at initialization
1517 time and the file is not used anymore after that. This is the only
1518 mode supported currently. Later, a value of zero for COPY might
1519 cause all reads to be delayed until the data is needed, but this is
1520 not yet implemented.
1522 The function returns the error code `GPG_ERR_NO_ERROR' if the data
1523 object was successfully created, `GPG_ERR_INV_VALUE' if DH or
1524 FILENAME is not a valid pointer, `GPG_ERR_NOT_IMPLEMENTED' if CODE
1525 is zero, and `GPG_ERR_ENOMEM' if not enough memory is available.
1527 -- Function: gpgme_error_t gpgme_data_new_from_filepart
1528 (gpgme_data_t *DH, const char *FILENAME, FILE *FP,
1529 off_t OFFSET, size_t LENGTH)
1530 The function `gpgme_data_new_from_filepart' creates a new
1531 `gpgme_data_t' object and fills it with a part of the file
1532 specified by FILENAME or FP.
1534 Exactly one of FILENAME and FP must be non-zero, the other must be
1535 zero. The argument that is not zero specifies the file from which
1536 LENGTH bytes are read into the data object, starting from OFFSET.
1538 The function returns the error code `GPG_ERR_NO_ERROR' if the data
1539 object was successfully created, `GPG_ERR_INV_VALUE' if DH and
1540 exactly one of FILENAME and FP is not a valid pointer, and
1541 `GPG_ERR_ENOMEM' if not enough memory is available.
1544 File: gpgme.info, Node: File Based Data Buffers, Next: Callback Based Data Buffers, Prev: Memory Based Data Buffers, Up: Creating Data Buffers
1546 6.1.2 File Based Data Buffers
1547 -----------------------------
1549 File based data objects operate directly on file descriptors or
1550 streams. Only a small amount of data is stored in core at any time, so
1551 the size of the data objects is not limited by GPGME.
1553 -- Function: gpgme_error_t gpgme_data_new_from_fd (gpgme_data_t *DH,
1555 The function `gpgme_data_new_from_fd' creates a new `gpgme_data_t'
1556 object and uses the file descriptor FD to read from (if used as an
1557 input data object) and write to (if used as an output data object).
1559 When using the data object as an input buffer, the function might
1560 read a bit more from the file descriptor than is actually needed
1561 by the crypto engine in the desired operation because of internal
1564 Note that GPGME assumes that the file descriptor is set to blocking
1565 mode. Errors during I/O operations, except for EINTR, are usually
1566 fatal for crypto operations.
1568 The function returns the error code `GPG_ERR_NO_ERROR' if the data
1569 object was successfully created, and `GPG_ERR_ENOMEM' if not
1570 enough memory is available.
1572 -- Function: gpgme_error_t gpgme_data_new_from_stream
1573 (gpgme_data_t *DH, FILE *STREAM)
1574 The function `gpgme_data_new_from_stream' creates a new
1575 `gpgme_data_t' object and uses the I/O stream STREAM to read from
1576 (if used as an input data object) and write to (if used as an
1577 output data object).
1579 When using the data object as an input buffer, the function might
1580 read a bit more from the stream than is actually needed by the
1581 crypto engine in the desired operation because of internal
1584 Note that GPGME assumes that the stream is in blocking mode.
1585 Errors during I/O operations, except for EINTR, are usually fatal
1586 for crypto operations.
1588 The function returns the error code `GPG_ERR_NO_ERROR' if the data
1589 object was successfully created, and `GPG_ERR_ENOMEM' if not
1590 enough memory is available.
1593 File: gpgme.info, Node: Callback Based Data Buffers, Prev: File Based Data Buffers, Up: Creating Data Buffers
1595 6.1.3 Callback Based Data Buffers
1596 ---------------------------------
1598 If neither memory nor file based data objects are a good fit for your
1599 application, you can implement the functions a data object provides
1600 yourself and create a data object from these callback functions.
1602 -- Data type: ssize_t (*gpgme_data_read_cb_t) (void *HANDLE,
1603 void *BUFFER, size_t SIZE)
1604 The `gpgme_data_read_cb_t' type is the type of functions which
1605 GPGME calls if it wants to read data from a user-implemented data
1606 object. The function should read up to SIZE bytes from the
1607 current read position into the space starting at BUFFER. The
1608 HANDLE is provided by the user at data object creation time.
1610 Note that GPGME assumes that the read blocks until data is
1611 available. Errors during I/O operations, except for EINTR, are
1612 usually fatal for crypto operations.
1614 The function should return the number of bytes read, 0 on EOF, and
1615 -1 on error. If an error occurs, ERRNO should be set to describe
1616 the type of the error.
1618 -- Data type: ssize_t (*gpgme_data_write_cb_t) (void *HANDLE,
1619 const void *BUFFER, size_t SIZE)
1620 The `gpgme_data_write_cb_t' type is the type of functions which
1621 GPGME calls if it wants to write data to a user-implemented data
1622 object. The function should write up to SIZE bytes to the current
1623 write position from the space starting at BUFFER. The HANDLE is
1624 provided by the user at data object creation time.
1626 Note that GPGME assumes that the write blocks until data is
1627 available. Errors during I/O operations, except for EINTR, are
1628 usually fatal for crypto operations.
1630 The function should return the number of bytes written, and -1 on
1631 error. If an error occurs, ERRNO should be set to describe the
1634 -- Data type: off_t (*gpgme_data_seek_cb_t) (void *HANDLE,
1635 off_t OFFSET, int WHENCE)
1636 The `gpgme_data_seek_cb_t' type is the type of functions which
1637 GPGME calls if it wants to change the current read/write position
1638 in a user-implemented data object, just like the `lseek' function.
1640 The function should return the new read/write position, and -1 on
1641 error. If an error occurs, ERRNO should be set to describe the
1644 -- Data type: void (*gpgme_data_release_cb_t) (void *HANDLE)
1645 The `gpgme_data_release_cb_t' type is the type of functions which
1646 GPGME calls if it wants to destroy a user-implemented data object.
1647 The HANDLE is provided by the user at data object creation time.
1649 -- Data type: struct gpgme_data_cbs
1650 This structure is used to store the data callback interface
1651 functions described above. It has the following members:
1653 `gpgme_data_read_cb_t read'
1654 This is the function called by GPGME to read data from the
1655 data object. It is only required for input data object.
1657 `gpgme_data_write_cb_t write'
1658 This is the function called by GPGME to write data to the
1659 data object. It is only required for output data object.
1661 `gpgme_data_seek_cb_t seek'
1662 This is the function called by GPGME to change the current
1663 read/write pointer in the data object (if available). It is
1666 `gpgme_data_release_cb_t release'
1667 This is the function called by GPGME to release a data
1668 object. It is optional.
1670 -- Function: gpgme_error_t gpgme_data_new_from_cbs (gpgme_data_t *DH,
1671 gpgme_data_cbs_t CBS, void *HANDLE)
1672 The function `gpgme_data_new_from_cbs' creates a new
1673 `gpgme_data_t' object and uses the user-provided callback functions
1674 to operate on the data object.
1676 The handle HANDLE is passed as first argument to the callback
1677 functions. This can be used to identify this data object.
1679 The function returns the error code `GPG_ERR_NO_ERROR' if the data
1680 object was successfully created, and `GPG_ERR_ENOMEM' if not
1681 enough memory is available.
1683 The following interface is deprecated and only provided for backward
1684 compatibility. Don't use it. It will be removed in a future version
1687 -- Function: gpgme_error_t gpgme_data_new_with_read_cb
1688 (gpgme_data_t *DH, int (*READFUNC) (void *HOOK, char *BUFFER,
1689 size_t COUNT, size_t *NREAD), void *HOOK_VALUE)
1690 The function `gpgme_data_new_with_read_cb' creates a new
1691 `gpgme_data_t' object and uses the callback function READFUNC to
1692 retrieve the data on demand. As the callback function can supply
1693 the data in any way it wants, this is the most flexible data type
1694 GPGME provides. However, it can not be used to write data.
1696 The callback function receives HOOK_VALUE as its first argument
1697 whenever it is invoked. It should return up to COUNT bytes in
1698 BUFFER, and return the number of bytes actually read in NREAD. It
1699 may return `0' in NREAD if no data is currently available. To
1700 indicate `EOF' the function should return with an error code of
1701 `-1' and set NREAD to `0'. The callback function may support to
1702 reset its internal read pointer if it is invoked with BUFFER and
1703 NREAD being `NULL' and COUNT being `0'.
1705 The function returns the error code `GPG_ERR_NO_ERROR' if the data
1706 object was successfully created, `GPG_ERR_INV_VALUE' if DH or
1707 READFUNC is not a valid pointer, and `GPG_ERR_ENOMEM' if not
1708 enough memory is available.
1711 File: gpgme.info, Node: Destroying Data Buffers, Next: Manipulating Data Buffers, Prev: Creating Data Buffers, Up: Exchanging Data
1713 6.2 Destroying Data Buffers
1714 ===========================
1716 -- Function: void gpgme_data_release (gpgme_data_t DH)
1717 The function `gpgme_data_release' destroys the data object with
1718 the handle DH. It releases all associated resources that were not
1719 provided by the user in the first place.
1721 -- Function: char * gpgme_data_release_and_get_mem (gpgme_data_t DH,
1723 The function `gpgme_data_release_and_get_mem' is like
1724 `gpgme_data_release', except that it returns the data buffer and
1725 its length that was provided by the object.
1727 The user has to release the buffer with `gpgme_free'. In case the
1728 user provided the data buffer in non-copy mode, a copy will be
1729 made for this purpose.
1731 In case an error returns, or there is no suitable data buffer that
1732 can be returned to the user, the function will return `NULL'. In
1733 any case, the data object DH is destroyed.
1735 -- Function: void gpgme_free (void *BUFFER)
1736 The function `gpgme_free' releases the memory returned by
1737 `gpgme_data_release_and_get_mem'. It should be used instead of
1738 the system libraries `free' function in case different allocators
1739 are used in a single program.
1742 File: gpgme.info, Node: Manipulating Data Buffers, Prev: Destroying Data Buffers, Up: Exchanging Data
1744 6.3 Manipulating Data Buffers
1745 =============================
1747 Data buffers contain data and meta-data. The following operations can
1748 be used to manipulate both.
1752 * Data Buffer I/O Operations:: I/O operations on data buffers.
1753 * Data Buffer Meta-Data:: Meta-data manipulation of data buffers.
1756 File: gpgme.info, Node: Data Buffer I/O Operations, Next: Data Buffer Meta-Data, Up: Manipulating Data Buffers
1758 6.3.1 Data Buffer I/O Operations
1759 --------------------------------
1761 -- Function: ssize_t gpgme_data_read (gpgme_data_t DH, void *BUFFER,
1763 The function `gpgme_data_read' reads up to LENGTH bytes from the
1764 data object with the handle DH into the space starting at BUFFER.
1766 If no error occurs, the actual amount read is returned. If the
1767 end of the data object is reached, the function returns 0.
1769 In all other cases, the function returns -1 and sets ERRNO.
1771 -- Function: ssize_t gpgme_data_write (gpgme_data_t DH,
1772 const void *BUFFER, size_t SIZE)
1773 The function `gpgme_data_write' writes up to SIZE bytes starting
1774 from BUFFER into the data object with the handle DH at the current
1777 The function returns the number of bytes actually written, or -1
1778 if an error occurs. If an error occurs, ERRNO is set.
1780 -- Function: off_t gpgme_data_seek (gpgme_data_t DH, off_t OFFSET,
1782 The function `gpgme_data_seek' changes the current read/write
1785 The WHENCE argument specifies how the OFFSET should be
1786 interpreted. It must be one of the following symbolic constants:
1789 Specifies that OFFSET is a count of characters from the
1790 beginning of the data object.
1793 Specifies that OFFSET is a count of characters from the
1794 current file position. This count may be positive or
1798 Specifies that OFFSET is a count of characters from the end of
1799 the data object. A negative count specifies a position
1800 within the current extent of the data object; a positive
1801 count specifies a position past the current end. If you set
1802 the position past the current end, and actually write data,
1803 you will extend the data object with zeros up to that
1806 If successful, the function returns the resulting file position,
1807 measured in bytes from the beginning of the data object. You can
1808 use this feature together with `SEEK_CUR' to read the current
1809 read/write position.
1811 If the function fails, -1 is returned and ERRNO is set.
1813 The following function is deprecated and should not be used. It will
1814 be removed in a future version of GPGME.
1816 -- Function: gpgme_error_t gpgme_data_rewind (gpgme_data_t DH)
1817 The function `gpgme_data_rewind' is equivalent to:
1819 return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
1820 ? gpgme_error_from_errno (errno) : 0;
1823 File: gpgme.info, Node: Data Buffer Meta-Data, Prev: Data Buffer I/O Operations, Up: Manipulating Data Buffers
1825 6.3.2 Data Buffer Meta-Data
1826 ---------------------------
1828 -- Function: char * gpgme_data_get_file_name (gpgme_data_t DH)
1829 The function `gpgme_data_get_file_name' returns a pointer to a
1830 string containing the file name associated with the data object.
1831 The file name will be stored in the output when encrypting or
1832 signing the data and will be returned to the user when decrypting
1833 or verifying the output data.
1835 If no error occurs, the string containing the file name is
1836 returned. Otherwise, `NULL' will be returned.
1838 -- Function: gpgme_error_t gpgme_data_set_file_name (gpgme_data_t DH,
1839 const char *FILE_NAME)
1840 The function `gpgme_data_set_file_name' sets the file name
1841 associated with the data object. The file name will be stored in
1842 the output when encrypting or signing the data and will be
1843 returned to the user when decrypting or verifying the output data.
1845 The function returns the error code `GPG_ERR_INV_VALUE' if DH is
1846 not a valid pointer and `GPG_ERR_ENOMEM' if not enough memory is
1849 -- Data type: enum gpgme_data_encoding_t
1850 The `gpgme_data_encoding_t' type specifies the encoding of a
1851 `gpgme_data_t' object. For input data objects, the encoding is
1852 useful to give the backend a hint on the type of data. For output
1853 data objects, the encoding can specify the output data format on
1854 certain operations. Please note that not all backends support all
1855 encodings on all operations. The following data types are
1858 `GPGME_DATA_ENCODING_NONE'
1859 This specifies that the encoding is not known. This is the
1860 default for a new data object. The backend will try its best
1861 to detect the encoding automatically.
1863 `GPGME_DATA_ENCODING_BINARY'
1864 This specifies that the data is encoding in binary form; i.e.
1865 there is no special encoding.
1867 `GPGME_DATA_ENCODING_BASE64'
1868 This specifies that the data is encoded using the Base-64
1869 encoding scheme as used by MIME and other protocols.
1871 `GPGME_DATA_ENCODING_ARMOR'
1872 This specifies that the data is encoded in an armored form as
1873 used by OpenPGP and PEM.
1875 `GPGME_DATA_ENCODING_URL'
1876 The data is a list of linefeed delimited URLs. This is only
1877 useful with `gpgme_op_import'.
1879 `GPGME_DATA_ENCODING_URL0'
1880 The data is a list of binary zero delimited URLs. This is
1881 only useful with `gpgme_op_import'.
1883 `GPGME_DATA_ENCODING_URLESC'
1884 The data is a list of linefeed delimited URLs with all
1885 control and space characters percent escaped. This mode is
1886 is not yet implemented.
1889 -- Function: gpgme_data_encoding_t gpgme_data_get_encoding
1891 The function `gpgme_data_get_encoding' returns the encoding of the
1892 data object with the handle DH. If DH is not a valid pointer
1893 (e.g. `NULL') `GPGME_DATA_ENCODING_NONE' is returned.
1895 -- Function: gpgme_error_t gpgme_data_set_encoding
1896 (gpgme_data_t DH, gpgme_data_encoding_t ENC)
1897 The function `gpgme_data_set_encoding' changes the encoding of the
1898 data object with the handle DH to ENC.
1901 File: gpgme.info, Node: Contexts, Next: UI Server Protocol, Prev: Exchanging Data, Up: Top
1906 All cryptographic operations in GPGME are performed within a context,
1907 which contains the internal state of the operation as well as
1908 configuration parameters. By using several contexts you can run
1909 several cryptographic operations in parallel, with different
1912 -- Data type: gpgme_ctx_t
1913 The `gpgme_ctx_t' type is a handle for a GPGME context, which is
1914 used to hold the configuration, status and result of cryptographic
1919 * Creating Contexts:: Creating new GPGME contexts.
1920 * Destroying Contexts:: Releasing GPGME contexts.
1921 * Result Management:: Managing the result of crypto operations.
1922 * Context Attributes:: Setting properties of a context.
1923 * Key Management:: Managing keys with GPGME.
1924 * Trust Item Management:: Managing trust items with GPGME.
1925 * Crypto Operations:: Using a context for cryptography.
1926 * Run Control:: Controlling how operations are run.
1929 File: gpgme.info, Node: Creating Contexts, Next: Destroying Contexts, Up: Contexts
1931 7.1 Creating Contexts
1932 =====================
1934 -- Function: gpgme_error_t gpgme_new (gpgme_ctx_t *CTX)
1935 The function `gpgme_new' creates a new `gpgme_ctx_t' object and
1936 returns a handle for it in CTX.
1938 The function returns the error code `GPG_ERR_NO_ERROR' if the
1939 context was successfully created, `GPG_ERR_INV_VALUE' if CTX is
1940 not a valid pointer, and `GPG_ERR_ENOMEM' if not enough memory is
1941 available. Also, it returns `GPG_ERR_NOT_OPERATIONAL' if
1942 `gpgme_check_version' was not called to initialize GPGME, and
1943 `GPG_ERR_SELFTEST_FAILED' if a selftest failed. Currently, the
1944 only selftest is for Windows MingW32 targets to see if
1945 `-mms-bitfields' was used (as required).
1948 File: gpgme.info, Node: Destroying Contexts, Next: Result Management, Prev: Creating Contexts, Up: Contexts
1950 7.2 Destroying Contexts
1951 =======================
1953 -- Function: void gpgme_release (gpgme_ctx_t CTX)
1954 The function `gpgme_release' destroys the context with the handle
1955 CTX and releases all associated resources.
1958 File: gpgme.info, Node: Result Management, Next: Context Attributes, Prev: Destroying Contexts, Up: Contexts
1960 7.3 Result Management
1961 =====================
1963 The detailed result of an operation is returned in operation-specific
1964 structures such as `gpgme_decrypt_result_t'. The corresponding
1965 retrieval functions such as `gpgme_op_decrypt_result' provide static
1966 access to the results after an operation completes. The following
1967 interfaces make it possible to detach a result structure from its
1968 associated context and give it a lifetime beyond that of the current
1969 operation or context.
1971 -- Function: void gpgme_result_ref (void *RESULT)
1972 The function `gpgme_result_ref' acquires an additional reference
1973 for the result RESULT, which may be of any type
1974 `gpgme_*_result_t'. As long as the user holds a reference, the
1975 result structure is guaranteed to be valid and unmodified.
1977 -- Function: void gpgme_result_unref (void *RESULT)
1978 The function `gpgme_result_unref' releases a reference for the
1979 result RESULT. If this was the last reference, the result
1980 structure will be destroyed and all resources associated to it
1983 Note that a context may hold its own references to result structures,
1984 typically until the context is destroyed or the next operation is
1985 started. In fact, these references are accessed through the
1986 `gpgme_op_*_result' functions.
1989 File: gpgme.info, Node: Context Attributes, Next: Key Management, Prev: Result Management, Up: Contexts
1991 7.4 Context Attributes
1992 ======================
1996 * Protocol Selection:: Selecting the protocol used by a context.
1997 * Crypto Engine:: Configuring the crypto engine.
1998 * ASCII Armor:: Requesting ASCII armored output.
1999 * Text Mode:: Choosing canonical text mode.
2000 * Included Certificates:: Including a number of certificates.
2001 * Key Listing Mode:: Selecting key listing mode.
2002 * Passphrase Callback:: Getting the passphrase from the user.
2003 * Progress Meter Callback:: Being informed about the progress.
2004 * Locale:: Setting the locale of a context.
2007 File: gpgme.info, Node: Protocol Selection, Next: Crypto Engine, Up: Context Attributes
2009 7.4.1 Protocol Selection
2010 ------------------------
2012 -- Function: gpgme_error_t gpgme_set_protocol (gpgme_ctx_t CTX,
2013 gpgme_protocol_t PROTO)
2014 The function `gpgme_set_protocol' sets the protocol used within
2015 the context CTX to PROTO. All crypto operations will be performed
2016 by the crypto engine configured for that protocol. *Note
2017 Protocols and Engines::.
2019 Setting the protocol with `gpgme_set_protocol' does not check if
2020 the crypto engine for that protocol is available and installed
2021 correctly. *Note Engine Version Check::.
2023 The function returns the error code `GPG_ERR_NO_ERROR' if the
2024 protocol could be set successfully, and `GPG_ERR_INV_VALUE' if
2025 PROTOCOL is not a valid protocol.
2027 -- Function: gpgme_protocol_t gpgme_get_protocol (gpgme_ctx_t CTX)
2028 The function `gpgme_get_protocol' retrieves the protocol currently
2029 use with the context CTX.
2032 File: gpgme.info, Node: Crypto Engine, Next: ASCII Armor, Prev: Protocol Selection, Up: Context Attributes
2037 The following functions can be used to set and retrieve the
2038 configuration of the crypto engines of a specific context. The default
2039 can also be retrieved without any particular context. *Note Engine
2040 Information::. The default can also be changed globally. *Note Engine
2043 -- Function: gpgme_engine_info_t gpgme_ctx_get_engine_info
2045 The function `gpgme_ctx_get_engine_info' returns a linked list of
2046 engine info structures. Each info structure describes the
2047 configuration of one configured backend, as used by the context
2050 The result is valid until the next invocation of
2051 `gpgme_ctx_set_engine_info' for this particular context.
2053 This function can not fail.
2055 -- Function: gpgme_error_t gpgme_ctx_set_engine_info (gpgme_ctx_t CTX,
2056 gpgme_protocol_t PROTO, const char *FILE_NAME,
2057 const char *HOME_DIR)
2058 The function `gpgme_ctx_set_engine_info' changes the configuration
2059 of the crypto engine implementing the protocol PROTO for the
2062 FILE_NAME is the file name of the executable program implementing
2063 this protocol, and HOME_DIR is the directory name of the
2064 configuration directory for this crypto engine. If HOME_DIR is
2065 `NULL', the engine's default will be used.
2067 Currently this function must be used before starting the first
2068 crypto operation. It is unspecified if and when the changes will
2069 take effect if the function is called after starting the first
2070 operation on the context CTX.
2072 This function returns the error code `GPG_ERR_NO_ERROR' if
2073 successful, or an eror code on failure.
2076 File: gpgme.info, Node: ASCII Armor, Next: Text Mode, Prev: Crypto Engine, Up: Context Attributes
2081 -- Function: void gpgme_set_armor (gpgme_ctx_t CTX, int YES)
2082 The function `gpgme_set_armor' specifies if the output should be
2083 ASCII armored. By default, output is not ASCII armored.
2085 ASCII armored output is disabled if YES is zero, and enabled
2088 -- Function: int gpgme_get_armor (gpgme_ctx_t CTX)
2089 The function `gpgme_get_armor' returns 1 if the output is ASCII
2090 armored, and `0' if it is not, or if CTX is not a valid pointer.
2093 File: gpgme.info, Node: Text Mode, Next: Included Certificates, Prev: ASCII Armor, Up: Context Attributes
2098 -- Function: void gpgme_set_textmode (gpgme_ctx_t CTX, int YES)
2099 The function `gpgme_set_textmode' specifies if canonical text mode
2100 should be used. By default, text mode is not used.
2102 Text mode is for example used for the RFC2015 signatures; note that
2103 the updated RFC 3156 mandates that the mail user agent does some
2104 preparations so that text mode is not needed anymore.
2106 This option is only relevant to the OpenPGP crypto engine, and
2107 ignored by all other engines.
2109 Canonical text mode is disabled if YES is zero, and enabled
2112 -- Function: int gpgme_get_textmode (gpgme_ctx_t CTX)
2113 The function `gpgme_get_textmode' returns 1 if canonical text mode
2114 is enabled, and `0' if it is not, or if CTX is not a valid pointer.
2117 File: gpgme.info, Node: Included Certificates, Next: Key Listing Mode, Prev: Text Mode, Up: Context Attributes
2119 7.4.5 Included Certificates
2120 ---------------------------
2122 -- Function: void gpgme_set_include_certs (gpgme_ctx_t CTX,
2124 The function `gpgme_set_include_certs' specifies how many
2125 certificates should be included in an S/MIME signed message. By
2126 default, only the sender's certificate is included. The possible
2127 values of NR_OF_CERTS are:
2129 `GPGME_INCLUDE_CERTS_DEFAULT'
2130 Fall back to the default of the crypto backend. This is the
2134 Include all certificates except the root certificate.
2137 Include all certificates.
2140 Include no certificates.
2143 Include the sender's certificate only.
2146 Include the first n certificates of the certificates path,
2147 starting from the sender's certificate. The number `n' must
2150 Values of NR_OF_CERTS smaller than -2 are undefined.
2152 This option is only relevant to the CMS crypto engine, and ignored
2153 by all other engines.
2155 -- Function: int gpgme_get_include_certs (gpgme_ctx_t CTX)
2156 The function `gpgme_get_include_certs' returns the number of
2157 certificates to include into an S/MIME signed message.
2160 File: gpgme.info, Node: Key Listing Mode, Next: Passphrase Callback, Prev: Included Certificates, Up: Context Attributes
2162 7.4.6 Key Listing Mode
2163 ----------------------
2165 -- Function: gpgme_error_t gpgme_set_keylist_mode (gpgme_ctx_t CTX,
2166 gpgme_keylist_mode_t MODE)
2167 The function `gpgme_set_keylist_mode' changes the default
2168 behaviour of the key listing functions. The value in MODE is a
2169 bitwise-or combination of one or multiple of the following bit
2172 `GPGME_KEYLIST_MODE_LOCAL'
2173 The `GPGME_KEYLIST_MODE_LOCAL' symbol specifies that the local
2174 keyring should be searched for keys in the keylisting
2175 operation. This is the default.
2177 `GPGME_KEYLIST_MODE_EXTERN'
2178 The `GPGME_KEYLIST_MODE_EXTERN' symbol specifies that an
2179 external source should be searched for keys in the keylisting
2180 operation. The type of external source is dependant on the
2181 crypto engine used and whether it is combined with
2182 `GPGME_KEYLIST_MODE_LOCAL'. For example, it can be a remote
2183 keyserver or LDAP certificate server.
2185 `GPGME_KEYLIST_MODE_SIGS'
2186 The `GPGME_KEYLIST_MODE_SIGS' symbol specifies that the key
2187 signatures should be included in the listed keys.
2189 `GPGME_KEYLIST_MODE_SIG_NOTATIONS'
2190 The `GPGME_KEYLIST_MODE_SIG_NOTATIONS' symbol specifies that
2191 the signature notations on key signatures should be included
2192 in the listed keys. This only works if
2193 `GPGME_KEYLIST_MODE_SIGS' is also enabled.
2195 `GPGME_KEYLIST_MODE_EPHEMERAL'
2196 The `GPGME_KEYLIST_MODE_EPHEMERAL' symbol specifies that keys
2197 flagged as ephemeral are included in the listing.
2199 `GPGME_KEYLIST_MODE_VALIDATE'
2200 The `GPGME_KEYLIST_MODE_VALIDATE' symbol specifies that the
2201 backend should do key or certificate validation and not just
2202 get the validity information from an internal cache. This
2203 might be an expensive operation and is in general not useful.
2204 Currently only implemented for the S/MIME backend and ignored
2208 At least one of `GPGME_KEYLIST_MODE_LOCAL' and
2209 `GPGME_KEYLIST_MODE_EXTERN' must be specified. For future binary
2210 compatibility, you should get the current mode with
2211 `gpgme_get_keylist_mode' and modify it by setting or clearing the
2212 appropriate bits, and then using that calculated value in the
2213 `gpgme_set_keylisting_mode' operation. This will leave all other
2214 bits in the mode value intact (in particular those that are not
2215 used in the current version of the library).
2217 The function returns the error code `GPG_ERR_NO_ERROR' if the mode
2218 could be set correctly, and `GPG_ERR_INV_VALUE' if CTX is not a
2219 valid pointer or MODE is not a valid mode.
2221 -- Function: gpgme_keylist_mode_t gpgme_get_keylist_mode
2223 The function `gpgme_get_keylist_mode' returns the current key
2224 listing mode of the context CTX. This value can then be modified
2225 and used in a subsequent `gpgme_set_keylist_mode' operation to
2226 only affect the desired bits (and leave all others intact).
2228 The function returns 0 if CTX is not a valid pointer, and the
2229 current mode otherwise. Note that 0 is not a valid mode value.
2232 File: gpgme.info, Node: Passphrase Callback, Next: Progress Meter Callback, Prev: Key Listing Mode, Up: Context Attributes
2234 7.4.7 Passphrase Callback
2235 -------------------------
2237 -- Data type: gpgme_error_t (*gpgme_passphrase_cb_t)(void *HOOK, const
2238 char *UID_HINT, const char *PASSPHRASE_INFO, int PREV_WAS_BAD, int FD)
2239 The `gpgme_passphrase_cb_t' type is the type of functions usable as
2240 passphrase callback function.
2242 The argument UID_HINT might contain a string that gives an
2243 indication for which user ID the passphrase is required. If this
2244 is not available, or not applicable (in the case of symmetric
2245 encryption, for example), UID_HINT will be `NULL'.
2247 The argument PASSPHRASE_INFO, if not `NULL', will give further
2248 information about the context in which the passphrase is required.
2249 This information is engine and operation specific.
2251 If this is the repeated attempt to get the passphrase, because
2252 previous attempts failed, then PREV_WAS_BAD is 1, otherwise it
2255 The user must write the passphrase, followed by a newline
2256 character, to the file descriptor FD. The function
2257 `gpgme_io_writen' should be used for the write operation. Note
2258 that if the user returns 0 to indicate success, the user must at
2259 least write a newline character before returning from the callback.
2261 If an error occurs, return the corresponding `gpgme_error_t'
2262 value. You can use the error code `GPG_ERR_CANCELED' to abort the
2263 operation. Otherwise, return `0'.
2265 -- Function: void gpgme_set_passphrase_cb (gpgme_ctx_t CTX,
2266 gpgme_passphrase_cb_t PASSFUNC, void *HOOK_VALUE)
2267 The function `gpgme_set_passphrase_cb' sets the function that is
2268 used when a passphrase needs to be provided by the user to
2269 PASSFUNC. The function PASSFUNC needs to implemented by the user,
2270 and whenever it is called, it is called with its first argument
2271 being HOOK_VALUE. By default, no passphrase callback function is
2274 Not all crypto engines require this callback to retrieve the
2275 passphrase. It is better if the engine retrieves the passphrase
2276 from a trusted agent (a daemon process), rather than having each
2277 user to implement their own passphrase query. Some engines do not
2278 even support an external passphrase callback at all, in this case
2279 the error code `GPG_ERR_NOT_SUPPORTED' is returned.
2281 The user can disable the use of a passphrase callback function by
2282 calling `gpgme_set_passphrase_cb' with PASSFUNC being `NULL'.
2284 -- Function: void gpgme_get_passphrase_cb (gpgme_ctx_t CTX,
2285 gpgme_passphrase_cb_t *PASSFUNC, void **HOOK_VALUE)
2286 The function `gpgme_get_passphrase_cb' returns the function that
2287 is used when a passphrase needs to be provided by the user in
2288 *PASSFUNC, and the first argument for this function in
2289 *HOOK_VALUE. If no passphrase callback is set, or CTX is not a
2290 valid pointer, `NULL' is returned in both variables.
2292 PASSFUNC or HOOK_VALUE can be `NULL'. In this case, the
2293 corresponding value will not be returned.
2296 File: gpgme.info, Node: Progress Meter Callback, Next: Locale, Prev: Passphrase Callback, Up: Context Attributes
2298 7.4.8 Progress Meter Callback
2299 -----------------------------
2301 -- Data type: void (*gpgme_progress_cb_t)(void *HOOK, const char
2302 *WHAT, int TYPE, int CURRENT, int TOTAL)
2303 The `gpgme_progress_cb_t' type is the type of functions usable as
2304 progress callback function.
2306 The arguments are specific to the crypto engine. More information
2307 about the progress information returned from the GnuPG engine can
2308 be found in the GnuPG source code in the file `doc/DETAILS' in the
2311 -- Function: void gpgme_set_progress_cb (gpgme_ctx_t CTX,
2312 gpgme_progress_cb_t PROGFUNC, void *HOOK_VALUE)
2313 The function `gpgme_set_progress_cb' sets the function that is
2314 used when progress information about a cryptographic operation is
2315 available. The function PROGFUNC needs to implemented by the
2316 user, and whenever it is called, it is called with its first
2317 argument being HOOK_VALUE. By default, no progress callback
2320 Setting a callback function allows an interactive program to
2321 display progress information about a long operation to the user.
2323 The user can disable the use of a progress callback function by
2324 calling `gpgme_set_progress_cb' with PROGFUNC being `NULL'.
2326 -- Function: void gpgme_get_progress_cb (gpgme_ctx_t CTX,
2327 gpgme_progress_cb_t *PROGFUNC, void **HOOK_VALUE)
2328 The function `gpgme_get_progress_cb' returns the function that is
2329 used to inform the user about the progress made in *PROGFUNC, and
2330 the first argument for this function in *HOOK_VALUE. If no
2331 progress callback is set, or CTX is not a valid pointer, `NULL' is
2332 returned in both variables.
2334 PROGFUNC or HOOK_VALUE can be `NULL'. In this case, the
2335 corresponding value will not be returned.
2338 File: gpgme.info, Node: Locale, Prev: Progress Meter Callback, Up: Context Attributes
2343 A locale setting can be associated with a context. This locale is
2344 passed to the crypto engine, and used for applications like the PIN
2345 entry, which is displayed to the user when entering a passphrase is
2348 The default locale is used to initialize the locale setting of all
2349 contexts created afterwards.
2351 -- Function: gpgme_error_t gpgme_set_locale (gpgme_ctx_t CTX,
2352 int CATEGORY, const char *VALUE)
2353 The function `gpgme_set_locale' sets the locale of the context
2354 CTX, or the default locale if CTX is a null pointer.
2356 The locale settings that should be changed are specified by
2357 CATEGORY. Supported categories are `LC_CTYPE', `LC_MESSAGES', and
2358 `LC_ALL', which is a wildcard you can use if you want to change
2359 all the categories at once.
2361 The value to be used for the locale setting is VALUE, which will
2362 be copied to GPGME's internal data structures. VALUE can be a
2363 null pointer, which disables setting the locale, and will make PIN
2364 entry and other applications use their default setting, which is
2365 usually not what you want.
2367 Note that the settings are only used if the application runs on a
2368 text terminal, and that the settings should fit the configuration
2369 of the output terminal. Normally, it is sufficient to initialize
2370 the default value at startup.
2372 The function returns an error if not enough memory is available.
2375 File: gpgme.info, Node: Key Management, Next: Trust Item Management, Prev: Context Attributes, Up: Contexts
2380 Some of the cryptographic operations require that recipients or signers
2381 are specified. This is always done by specifying the respective keys
2382 that should be used for the operation. The following section describes
2383 how such keys can be selected and manipulated.
2385 -- Data type: gpgme_sub_key_t
2386 The `gpgme_sub_key_t' type is a pointer to a subkey structure.
2387 Sub keys are one component of a `gpgme_key_t' object. In fact,
2388 subkeys are those parts that contains the real information about
2389 the individual cryptographic keys that belong to the same key
2390 object. One `gpgme_key_t' can contain several subkeys. The first
2391 subkey in the linked list is also called the primary key.
2393 The subkey structure has the following members:
2395 `gpgme_sub_key_t next'
2396 This is a pointer to the next subkey structure in the linked
2397 list, or `NULL' if this is the last element.
2399 `unsigned int revoked : 1'
2400 This is true if the subkey is revoked.
2402 `unsigned int expired : 1'
2403 This is true if the subkey is expired.
2405 `unsigned int disabled : 1'
2406 This is true if the subkey is disabled.
2408 `unsigned int invalid : 1'
2409 This is true if the subkey is invalid.
2411 `unsigned int can_encrypt : 1'
2412 This is true if the subkey can be used for encryption.
2414 `unsigned int can_sign : 1'
2415 This is true if the subkey can be used to create data
2418 `unsigned int can_certify : 1'
2419 This is true if the subkey can be used to create key
2422 `unsigned int can_authenticate : 1'
2423 This is true if the subkey can be used for authentication.
2425 `unsigned int is_qualified : 1'
2426 This is true if the subkey can be used for qualified
2427 signatures according to local government regulations.
2429 `unsigned int secret : 1'
2430 This is true if the subkey is a secret key. Note that it
2431 will be false if the key is actually a stub key; i.e. a
2432 secret key operation is currently not possible (offline-key).
2434 `gpgme_pubkey_algo_t pubkey_algo'
2435 This is the public key algorithm supported by this subkey.
2437 `unsigned int length'
2438 This is the length of the subkey (in bits).
2441 This is the key ID of the subkey in hexadecimal digits.
2444 This is the fingerprint of the subkey in hexadecimal digits,
2447 `long int timestamp'
2448 This is the creation timestamp of the subkey. This is -1 if
2449 the timestamp is invalid, and 0 if it is not available.
2452 This is the expiration timestamp of the subkey, or 0 if the
2453 subkey does not expire.
2455 -- Data type: gpgme_key_sig_t
2456 The `gpgme_key_sig_t' type is a pointer to a key signature
2457 structure. Key signatures are one component of a `gpgme_key_t'
2458 object, and validate user IDs on the key.
2460 The signatures on a key are only available if the key was retrieved
2461 via a listing operation with the `GPGME_KEYLIST_MODE_SIGS' mode
2462 enabled, because it can be expensive to retrieve all signatures of
2465 The signature notations on a key signature are only available if
2466 the key was retrieved via a listing operation with the
2467 `GPGME_KEYLIST_MODE_SIG_NOTATIONS' mode enabled, because it can be
2468 expensive to retrieve all signature notations.
2470 The key signature structure has the following members:
2472 `gpgme_key_sig_t next'
2473 This is a pointer to the next key signature structure in the
2474 linked list, or `NULL' if this is the last element.
2476 `unsigned int revoked : 1'
2477 This is true if the key signature is a revocation signature.
2479 `unsigned int expired : 1'
2480 This is true if the key signature is expired.
2482 `unsigned int invalid : 1'
2483 This is true if the key signature is invalid.
2485 `unsigned int exportable : 1'
2486 This is true if the key signature is exportable.
2488 `gpgme_pubkey_algo_t pubkey_algo'
2489 This is the public key algorithm used to create the signature.
2492 This is the key ID of the key (in hexadecimal digits) used to
2493 create the signature.
2495 `long int timestamp'
2496 This is the creation timestamp of the key signature. This is
2497 -1 if the timestamp is invalid, and 0 if it is not available.
2500 This is the expiration timestamp of the key signature, or 0
2501 if the key signature does not expire.
2503 `gpgme_error_t status'
2504 This is the status of the signature and has the same meaning
2505 as the member of the same name in a `gpgme_signature_t'
2508 `unsigned int sig_class'
2509 This specifies the signature class of the key signature. The
2510 meaning is specific to the crypto engine.
2513 This is the main user ID of the key used to create the
2517 This is the name component of `uid', if available.
2520 This is the comment component of `uid', if available.
2523 This is the email component of `uid', if available.
2525 `gpgme_sig_notation_t notations'
2526 This is a linked list with the notation data and policy URLs.
2528 -- Data type: gpgme_user_id_t
2529 A user ID is a component of a `gpgme_key_t' object. One key can
2530 have many user IDs. The first one in the list is the main (or
2533 The user ID structure has the following members.
2535 `gpgme_user_id_t next'
2536 This is a pointer to the next user ID structure in the linked
2537 list, or `NULL' if this is the last element.
2539 `unsigned int revoked : 1'
2540 This is true if the user ID is revoked.
2542 `unsigned int invalid : 1'
2543 This is true if the user ID is invalid.
2545 `gpgme_validity_t validity'
2546 This specifies the validity of the user ID.
2549 This is the user ID string.
2552 This is the name component of `uid', if available.
2555 This is the comment component of `uid', if available.
2558 This is the email component of `uid', if available.
2560 `gpgme_key_sig_t signatures'
2561 This is a linked list with the signatures on this user ID.
2563 -- Data type: gpgme_key_t
2564 The `gpgme_key_t' type is a pointer to a key object. It has the
2567 `gpgme_keylist_mode_t keylist_mode'
2568 The keylist mode that was active when the key was retrieved.
2570 `unsigned int revoked : 1'
2571 This is true if the key is revoked.
2573 `unsigned int expired : 1'
2574 This is true if the key is expired.
2576 `unsigned int disabled : 1'
2577 This is true if the key is disabled.
2579 `unsigned int invalid : 1'
2580 This is true if the key is invalid. This might have several
2581 reasons, for a example for the S/MIME backend, it will be set
2582 in during key listsing if the key could not be validated due
2583 to a missing certificates or unmatched policies.
2585 `unsigned int can_encrypt : 1'
2586 This is true if the key (ie one of its subkeys) can be used
2589 `unsigned int can_sign : 1'
2590 This is true if the key (ie one of its subkeys) can be used
2591 to create data signatures.
2593 `unsigned int can_certify : 1'
2594 This is true if the key (ie one of its subkeys) can be used
2595 to create key certificates.
2597 `unsigned int can_authenticate : 1'
2598 This is true if the key (ie one of its subkeys) can be used
2601 `unsigned int is_qualified : 1'
2602 This is true if the key can be used for qualified signatures
2603 according to local government regulations.
2605 `unsigned int secret : 1'
2606 This is true if the key is a secret key. Note, that this
2607 will always be true even if the corresponding subkey flag may
2608 be false (offline/stub keys).
2610 `gpgme_protocol_t protocol'
2611 This is the protocol supported by this key.
2613 `char *issuer_serial'
2614 If `protocol' is `GPGME_PROTOCOL_CMS', then this is the
2618 If `protocol' is `GPGME_PROTOCOL_CMS', then this is the
2622 If `protocol' is `GPGME_PROTOCOL_CMS', then this is the chain
2623 ID, which can be used to built the certificate chain.
2625 `gpgme_validity_t owner_trust'
2626 If `protocol' is `GPGME_PROTOCOL_OpenPGP', then this is the
2629 `gpgme_sub_key_t subkeys'
2630 This is a linked list with the subkeys of the key. The first
2631 subkey in the list is the primary key and usually available.
2633 `gpgme_user_id_t uids'
2634 This is a linked list with the user IDs of the key. The
2635 first user ID in the list is the main (or primary) user ID.
2639 * Listing Keys:: Browsing the list of available keys.
2640 * Information About Keys:: Requesting detailed information about keys.
2641 * Key Signatures:: Listing the signatures on a key.
2642 * Manipulating Keys:: Operations on keys.
2643 * Generating Keys:: Creating new key pairs.
2644 * Exporting Keys:: Retrieving key data from the key ring.
2645 * Importing Keys:: Adding keys to the key ring.
2646 * Deleting Keys:: Removing keys from the key ring.
2647 * Changing Passphrases:: Change the passphrase of a key.
2648 * Advanced Key Editing:: Advanced key edit operation.
2651 File: gpgme.info, Node: Listing Keys, Next: Information About Keys, Up: Key Management
2656 -- Function: gpgme_error_t gpgme_op_keylist_start (gpgme_ctx_t CTX,
2657 const char *PATTERN, int SECRET_ONLY)
2658 The function `gpgme_op_keylist_start' initiates a key listing
2659 operation inside the context CTX. It sets everything up so that
2660 subsequent invocations of `gpgme_op_keylist_next' return the keys
2663 If PATTERN is `NULL', all available keys are returned. Otherwise,
2664 PATTERN contains an engine specific expression that is used to
2665 limit the list to all keys matching the pattern. Note that the
2666 total length of the pattern is restricted to an engine-specific
2667 maximum (a couple of hundred characters are usually accepted). The
2668 pattern 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
2670 their fingerprints or key IDs.
2672 If SECRET_ONLY is not `0', the list is restricted to secret keys
2675 The context will be busy until either all keys are received (and
2676 `gpgme_op_keylist_next' returns `GPG_ERR_EOF'), or
2677 `gpgme_op_keylist_end' is called to finish the operation.
2679 The function returns the error code `GPG_ERR_INV_VALUE' if CTX is
2680 not a valid pointer, and passes through any errors that are
2681 reported by the crypto engine support routines.
2683 -- Function: gpgme_error_t gpgme_op_keylist_ext_start
2684 (gpgme_ctx_t CTX, const char *PATTERN[], int SECRET_ONLY,
2686 The function `gpgme_op_keylist_ext_start' initiates an extended
2687 key listing operation inside the context CTX. It sets everything
2688 up so that subsequent invocations of `gpgme_op_keylist_next'
2689 return the keys in the list.
2691 If PATTERN or *PATTERN is `NULL', all available keys are returned.
2692 Otherwise, PATTERN is a `NULL' terminated array of strings that
2693 are used to limit the list to all keys matching at least one of
2694 the patterns verbatim. Note that the total length of all patterns
2695 is restricted to an engine-specific maximum (the exact limit also
2696 depends on the number of patterns and amount of quoting required,
2697 but a couple of hundred characters are usually accepted).
2698 Patterns should be used to restrict the search to a certain common
2699 name or user, not to list many specific keys at once by listing
2700 their fingerprints or key IDs.
2702 If SECRET_ONLY is not `0', the list is restricted to secret keys
2705 The value of RESERVED must be `0'.
2707 The context will be busy until either all keys are received (and
2708 `gpgme_op_keylist_next' returns `GPG_ERR_EOF'), or
2709 `gpgme_op_keylist_end' is called to finish the operation.
2711 The function returns the error code `GPG_ERR_INV_VALUE' if CTX is
2712 not a valid pointer, and passes through any errors that are
2713 reported by the crypto engine support routines.
2715 -- Function: gpgme_error_t gpgme_op_keylist_next (gpgme_ctx_t CTX,
2717 The function `gpgme_op_keylist_next' returns the next key in the
2718 list created by a previous `gpgme_op_keylist_start' operation in
2719 the context CTX. The key will have one reference for the user.
2720 *Note Manipulating Keys::.
2722 This is the only way to get at `gpgme_key_t' objects in GPGME.
2724 If the last key in the list has already been returned,
2725 `gpgme_op_keylist_next' returns `GPG_ERR_EOF'.
2727 The function returns the error code `GPG_ERR_INV_VALUE' if CTX or
2728 R_KEY is not a valid pointer, and `GPG_ERR_ENOMEM' if there is not
2729 enough memory for the operation.
2731 -- Function: gpgme_error_t gpgme_op_keylist_end (gpgme_ctx_t CTX)
2732 The function `gpgme_op_keylist_end' ends a pending key list
2733 operation in the context CTX.
2735 After the operation completed successfully, the result of the key
2736 listing operation can be retrieved with `gpgme_op_keylist_result'.
2738 The function returns the error code `GPG_ERR_INV_VALUE' if CTX is
2739 not a valid pointer, and `GPG_ERR_ENOMEM' if at some time during
2740 the operation there was not enough memory available.
2742 The following example illustrates how all keys containing a certain
2743 string (`g10code') can be listed with their key ID and the name and
2744 e-mail address of the main user ID:
2748 gpgme_error_t err = gpgme_new (&ctx);
2752 err = gpgme_op_keylist_start (ctx, "g10code", 0);
2755 err = gpgme_op_keylist_next (ctx, &key);
2758 printf ("%s:", key->subkeys->keyid);
2759 if (key->uids && key->uids->name)
2760 printf (" %s", key->uids->name);
2761 if (key->uids && key->uids->email)
2762 printf (" <%s>", key->uids->email);
2764 gpgme_key_release (key);
2766 gpgme_release (ctx);
2768 if (gpg_err_code (err) != GPG_ERR_EOF)
2770 fprintf (stderr, "can not list keys: %s\n", gpgme_strerror (err));
2774 -- Data type: gpgme_keylist_result_t
2775 This is a pointer to a structure used to store the result of a
2776 `gpgme_op_keylist_*' operation. After successfully ending a key
2777 listing operation, you can retrieve the pointer to the result with
2778 `gpgme_op_keylist_result'. The structure contains the following
2781 `unsigned int truncated : 1'
2782 This is true if the crypto backend had to truncate the
2783 result, and less than the desired keys could be listed.
2785 -- Function: gpgme_keylist_result_t gpgme_op_keylist_result
2787 The function `gpgme_op_keylist_result' returns a
2788 `gpgme_keylist_result_t' pointer to a structure holding the result
2789 of a `gpgme_op_keylist_*' operation. The pointer is only valid if
2790 the last operation on the context was a key listing operation, and
2791 if this operation finished successfully. The returned pointer is
2792 only valid until the next operation is started on the context.
2794 In a simple program, for which a blocking operation is acceptable,
2795 the following function can be used to retrieve a single key.
2797 -- Function: gpgme_error_t gpgme_get_key (gpgme_ctx_t CTX,
2798 const char *FPR, gpgme_key_t *R_KEY, int SECRET)
2799 The function `gpgme_get_key' gets the key with the fingerprint (or
2800 key ID) FPR from the crypto backend and return it in R_KEY. If
2801 SECRET is true, get the secret key. The currently active keylist
2802 mode is used to retrieve the key. The key will have one reference
2805 If the key is not found in the keyring, `gpgme_get_key' returns
2806 the error code `GPG_ERR_EOF' and *R_KEY will be set to `NULL'.
2808 The function returns the error code `GPG_ERR_INV_VALUE' if CTX or
2809 R_KEY is not a valid pointer or FPR is not a fingerprint or key
2810 ID, `GPG_ERR_AMBIGUOUS_NAME' if the key ID was not a unique
2811 specifier for a key, and `GPG_ERR_ENOMEM' if at some time during
2812 the operation there was not enough memory available.
2815 File: gpgme.info, Node: Information About Keys, Next: Key Signatures, Prev: Listing Keys, Up: Key Management
2817 7.5.2 Information About Keys
2818 ----------------------------
2820 Please see the beginning of this section for more information about
2821 `gpgme_key_t' objects.
2823 -- Data type: gpgme_validity_t
2824 The `gpgme_validity_t' type is used to specify the validity of a
2825 user ID in a key. The following validities are defined:
2827 `GPGME_VALIDITY_UNKNOWN'
2828 The user ID is of unknown validity. The string
2829 representation of this validity is "?".
2831 `GPGME_VALIDITY_UNDEFINED'
2832 The validity of the user ID is undefined. The string
2833 representation of this validity is "q".
2835 `GPGME_VALIDITY_NEVER'
2836 The user ID is never valid. The string representation of this
2839 `GPGME_VALIDITY_MARGINAL'
2840 The user ID is marginally valid. The string representation
2841 of this validity is "m".
2843 `GPGME_VALIDITY_FULL'
2844 The user ID is fully valid. The string representation of this
2847 `GPGME_VALIDITY_ULTIMATE'
2848 The user ID is ultimately valid. The string representation
2849 of this validity is "u".
2851 The following interfaces are deprecated and only provided for
2852 backward compatibility. Don't use them. They will be removed in a
2853 future version of GPGME.
2855 -- Data type: gpgme_attr_t
2856 The `gpgme_attr_t' type is used to specify a key or trust item
2857 attribute. The following attributes are defined:
2860 This is the key ID of a sub key. It is representable as a
2863 For trust items, the trust item refers to the key with this
2867 This is the fingerprint of a sub key. It is representable as
2871 This is the crypto algorithm for which the sub key can be
2872 used. It is representable as a string and as a number. The
2873 numbers correspond to the `enum gcry_pk_algos' values in the
2877 This is the key length of a sub key. It is representable as a
2880 `GPGME_ATTR_CREATED'
2881 This is the timestamp at creation time of a sub key. It is
2882 representable as a number.
2885 This is the expiration time of a sub key. It is
2886 representable as a number.
2889 XXX FIXME (also for trust items)
2892 This is a user ID. There can be more than one user IDs in a
2893 GPGME_KEY_T object. The first one (with index 0) is the
2894 primary user ID. The user ID is representable as a number.
2896 For trust items, this is the user ID associated with this
2900 This is the name belonging to a user ID. It is representable
2904 This is the email address belonging to a user ID. It is
2905 representable as a string.
2907 `GPGME_ATTR_COMMENT'
2908 This is the comment belonging to a user ID. It is
2909 representable as a string.
2911 `GPGME_ATTR_VALIDITY'
2912 This is the validity belonging to a user ID. It is
2913 representable as a string and as a number. See below for a
2914 list of available validities.
2916 For trust items, this is the validity that is associated with
2919 `GPGME_ATTR_UID_REVOKED'
2920 This specifies if a user ID is revoked. It is representable
2921 as a number, and is `1' if the user ID is revoked, and `0'
2924 `GPGME_ATTR_UID_INVALID'
2925 This specifies if a user ID is invalid. It is representable
2926 as a number, and is `1' if the user ID is invalid, and `0'
2930 This is the trust level of a trust item.
2933 This returns information about the type of key. For the
2934 string function this will eother be "PGP" or "X.509". The
2935 integer function returns 0 for PGP and 1 for X.509. It is
2936 also used for the type of a trust item.
2938 `GPGME_ATTR_IS_SECRET'
2939 This specifies if the key is a secret key. It is
2940 representable as a number, and is `1' if the key is revoked,
2943 `GPGME_ATTR_KEY_REVOKED'
2944 This specifies if a sub key is revoked. It is representable
2945 as a number, and is `1' if the key is revoked, and `0'
2948 `GPGME_ATTR_KEY_INVALID'
2949 This specifies if a sub key is invalid. It is representable
2950 as a number, and is `1' if the key is invalid, and `0'
2953 `GPGME_ATTR_KEY_EXPIRED'
2954 This specifies if a sub key is expired. It is representable
2955 as a number, and is `1' if the key is expired, and `0'
2958 `GPGME_ATTR_KEY_DISABLED'
2959 This specifies if a sub key is disabled. It is representable
2960 as a number, and is `1' if the key is disabled, and `0'
2963 `GPGME_ATTR_KEY_CAPS'
2964 This is a description of the capabilities of a sub key. It is
2965 representable as a string. The string contains the letter
2966 "e" if the key can be used for encryption, "s" if the key can
2967 be used for signatures, and "c" if the key can be used for
2970 `GPGME_ATTR_CAN_ENCRYPT'
2971 This specifies if a sub key can be used for encryption. It is
2972 representable as a number, and is `1' if the sub key can be
2973 used for encryption, and `0' otherwise.
2975 `GPGME_ATTR_CAN_SIGN'
2976 This specifies if a sub key can be used to create data
2977 signatures. It is representable as a number, and is `1' if
2978 the sub key can be used for signatures, and `0' otherwise.
2980 `GPGME_ATTR_CAN_CERTIFY'
2981 This specifies if a sub key can be used to create key
2982 certificates. It is representable as a number, and is `1' if
2983 the sub key can be used for certifications, and `0' otherwise.
2986 The X.509 issuer serial attribute of the key. It is
2987 representable as a string.
2990 The X.509 issuer name attribute of the key. It is
2991 representable as a string.
2993 `GPGME_ATTR_CHAINID'
2994 The X.509 chain ID can be used to build the certification
2995 chain. It is representable as a string.
2997 -- Function: const char * gpgme_key_get_string_attr (gpgme_key_t KEY,
2998 gpgme_attr_t WHAT, const void *RESERVED, int IDX)
2999 The function `gpgme_key_get_string_attr' returns the value of the
3000 string-representable attribute WHAT of key KEY. If the attribute
3001 is an attribute of a sub key or an user ID, IDX specifies the sub
3002 key or user ID of which the attribute value is returned. The
3003 argument RESERVED is reserved for later use and should be `NULL'.
3005 The string returned is only valid as long as the key is valid.
3007 The function returns `0' if an attribute can't be returned as a
3008 string, KEY is not a valid pointer, IDX out of range, or RESERVED
3011 -- Function: unsigned long gpgme_key_get_ulong_attr (gpgme_key_t KEY,
3012 gpgme_attr_t WHAT, const void *RESERVED, int IDX)
3013 The function `gpgme_key_get_ulong_attr' returns the value of the
3014 number-representable attribute WHAT of key KEY. If the attribute
3015 is an attribute of a sub key or an user ID, IDX specifies the sub
3016 key or user ID of which the attribute value is returned. The
3017 argument RESERVED is reserved for later use and should be `NULL'.
3019 The function returns `0' if the attribute can't be returned as a
3020 number, KEY is not a valid pointer, IDX out of range, or RESERVED
3024 File: gpgme.info, Node: Key Signatures, Next: Manipulating Keys, Prev: Information About Keys, Up: Key Management
3026 7.5.3 Key Signatures
3027 --------------------
3029 The following interfaces are deprecated and only provided for backward
3030 compatibility. Don't use them. They will be removed in a future
3033 The signatures on a key are only available if the key was retrieved
3034 via a listing operation with the `GPGME_KEYLIST_MODE_SIGS' mode
3035 enabled, because it is expensive to retrieve all signatures of a key.
3037 So, before using the below interfaces to retrieve the signatures on a
3038 key, you have to make sure that the key was listed with signatures
3039 enabled. One convenient, but blocking, way to do this is to use the
3040 function `gpgme_get_key'.
3042 -- Data type: gpgme_attr_t
3043 The `gpgme_attr_t' type is used to specify a key signature
3044 attribute. The following attributes are defined:
3047 This is the key ID of the key which was used for the
3048 signature. It is representable as a string.
3051 This is the crypto algorithm used to create the signature.
3052 It is representable as a string and as a number. The numbers
3053 correspond to the `enum gcry_pk_algos' values in the gcrypt
3056 `GPGME_ATTR_CREATED'
3057 This is the timestamp at creation time of the signature. It
3058 is representable as a number.
3061 This is the expiration time of the signature. It is
3062 representable as a number.
3065 This is the user ID associated with the signing key. The
3066 user ID is representable as a number.
3069 This is the name belonging to a user ID. It is representable
3073 This is the email address belonging to a user ID. It is
3074 representable as a string.
3076 `GPGME_ATTR_COMMENT'
3077 This is the comment belonging to a user ID. It is
3078 representable as a string.
3080 `GPGME_ATTR_KEY_REVOKED'
3081 This specifies if a key signature is a revocation signature.
3082 It is representable as a number, and is `1' if the key is
3083 revoked, and `0' otherwise.
3085 `GPGME_ATTR_SIG_CLASS'
3086 This specifies the signature class of a key signature. It is
3087 representable as a number. The meaning is specific to the
3090 `GPGME_ATTR_SIG_CLASS'
3091 This specifies the signature class of a key signature. It is
3092 representable as a number. The meaning is specific to the
3095 `GPGME_ATTR_SIG_STATUS'
3096 This is the same value as returned by `gpgme_get_sig_status'.
3098 -- Function: const char * gpgme_key_sig_get_string_attr
3099 (gpgme_key_t KEY, int UID_IDX, gpgme_attr_t WHAT,
3100 const void *RESERVED, int IDX)
3101 The function `gpgme_key_sig_get_string_attr' returns the value of
3102 the string-representable attribute WHAT of the signature IDX on
3103 the user ID UID_IDX in the key KEY. The argument RESERVED is
3104 reserved for later use and should be `NULL'.
3106 The string returned is only valid as long as the key is valid.
3108 The function returns `0' if an attribute can't be returned as a
3109 string, KEY is not a valid pointer, UID_IDX or IDX out of range,
3110 or RESERVED not `NULL'.
3112 -- Function: unsigned long gpgme_key_sig_get_ulong_attr
3113 (gpgme_key_t KEY, int UID_IDX, gpgme_attr_t WHAT,
3114 const void *RESERVED, int IDX)
3115 The function `gpgme_key_sig_get_ulong_attr' returns the value of
3116 the number-representable attribute WHAT of the signature IDX on
3117 the user ID UID_IDX in the key KEY. The argument RESERVED is
3118 reserved for later use and should be `NULL'.
3120 The function returns `0' if an attribute can't be returned as a
3121 string, KEY is not a valid pointer, UID_IDX or IDX out of range,
3122 or RESERVED not `NULL'.
3125 File: gpgme.info, Node: Manipulating Keys, Next: Generating Keys, Prev: Key Signatures, Up: Key Management
3127 7.5.4 Manipulating Keys
3128 -----------------------
3130 -- Function: void gpgme_key_ref (gpgme_key_t KEY)
3131 The function `gpgme_key_ref' acquires an additional reference for
3134 -- Function: void gpgme_key_unref (gpgme_key_t KEY)
3135 The function `gpgme_key_unref' releases a reference for the key
3136 KEY. If this was the last reference, the key will be destroyed
3137 and all resources associated to it will be released.
3139 The following interface is deprecated and only provided for backward
3140 compatibility. Don't use it. It will be removed in a future version
3143 -- Function: void gpgme_key_release (gpgme_key_t KEY)
3144 The function `gpgme_key_release' is equivalent to
3148 File: gpgme.info, Node: Generating Keys, Next: Exporting Keys, Prev: Manipulating Keys, Up: Key Management
3150 7.5.5 Generating Keys
3151 ---------------------
3153 -- Function: gpgme_error_t gpgme_op_genkey (gpgme_ctx_t CTX,
3154 const char *PARMS, gpgme_data_t PUBLIC, gpgme_data_t SECRET)
3155 The function `gpgme_op_genkey' generates a new key pair in the
3156 context CTX. The meaning of PUBLIC and SECRET depends on the
3159 GnuPG does not support PUBLIC and SECRET, they should be `NULL'.
3160 GnuPG will generate a key pair and add it to the standard key
3161 ring. The fingerprint of the generated key is available with
3162 `gpgme_op_genkey_result'.
3164 GpgSM requires PUBLIC to be a writable data object. GpgSM will
3165 generate a secret key (which will be stored by `gpg-agent', and
3166 return a certificate request in PUBLIC, which then needs to be
3167 signed by the certification authority and imported before it can be
3168 used. GpgSM does not make the fingerprint available.
3170 The argument PARMS specifies parameters for the key in an XML
3171 string. The details about the format of PARMS are specific to the
3172 crypto engine used by CTX. Here is an example for GnuPG as the
3173 crypto engine (all parameters of OpenPGP key generation are
3174 documented in the GPG manual):
3176 <GnupgKeyParms format="internal">
3178 Subkey-Type: default
3179 Name-Real: Joe Tester
3180 Name-Comment: with stupid passphrase
3181 Name-Email: joe@foo.bar
3186 Here is an example for GpgSM as the crypto engine (all parameters
3187 of OpenPGP key generation are documented in the GPGSM manual):
3189 <GnupgKeyParms format="internal">
3192 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
3193 Name-Email: joe@foo.bar
3196 Strings should be given in UTF-8 encoding. The only format
3197 supported for now is "internal". The content of the
3198 `GnupgKeyParms' container is passed verbatim to the crypto
3199 backend. Control statements are not allowed.
3201 After the operation completed successfully, the result can be
3202 retrieved with `gpgme_op_genkey_result'.
3204 The function returns the error code `GPG_ERR_NO_ERROR' if the
3205 operation could be started successfully, `GPG_ERR_INV_VALUE' if
3206 PARMS is not a valid XML string, `GPG_ERR_NOT_SUPPORTED' if PUBLIC
3207 or SECRET is not valid, and `GPG_ERR_GENERAL' if no key was
3208 created by the backend.
3210 -- Function: gpgme_error_t gpgme_op_genkey_start (gpgme_ctx_t CTX,
3211 const char *PARMS, gpgme_data_t PUBLIC, gpgme_data_t SECRET)
3212 The function `gpgme_op_genkey_start' initiates a `gpgme_op_genkey'
3213 operation. It can be completed by calling `gpgme_wait' on the
3214 context. *Note Waiting For Completion::.
3216 The function returns the error code `GPG_ERR_NO_ERROR' if the
3217 operation could be started successfully, `GPG_ERR_INV_VALUE' if
3218 PARMS is not a valid XML string, and `GPG_ERR_NOT_SUPPORTED' if
3219 PUBLIC or SECRET is not `NULL'.
3221 -- Data type: gpgme_genkey_result_t
3222 This is a pointer to a structure used to store the result of a
3223 `gpgme_op_genkey' operation. After successfully generating a key,
3224 you can retrieve the pointer to the result with
3225 `gpgme_op_genkey_result'. The structure contains the following
3228 `unsigned int primary : 1'
3229 This is a flag that is set to 1 if a primary key was created
3232 `unsigned int sub : 1'
3233 This is a flag that is set to 1 if a subkey was created and
3237 This is the fingerprint of the key that was created. If both
3238 a primary and a sub key were generated, the fingerprint of
3239 the primary key will be returned. If the crypto engine does
3240 not provide the fingerprint, `fpr' will be a null pointer.
3242 -- Function: gpgme_genkey_result_t gpgme_op_genkey_result
3244 The function `gpgme_op_genkey_result' returns a
3245 `gpgme_genkey_result_t' pointer to a structure holding the result
3246 of a `gpgme_op_genkey' operation. The pointer is only valid if the
3247 last operation on the context was a `gpgme_op_genkey' or
3248 `gpgme_op_genkey_start' operation, and if this operation finished
3249 successfully. The returned pointer is only valid until the next
3250 operation is started on the context.
3253 File: gpgme.info, Node: Exporting Keys, Next: Importing Keys, Prev: Generating Keys, Up: Key Management
3255 7.5.6 Exporting Keys
3256 --------------------
3258 Exporting keys means the same as running `gpg' with the command
3259 `--export'. However, a mode flag can be used to change the way the
3260 export works. The available mode flags are described below, they may
3263 `GPGME_EXPORT_MODE_EXTERN'
3264 If this bit is set, the output is send directly to the default
3265 keyserver. This is currently only allowed for OpenPGP keys. It is
3266 good practise to not send more than a few dozens key to a
3267 keyserver at one time. Using this flag requires that the KEYDATA
3268 argument of the export function is set to `NULL'.
3270 `GPGME_EXPORT_MODE_MINIMAL'
3271 If this bit is set, the smallest possible key is exported. For
3272 OpenPGP keys it removes all signatures except for the latest
3273 self-signatures. For X.509 keys it has no effect.
3276 -- Function: gpgme_error_t gpgme_op_export (gpgme_ctx_t CTX,
3277 const char *PATTERN, gpgme_export_mode_t MODE,
3278 gpgme_data_t KEYDATA)
3279 The function `gpgme_op_export' extracts public keys and returns
3280 them in the data buffer KEYDATA. The output format of the key
3281 data returned is determined by the ASCII armor attribute set for
3282 the context CTX, or, if that is not set, by the encoding specified
3285 If PATTERN is `NULL', all available keys are returned. Otherwise,
3286 PATTERN contains an engine specific expression that is used to
3287 limit the list to all keys matching the pattern.
3289 MODE is usually 0; other values are described above.
3291 The function returns the error code `GPG_ERR_NO_ERROR' if the
3292 operation completed successfully, `GPG_ERR_INV_VALUE' if KEYDATA
3293 is not a valid empty data buffer, and passes through any errors
3294 that are reported by the crypto engine support routines.
3296 -- Function: gpgme_error_t gpgme_op_export_start (gpgme_ctx_t CTX,
3297 const char *PATTERN, gpgme_export_mode_t MODE,
3298 gpgme_data_t KEYDATA)
3299 The function `gpgme_op_export_start' initiates a `gpgme_op_export'
3300 operation. It can be completed by calling `gpgme_wait' on the
3301 context. *Note Waiting For Completion::.
3303 The function returns the error code `GPG_ERR_NO_ERROR' if the
3304 operation could be started successfully, and `GPG_ERR_INV_VALUE'
3305 if KEYDATA is not a valid empty data buffer.
3307 -- Function: gpgme_error_t gpgme_op_export_ext (gpgme_ctx_t CTX,
3308 const char *PATTERN[], gpgme_export_mode_t MODE,
3309 gpgme_data_t KEYDATA)
3310 The function `gpgme_op_export' extracts public keys and returns
3311 them in the data buffer KEYDATA. The output format of the key
3312 data returned is determined by the ASCII armor attribute set for
3313 the context CTX, or, if that is not set, by the encoding specified
3316 If PATTERN or *PATTERN is `NULL', all available keys are returned.
3317 Otherwise, PATTERN is a `NULL' terminated array of strings that
3318 are used to limit the list to all keys matching at least one of
3319 the patterns verbatim.
3321 MODE is usually 0; other values are described above.
3323 The function returns the error code `GPG_ERR_NO_ERROR' if the
3324 operation completed successfully, `GPG_ERR_INV_VALUE' if KEYDATA
3325 is not a valid empty data buffer, and passes through any errors
3326 that are reported by the crypto engine support routines.
3328 -- Function: gpgme_error_t gpgme_op_export_ext_start (gpgme_ctx_t CTX,
3329 const char *PATTERN[], gpgme_export_mode_t MODE,
3330 gpgme_data_t KEYDATA)
3331 The function `gpgme_op_export_ext_start' initiates a
3332 `gpgme_op_export_ext' operation. It can be completed by calling
3333 `gpgme_wait' on the context. *Note Waiting For Completion::.
3335 The function returns the error code `GPG_ERR_NO_ERROR' if the
3336 operation could be started successfully, and `GPG_ERR_INV_VALUE'
3337 if KEYDATA is not a valid empty data buffer.
3339 -- Function: gpgme_error_t gpgme_op_export_keys (gpgme_ctx_t CTX,
3340 gpgme_key_t keys[], gpgme_export_mode_t MODE,
3341 gpgme_data_t KEYDATA)
3342 The function `gpgme_op_export_keys' extracts public keys and
3343 returns them in the data buffer KEYDATA. The output format of the
3344 key data returned is determined by the ASCII armor attribute set
3345 for the context CTX, or, if that is not set, by the encoding
3346 specified for KEYDATA.
3348 The keys to export are taken form the `NULL' terminated array
3349 KEYS. Only keys of the the currently selected protocol of CTX
3350 which do have a fingerprint set are considered for export. Other
3351 keys specified by the KEYS are ignored. In particular OpenPGP
3352 keys retrieved via an external key listing are not included.
3354 MODE is usually 0; other values are described above.
3356 The function returns the error code `GPG_ERR_NO_ERROR' if the
3357 operation completed successfully, `GPG_ERR_INV_VALUE' if KEYDATA
3358 is not a valid empty data buffer, `GPG_ERR_NO_DATA' if no useful
3359 keys are in KEYS and passes through any errors that are reported
3360 by the crypto engine support routines.
3362 -- Function: gpgme_error_t gpgme_op_export_keys_start
3363 (gpgme_ctx_t CTX, gpgme_key_t KEYS[],
3364 gpgme_export_mode_t MODE, gpgme_data_t KEYDATA)
3365 The function `gpgme_op_export_keys_start' initiates a
3366 `gpgme_op_export_ext' operation. It can be completed by calling
3367 `gpgme_wait' on the context. *Note Waiting For Completion::.
3369 The function returns the error code `GPG_ERR_NO_ERROR' if the
3370 operation could be started successfully, and `GPG_ERR_INV_VALUE'
3371 if KEYDATA is not a valid empty data buffer, `GPG_ERR_NO_DATA' if
3372 no useful keys are in KEYS and passes through any errors that are
3373 reported by the crypto engine support routines.
3376 File: gpgme.info, Node: Importing Keys, Next: Deleting Keys, Prev: Exporting Keys, Up: Key Management
3378 7.5.7 Importing Keys
3379 --------------------
3381 Importing keys means the same as running `gpg' with the command
3384 -- Function: gpgme_error_t gpgme_op_import (gpgme_ctx_t CTX,
3385 gpgme_data_t KEYDATA)
3386 The function `gpgme_op_import' adds the keys in the data buffer
3387 KEYDATA to the key ring of the crypto engine used by CTX. The
3388 format of KEYDATA can be ASCII armored, for example, but the
3389 details are specific to the crypto engine.
3391 After the operation completed successfully, the result can be
3392 retrieved with `gpgme_op_import_result'.
3394 The function returns the error code `GPG_ERR_NO_ERROR' if the
3395 import was completed successfully, `GPG_ERR_INV_VALUE' if KEYDATA
3396 if CTX or KEYDATA is not a valid pointer, and `GPG_ERR_NO_DATA' if
3397 KEYDATA is an empty data buffer.
3399 -- Function: gpgme_error_t gpgme_op_import_start (gpgme_ctx_t CTX,
3400 gpgme_data_t KEYDATA)
3401 The function `gpgme_op_import_start' initiates a `gpgme_op_import'
3402 operation. It can be completed by calling `gpgme_wait' on the
3403 context. *Note Waiting For Completion::.
3405 The function returns the error code `GPG_ERR_NO_ERROR' if the
3406 import could be started successfully, `GPG_ERR_INV_VALUE' if
3407 KEYDATA if CTX or KEYDATA is not a valid pointer, and
3408 `GPG_ERR_NO_DATA' if KEYDATA is an empty data buffer.
3410 -- Function: gpgme_error_t gpgme_op_import_keys (gpgme_ctx_t CTX,
3412 The function `gpgme_op_import_keys' adds the keys described by the
3413 `NULL' terminated array KEYS to the key ring of the crypto engine
3414 used by CTX. This function is the general interface to move a key
3415 from one crypto engine to another as long as they are compatible.
3416 In particular it is used to actually import and make keys
3417 permanent which have been retrieved from an external source (i.e.
3418 using `GPGME_KEYLIST_MODE_EXTERN'). (1)
3420 Only keys of the the currently selected protocol of CTX are
3421 considered for import. Other keys specified by the KEYS are
3422 ignored. As of now all considered keys must have been retrieved
3423 using the same method, that is the used key listing mode must be
3426 After the operation completed successfully, the result can be
3427 retrieved with `gpgme_op_import_result'.
3429 The function returns the error code `GPG_ERR_NO_ERROR' if the
3430 import was completed successfully, `GPG_ERR_INV_VALUE' if KEYDATA
3431 if CTX or KEYDATA is not a valid pointer, `GPG_ERR_CONFLICT' if
3432 the key listing mode does not match, and `GPG_ERR_NO_DATA' if no
3433 keys are considered for export.
3435 -- Function: gpgme_error_t gpgme_op_import_keys_start
3436 (gpgme_ctx_t CTX, gpgme_key_t *KEYS)
3437 The function `gpgme_op_import_keys_start' initiates a
3438 `gpgme_op_import_keys' operation. It can be completed by calling
3439 `gpgme_wait' on the context. *Note Waiting For Completion::.
3441 The function returns the error code `GPG_ERR_NO_ERROR' if the
3442 import was completed successfully, `GPG_ERR_INV_VALUE' if KEYDATA
3443 if CTX or KEYDATA is not a valid pointer, `GPG_ERR_CONFLICT' if
3444 the key listing mode does not match, and `GPG_ERR_NO_DATA' if no
3445 keys are considered for export.
3447 -- Data type: gpgme_import_status_t
3448 This is a pointer to a structure used to store a part of the
3449 result of a `gpgme_op_import' operation. For each considered key
3450 one status is added that contains information about the result of
3451 the import. The structure contains the following members:
3453 `gpgme_import_status_t next'
3454 This is a pointer to the next status structure in the linked
3455 list, or `NULL' if this is the last element.
3458 This is the fingerprint of the key that was considered.
3460 `gpgme_error_t result'
3461 If the import was not successful, this is the error value
3462 that caused the import to fail. Otherwise the error code is
3465 `unsigned int status'
3466 This is a bit-wise OR of the following flags that give more
3467 information about what part of the key was imported. If the
3468 key was already known, this might be 0.
3474 The key contained new user IDs.
3477 The key contained new signatures.
3479 `GPGME_IMPORT_SUBKEY'
3480 The key contained new sub keys.
3482 `GPGME_IMPORT_SECRET'
3483 The key contained a secret key.
3485 -- Data type: gpgme_import_result_t
3486 This is a pointer to a structure used to store the result of a
3487 `gpgme_op_import' operation. After a successful import operation,
3488 you can retrieve the pointer to the result with
3489 `gpgme_op_import_result'. The structure contains the following
3493 The total number of considered keys.
3496 The number of keys without user ID.
3499 The total number of imported keys.
3502 The number of imported RSA keys.
3505 The number of unchanged keys.
3508 The number of new user IDs.
3511 The number of new sub keys.
3514 The number of new signatures.
3517 The number of new revocations.
3520 The total number of secret keys read.
3523 The number of imported secret keys.
3526 The number of unchanged secret keys.
3529 The number of keys not imported.
3531 `gpgme_import_status_t imports'
3532 A list of gpgme_import_status_t objects which contain more
3533 information about the keys for which an import was attempted.
3535 -- Function: gpgme_import_result_t gpgme_op_import_result
3537 The function `gpgme_op_import_result' returns a
3538 `gpgme_import_result_t' pointer to a structure holding the result
3539 of a `gpgme_op_import' operation. The pointer is only valid if
3540 the last operation on the context was a `gpgme_op_import' or
3541 `gpgme_op_import_start' operation, and if this operation finished
3542 successfully. The returned pointer is only valid until the next
3543 operation is started on the context.
3545 The following interface is deprecated and only provided for backward
3546 compatibility. Don't use it. It will be removed in a future version
3549 -- Function: gpgme_error_t gpgme_op_import_ext (gpgme_ctx_t CTX,
3550 gpgme_data_t KEYDATA, int *NR)
3551 The function `gpgme_op_import_ext' is equivalent to:
3553 gpgme_error_t err = gpgme_op_import (ctx, keydata);
3556 gpgme_import_result_t result = gpgme_op_import_result (ctx);
3557 *nr = result->considered;
3560 ---------- Footnotes ----------
3562 (1) Thus it is a replacement for the usual workaround of exporting
3563 and then importing a key to make an X.509 key permanent.
3566 File: gpgme.info, Node: Deleting Keys, Next: Changing Passphrases, Prev: Importing Keys, Up: Key Management
3571 -- Function: gpgme_error_t gpgme_op_delete (gpgme_ctx_t CTX,
3572 const gpgme_key_t KEY, int ALLOW_SECRET)
3573 The function `gpgme_op_delete' deletes the key KEY from the key
3574 ring of the crypto engine used by CTX. If ALLOW_SECRET is `0',
3575 only public keys are deleted, otherwise secret keys are deleted as
3576 well, if that is supported.
3578 The function returns the error code `GPG_ERR_NO_ERROR' if the key
3579 was deleted successfully, `GPG_ERR_INV_VALUE' if CTX or KEY is not
3580 a valid pointer, `GPG_ERR_NO_PUBKEY' if KEY could not be found in
3581 the keyring, `GPG_ERR_AMBIGUOUS_NAME' if the key was not specified
3582 unambiguously, and `GPG_ERR_CONFLICT' if the secret key for KEY is
3583 available, but ALLOW_SECRET is zero.
3585 -- Function: gpgme_error_t gpgme_op_delete_start (gpgme_ctx_t CTX,
3586 const gpgme_key_t KEY, int ALLOW_SECRET)
3587 The function `gpgme_op_delete_start' initiates a `gpgme_op_delete'
3588 operation. It can be completed by calling `gpgme_wait' on the
3589 context. *Note Waiting For Completion::.
3591 The function returns the error code `GPG_ERR_NO_ERROR' if the
3592 operation was started successfully, and `GPG_ERR_INV_VALUE' if CTX
3593 or KEY is not a valid pointer.
3596 File: gpgme.info, Node: Changing Passphrases, Next: Advanced Key Editing, Prev: Deleting Keys, Up: Key Management
3598 7.5.9 Changing Passphrases
3599 --------------------------
3601 -- Function: gpgme_error_t gpgme_op_passwd (gpgme_ctx_t CTX,
3602 const gpgme_key_t KEY, unsigned int FLAGS)
3603 The function `gpgme_op_passwd' changes the passphrase of the
3604 private key associated with KEY. The only allowed value for FLAGS
3605 is `0'. The backend engine will usually popup a window to ask for
3606 the old and the new passphrase. Thus this function is not useful
3607 in a server application (where passphrases are not required
3610 Note that old `gpg' engines (before version 2.0.15) do not support
3611 this command and will silently ignore it.
3613 -- Function: gpgme_error_t gpgme_op_passwd_start (gpgme_ctx_t CTX,
3614 const gpgme_key_t KEY, unsigned int FLAGS)
3615 The function `gpgme_op_passwd_start' initiates a `gpgme_op_passwd'
3616 operation. It can be completed by calling `gpgme_wait' on the
3617 context. *Note Waiting For Completion::.
3619 The function returns `0' if the operation was started successfully,
3620 and an error code if one of the arguments is not valid or the
3621 oepration could not be started.
3624 File: gpgme.info, Node: Advanced Key Editing, Prev: Changing Passphrases, Up: Key Management
3626 7.5.10 Advanced Key Editing
3627 ---------------------------
3629 -- Data type: gpgme_error_t (*gpgme_edit_cb_t) (void *HANDLE,
3630 gpgme_status_code_t STATUS, const char *ARGS, int FD)
3631 The `gpgme_edit_cb_t' type is the type of functions which GPGME
3632 calls if it a key edit operation is on-going. The status code
3633 STATUS and the argument line ARGS are passed through by GPGME from
3634 the crypto engine. The file descriptor FD is -1 for normal status
3635 messages. If STATUS indicates a command rather than a status
3636 message, the response to the command should be written to FD. The
3637 HANDLE is provided by the user at start of operation.
3639 The function should return `GPG_ERR_NO_ERROR' or an error value.
3641 -- Function: gpgme_error_t gpgme_op_edit (gpgme_ctx_t CTX,
3642 gpgme_key_t KEY, gpgme_edit_cb_t FNC, void *HANDLE,
3644 The function `gpgme_op_edit' processes the key KEY interactively,
3645 using the edit callback function FNC with the handle HANDLE. The
3646 callback is invoked for every status and command request from the
3647 crypto engine. The output of the crypto engine is written to the
3650 Note that the protocol between the callback function and the crypto
3651 engine is specific to the crypto engine and no further support in
3652 implementing this protocol correctly is provided by GPGME.
3654 The function returns the error code `GPG_ERR_NO_ERROR' if the edit
3655 operation completes successfully, `GPG_ERR_INV_VALUE' if CTX or
3656 KEY is not a valid pointer, and any error returned by the crypto
3657 engine or the edit callback handler.
3659 -- Function: gpgme_error_t gpgme_op_edit_start (gpgme_ctx_t CTX,
3660 gpgme_key_t KEY, gpgme_edit_cb_t FNC, void *HANDLE,
3662 The function `gpgme_op_edit_start' initiates a `gpgme_op_edit'
3663 operation. It can be completed by calling `gpgme_wait' on the
3664 context. *Note Waiting For Completion::.
3666 The function returns the error code `GPG_ERR_NO_ERROR' if the
3667 operation was started successfully, and `GPG_ERR_INV_VALUE' if CTX
3668 or KEY is not a valid pointer.
3670 -- Function: gpgme_error_t gpgme_op_card_edit (gpgme_ctx_t CTX,
3671 gpgme_key_t KEY, gpgme_edit_cb_t FNC, void *HANDLE,
3673 The function `gpgme_op_card_edit' is analogous to `gpgme_op_edit',
3674 but should be used to process the smart card corresponding to the
3677 -- Function: gpgme_error_t gpgme_op_card_edit_start (gpgme_ctx_t CTX,
3678 gpgme_key_t KEY, gpgme_edit_cb_t FNC, void *HANDLE,
3680 The function `gpgme_op_card_edit_start' initiates a
3681 `gpgme_op_card_edit' operation. It can be completed by calling
3682 `gpgme_wait' on the context. *Note Waiting For Completion::.
3684 The function returns the error code `GPG_ERR_NO_ERROR' if the
3685 operation was started successfully, and `GPG_ERR_INV_VALUE' if CTX
3686 or KEY is not a valid pointer.
3689 File: gpgme.info, Node: Trust Item Management, Next: Crypto Operations, Prev: Key Management, Up: Contexts
3691 7.6 Trust Item Management
3692 =========================
3694 *Caution:* The trust items interface is experimental.
3696 -- Data type: gpgme_trust_item_t
3697 The `gpgme_trust_item_t' type is a pointer to a trust item object.
3698 It has the following members:
3701 This is a string describing the key to which this trust items
3705 This is the type of the trust item. A value of 1 refers to a
3706 key, a value of 2 refers to a user ID.
3709 This is the trust level.
3712 The owner trust if `type' is 1.
3715 The calculated validity.
3718 The user name if `type' is 2.
3722 * Listing Trust Items:: Browsing the list of available trust items.
3723 * Information About Trust Items:: Requesting information about trust items.
3724 * Manipulating Trust Items:: Operations on trust items.
3727 File: gpgme.info, Node: Listing Trust Items, Next: Information About Trust Items, Up: Trust Item Management
3729 7.6.1 Listing Trust Items
3730 -------------------------
3732 -- Function: gpgme_error_t gpgme_op_trustlist_start (gpgme_ctx_t CTX,
3733 const char *PATTERN, int MAX_LEVEL)
3734 The function `gpgme_op_trustlist_start' initiates a trust item
3735 listing operation inside the context CTX. It sets everything up
3736 so that subsequent invocations of `gpgme_op_trustlist_next' return
3737 the trust items in the list.
3739 The string PATTERN contains an engine specific expression that is
3740 used to limit the list to all trust items matching the pattern. It
3741 can not be the empty string.
3743 The argument MAX_LEVEL is currently ignored.
3745 The context will be busy until either all trust items are received
3746 (and `gpgme_op_trustlist_next' returns `GPG_ERR_EOF'), or
3747 `gpgme_op_trustlist_end' is called to finish the operation.
3749 The function returns the error code `GPG_ERR_INV_VALUE' if CTX is
3750 not a valid pointer, and passes through any errors that are
3751 reported by the crypto engine support routines.
3753 -- Function: gpgme_error_t gpgme_op_trustlist_next (gpgme_ctx_t CTX,
3754 gpgme_trust_item_t *R_ITEM)
3755 The function `gpgme_op_trustlist_next' returns the next trust item
3756 in the list created by a previous `gpgme_op_trustlist_start'
3757 operation in the context CTX. The trust item can be destroyed
3758 with `gpgme_trust_item_release'. *Note Manipulating Trust Items::.
3760 This is the only way to get at `gpgme_trust_item_t' objects in
3763 If the last trust item in the list has already been returned,
3764 `gpgme_op_trustlist_next' returns `GPG_ERR_EOF'.
3766 The function returns the error code `GPG_ERR_INV_VALUE' if CTX or
3767 R_ITEM is not a valid pointer, and `GPG_ERR_ENOMEM' if there is
3768 not enough memory for the operation.
3770 -- Function: gpgme_error_t gpgme_op_trustlist_end (gpgme_ctx_t CTX)
3771 The function `gpgme_op_trustlist_end' ends a pending trust list
3772 operation in the context CTX.
3774 The function returns the error code `GPG_ERR_INV_VALUE' if CTX is
3775 not a valid pointer, and `GPG_ERR_ENOMEM' if at some time during
3776 the operation there was not enough memory available.
3779 File: gpgme.info, Node: Information About Trust Items, Next: Manipulating Trust Items, Prev: Listing Trust Items, Up: Trust Item Management
3781 7.6.2 Information About Trust Items
3782 -----------------------------------
3784 The following interfaces are deprecated and only provided for backward
3785 compatibility. Don't use them. They will be removed in a future
3788 Trust items have attributes which can be queried using the interfaces
3789 below. The attribute identifiers are shared with those for key
3790 attributes. *Note Information About Keys::.
3792 -- Function: const char * gpgme_trust_item_get_string_attr
3793 (gpgme_trust_item_t ITEM, gpgme_attr_t WHAT,
3794 const void *RESERVED, int IDX)
3795 The function `gpgme_trust_item_get_string_attr' returns the value
3796 of the string-representable attribute WHAT of trust item ITEM.
3797 The arguments IDX and RESERVED are reserved for later use and
3798 should be `0' and `NULL' respectively.
3800 The string returned is only valid as long as the key is valid.
3802 The function returns `0' if an attribute can't be returned as a
3803 string, KEY is not a valid pointer, IDX out of range, or RESERVED
3806 -- Function: int gpgme_trust_item_get_int_attr
3807 (gpgme_trust_item_t ITEM, gpgme_attr_t WHAT,
3808 const void *RESERVED, int IDX)
3809 The function `gpgme_trust_item_get_int_attr' returns the value of
3810 the number-representable attribute WHAT of trust item ITEM. If
3811 the attribute occurs more than once in the trust item, the index
3812 is specified by IDX. However, currently no such attribute exists,
3813 so IDX should be `0'. The argument RESERVED is reserved for later
3814 use and should be `NULL'.
3816 The function returns `0' if the attribute can't be returned as a
3817 number, KEY is not a valid pointer, IDX out of range, or RESERVED
3821 File: gpgme.info, Node: Manipulating Trust Items, Prev: Information About Trust Items, Up: Trust Item Management
3823 7.6.3 Manipulating Trust Items
3824 ------------------------------
3826 -- Function: void gpgme_trust_item_ref (gpgme_trust_item_t ITEM)
3827 The function `gpgme_trust_item_ref' acquires an additional
3828 reference for the trust item ITEM.
3830 -- Function: void gpgme_trust_item_unref (gpgme_trust_item_t ITEM)
3831 The function `gpgme_trust_item_unref' releases a reference for the
3832 trust item ITEM. If this was the last reference, the trust item
3833 will be destroyed and all resources associated to it will be
3836 The following interface is deprecated and only provided for backward
3837 compatibility. Don't use it. It will be removed in a future version
3840 -- Function: void gpgme_trust_item_release (gpgme_trust_item_t ITEM)
3841 The function `gpgme_trust_item_release' is an alias for
3842 `gpgme_trust_item_unref'.
3845 File: gpgme.info, Node: Crypto Operations, Next: Run Control, Prev: Trust Item Management, Up: Contexts
3847 7.7 Crypto Operations
3848 =====================
3850 Sometimes, the result of a crypto operation returns a list of invalid
3851 keys encountered in processing the request. The following structure is
3852 used to hold information about such a key.
3854 -- Data type: gpgme_invalid_key_t
3855 This is a pointer to a structure used to store a part of the
3856 result of a crypto operation which takes user IDs as one input
3857 parameter. The structure contains the following members:
3859 `gpgme_invalid_key_t next'
3860 This is a pointer to the next invalid key structure in the
3861 linked list, or `NULL' if this is the last element.
3864 The fingerprint or key ID of the invalid key encountered.
3866 `gpgme_error_t reason'
3867 An error code describing the reason why the key was found
3872 * Decrypt:: Decrypting a ciphertext.
3873 * Verify:: Verifying a signature.
3874 * Decrypt and Verify:: Decrypting a signed ciphertext.
3875 * Sign:: Creating a signature.
3876 * Encrypt:: Encrypting a plaintext.
3879 File: gpgme.info, Node: Decrypt, Next: Verify, Up: Crypto Operations
3884 -- Function: gpgme_error_t gpgme_op_decrypt (gpgme_ctx_t CTX,
3885 gpgme_data_t CIPHER, gpgme_data_t PLAIN)
3886 The function `gpgme_op_decrypt' decrypts the ciphertext in the
3887 data object CIPHER and stores it into the data object PLAIN.
3889 The function returns the error code `GPG_ERR_NO_ERROR' if the
3890 ciphertext could be decrypted successfully, `GPG_ERR_INV_VALUE' if
3891 CTX, CIPHER or PLAIN is not a valid pointer, `GPG_ERR_NO_DATA' if
3892 CIPHER does not contain any data to decrypt,
3893 `GPG_ERR_DECRYPT_FAILED' if CIPHER is not a valid cipher text,
3894 `GPG_ERR_BAD_PASSPHRASE' if the passphrase for the secret key
3895 could not be retrieved, and passes through any errors that are
3896 reported by the crypto engine support routines.
3898 -- Function: gpgme_error_t gpgme_op_decrypt_start (gpgme_ctx_t CTX,
3899 gpgme_data_t CIPHER, gpgme_data_t PLAIN)
3900 The function `gpgme_op_decrypt_start' initiates a
3901 `gpgme_op_decrypt' operation. It can be completed by calling
3902 `gpgme_wait' on the context. *Note Waiting For Completion::.
3904 The function returns the error code `GPG_ERR_NO_ERROR' if the
3905 operation could be started successfully, and `GPG_ERR_INV_VALUE'
3906 if CIPHER or PLAIN is not a valid pointer.
3908 -- Data type: gpgme_recipient_t
3909 This is a pointer to a structure used to store information about
3910 the recipient of an encrypted text which is decrypted in a
3911 `gpgme_op_decrypt' operation. This information (except for the
3912 status field) is even available before the operation finished
3913 successfully, for example in a passphrase callback. The structure
3914 contains the following members:
3916 `gpgme_recipient_t next'
3917 This is a pointer to the next recipient structure in the
3918 linked list, or `NULL' if this is the last element.
3920 `gpgme_pubkey_algo_t'
3921 The public key algorithm used in the encryption.
3923 `unsigned int wrong_key_usage : 1'
3924 This is true if the key was not used according to its policy.
3927 This is the key ID of the key (in hexadecimal digits) used as
3930 `gpgme_error_t status'
3931 This is an error number with the error code GPG_ERR_NO_SECKEY
3932 if the secret key for this recipient is not available, and 0
3935 -- Data type: gpgme_decrypt_result_t
3936 This is a pointer to a structure used to store the result of a
3937 `gpgme_op_decrypt' operation. After successfully decrypting data,
3938 you can retrieve the pointer to the result with
3939 `gpgme_op_decrypt_result'. The structure contains the following
3942 `char *unsupported_algorithm'
3943 If an unsupported algorithm was encountered, this string
3944 describes the algorithm that is not supported.
3946 `unsigned int wrong_key_usage : 1'
3947 This is true if the key was not used according to its policy.
3949 `gpgme_recipient_t recipients'
3950 This is a linked list of recipients to which this message was
3954 This is the filename of the original plaintext message file
3955 if it is known, otherwise this is a null pointer.
3957 -- Function: gpgme_decrypt_result_t gpgme_op_decrypt_result
3959 The function `gpgme_op_decrypt_result' returns a
3960 `gpgme_decrypt_result_t' pointer to a structure holding the result
3961 of a `gpgme_op_decrypt' operation. The pointer is only valid if
3962 the last operation on the context was a `gpgme_op_decrypt' or
3963 `gpgme_op_decrypt_start' operation. If the operation failed this
3964 might be a `NULL' pointer. The returned pointer is only valid
3965 until the next operation is started on the context.
3968 File: gpgme.info, Node: Verify, Next: Decrypt and Verify, Prev: Decrypt, Up: Crypto Operations
3973 -- Function: gpgme_error_t gpgme_op_verify (gpgme_ctx_t CTX,
3974 gpgme_data_t SIG, gpgme_data_t SIGNED_TEXT,
3976 The function `gpgme_op_verify' verifies that the signature in the
3977 data object SIG is a valid signature. If SIG is a detached
3978 signature, then the signed text should be provided in SIGNED_TEXT
3979 and PLAIN should be a null pointer. Otherwise, if SIG is a normal
3980 (or cleartext) signature, SIGNED_TEXT should be a null pointer and
3981 PLAIN should be a writable data object that will contain the
3982 plaintext after successful verification.
3984 The results of the individual signature verifications can be
3985 retrieved with `gpgme_op_verify_result'.
3987 The function returns the error code `GPG_ERR_NO_ERROR' if the
3988 operation could be completed successfully, `GPG_ERR_INV_VALUE' if
3989 CTX, SIG or PLAIN is not a valid pointer, `GPG_ERR_NO_DATA' if SIG
3990 does not contain any data to verify, and passes through any errors
3991 that are reported by the crypto engine support routines.
3993 -- Function: gpgme_error_t gpgme_op_verify_start (gpgme_ctx_t CTX,
3994 gpgme_data_t SIG, gpgme_data_t SIGNED_TEXT,
3996 The function `gpgme_op_verify_start' initiates a `gpgme_op_verify'
3997 operation. It can be completed by calling `gpgme_wait' on the
3998 context. *Note Waiting For Completion::.
4000 The function returns the error code `GPG_ERR_NO_ERROR' if the
4001 operation could be started successfully, `GPG_ERR_INV_VALUE' if
4002 CTX, SIG or PLAIN is not a valid pointer, and `GPG_ERR_NO_DATA' if
4003 SIG or PLAIN does not contain any data to verify.
4005 -- Data type: gpgme_sig_notation_t
4006 This is a pointer to a structure used to store a part of the
4007 result of a `gpgme_op_verify' operation. The structure contains
4008 the following members:
4010 `gpgme_sig_notation_t next'
4011 This is a pointer to the next new signature notation
4012 structure in the linked list, or `NULL' if this is the last
4016 The name of the notation field. If this is `NULL', then the
4017 member `value' will contain a policy URL.
4020 The length of the `name' field. For strings the length is
4021 counted without the trailing binary zero.
4024 The value of the notation field. If `name' is `NULL', then
4025 this is a policy URL.
4028 The length of the `value' field. For strings the length is
4029 counted without the trailing binary zero.
4031 `gpgme_sig_notation_flags_t flags'
4032 The accumulated flags field. This field contains the flags
4033 associated with the notation data in an accumulated form
4034 which can be used as an argument to the function
4035 `gpgme_sig_notation_add'. The value `flags' is a bitwise-or
4036 combination of one or multiple of the following bit values:
4038 `GPGME_SIG_NOTATION_HUMAN_READABLE'
4039 The `GPGME_SIG_NOTATION_HUMAN_READABLE' symbol specifies
4040 that the notation data is in human readable form
4042 `GPGME_SIG_NOTATION_CRITICAL'
4043 The `GPGME_SIG_NOTATION_CRITICAL' symbol specifies that
4044 the notation data is critical.
4047 `unsigned int human_readable : 1'
4048 This is true if the `GPGME_SIG_NOTATION_HUMAN_READABLE' flag
4049 is set and false otherwise. This flag is only valid for
4050 notation data, not for policy URLs.
4052 `unsigned int critical : 1'
4053 This is true if the `GPGME_SIG_NOTATION_CRITICAL' flag is set
4054 and false otherwise. This flag is valid for notation data
4058 -- Data type: gpgme_signature_t
4059 This is a pointer to a structure used to store a part of the
4060 result of a `gpgme_op_verify' operation. The structure contains
4061 the following members:
4063 `gpgme_signature_t next'
4064 This is a pointer to the next new signature structure in the
4065 linked list, or `NULL' if this is the last element.
4067 `gpgme_sigsum_t summary'
4068 This is a bit vector giving a summary of the signature
4069 status. It provides an easy interface to a defined semantic
4070 of the signature status. Checking just one bit is sufficient
4071 to see whether a signature is valid without any restrictions.
4073 The defined bits are:
4074 `GPGME_SIGSUM_VALID'
4075 The signature is fully valid.
4077 `GPGME_SIGSUM_GREEN'
4078 The signature is good but one might want to display some
4079 extra information. Check the other bits.
4082 The signature is bad. It might be useful to check other
4083 bits and display more information, i.e. a revoked
4084 certificate might not render a signature invalid when
4085 the message was received prior to the cause for the
4088 `GPGME_SIGSUM_KEY_REVOKED'
4089 The key or at least one certificate has been revoked.
4091 `GPGME_SIGSUM_KEY_EXPIRED'
4092 The key or one of the certificates has expired. It is
4093 probably a good idea to display the date of the
4096 `GPGME_SIGSUM_SIG_EXPIRED'
4097 The signature has expired.
4099 `GPGME_SIGSUM_KEY_MISSING'
4100 Can't verify due to a missing key or certificate.
4102 `GPGME_SIGSUM_CRL_MISSING'
4103 The CRL (or an equivalent mechanism) is not available.
4105 `GPGME_SIGSUM_CRL_TOO_OLD'
4106 Available CRL is too old.
4108 `GPGME_SIGSUM_BAD_POLICY'
4109 A policy requirement was not met.
4111 `GPGME_SIGSUM_SYS_ERROR'
4112 A system error occured.
4115 This is the fingerprint or key ID of the signature.
4117 `gpgme_error_t status'
4118 This is the status of the signature. In particular, the
4119 following status codes are of interest:
4122 This status indicates that the signature is valid. For
4123 the combined result this status means that all
4124 signatures are valid.
4126 `GPG_ERR_SIG_EXPIRED'
4127 This status indicates that the signature is valid but
4128 expired. For the combined result this status means
4129 that all signatures are valid and expired.
4131 `GPG_ERR_KEY_EXPIRED'
4132 This status indicates that the signature is valid but
4133 the key used to verify the signature has expired. For
4134 the combined result this status means that all
4135 signatures are valid and all keys are expired.
4137 `GPG_ERR_CERT_REVOKED'
4138 This status indicates that the signature is valid but
4139 the key used to verify the signature has been revoked.
4140 For the combined result this status means that all
4141 signatures are valid and all keys are revoked.
4143 `GPG_ERR_BAD_SIGNATURE'
4144 This status indicates that the signature is invalid.
4145 For the combined result this status means that all
4146 signatures are invalid.
4149 This status indicates that the signature could not be
4150 verified due to a missing key. For the combined
4151 result this status means that all signatures could not
4152 be checked due to missing keys.
4155 This status indicates that there was some other error
4156 which prevented the signature verification.
4158 `gpgme_sig_notation_t notations'
4159 This is a linked list with the notation data and policy URLs.
4161 `unsigned long timestamp'
4162 The creation timestamp of this signature.
4164 `unsigned long exp_timestamp'
4165 The expiration timestamp of this signature, or 0 if the
4166 signature does not expire.
4168 `unsigned int wrong_key_usage : 1'
4169 This is true if the key was not used according to its policy.
4171 `unsigned int pka_trust : 2'
4172 This is set to the trust information gained by means of the
4173 PKA system. Values are:
4175 No PKA information available or verification not
4179 PKA verification failed.
4182 PKA verification succeeded.
4185 Reserved for future use.
4186 Depending on the configuration of the engine, this metric may
4187 also be reflected by the validity of the signature.
4189 `unsigned int chain_model : 1'
4190 This is true if the validity of the signature has been
4191 checked using the chain model. In the chain model the time
4192 the signature has been created must be within the validity
4193 period of the certificate and the time the certificate itself
4194 has been created must be within the validity period of the
4195 issuing certificate. In contrast the default validation model
4196 checks the validity of signature as well at the entire
4197 certificate chain at the current time.
4199 `gpgme_validity_t validity'
4200 The validity of the signature.
4202 `gpgme_error_t validity_reason'
4203 If a signature is not valid, this provides a reason why.
4205 `gpgme_pubkey_algo_t'
4206 The public key algorithm used to create this signature.
4209 The hash algorithm used to create this signature.
4211 -- Data type: gpgme_verify_result_t
4212 This is a pointer to a structure used to store the result of a
4213 `gpgme_op_verify' operation. After verifying a signature, you can
4214 retrieve the pointer to the result with `gpgme_op_verify_result'.
4215 If the operation failed this might be a `NULL' pointer. The
4216 structure contains the following member:
4218 `gpgme_signature_t signatures'
4219 A linked list with information about all signatures for which
4220 a verification was attempted.
4223 This is the filename of the original plaintext message file
4224 if it is known, otherwise this is a null pointer.
4226 -- Function: gpgme_verify_result_t gpgme_op_verify_result
4228 The function `gpgme_op_verify_result' returns a
4229 `gpgme_verify_result_t' pointer to a structure holding the result
4230 of a `gpgme_op_verify' operation. The pointer is only valid if
4231 the last operation on the context was a `gpgme_op_verify',
4232 `gpgme_op_verify_start', `gpgme_op_decrypt_verify' or
4233 `gpgme_op_decrypt_verify_start' operation, and if this operation
4234 finished successfully (for `gpgme_op_decrypt_verify' and
4235 `gpgme_op_decrypt_verify_start', the error code `GPG_ERR_NO_DATA'
4236 counts as successful in this context). The returned pointer is
4237 only valid until the next operation is started on the context.
4239 The following interfaces are deprecated and only provided for
4240 backward compatibility. Don't use them. They will be removed in a
4241 future version of GPGME.
4243 -- Data type: enum gpgme_sig_stat_t
4244 The `gpgme_sig_stat_t' type holds the result of a signature check,
4245 or the combined result of all signatures. The following results
4248 `GPGME_SIG_STAT_NONE'
4249 This status should not occur in normal operation.
4251 `GPGME_SIG_STAT_GOOD'
4252 This status indicates that the signature is valid. For the
4253 combined result this status means that all signatures are
4256 `GPGME_SIG_STAT_GOOD_EXP'
4257 This status indicates that the signature is valid but
4258 expired. For the combined result this status means that all
4259 signatures are valid and expired.
4261 `GPGME_SIG_STAT_GOOD_EXPKEY'
4262 This status indicates that the signature is valid but the key
4263 used to verify the signature has expired. For the combined
4264 result this status means that all signatures are valid and
4265 all keys are expired.
4267 `GPGME_SIG_STAT_BAD'
4268 This status indicates that the signature is invalid. For the
4269 combined result this status means that all signatures are
4272 `GPGME_SIG_STAT_NOKEY'
4273 This status indicates that the signature could not be
4274 verified due to a missing key. For the combined result this
4275 status means that all signatures could not be checked due to
4278 `GPGME_SIG_STAT_NOSIG'
4279 This status indicates that the signature data provided was
4280 not a real signature.
4282 `GPGME_SIG_STAT_ERROR'
4283 This status indicates that there was some other error which
4284 prevented the signature verification.
4286 `GPGME_SIG_STAT_DIFF'
4287 For the combined result this status means that at least two
4288 signatures have a different status. You can get each key's
4289 status with `gpgme_get_sig_status'.
4291 -- Function: const char * gpgme_get_sig_status (gpgme_ctx_t CTX,
4292 int IDX, gpgme_sig_stat_t *R_STAT, time_t *R_CREATED)
4293 The function `gpgme_get_sig_status' is equivalent to:
4295 gpgme_verify_result_t result;
4296 gpgme_signature_t sig;
4298 result = gpgme_op_verify_result (ctx);
4299 sig = result->signatures;
4311 switch (gpg_err_code (sig->status))
4313 case GPG_ERR_NO_ERROR:
4314 *r_stat = GPGME_SIG_STAT_GOOD;
4317 case GPG_ERR_BAD_SIGNATURE:
4318 *r_stat = GPGME_SIG_STAT_BAD;
4321 case GPG_ERR_NO_PUBKEY:
4322 *r_stat = GPGME_SIG_STAT_NOKEY;
4325 case GPG_ERR_NO_DATA:
4326 *r_stat = GPGME_SIG_STAT_NOSIG;
4329 case GPG_ERR_SIG_EXPIRED:
4330 *r_stat = GPGME_SIG_STAT_GOOD_EXP;
4333 case GPG_ERR_KEY_EXPIRED:
4334 *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY;
4338 *r_stat = GPGME_SIG_STAT_ERROR;
4343 *r_created = sig->timestamp;
4346 -- Function: const char * gpgme_get_sig_string_attr (gpgme_ctx_t CTX,
4347 int IDX, gpgme_attr_t WHAT, int WHATIDX)
4348 The function `gpgme_get_sig_string_attr' is equivalent to:
4350 gpgme_verify_result_t result;
4351 gpgme_signature_t sig;
4353 result = gpgme_op_verify_result (ctx);
4354 sig = result->signatures;
4366 case GPGME_ATTR_FPR:
4369 case GPGME_ATTR_ERRTOK:
4371 return sig->wrong_key_usage ? "Wrong_Key_Usage" : "";
4380 -- Function: const char * gpgme_get_sig_ulong_attr (gpgme_ctx_t CTX,
4381 int IDX, gpgme_attr_t WAHT, int WHATIDX)
4382 The function `gpgme_get_sig_ulong_attr' is equivalent to:
4384 gpgme_verify_result_t result;
4385 gpgme_signature_t sig;
4387 result = gpgme_op_verify_result (ctx);
4388 sig = result->signatures;
4400 case GPGME_ATTR_CREATED:
4401 return sig->timestamp;
4403 case GPGME_ATTR_EXPIRE:
4404 return sig->exp_timestamp;
4406 case GPGME_ATTR_VALIDITY:
4407 return (unsigned long) sig->validity;
4409 case GPGME_ATTR_SIG_STATUS:
4410 switch (sig->status)
4412 case GPG_ERR_NO_ERROR:
4413 return GPGME_SIG_STAT_GOOD;
4415 case GPG_ERR_BAD_SIGNATURE:
4416 return GPGME_SIG_STAT_BAD;
4418 case GPG_ERR_NO_PUBKEY:
4419 return GPGME_SIG_STAT_NOKEY;
4421 case GPG_ERR_NO_DATA:
4422 return GPGME_SIG_STAT_NOSIG;
4424 case GPG_ERR_SIG_EXPIRED:
4425 return GPGME_SIG_STAT_GOOD_EXP;
4427 case GPG_ERR_KEY_EXPIRED:
4428 return GPGME_SIG_STAT_GOOD_EXPKEY;
4431 return GPGME_SIG_STAT_ERROR;
4434 case GPGME_ATTR_SIG_SUMMARY:
4435 return sig->summary;
4442 -- Function: const char * gpgme_get_sig_key (gpgme_ctx_t CTX, int IDX,
4444 The function `gpgme_get_sig_key' is equivalent to:
4446 gpgme_verify_result_t result;
4447 gpgme_signature_t sig;
4449 result = gpgme_op_verify_result (ctx);
4450 sig = result->signatures;
4458 return gpg_error (GPG_ERR_EOF);
4460 return gpgme_get_key (ctx, sig->fpr, r_key, 0);
4463 File: gpgme.info, Node: Decrypt and Verify, Next: Sign, Prev: Verify, Up: Crypto Operations
4465 7.7.3 Decrypt and Verify
4466 ------------------------
4468 -- Function: gpgme_error_t gpgme_op_decrypt_verify (gpgme_ctx_t CTX,
4469 gpgme_data_t CIPHER, gpgme_data_t PLAIN)
4470 The function `gpgme_op_decrypt_verify' decrypts the ciphertext in
4471 the data object CIPHER and stores it into the data object PLAIN.
4472 If CIPHER contains signatures, they will be verified.
4474 After the operation completed, `gpgme_op_decrypt_result' and
4475 `gpgme_op_verify_result' can be used to retrieve more information
4476 about the signatures.
4478 If the error code `GPG_ERR_NO_DATA' is returned, CIPHER does not
4479 contain any data to decrypt. However, it might still be signed.
4480 The information about detected signatures is available with
4481 `gpgme_op_verify_result' in this case.
4483 The function returns the error code `GPG_ERR_NO_ERROR' if the
4484 ciphertext could be decrypted successfully, `GPG_ERR_INV_VALUE' if
4485 CTX, CIPHER or PLAIN is not a valid pointer, `GPG_ERR_NO_DATA' if
4486 CIPHER does not contain any data to decrypt,
4487 `GPG_ERR_DECRYPT_FAILED' if CIPHER is not a valid cipher text,
4488 `GPG_ERR_BAD_PASSPHRASE' if the passphrase for the secret key
4489 could not be retrieved, and passes through any errors that are
4490 reported by the crypto engine support routines.
4492 -- Function: gpgme_error_t gpgme_op_decrypt_verify (gpgme_ctx_t CTX,
4493 gpgme_data_t CIPHER, gpgme_data_t PLAIN)
4494 The function `gpgme_op_decrypt_verify_start' initiates a
4495 `gpgme_op_decrypt_verify' operation. It can be completed by
4496 calling `gpgme_wait' on the context. *Note Waiting For
4499 The function returns the error code `GPG_ERR_NO_ERROR' if the
4500 operation could be started successfully, `GPG_ERR_INV_VALUE' if
4501 CTX, CIPHER, PLAIN or R_STAT is not a valid pointer, and
4502 `GPG_ERR_NO_DATA' if CIPHER does not contain any data to decrypt.
4505 File: gpgme.info, Node: Sign, Next: Encrypt, Prev: Decrypt and Verify, Up: Crypto Operations
4510 A signature can contain signatures by one or more keys. The set of
4511 keys used to create a signatures is contained in a context, and is
4512 applied to all following signing operations in this context (until the
4517 * Selecting Signers:: How to choose the keys to sign with.
4518 * Creating a Signature:: How to create a signature.
4519 * Signature Notation Data:: How to add notation data to a signature.
4522 File: gpgme.info, Node: Selecting Signers, Next: Creating a Signature, Up: Sign
4524 7.7.4.1 Selecting Signers
4525 .........................
4527 -- Function: void gpgme_signers_clear (gpgme_ctx_t CTX)
4528 The function `gpgme_signers_clear' releases a reference for each
4529 key on the signers list and removes the list of signers from the
4532 Every context starts with an empty list.
4534 -- Function: gpgme_error_t gpgme_signers_add (gpgme_ctx_t CTX,
4535 const gpgme_key_t KEY)
4536 The function `gpgme_signers_add' adds the key KEY to the list of
4537 signers in the context CTX.
4539 Calling this function acquires an additional reference for the key.
4541 -- Function: gpgme_key_t gpgme_signers_enum (const gpgme_ctx_t CTX,
4543 The function `gpgme_signers_enum' returns the SEQth key in the
4544 list of signers in the context CTX. An additional reference is
4545 acquired for the user.
4547 If SEQ is out of range, `NULL' is returned.
4550 File: gpgme.info, Node: Creating a Signature, Next: Signature Notation Data, Prev: Selecting Signers, Up: Sign
4552 7.7.4.2 Creating a Signature
4553 ............................
4555 -- Data type: enum gpgme_sig_mode_t
4556 The `gpgme_sig_mode_t' type is used to specify the desired type of
4557 a signature. The following modes are available:
4559 `GPGME_SIG_MODE_NORMAL'
4560 A normal signature is made, the output includes the plaintext
4563 `GPGME_SIG_MODE_DETACH'
4564 A detached signature is made.
4566 `GPGME_SIG_MODE_CLEAR'
4567 A clear text signature is made. The ASCII armor and text
4568 mode settings of the context are ignored.
4570 -- Function: gpgme_error_t gpgme_op_sign (gpgme_ctx_t CTX,
4571 gpgme_data_t PLAIN, gpgme_data_t SIG, gpgme_sig_mode_t MODE)
4572 The function `gpgme_op_sign' creates a signature for the text in
4573 the data object PLAIN and returns it in the data object SIG. The
4574 type of the signature created is determined by the ASCII armor
4575 (or, if that is not set, by the encoding specified for SIG), the
4576 text mode attributes set for the context CTX and the requested
4577 signature mode MODE.
4579 After the operation completed successfully, the result can be
4580 retrieved with `gpgme_op_sign_result'.
4582 If an S/MIME signed message is created using the CMS crypto engine,
4583 the number of certificates to include in the message can be
4584 specified with `gpgme_set_include_certs'. *Note Included
4587 The function returns the error code `GPG_ERR_NO_ERROR' if the
4588 signature could be created successfully, `GPG_ERR_INV_VALUE' if
4589 CTX, PLAIN or SIG is not a valid pointer, `GPG_ERR_NO_DATA' if the
4590 signature could not be created, `GPG_ERR_BAD_PASSPHRASE' if the
4591 passphrase for the secret key could not be retrieved,
4592 `GPG_ERR_UNUSABLE_SECKEY' if there are invalid signers, and passes
4593 through any errors that are reported by the crypto engine support
4596 -- Function: gpgme_error_t gpgme_op_sign_start (gpgme_ctx_t CTX,
4597 gpgme_data_t PLAIN, gpgme_data_t SIG, gpgme_sig_mode_t MODE)
4598 The function `gpgme_op_sign_start' initiates a `gpgme_op_sign'
4599 operation. It can be completed by calling `gpgme_wait' on the
4600 context. *Note Waiting For Completion::.
4602 The function returns the error code `GPG_ERR_NO_ERROR' if the
4603 operation could be started successfully, and `GPG_ERR_INV_VALUE'
4604 if CTX, PLAIN or SIG is not a valid pointer.
4606 -- Data type: gpgme_new_signature_t
4607 This is a pointer to a structure used to store a part of the
4608 result of a `gpgme_op_sign' operation. The structure contains the
4611 `gpgme_new_signature_t next'
4612 This is a pointer to the next new signature structure in the
4613 linked list, or `NULL' if this is the last element.
4615 `gpgme_sig_mode_t type'
4616 The type of this signature.
4618 `gpgme_pubkey_algo_t'
4619 The public key algorithm used to create this signature.
4622 The hash algorithm used to create this signature.
4624 `unsigned int sig_class'
4625 The signature class of this signature.
4627 `long int timestamp'
4628 The creation timestamp of this signature.
4631 The fingerprint of the key which was used to create this
4634 -- Data type: gpgme_sign_result_t
4635 This is a pointer to a structure used to store the result of a
4636 `gpgme_op_sign' operation. After successfully generating a
4637 signature, you can retrieve the pointer to the result with
4638 `gpgme_op_sign_result'. The structure contains the following
4641 `gpgme_invalid_key_t invalid_signers'
4642 A linked list with information about all invalid keys for
4643 which a signature could not be created.
4645 `gpgme_new_signature_t signatures'
4646 A linked list with information about all signatures created.
4648 -- Function: gpgme_sign_result_t gpgme_op_sign_result (gpgme_ctx_t CTX)
4649 The function `gpgme_op_sign_result' returns a
4650 `gpgme_sign_result_t' pointer to a structure holding the result of
4651 a `gpgme_op_sign' operation. The pointer is only valid if the
4652 last operation on the context was a `gpgme_op_sign',
4653 `gpgme_op_sign_start', `gpgme_op_encrypt_sign' or
4654 `gpgme_op_encrypt_sign_start' operation. If that operation
4655 failed, the function might return a `NULL' pointer. The returned
4656 pointer is only valid until the next operation is started on the
4660 File: gpgme.info, Node: Signature Notation Data, Prev: Creating a Signature, Up: Sign
4662 7.7.4.3 Signature Notation Data
4663 ...............................
4665 Using the following functions, you can attach arbitrary notation data
4666 to a signature. This information is then available to the user when
4667 the signature is verified.
4669 -- Function: void gpgme_sig_notation_clear (gpgme_ctx_t CTX)
4670 The function `gpgme_sig_notation_clear' removes the notation data
4671 from the context CTX. Subsequent signing operations from this
4672 context will not include any notation data.
4674 Every context starts with an empty notation data list.
4676 -- Function: gpgme_error_t gpgme_sig_notation_add (gpgme_ctx_t CTX,
4677 const char *NAME, const char *VALUE,
4678 gpgme_sig_notation_flags_t FLAGS)
4679 The function `gpgme_sig_notation_add' adds the notation data with
4680 the name NAME and the value VALUE to the context CTX.
4682 Subsequent signing operations will include this notation data, as
4683 well as any other notation data that was added since the creation
4684 of the context or the last `gpgme_sig_notation_clear' operation.
4686 The arguments NAME and VALUE must be `NUL'-terminated strings in
4687 human-readable form. The flag `GPGME_SIG_NOTATION_HUMAN_READABLE'
4688 is implied (non-human-readable notation data is currently not
4689 supported). The strings must be in UTF-8 encoding.
4691 If NAME is `NULL', then VALUE should be a policy URL.
4693 The function `gpgme_sig_notation_add' returns the error code
4694 `GPG_ERR_NO_ERROR' if the notation data could be added
4695 successfully, `GPG_ERR_INV_VALUE' if CTX is not a valid pointer,
4696 or if NAME, VALUE and FLAGS are an invalid combination. The
4697 function also passes through any errors that are reported by the
4698 crypto engine support routines.
4700 -- Function: gpgme_sig_notation_t gpgme_sig_notation_get
4701 (const gpgme_ctx_t CTX)
4702 The function `gpgme_sig_notation_get' returns the linked list of
4703 notation data structures that are contained in the context CTX.
4705 If CTX is not a valid pointer, or there is no notation data added
4706 for this context, `NULL' is returned.
4709 File: gpgme.info, Node: Encrypt, Prev: Sign, Up: Crypto Operations
4714 One plaintext can be encrypted for several recipients at the same time.
4715 The list of recipients is created independently of any context, and
4716 then passed to the encryption operation.
4720 * Encrypting a Plaintext:: How to encrypt a plaintext.
4723 File: gpgme.info, Node: Encrypting a Plaintext, Up: Encrypt
4725 7.7.5.1 Encrypting a Plaintext
4726 ..............................
4728 -- Function: gpgme_error_t gpgme_op_encrypt (gpgme_ctx_t CTX,
4729 gpgme_key_t RECP[], gpgme_encrypt_flags_t FLAGS,
4730 gpgme_data_t PLAIN, gpgme_data_t CIPHER)
4731 The function `gpgme_op_encrypt' encrypts the plaintext in the data
4732 object PLAIN for the recipients RECP and stores the ciphertext in
4733 the data object CIPHER. The type of the ciphertext created is
4734 determined by the ASCII armor (or, if that is not set, by the
4735 encoding specified for CIPHER) and the text mode attributes set
4736 for the context CTX.
4738 KEY must be a `NULL'-terminated array of keys. The user must keep
4739 references for all keys during the whole duration of the call (but
4740 see `gpgme_op_encrypt_start' for the requirements with the
4741 asynchronous variant).
4743 The value in FLAGS is a bitwise-or combination of one or multiple
4744 of the following bit values:
4746 `GPGME_ENCRYPT_ALWAYS_TRUST'
4747 The `GPGME_ENCRYPT_ALWAYS_TRUST' symbol specifies that all the
4748 recipients in RECP should be trusted, even if the keys do not
4749 have a high enough validity in the keyring. This flag should
4750 be used with care; in general it is not a good idea to use
4753 `GPGME_ENCRYPT_NO_ENCRYPT_TO'
4754 The `GPGME_ENCRYPT_NO_ENCRYPT_TO' symbol specifies that no
4755 default or hidden default recipients as configured in the
4756 crypto backend should be included. This can be useful for
4757 managing different user profiles.
4759 If `GPG_ERR_UNUSABLE_PUBKEY' is returned, some recipients in RECP
4760 are invalid, but not all. In this case the plaintext might be
4761 encrypted for all valid recipients and returned in CIPHER (if this
4762 happens depends on the crypto engine). More information about the
4763 invalid recipients is available with `gpgme_op_encrypt_result'.
4765 If RECP is `NULL', symmetric rather than public key encryption is
4766 performed. Symmetrically encrypted cipher text can be deciphered
4767 with `gpgme_op_decrypt'. Note that in this case the crypto
4768 backend needs to retrieve a passphrase from the user. Symmetric
4769 encryption is currently only supported for the OpenPGP crypto
4772 The function returns the error code `GPG_ERR_NO_ERROR' if the
4773 ciphertext could be created successfully, `GPG_ERR_INV_VALUE' if
4774 CTX, RECP, PLAIN or CIPHER is not a valid pointer,
4775 `GPG_ERR_UNUSABLE_PUBKEY' if RECP contains some invalid
4776 recipients, `GPG_ERR_BAD_PASSPHRASE' if the passphrase for the
4777 symmetric key could not be retrieved, and passes through any
4778 errors that are reported by the crypto engine support routines.
4780 -- Function: gpgme_error_t gpgme_op_encrypt_start (gpgme_ctx_t CTX,
4781 gpgme_key_t RECP[], gpgme_encrypt_flags_t FLAGS,
4782 gpgme_data_t PLAIN, gpgme_data_t CIPHER)
4783 The function `gpgme_op_encrypt_start' initiates a
4784 `gpgme_op_encrypt' operation. It can be completed by calling
4785 `gpgme_wait' on the context. *Note Waiting For Completion::.
4787 References to the keys only need to be held for the duration of
4788 this call. The user can release its references to the keys after
4789 this function returns, even if the operation is not yet finished.
4791 The function returns the error code `GPG_ERR_NO_ERROR' if the
4792 operation could be started successfully, `GPG_ERR_INV_VALUE' if
4793 CTX, RSET, PLAIN or CIPHER is not a valid pointer, and
4794 `GPG_ERR_UNUSABLE_PUBKEY' if RSET does not contain any valid
4797 -- Data type: gpgme_encrypt_result_t
4798 This is a pointer to a structure used to store the result of a
4799 `gpgme_op_encrypt' operation. After successfully encrypting data,
4800 you can retrieve the pointer to the result with
4801 `gpgme_op_encrypt_result'. The structure contains the following
4804 `gpgme_invalid_key_t invalid_recipients'
4805 A linked list with information about all invalid keys for
4806 which the data could not be encrypted.
4808 -- Function: gpgme_encrypt_result_t gpgme_op_encrypt_result
4810 The function `gpgme_op_encrypt_result' returns a
4811 `gpgme_encrypt_result_t' pointer to a structure holding the result
4812 of a `gpgme_op_encrypt' operation. The pointer is only valid if
4813 the last operation on the context was a `gpgme_op_encrypt',
4814 `gpgme_op_encrypt_start', `gpgme_op_sign' or `gpgme_op_sign_start'
4815 operation. If this operation failed, this might be a `NULL'
4816 pointer. The returned pointer is only valid until the next
4817 operation is started on the context.
4819 -- Function: gpgme_error_t gpgme_op_encrypt_sign (gpgme_ctx_t CTX,
4820 gpgme_key_t RECP[], gpgme_encrypt_flags_t FLAGS,
4821 gpgme_data_t PLAIN, gpgme_data_t CIPHER)
4822 The function `gpgme_op_encrypt_sign' does a combined encrypt and
4823 sign operation. It is used like `gpgme_op_encrypt', but the
4824 ciphertext also contains signatures for the signers listed in CTX.
4826 The combined encrypt and sign operation is currently only available
4827 for the OpenPGP crypto engine.
4829 -- Function: gpgme_error_t gpgme_op_encrypt_sign_start
4830 (gpgme_ctx_t CTX, gpgme_key_t RECP,
4831 gpgme_encrypt_flags_t FLAGS, gpgme_data_t PLAIN,
4832 gpgme_data_t CIPHER)
4833 The function `gpgme_op_encrypt_sign_start' initiates a
4834 `gpgme_op_encrypt_sign' operation. It can be completed by calling
4835 `gpgme_wait' on the context. *Note Waiting For Completion::.
4837 The function returns the error code `GPG_ERR_NO_ERROR' if the
4838 operation could be started successfully, and `GPG_ERR_INV_VALUE'
4839 if CTX, RSET, PLAIN or CIPHER is not a valid pointer.
4842 File: gpgme.info, Node: Run Control, Prev: Crypto Operations, Up: Contexts
4847 GPGME supports running operations synchronously and asynchronously.
4848 You can use asynchronous operation to set up a context up to initiating
4849 the desired operation, but delay performing it to a later point.
4851 Furthermore, you can use an external event loop to control exactly
4852 when GPGME runs. This ensures that GPGME only runs when necessary and
4853 also prevents it from blocking for a long time.
4857 * Waiting For Completion:: Waiting until an operation is completed.
4858 * Using External Event Loops:: Advanced control over what happens when.
4859 * Cancellation:: How to end pending operations prematurely.
4862 File: gpgme.info, Node: Waiting For Completion, Next: Using External Event Loops, Up: Run Control
4864 7.8.1 Waiting For Completion
4865 ----------------------------
4867 -- Function: gpgme_ctx_t gpgme_wait (gpgme_ctx_t CTX,
4868 gpgme_error_t *STATUS, int HANG)
4869 The function `gpgme_wait' continues the pending operation within
4870 the context CTX. In particular, it ensures the data exchange
4871 between GPGME and the crypto backend and watches over the run time
4872 status of the backend process.
4874 If HANG is true, the function does not return until the operation
4875 is completed or cancelled. Otherwise the function will not block
4878 The error status of the finished operation is returned in STATUS
4879 if `gpgme_wait' does not return `NULL'.
4881 The CTX argument can be `NULL'. In that case, `gpgme_wait' waits
4882 for any context to complete its operation.
4884 `gpgme_wait' can be used only in conjunction with any context that
4885 has a pending operation initiated with one of the
4886 `gpgme_op_*_start' functions except `gpgme_op_keylist_start' and
4887 `gpgme_op_trustlist_start' (for which you should use the
4888 corresponding `gpgme_op_*_next' functions). If CTX is `NULL', all
4889 of such contexts are waited upon and possibly returned.
4890 Synchronous operations running in parallel, as well as key and
4891 trust item list operations, do not affect `gpgme_wait'.
4893 In a multi-threaded environment, only one thread should ever call
4894 `gpgme_wait' at any time, irregardless if CTX is specified or not.
4895 This means that all calls to this function should be fully
4896 synchronized by locking primitives. It is safe to start
4897 asynchronous operations while a thread is running in `gpgme_wait'.
4899 The function returns the CTX of the context which has finished the
4900 operation. If HANG is false, and the timeout expires, `NULL' is
4901 returned and `*status' will be set to 0. If an error occurs,
4902 `NULL' is returned and the error is returned in `*status'.
4905 File: gpgme.info, Node: Using External Event Loops, Next: Cancellation, Prev: Waiting For Completion, Up: Run Control
4907 7.8.2 Using External Event Loops
4908 --------------------------------
4910 GPGME hides the complexity of the communication between the library and
4911 the crypto engine. The price of this convenience is that the calling
4912 thread can block arbitrary long waiting for the data returned by the
4913 crypto engine. In single-threaded programs, in particular if they are
4914 interactive, this is an unwanted side-effect. OTOH, if `gpgme_wait' is
4915 used without the HANG option being enabled, it might be called
4916 unnecessarily often, wasting CPU time that could be used otherwise.
4918 The I/O callback interface described in this section lets the user
4919 take control over what happens when. GPGME will provide the user with
4920 the file descriptors that should be monitored, and the callback
4921 functions that should be invoked when a file descriptor is ready for
4922 reading or writing. It is then the user's responsibility to decide
4923 when to check the file descriptors and when to invoke the callback
4924 functions. Usually this is done in an event loop, that also checks for
4925 events in other parts of the program. If the callback functions are
4926 only called when the file descriptors are ready, GPGME will never
4927 block. This gives the user more control over the program flow, and
4928 allows to perform other tasks when GPGME would block otherwise.
4930 By using this advanced mechanism, GPGME can be integrated smoothly
4931 into GUI toolkits like GTK+ even for single-threaded programs.
4935 * I/O Callback Interface:: How I/O callbacks are registered.
4936 * Registering I/O Callbacks:: How to use I/O callbacks for a context.
4937 * I/O Callback Example:: An example how to use I/O callbacks.
4938 * I/O Callback Example GTK+:: How to use GPGME with GTK+.
4939 * I/O Callback Example GDK:: How to use GPGME with GDK.
4940 * I/O Callback Example Qt:: How to use GPGME with Qt.
4943 File: gpgme.info, Node: I/O Callback Interface, Next: Registering I/O Callbacks, Up: Using External Event Loops
4945 7.8.2.1 I/O Callback Interface
4946 ..............................
4948 -- Data type: gpgme_error_t (*gpgme_io_cb_t) (void *DATA, int FD)
4949 The `gpgme_io_cb_t' type is the type of functions which GPGME
4950 wants to register as I/O callback handlers using the
4951 `gpgme_register_io_cb_t' functions provided by the user.
4953 DATA and FD are provided by GPGME when the I/O callback handler is
4954 registered, and should be passed through to the handler when it is
4955 invoked by the user because it noticed activity on the file
4958 The callback handler always returns `0', but you should consider
4959 the return value to be reserved for later use.
4961 -- Data type: gpgme_error_t (*gpgme_register_io_cb_t) (void *DATA,
4962 int FD, int DIR, gpgme_io_cb_t FNC, void *FNC_DATA, void **TAG)
4963 The `gpgme_register_io_cb_t' type is the type of functions which
4964 can be called by GPGME to register an I/O callback function FNC
4965 for the file descriptor FD with the user. FNC_DATA should be
4966 passed as the first argument to FNC when the handler is invoked
4967 (the second argument should be FD). If DIR is 0, FNC should be
4968 called by the user when FD is ready for writing. If DIR is 1, FNC
4969 should be called when FD is ready for reading.
4971 DATA was provided by the user when registering the
4972 `gpgme_register_io_cb_t' function with GPGME and will always be
4973 passed as the first argument when registering a callback function.
4974 For example, the user can use this to determine the event loop to
4975 which the file descriptor should be added.
4977 GPGME will call this function when a crypto operation is initiated
4978 in a context for which the user has registered I/O callback
4979 handler functions with `gpgme_set_io_cbs'. It can also call this
4980 function when it is in an I/O callback handler for a file
4981 descriptor associated to this context.
4983 The user should return a unique handle in TAG identifying this I/O
4984 callback registration, which will be passed to the
4985 `gpgme_register_io_cb_t' function without interpretation when the
4986 file descriptor should not be monitored anymore.
4988 -- Data type: void (*gpgme_remove_io_cb_t) (void *TAG)
4989 The `gpgme_remove_io_cb_t' type is the type of functions which can
4990 be called by GPGME to remove an I/O callback handler that was
4991 registered before. TAG is the handle that was returned by the
4992 `gpgme_register_io_cb_t' for this I/O callback.
4994 GPGME can call this function when a crypto operation is in an I/O
4995 callback. It will also call this function when the context is
4996 destroyed while an operation is pending.
4998 -- Data type: enum gpgme_event_io_t
4999 The `gpgme_event_io_t' type specifies the type of an event that is
5000 reported to the user by GPGME as a consequence of an I/O
5001 operation. The following events are defined:
5004 The operation is fully initialized now, and you can start to
5005 run the registered I/O callback handlers now. Note that
5006 registered I/O callback handlers must not be run before this
5007 event is signalled. TYPE_DATA is `NULL' and reserved for
5011 The operation is finished, the last I/O callback for this
5012 operation was removed. The accompanying TYPE_DATA points to a
5013 `gpgme_error_t' variable that contains the status of the
5014 operation that finished. This event is signalled after the
5015 last I/O callback has been removed.
5017 `GPGME_EVENT_NEXT_KEY'
5018 In a `gpgme_op_keylist_start' operation, the next key was
5019 received from the crypto engine. The accompanying TYPE_DATA
5020 is a `gpgme_key_t' variable that contains the key with one
5021 reference for the user.
5023 `GPGME_EVENT_NEXT_TRUSTITEM'
5024 In a `gpgme_op_trustlist_start' operation, the next trust item
5025 was received from the crypto engine. The accompanying
5026 TYPE_DATA is a `gpgme_trust_item_t' variable that contains
5027 the trust item with one reference for the user.
5029 -- Data type: void (*gpgme_event_io_cb_t) (void *DATA,
5030 gpgme_event_io_t TYPE, void *TYPE_DATA)
5031 The `gpgme_event_io_cb_t' type is the type of functions which can
5032 be called by GPGME to signal an event for an operation running in
5033 a context which has I/O callback functions registered by the user.
5035 DATA was provided by the user when registering the
5036 `gpgme_event_io_cb_t' function with GPGME and will always be
5037 passed as the first argument when registering a callback function.
5038 For example, the user can use this to determine the context in
5039 which this event has occured.
5041 TYPE will specify the type of event that has occured. TYPE_DATA
5042 specifies the event further, as described in the above list of
5043 possible `gpgme_event_io_t' types.
5045 GPGME can call this function in an I/O callback handler.
5048 File: gpgme.info, Node: Registering I/O Callbacks, Next: I/O Callback Example, Prev: I/O Callback Interface, Up: Using External Event Loops
5050 7.8.2.2 Registering I/O Callbacks
5051 .................................
5053 -- Data type: struct gpgme_io_cb_ts
5054 This structure is used to store the I/O callback interface
5055 functions described in the previous section. It has the following
5058 `gpgme_register_io_cb_t add'
5059 This is the function called by GPGME to register an I/O
5060 callback handler. It must be specified.
5063 This is passed as the first argument to the `add' function
5064 when it is called by GPGME. For example, it can be used to
5065 determine the event loop to which the file descriptor should
5068 `gpgme_remove_io_cb_t remove'
5069 This is the function called by GPGME to remove an I/O
5070 callback handler. It must be specified.
5072 `gpgme_event_io_cb_t event'
5073 This is the function called by GPGME to signal an event for
5074 an operation. It must be specified, because at least the
5075 start event must be processed.
5078 This is passed as the first argument to the `event' function
5079 when it is called by GPGME. For example, it can be used to
5080 determine the context in which the event has occured.
5082 -- Function: void gpgme_set_io_cbs (gpgme_ctx_t CTX,
5083 struct gpgme_io_cb_ts *IO_CBS)
5084 The function `gpgme_set_io_cbs' enables the I/O callback interface
5085 for the context CTX. The I/O callback functions are specified by
5088 If IO_CBS->`add' is `NULL', the I/O callback interface is disabled
5089 for the context, and normal operation is restored.
5091 -- Function: void gpgme_get_io_cbs (gpgme_ctx_t CTX,
5092 struct gpgme_io_cb_ts *IO_CBS)
5093 The function `gpgme_get_io_cbs' returns the I/O callback functions
5094 set with `gpgme_set_io_cbs' in IO_CBS.
5097 File: gpgme.info, Node: I/O Callback Example, Next: I/O Callback Example GTK+, Prev: Registering I/O Callbacks, Up: Using External Event Loops
5099 7.8.2.3 I/O Callback Example
5100 ............................
5102 To actually use an external event loop, you have to implement the I/O
5103 callback functions that are used by GPGME to register and unregister
5104 file descriptors. Furthermore, you have to actually monitor these file
5105 descriptors for activity and call the appropriate I/O callbacks.
5107 The following example illustrates how to do that. The example uses
5108 locking to show in which way the callbacks and the event loop can run
5109 concurrently. For the event loop, we use a fixed array. For a
5110 real-world implementation, you should use a dynamically sized structure
5111 because the number of file descriptors needed for a crypto operation in
5112 GPGME is not predictable.
5117 #include <pthread.h>
5118 #include <sys/types.h>
5121 /* The following structure holds the result of a crypto operation. */
5128 /* The following structure holds the data associated with one I/O
5141 pthread_mutex_t lock;
5143 /* Unused slots are marked with FD being -1. */
5144 struct one_fd fds[MAX_FDS];
5147 The following functions implement the I/O callback interface.
5150 add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc, void *fnc_data,
5153 struct event_loop *loop = data;
5154 struct one_fd *fds = loop->fds;
5157 pthread_mutex_lock (&loop->lock);
5158 for (i = 0; i < MAX_FDS; i++)
5160 if (fds[i].fd == -1)
5165 fds[i].fnc_data = fnc_data;
5170 pthread_mutex_unlock (&loop->lock);
5172 return gpg_error (GPG_ERR_GENERAL);
5178 remove_io_cb (void *tag)
5180 struct one_fd *fd = tag;
5181 struct event_loop *loop = fd->loop;
5183 pthread_mutex_lock (&loop->lock);
5185 pthread_mutex_unlock (&loop->lock);
5189 event_io_cb (void *data, gpgme_event_io_t type, void *type_data)
5191 struct op_result *result = data;
5193 /* We don't support list operations here. */
5194 if (type == GPGME_EVENT_DONE)
5197 result->err = *type_data;
5201 The final missing piece is the event loop, which will be presented
5202 next. We only support waiting for the success of a single operation.
5205 do_select (struct event_loop *loop)
5211 struct one_fd *fdlist = loop->fds;
5213 pthread_mutex_lock (&loop->lock);
5216 for (i = 0; i < MAX_FDS; i++)
5217 if (fdlist[i].fd != -1)
5218 FD_SET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds);
5219 pthread_mutex_unlock (&loop->unlock);
5223 n = select (FD_SETSIZE, &rfds, &wfds, NULL, 0);
5225 while (n < 0 && errno == EINTR);
5228 return n; /* Error or timeout. */
5230 pthread_mutex_lock (&loop->lock);
5231 for (i = 0; i < MAX_FDS && n; i++)
5233 if (fdlist[i].fd != -1)
5235 if (FD_ISSET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds))
5240 /* The I/O callback handler can register/remove callbacks,
5241 so we have to unlock the file descriptor list. */
5242 pthread_mutex_unlock (&loop->lock);
5243 (*fdlist[i].fnc) (fdlist[i].fnc_data, fdlist[i].fd);
5244 pthread_mutex_lock (&loop->lock);
5248 pthread_mutex_unlock (&loop->lock);
5253 wait_for_op (struct event_loop *loop, struct op_result *result)
5259 ret = do_select (loop);
5261 while (ret >= 0 && !result->done);
5264 The main function shows how to put it all together.
5267 main (int argc, char *argv[])
5269 struct event_loop loop;
5270 struct op_result result;
5273 gpgme_data_t sig, text;
5275 struct gpgme_io_cb_ts io_cbs =
5286 /* Initialize the loop structure. */
5287 pthread_mutex_init (&loop.lock, NULL);
5288 for (i = 0; i < MAX_FDS; i++)
5289 loop->fds[i].fd = -1;
5291 /* Initialize the result structure. */
5294 err = gpgme_data_new_from_file (&sig, "signature", 1);
5296 err = gpgme_data_new_from_file (&text, "text", 1);
5298 err = gpgme_new (&ctx);
5301 gpgme_set_io_cbs (ctx, &io_cbs);
5302 err = gpgme_op_verify_start (ctx, sig, text, NULL);
5306 fprintf (stderr, "gpgme error: %s: %s\n",
5307 gpgme_strsource (err), gpgme_strerror (err));
5311 wait_for_op (&loop, &result);
5314 fprintf (stderr, "select error\n");
5319 fprintf (stderr, "verification failed: %s: %s\n",
5320 gpgme_strsource (result.err), gpgme_strerror (result.err));
5323 /* Evaluate verify result. */
5329 File: gpgme.info, Node: I/O Callback Example GTK+, Next: I/O Callback Example GDK, Prev: I/O Callback Example, Up: Using External Event Loops
5331 7.8.2.4 I/O Callback Example GTK+
5332 .................................
5334 The I/O callback interface can be used to integrate GPGME with the GTK+
5335 event loop. The following code snippets shows how this can be done
5336 using the appropriate register and remove I/O callback functions. In
5337 this example, the private data of the register I/O callback function is
5338 unused. The event notifications is missing because it does not require
5339 any GTK+ specific setup.
5341 #include <gtk/gtk.h>
5343 struct my_gpgme_io_cb
5347 guint input_handler_id
5351 my_gpgme_io_cb (gpointer data, gint source, GdkInputCondition condition)
5353 struct my_gpgme_io_cb *iocb = data;
5354 (*(iocb->fnc)) (iocb->data, source);
5358 my_gpgme_remove_io_cb (void *data)
5360 struct my_gpgme_io_cb *iocb = data;
5361 gtk_input_remove (data->input_handler_id);
5365 my_gpgme_register_io_callback (void *data, int fd, int dir, gpgme_io_cb_t fnc,
5366 void *fnc_data, void **tag)
5368 struct my_gpgme_io_cb *iocb = g_malloc (sizeof (struct my_gpgme_io_cb));
5370 iocb->data = fnc_data;
5371 iocb->input_handler_id = gtk_input_add_full (fd, dir
5374 my_gpgme_io_callback,
5381 File: gpgme.info, Node: I/O Callback Example GDK, Next: I/O Callback Example Qt, Prev: I/O Callback Example GTK+, Up: Using External Event Loops
5383 7.8.2.5 I/O Callback Example GDK
5384 ................................
5386 The I/O callback interface can also be used to integrate GPGME with the
5387 GDK event loop. The following code snippets shows how this can be done
5388 using the appropriate register and remove I/O callback functions. In
5389 this example, the private data of the register I/O callback function is
5390 unused. The event notifications is missing because it does not require
5391 any GDK specific setup.
5393 It is very similar to the GTK+ example in the previous section.
5395 #include <gdk/gdk.h>
5397 struct my_gpgme_io_cb
5405 my_gpgme_io_cb (gpointer data, gint source, GdkInputCondition condition)
5407 struct my_gpgme_io_cb *iocb = data;
5408 (*(iocb->fnc)) (iocb->data, source);
5412 my_gpgme_remove_io_cb (void *data)
5414 struct my_gpgme_io_cb *iocb = data;
5415 gdk_input_remove (data->tag);
5419 my_gpgme_register_io_callback (void *data, int fd, int dir, gpgme_io_cb_t fnc,
5420 void *fnc_data, void **tag)
5422 struct my_gpgme_io_cb *iocb = g_malloc (sizeof (struct my_gpgme_io_cb));
5424 iocb->data = fnc_data;
5425 iocb->tag = gtk_input_add_full (fd, dir ? GDK_INPUT_READ : GDK_INPUT_WRITE,
5426 my_gpgme_io_callback, iocb, NULL);
5432 File: gpgme.info, Node: I/O Callback Example Qt, Prev: I/O Callback Example GDK, Up: Using External Event Loops
5434 7.8.2.6 I/O Callback Example Qt
5435 ...............................
5437 The I/O callback interface can also be used to integrate GPGME with the
5438 Qt event loop. The following code snippets show how this can be done
5439 using the appropriate register and remove I/O callback functions. In
5440 this example, the private data of the register I/O callback function is
5441 unused. The event notifications is missing because it does not require
5442 any Qt specific setup.
5444 #include <qsocketnotifier.h>
5445 #include <qapplication.h>
5448 IOCB( GpgmeIOCb f, void * d, QSocketNotifier * n )
5449 : func( f ), data( d ), notifier( n ) {}
5452 QSocketNotifier * notifier;
5455 class MyApp : public QApplication {
5459 static void registerGpgmeIOCallback( void * data, int fd, int dir,
5460 GpgmeIOCb func, void * func_data,
5462 QSocketNotifier * n =
5463 new QSocketNotifier( fd, dir ? QSocketNotifier::Read
5464 : QSocketNotifier::Write );
5465 connect( n, SIGNAL(activated(int)),
5466 qApp, SLOT(slotGpgmeIOCallback(int)) );
5467 qApp->mIOCBs.push_back( IOCB( func, func_data, n ) );
5471 static void removeGpgmeIOCallback( void * tag ) {
5473 QSocketNotifier * n = static_cast<QSocketNotifier*>( tag );
5474 for ( QValueList<IOCB>::iterator it = qApp->mIOCBs.begin() ;
5475 it != qApp->mIOCBs.end() ; ++it )
5476 if ( it->notifier == n ) {
5477 delete it->notifier;
5478 qApp->mIOCBs.erase( it );
5484 void slotGpgmeIOCallback( int fd ) {
5485 for ( QValueList<IOCB>::const_iterator it = mIOCBs.begin() ;
5486 it != mIOCBs.end() ; ++it )
5487 if ( it->notifier && it->notifier->socket() == fd )
5488 (*(it->func)) ( it->func_data, fd );
5494 QValueList<IOCB> mIOCBs;
5499 File: gpgme.info, Node: Cancellation, Prev: Using External Event Loops, Up: Run Control
5504 Sometimes you do not want to wait for an operation to finish. GPGME
5505 provides two different functions to achieve that. The function
5506 `gpgme_cancel' takes effect immediately. When it returns, the
5507 operation is effectively canceled. However, it has some limitations
5508 and can not be used with synchronous operations. In contrast, the
5509 function `gpgme_cancel_async' can be used with any context and from any
5510 thread, but it is not guaranteed to take effect immediately. Instead,
5511 cancellation occurs at the next possible time (typically the next time
5512 I/O occurs in the target context).
5514 -- Function: gpgme_ctx_t gpgme_cancel (gpgme_ctx_t CTX)
5515 The function `gpgme_cancel' attempts to cancel a pending operation
5516 in the context CTX. This only works if you use the global event
5517 loop or your own event loop.
5519 If you use the global event loop, you must not call `gpgme_wait'
5520 or `gpgme_wait' during cancellation. After successful
5521 cancellation, you can call `gpgme_wait' (optionally waiting on
5522 CTX), and the context CTX will appear as if it had finished with
5523 the error code `GPG_ERR_CANCEL'.
5525 If you use your an external event loop, you must ensure that no I/O
5526 callbacks are invoked for this context (for example by halting the
5527 event loop). On successful cancellation, all registered I/O
5528 callbacks for this context will be unregistered, and a
5529 `GPGME_EVENT_DONE' event with the error code `GPG_ERR_CANCEL' will
5532 The function returns an error code if the cancellation failed (in
5533 this case the state of CTX is not modified).
5535 -- Function: gpgme_ctx_t gpgme_cancel_async (gpgme_ctx_t CTX)
5536 The function `gpgme_cancel' attempts to cancel a pending operation
5537 in the context CTX. This can be called by any thread at any time
5538 after starting an operation on the context, but will not take
5539 effect immediately. The actual cancellation happens at the next
5540 time GPGME processes I/O in that context.
5542 The function returns an error code if the cancellation failed (in
5543 this case the state of CTX is not modified).
5546 File: gpgme.info, Node: UI Server Protocol, Next: Library Copying, Prev: Contexts, Up: Top
5548 Appendix A The GnuPG UI Server Protocol
5549 ***************************************
5551 This section specifies the protocol used between clients and a User
5552 Interface Server (UI server). This protocol helps to build a system
5553 where all cryptographic operations are done by a server and the server
5554 is responsible for all dialogs. Although GPGME has no direct support
5555 for this protocol it is believed that servers will utilize the GPGME
5556 library; thus having the specification included in this manual is an
5557 appropriate choice. This protocol should be referenced as `The GnuPG
5558 UI Server Protocol'.
5560 A server needs to implement these commands:(1)
5564 * UI Server Encrypt:: Encrypt a message.
5565 * UI Server Sign:: Sign a message.
5566 * UI Server Decrypt:: Decrypt a message.
5567 * UI Server Verify:: Verify a message.
5568 * UI Server Set Input Files:: Specifying the input files to operate on.
5569 * UI Server Sign/Encrypt Files:: Encrypting and signing files.
5570 * UI Server Verify/Decrypt Files:: Decrypting and verifying files.
5571 * UI Server Import/Export Keys:: Managing certificates.
5572 * UI Server Checksum Files:: Create and verify checksums for files.
5573 * Miscellaneous UI Server Commands:: Commands not related to a specific operation.
5575 ---------- Footnotes ----------
5577 (1) In all examples we assume that the connection has already been
5578 established; see the Assuan manual for details.
5581 File: gpgme.info, Node: UI Server Encrypt, Next: UI Server Sign, Up: UI Server Protocol
5583 A.1 UI Server: Encrypt a Message
5584 ================================
5586 Before encryption can be done the recipients must be set using the
5589 -- Command: RECIPIENT STRING
5590 Set the recipient for the encryption. STRING is an RFC-2822
5591 recipient name ("mailbox" as per section 3.4). This command may
5592 or may not check the recipient for validity right away; if it does
5593 not all recipients are expected to be checked at the time of the
5594 `ENCRYPT' command. All `RECIPIENT' commands are cumulative until a
5595 successful `ENCRYPT' command or until a `RESET' command.
5596 Linefeeds are obviously not allowed in STRING and should be folded
5597 into spaces (which are equivalent).
5599 To tell the server the source and destination of the data, the next two
5600 commands are to be used:
5602 -- Command: INPUT FD=N
5603 Set the file descriptor for the message to be encrypted to N. The
5604 message send to the server is binary encoded.
5606 GpgOL is a Windows only program, thus N is not a libc file
5607 descriptor but a regular system handle. Given that the Assuan
5608 connection works over a socket, it is not possible to use regular
5609 inheritance to make the file descriptor available to the server.
5610 Thus `DuplicateHandle' needs to be used to duplicate a handle to
5611 the server process. This is the reason that the server needs to
5612 implement the `GETINFO pid' command. Sending this command a second
5613 time replaces the file descriptor set by the last one.
5615 -- Command: OUTPUT FD=N
5616 Set the file descriptor to be used for the output (i.e. the
5617 encrypted message) to N. For OpenPGP, the output needs to be
5618 ASCII armored; for CMS, the output needs to be Base-64 encoded.
5619 For details on the file descriptor, see the `INPUT' command.
5621 The setting of the recipients, the data source and destination may
5622 happen in any order, even intermixed. If this has been done the actual
5623 encryption operation is called using:
5625 -- Command: ENCRYPT --protocol=NAME
5626 This command reads the plaintext from the file descriptor set by
5627 the `INPUT' command, encrypts it and writes the ciphertext to the
5628 file descriptor set by the `OUTPUT' command. The server may (and
5629 should) overlap reading and writing. The recipients used for the
5630 encryption are all the recipients set so far. If any recipient is
5631 not usable the server should take appropriate measures to notify
5632 the user about the problem and may cancel the operation by
5633 returning an error code. The used file descriptors are void after
5634 this command; the recipient list is only cleared if the server
5637 Because GpgOL uses a streaming mode of operation the server is not
5638 allowed to auto select the protocol and must obey to the mandatory
5642 Use the OpenPGP protocol (RFC-2440).
5645 Use the CMS (PKCS#7) protocol (RFC-3852).
5648 To support automagically selection of the protocol depending on the
5649 selected keys, the server MAY implement the command:
5651 -- Command: PREP_ENCRYPT [--protocol=NAME] [--expect-sign]
5652 This commands considers all recipients set so far and decides
5653 whether it is able to take input and start the actual encryption.
5654 This is kind of a dry-run `ENCRYPT' without requiring or using the
5655 input and output file descriptors. The server shall cache the
5656 result of any user selection to avoid asking this again when the
5657 actual `ENCRYPT' command is send. The `--protocol' option is
5658 optional; if it is not given, the server should allow the user to
5659 select the protocol to be used based on the recipients given or by
5662 If `--expect-sign' is given the server should expect that the
5663 message will also be signed and use this hint to present a unified
5664 recipient and signer selection dialog if possible and desired. A
5665 selected signer should then be cached for the expected SIGN command
5666 (which is expected in the same session but possible on another
5669 If this command is given again before a successful `ENCRYPT'
5670 command, the second one takes effect.
5672 Before sending the OK response the server shall tell the client the
5673 protocol to be used (either the one given by the argument or the
5674 one selected by the user) by means of a status line:
5676 -- Status line: PROTOCOL NAME
5677 Advise the client to use the protocol NAME for the `ENCRYPT'
5678 command. The valid protocol names are listed under the
5679 description of the `ENCRYPT' command. The server shall emit
5680 exactly one PROTOCOL status line.
5682 Here is an example of a complete encryption sequence; client lines are
5683 indicated by a C:, server responses by C::
5687 C: RECIPIENT foo@example.net
5689 C: RECIPIENT bar@example.com
5692 S: S PROTOCOL OpenPGP
5702 File: gpgme.info, Node: UI Server Sign, Next: UI Server Decrypt, Prev: UI Server Encrypt, Up: UI Server Protocol
5704 A.2 UI Server: Sign a Message
5705 =============================
5707 The server needs to implement opaque signing as well as detached
5708 signing. Due to the nature of OpenPGP messages it is always required to
5709 send the entire message to the server; sending just the hash is not
5710 possible. The following two commands are required to set the input and
5711 output file descriptors:
5713 -- Command: INPUT FD=N
5714 Set the file descriptor for the message to be signed to N. The
5715 message send to the server is binary encoded. For details on the
5716 file descriptor, see the description of `INPUT' in the `ENCRYPT'
5719 -- Command: OUTPUT FD=N
5720 Set the file descriptor to be used for the output. The output is
5721 either the complete signed message or in case of a detached
5722 signature just that detached signature. For OpenPGP, the output
5723 needs to be ASCII armored; for CMS, the output needs to be Base-64
5724 encoded. For details on the file descriptor, see the `INPUT'
5727 To allow the server the selection of a non-default signing key the
5728 client may optionally use the `SENDER' command, see *note command
5731 The signing operation is then initiated by:
5733 -- Command: SIGN --protocol=NAME [--detached]
5734 Sign the data set with the `INPUT' command and write it to the sink
5735 set by OUTPUT. NAME is the signing protocol used for the message.
5736 For a description of the allowed protocols see the `ENCRYPT'
5737 command. With option `--detached' given, a detached signature is
5738 created; this is actually the usual way the command is used.
5740 The client expects the server to send at least this status information
5741 before the final OK response:
5743 -- Status line: MICALG STRING
5744 The STRING represents the hash algorithm used to create the
5745 signature. It is used with MOSS style signature messages and
5746 defined by PGP/MIME (RFC-3156) and S/MIME (RFC-3851). The GPGME
5747 library has a supporting function `gpgme_hash_algo_name' to return
5748 the algorithm name as a string. This string needs to be
5749 lowercased and for OpenPGP prefixed with "`pgp-'".
5752 File: gpgme.info, Node: UI Server Decrypt, Next: UI Server Verify, Prev: UI Server Sign, Up: UI Server Protocol
5754 A.3 UI Server: Decrypt a Message
5755 ================================
5757 Decryption may include the verification of OpenPGP messages. This is
5758 due to the often used combined signing/encryption modus of OpenPGP. The
5759 client may pass an option to the server to inhibit the signature
5760 verification. The following two commands are required to set the input
5761 and output file descriptors:
5763 -- Command: INPUT FD=N
5764 Set the file descriptor for the message to be decrypted to N. The
5765 message send to the server is either binary encoded or -- in the
5766 case of OpenPGP -- ASCII armored. For details on the file
5767 descriptor, see the description of `INPUT' in the `ENCRYPT'
5770 -- Command: OUTPUT FD=N
5771 Set the file descriptor to be used for the output. The output is
5772 binary encoded. For details on the file descriptor, see the
5773 description of `INPUT' in the `ENCRYPT' section.
5775 The decryption is started with the command:
5777 -- Command: DECRYPT --protocol=NAME [--no-verify]
5778 NAME is the encryption protocol used for the message. For a
5779 description of the allowed protocols see the `ENCRYPT' command.
5780 This argument is mandatory. If the option `--no-verify' is given,
5781 the server should not try to verify a signature, in case the input
5782 data is an OpenPGP combined message.
5785 File: gpgme.info, Node: UI Server Verify, Next: UI Server Set Input Files, Prev: UI Server Decrypt, Up: UI Server Protocol
5787 A.4 UI Server: Verify a Message
5788 ===============================
5790 The server needs to support the verification of opaque signatures as
5791 well as detached signatures. The kind of input sources controls what
5792 kind message is to be verified.
5794 -- Command: MESSAGE FD=N
5795 This command is used with detached signatures to set the file
5796 descriptor for the signed data to N. The data is binary encoded
5797 (used verbatim). For details on the file descriptor, see the
5798 description of `INPUT' in the `ENCRYPT' section.
5800 -- Command: INPUT FD=N
5801 Set the file descriptor for the opaque message or the signature
5802 part of a detached signature to N. The message send to the server
5803 is either binary encoded or - in the case of OpenPGP - ASCII
5804 armored. For details on the file descriptor, see the description
5805 of `INPUT' in the `ENCRYPT' section.
5807 -- Command: OUTPUT FD=N
5808 Set the file descriptor to be used for the output. The output is
5809 binary encoded and only used for opaque signatures. For details
5810 on the file descriptor, see the description of `INPUT' in the
5813 The verification is then started using:
5815 -- Command: VERIFY --protocol=NAME [--silent]
5816 NAME is the signing protocol used for the message. For a
5817 description of the allowed protocols see the `ENCRYPT' command.
5818 This argument is mandatory. Depending on the combination of
5819 `MESSAGE' `INPUT' and `OUTPUT' commands, the server needs to
5820 select the appropriate verification mode:
5823 This indicates a detached signature. Output data is not
5827 This indicates an opaque signature. As no output command has
5828 been given, the server is only required to check the
5832 This indicates an opaque signature. The server shall write
5833 the signed data to the file descriptor set by the output
5834 command. This data shall even be written if the signatures
5837 With `--silent' the server shall not display any dialog; this is for
5838 example used by the client to get the content of opaque signed
5839 messages. The client expects the server to send at least this status
5840 information before the final OK response:
5842 -- Status line: SIGSTATUS FLAG DISPLAYSTRING
5843 Returns the status for the signature and a short string explaining
5844 the status. Valid values for FLAG are:
5847 The message has a signature but it could not not be verified
5848 due to a missing key.
5851 The signature is fully valid.
5854 The signature is valid but additional information was shown
5855 regarding the validity of the key.
5858 The signature is not valid.
5860 DISPLAYSTRING is a percent-and-plus-encoded string with a short
5861 human readable description of the status. For example
5863 S SIGSTATUS green Good+signature+from+Keith+Moon+<keith@example.net>
5865 Note that this string needs to fit into an Assuan line and should
5866 be short enough to be displayed as short one-liner on the clients
5867 window. As usual the encoding of this string is UTF-8 and it
5868 should be send in its translated form.
5870 The server shall send one status line for every signature found on
5875 File: gpgme.info, Node: UI Server Set Input Files, Next: UI Server Sign/Encrypt Files, Prev: UI Server Verify, Up: UI Server Protocol
5877 A.5 UI Server: Specifying the input files to operate on.
5878 ========================================================
5880 All file related UI server commands operate on a number of input files
5881 or directories, specified by one or more `FILE' commands:
5883 -- Command: FILE NAME [-continued]
5884 Add the file or directory NAME to the list of pathnames to be
5885 processed by the server. The parameter NAME must be an absolute
5886 path name (including the drive letter) and is percent espaced (in
5887 particular, the characters %, = and white space characters are
5888 always escaped). The option `--continued' is present for all but
5889 the last `FILE' command.
5892 File: gpgme.info, Node: UI Server Sign/Encrypt Files, Next: UI Server Verify/Decrypt Files, Prev: UI Server Set Input Files, Up: UI Server Protocol
5894 A.6 UI Server: Encrypting and signing files.
5895 ============================================
5897 First, the input files need to be specified by one or more `FILE'
5898 commands. Afterwards, the actual operation is requested:
5900 -- Command: ENCRYPT_FILES -nohup
5901 -- Command: SIGN_FILES -nohup
5902 -- Command: ENCRYPT_SIGN_FILES -nohup
5903 Request that the files specified by `FILE' are encrypted and/or
5904 signed. The command selects the default action. The UI server may
5905 allow the user to change this default afterwards interactively, and
5906 even abort the operation or complete it only on some of the
5907 selected files and directories.
5909 What it means to encrypt or sign a file or directory is specific to
5910 the preferences of the user, the functionality the UI server
5911 provides, and the selected protocol. Typically, for each input
5912 file a new file is created under the original filename plus a
5913 protocol specific extension (like `.gpg' or `.sig'), which contain
5914 the encrypted/signed file or a detached signature. For
5915 directories, the server may offer multiple options to the user
5916 (for example ignore or process recursively).
5918 The `ENCRYPT_SIGN_FILES' command requests a combined sign and
5919 encrypt operation. It may not be available for all protocols (for
5920 example, it is available for OpenPGP but not for CMS).
5922 The option `--nohup' is mandatory. It is currently unspecified
5923 what should happen if `--nohup' is not present. Because `--nohup'
5924 is present, the server always returns `OK' promptly, and completes
5925 the operation asynchronously.
5928 File: gpgme.info, Node: UI Server Verify/Decrypt Files, Next: UI Server Import/Export Keys, Prev: UI Server Sign/Encrypt Files, Up: UI Server Protocol
5930 A.7 UI Server: Decrypting and verifying files.
5931 ==============================================
5933 First, the input files need to be specified by one or more `FILE'
5934 commands. Afterwards, the actual operation is requested:
5936 -- Command: DECRYPT_FILES -nohup
5937 -- Command: VERIFY_FILES -nohup
5938 -- Command: DECRYPT_VERIFY_FILES -nohup
5939 Request that the files specified by `FILE' are decrypted and/or
5940 verified. The command selects the default action. The UI server
5941 may allow the user to change this default afterwards
5942 interactively, and even abort the operation or complete it only on
5943 some of the selected files and directories.
5945 What it means to decrypt or verify a file or directory is specific
5946 to the preferences of the user, the functionality the UI server
5947 provides, and the selected protocol. Typically, for decryption, a
5948 new file is created for each input file under the original
5949 filename minus a protocol specific extension (like `.gpg') which
5950 contains the original plaintext. For verification a status is
5951 displayed for each signed input file, indicating if it is signed,
5952 and if yes, if the signature is valid. For files that are signed
5953 and encrypted, the `VERIFY' command transiently decrypts the file
5954 to verify the enclosed signature. For directories, the server may
5955 offer multiple options to the user (for example ignore or process
5958 The option `--nohup' is mandatory. It is currently unspecified
5959 what should happen if `--nohup' is not present. Because `--nohup'
5960 is present, the server always returns `OK' promptly, and completes
5961 the operation asynchronously.
5964 File: gpgme.info, Node: UI Server Import/Export Keys, Next: UI Server Checksum Files, Prev: UI Server Verify/Decrypt Files, Up: UI Server Protocol
5966 A.8 UI Server: Managing certificates.
5967 =====================================
5969 First, the input files need to be specified by one or more `FILE'
5970 commands. Afterwards, the actual operation is requested:
5972 -- Command: IMPORT_FILES -nohup
5973 Request that the certificates contained in the files specified by
5974 `FILE' are imported into the local certificate databases.
5976 For directories, the server may offer multiple options to the user
5977 (for example ignore or process recursively).
5979 The option `--nohup' is mandatory. It is currently unspecified
5980 what should happen if `--nohup' is not present. Because `--nohup'
5981 is present, the server always returns `OK' promptly, and completes
5982 the operation asynchronously.
5984 FIXME: It may be nice to support an `EXPORT' command as well, which
5985 is enabled by the context menu of the background of a directory.
5988 File: gpgme.info, Node: UI Server Checksum Files, Next: Miscellaneous UI Server Commands, Prev: UI Server Import/Export Keys, Up: UI Server Protocol
5990 A.9 UI Server: Create and verify checksums for files.
5991 =====================================================
5993 First, the input files need to be specified by one or more `FILE'
5994 commands. Afterwards, the actual operation is requested:
5996 -- Command: CHECKSUM_CREATE_FILES -nohup
5997 Request that checksums are created for the files specifed by
5998 `FILE'. The choice of checksum algorithm and the destination
5999 storage and format for the created checksums depend on the
6000 preferences of the user and the functionality provided by the UI
6001 server. For directories, the server may offer multiple options to
6002 the user (for example ignore or process recursively).
6004 The option `--nohup' is mandatory. It is currently unspecified
6005 what should happen if `--nohup' is not present. Because `--nohup'
6006 is present, the server always returns `OK' promptly, and completes
6007 the operation asynchronously.
6009 -- Command: CHECKSUM_VERIFY_FILES -nohup
6010 Request that checksums are created for the files specifed by
6011 `FILE' and verified against previously created and stored
6012 checksums. The choice of checksum algorithm and the source storage
6013 and format for previously created checksums depend on the
6014 preferences of the user and the functionality provided by the UI
6015 server. For directories, the server may offer multiple options to
6016 the user (for example ignore or process recursively).
6018 If the source storage of previously created checksums is available
6019 to the user through the Windows shell, this command may also
6020 accept such checksum files as `FILE' arguments. In this case, the
6021 UI server should instead verify the checksum of the referenced
6022 files as if they were given as INPUT files.
6024 The option `--nohup' is mandatory. It is currently unspecified
6025 what should happen if `--nohup' is not present. Because `--nohup'
6026 is present, the server always returns `OK' promptly, and completes
6027 the operation asynchronously.
6030 File: gpgme.info, Node: Miscellaneous UI Server Commands, Prev: UI Server Checksum Files, Up: UI Server Protocol
6032 A.10 Miscellaneous UI Server Commands
6033 =====================================
6035 The server needs to implement the following commands which are not
6036 related to a specific command:
6038 -- Command: GETINFO WHAT
6039 This is a multi purpose command, commonly used to return a variety
6040 of information. The required subcommands as described by the WHAT
6044 Return the process id of the server in decimal notation using
6045 an Assuan data line.
6047 To allow the server to pop up the windows in the correct relation to the
6048 client, the client is advised to tell the server by sending the option:
6050 -- Command option: window-id NUMBER
6051 The NUMBER represents the native window ID of the clients current
6052 window. On Windows systems this is a windows handle (`HWND') and
6053 on X11 systems it is the `X Window ID'. The number needs to be
6054 given as a hexadecimal value so that it is easier to convey pointer
6055 values (e.g. `HWND').
6057 A client may want to fire up the certificate manager of the server. To
6058 do this it uses the Assuan command:
6060 -- Command: START_KEYMANAGER
6061 The server shall pop up the main window of the key manager (aka
6062 certificate manager). The client expects that the key manager is
6063 brought into the foregound and that this command immediatley
6064 returns (does not wait until the key manager has been fully
6067 A client may want to fire up the configuration dialog of the server. To
6068 do this it uses the Assuan command:
6070 -- Command: START_CONFDIALOG
6071 The server shall pop up its configuration dialog. The client
6072 expects that this dialog is brought into the foregound and that
6073 this command immediatley returns (i.e. it does not wait until the
6074 dialog has been fully brought up).
6076 When doing an operation on a mail, it is useful to let the server know
6077 the address of the sender:
6079 -- Command: SENDER [--info] [--protocol=NAME] EMAIL
6080 EMAIL is the plain ASCII encoded address ("addr-spec" as per
6081 RFC-2822) enclosed in angle brackets. The address set with this
6082 command is valid until a successful completion of the operation or
6083 until a `RESET' command. A second command overrides the effect of
6084 the first one; if EMAIL is not given and `--info' is not used, the
6085 server shall use the default signing key.
6087 If option `--info' is not given, the server shall also suggest a
6088 protocol to use for signing. The client may use this suggested
6089 protocol on its own discretion. The same status line as with
6090 PREP_ENCRYPT is used for this.
6092 The option `--protocol' may be used to give the server a hint on
6093 which signing protocol should be preferred.
6095 To allow the UI-server to visually identify a running operation or to
6096 associate operations the server MAY support the command:
6098 -- Command: SESSION NUMBER [STRING]
6099 The NUMBER is an arbitrary value, a server may use to associate
6100 simultaneous running sessions. It is a 32 bit unsigned integer
6101 with `0' as a special value indicating that no session association
6104 If STRING is given, the server may use this as the title of a
6105 window or, in the case of an email operation, to extract the
6106 sender's address. The string may contain spaces; thus no
6107 plus-escaping is used.
6109 This command may be used at any time and overrides the effect of
6110 the last command. A `RESET' undoes the effect of this command.
6114 File: gpgme.info, Node: Library Copying, Next: Copying, Prev: UI Server Protocol, Up: Top
6116 GNU Lesser General Public License
6117 *********************************
6119 Version 2.1, February 1999
6121 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
6122 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
6124 Everyone is permitted to copy and distribute verbatim copies
6125 of this license document, but changing it is not allowed.
6127 [This is the first released version of the Lesser GPL. It also counts
6128 as the successor of the GNU Library Public License, version 2, hence the
6129 version number 2.1.]
6134 The licenses for most software are designed to take away your freedom
6135 to share and change it. By contrast, the GNU General Public Licenses
6136 are intended to guarantee your freedom to share and change free
6137 software--to make sure the software is free for all its users.
6139 This license, the Lesser General Public License, applies to some
6140 specially designated software--typically libraries--of the Free
6141 Software Foundation and other authors who decide to use it. You can use
6142 it too, but we suggest you first think carefully about whether this
6143 license or the ordinary General Public License is the better strategy to
6144 use in any particular case, based on the explanations below.
6146 When we speak of free software, we are referring to freedom of use,
6147 not price. Our General Public Licenses are designed to make sure that
6148 you have the freedom to distribute copies of free software (and charge
6149 for this service if you wish); that you receive source code or can get
6150 it if you want it; that you can change the software and use pieces of it
6151 in new free programs; and that you are informed that you can do these
6154 To protect your rights, we need to make restrictions that forbid
6155 distributors to deny you these rights or to ask you to surrender these
6156 rights. These restrictions translate to certain responsibilities for
6157 you if you distribute copies of the library or if you modify it.
6159 For example, if you distribute copies of the library, whether gratis
6160 or for a fee, you must give the recipients all the rights that we gave
6161 you. You must make sure that they, too, receive or can get the source
6162 code. If you link other code with the library, you must provide
6163 complete object files to the recipients, so that they can relink them
6164 with the library after making changes to the library and recompiling
6165 it. And you must show them these terms so they know their rights.
6167 We protect your rights with a two-step method: (1) we copyright the
6168 library, and (2) we offer you this license, which gives you legal
6169 permission to copy, distribute and/or modify the library.
6171 To protect each distributor, we want to make it very clear that
6172 there is no warranty for the free library. Also, if the library is
6173 modified by someone else and passed on, the recipients should know that
6174 what they have is not the original version, so that the original
6175 author's reputation will not be affected by problems that might be
6176 introduced by others.
6178 Finally, software patents pose a constant threat to the existence of
6179 any free program. We wish to make sure that a company cannot
6180 effectively restrict the users of a free program by obtaining a
6181 restrictive license from a patent holder. Therefore, we insist that
6182 any patent license obtained for a version of the library must be
6183 consistent with the full freedom of use specified in this license.
6185 Most GNU software, including some libraries, is covered by the
6186 ordinary GNU General Public License. This license, the GNU Lesser
6187 General Public License, applies to certain designated libraries, and is
6188 quite different from the ordinary General Public License. We use this
6189 license for certain libraries in order to permit linking those
6190 libraries into non-free programs.
6192 When a program is linked with a library, whether statically or using
6193 a shared library, the combination of the two is legally speaking a
6194 combined work, a derivative of the original library. The ordinary
6195 General Public License therefore permits such linking only if the
6196 entire combination fits its criteria of freedom. The Lesser General
6197 Public License permits more lax criteria for linking other code with
6200 We call this license the "Lesser" General Public License because it
6201 does _Less_ to protect the user's freedom than the ordinary General
6202 Public License. It also provides other free software developers Less
6203 of an advantage over competing non-free programs. These disadvantages
6204 are the reason we use the ordinary General Public License for many
6205 libraries. However, the Lesser license provides advantages in certain
6206 special circumstances.
6208 For example, on rare occasions, there may be a special need to
6209 encourage the widest possible use of a certain library, so that it
6210 becomes a de-facto standard. To achieve this, non-free programs must be
6211 allowed to use the library. A more frequent case is that a free
6212 library does the same job as widely used non-free libraries. In this
6213 case, there is little to gain by limiting the free library to free
6214 software only, so we use the Lesser General Public License.
6216 In other cases, permission to use a particular library in non-free
6217 programs enables a greater number of people to use a large body of free
6218 software. For example, permission to use the GNU C Library in non-free
6219 programs enables many more people to use the whole GNU operating
6220 system, as well as its variant, the GNU/Linux operating system.
6222 Although the Lesser General Public License is Less protective of the
6223 users' freedom, it does ensure that the user of a program that is
6224 linked with the Library has the freedom and the wherewithal to run that
6225 program using a modified version of the Library.
6227 The precise terms and conditions for copying, distribution and
6228 modification follow. Pay close attention to the difference between a
6229 "work based on the library" and a "work that uses the library". The
6230 former contains code derived from the library, whereas the latter must
6231 be combined with the library in order to run.
6233 GNU LESSER GENERAL PUBLIC LICENSE
6234 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
6235 0. This License Agreement applies to any software library or other
6236 program which contains a notice placed by the copyright holder or
6237 other authorized party saying it may be distributed under the
6238 terms of this Lesser General Public License (also called "this
6239 License"). Each licensee is addressed as "you".
6241 A "library" means a collection of software functions and/or data
6242 prepared so as to be conveniently linked with application programs
6243 (which use some of those functions and data) to form executables.
6245 The "Library", below, refers to any such software library or work
6246 which has been distributed under these terms. A "work based on the
6247 Library" means either the Library or any derivative work under
6248 copyright law: that is to say, a work containing the Library or a
6249 portion of it, either verbatim or with modifications and/or
6250 translated straightforwardly into another language. (Hereinafter,
6251 translation is included without limitation in the term
6254 "Source code" for a work means the preferred form of the work for
6255 making modifications to it. For a library, complete source code
6256 means all the source code for all modules it contains, plus any
6257 associated interface definition files, plus the scripts used to
6258 control compilation and installation of the library.
6260 Activities other than copying, distribution and modification are
6261 not covered by this License; they are outside its scope. The act
6262 of running a program using the Library is not restricted, and
6263 output from such a program is covered only if its contents
6264 constitute a work based on the Library (independent of the use of
6265 the Library in a tool for writing it). Whether that is true
6266 depends on what the Library does and what the program that uses
6269 1. You may copy and distribute verbatim copies of the Library's
6270 complete source code as you receive it, in any medium, provided
6271 that you conspicuously and appropriately publish on each copy an
6272 appropriate copyright notice and disclaimer of warranty; keep
6273 intact all the notices that refer to this License and to the
6274 absence of any warranty; and distribute a copy of this License
6275 along with the Library.
6277 You may charge a fee for the physical act of transferring a copy,
6278 and you may at your option offer warranty protection in exchange
6281 2. You may modify your copy or copies of the Library or any portion
6282 of it, thus forming a work based on the Library, and copy and
6283 distribute such modifications or work under the terms of Section 1
6284 above, provided that you also meet all of these conditions:
6286 a. The modified work must itself be a software library.
6288 b. You must cause the files modified to carry prominent notices
6289 stating that you changed the files and the date of any change.
6291 c. You must cause the whole of the work to be licensed at no
6292 charge to all third parties under the terms of this License.
6294 d. If a facility in the modified Library refers to a function or
6295 a table of data to be supplied by an application program that
6296 uses the facility, other than as an argument passed when the
6297 facility is invoked, then you must make a good faith effort
6298 to ensure that, in the event an application does not supply
6299 such function or table, the facility still operates, and
6300 performs whatever part of its purpose remains meaningful.
6302 (For example, a function in a library to compute square roots
6303 has a purpose that is entirely well-defined independent of the
6304 application. Therefore, Subsection 2d requires that any
6305 application-supplied function or table used by this function
6306 must be optional: if the application does not supply it, the
6307 square root function must still compute square roots.)
6309 These requirements apply to the modified work as a whole. If
6310 identifiable sections of that work are not derived from the
6311 Library, and can be reasonably considered independent and separate
6312 works in themselves, then this License, and its terms, do not
6313 apply to those sections when you distribute them as separate
6314 works. But when you distribute the same sections as part of a
6315 whole which is a work based on the Library, the distribution of
6316 the whole must be on the terms of this License, whose permissions
6317 for other licensees extend to the entire whole, and thus to each
6318 and every part regardless of who wrote it.
6320 Thus, it is not the intent of this section to claim rights or
6321 contest your rights to work written entirely by you; rather, the
6322 intent is to exercise the right to control the distribution of
6323 derivative or collective works based on the Library.
6325 In addition, mere aggregation of another work not based on the
6326 Library with the Library (or with a work based on the Library) on
6327 a volume of a storage or distribution medium does not bring the
6328 other work under the scope of this License.
6330 3. You may opt to apply the terms of the ordinary GNU General Public
6331 License instead of this License to a given copy of the Library.
6332 To do this, you must alter all the notices that refer to this
6333 License, so that they refer to the ordinary GNU General Public
6334 License, version 2, instead of to this License. (If a newer
6335 version than version 2 of the ordinary GNU General Public License
6336 has appeared, then you can specify that version instead if you
6337 wish.) Do not make any other change in these notices.
6339 Once this change is made in a given copy, it is irreversible for
6340 that copy, so the ordinary GNU General Public License applies to
6341 all subsequent copies and derivative works made from that copy.
6343 This option is useful when you wish to copy part of the code of
6344 the Library into a program that is not a library.
6346 4. You may copy and distribute the Library (or a portion or
6347 derivative of it, under Section 2) in object code or executable
6348 form under the terms of Sections 1 and 2 above provided that you
6349 accompany it with the complete corresponding machine-readable
6350 source code, which must be distributed under the terms of Sections
6351 1 and 2 above on a medium customarily used for software
6354 If distribution of object code is made by offering access to copy
6355 from a designated place, then offering equivalent access to copy
6356 the source code from the same place satisfies the requirement to
6357 distribute the source code, even though third parties are not
6358 compelled to copy the source along with the object code.
6360 5. A program that contains no derivative of any portion of the
6361 Library, but is designed to work with the Library by being
6362 compiled or linked with it, is called a "work that uses the
6363 Library". Such a work, in isolation, is not a derivative work of
6364 the Library, and therefore falls outside the scope of this License.
6366 However, linking a "work that uses the Library" with the Library
6367 creates an executable that is a derivative of the Library (because
6368 it contains portions of the Library), rather than a "work that
6369 uses the library". The executable is therefore covered by this
6370 License. Section 6 states terms for distribution of such
6373 When a "work that uses the Library" uses material from a header
6374 file that is part of the Library, the object code for the work may
6375 be a derivative work of the Library even though the source code is
6376 not. Whether this is true is especially significant if the work
6377 can be linked without the Library, or if the work is itself a
6378 library. The threshold for this to be true is not precisely
6381 If such an object file uses only numerical parameters, data
6382 structure layouts and accessors, and small macros and small inline
6383 functions (ten lines or less in length), then the use of the object
6384 file is unrestricted, regardless of whether it is legally a
6385 derivative work. (Executables containing this object code plus
6386 portions of the Library will still fall under Section 6.)
6388 Otherwise, if the work is a derivative of the Library, you may
6389 distribute the object code for the work under the terms of Section
6390 6. Any executables containing that work also fall under Section 6,
6391 whether or not they are linked directly with the Library itself.
6393 6. As an exception to the Sections above, you may also combine or
6394 link a "work that uses the Library" with the Library to produce a
6395 work containing portions of the Library, and distribute that work
6396 under terms of your choice, provided that the terms permit
6397 modification of the work for the customer's own use and reverse
6398 engineering for debugging such modifications.
6400 You must give prominent notice with each copy of the work that the
6401 Library is used in it and that the Library and its use are covered
6402 by this License. You must supply a copy of this License. If the
6403 work during execution displays copyright notices, you must include
6404 the copyright notice for the Library among them, as well as a
6405 reference directing the user to the copy of this License. Also,
6406 you must do one of these things:
6408 a. Accompany the work with the complete corresponding
6409 machine-readable source code for the Library including
6410 whatever changes were used in the work (which must be
6411 distributed under Sections 1 and 2 above); and, if the work
6412 is an executable linked with the Library, with the complete
6413 machine-readable "work that uses the Library", as object code
6414 and/or source code, so that the user can modify the Library
6415 and then relink to produce a modified executable containing
6416 the modified Library. (It is understood that the user who
6417 changes the contents of definitions files in the Library will
6418 not necessarily be able to recompile the application to use
6419 the modified definitions.)
6421 b. Use a suitable shared library mechanism for linking with the
6422 Library. A suitable mechanism is one that (1) uses at run
6423 time a copy of the library already present on the user's
6424 computer system, rather than copying library functions into
6425 the executable, and (2) will operate properly with a modified
6426 version of the library, if the user installs one, as long as
6427 the modified version is interface-compatible with the version
6428 that the work was made with.
6430 c. Accompany the work with a written offer, valid for at least
6431 three years, to give the same user the materials specified in
6432 Subsection 6a, above, for a charge no more than the cost of
6433 performing this distribution.
6435 d. If distribution of the work is made by offering access to copy
6436 from a designated place, offer equivalent access to copy the
6437 above specified materials from the same place.
6439 e. Verify that the user has already received a copy of these
6440 materials or that you have already sent this user a copy.
6442 For an executable, the required form of the "work that uses the
6443 Library" must include any data and utility programs needed for
6444 reproducing the executable from it. However, as a special
6445 exception, the materials to be distributed need not include
6446 anything that is normally distributed (in either source or binary
6447 form) with the major components (compiler, kernel, and so on) of
6448 the operating system on which the executable runs, unless that
6449 component itself accompanies the executable.
6451 It may happen that this requirement contradicts the license
6452 restrictions of other proprietary libraries that do not normally
6453 accompany the operating system. Such a contradiction means you
6454 cannot use both them and the Library together in an executable
6455 that you distribute.
6457 7. You may place library facilities that are a work based on the
6458 Library side-by-side in a single library together with other
6459 library facilities not covered by this License, and distribute
6460 such a combined library, provided that the separate distribution
6461 of the work based on the Library and of the other library
6462 facilities is otherwise permitted, and provided that you do these
6465 a. Accompany the combined library with a copy of the same work
6466 based on the Library, uncombined with any other library
6467 facilities. This must be distributed under the terms of the
6470 b. Give prominent notice with the combined library of the fact
6471 that part of it is a work based on the Library, and explaining
6472 where to find the accompanying uncombined form of the same
6475 8. You may not copy, modify, sublicense, link with, or distribute the
6476 Library except as expressly provided under this License. Any
6477 attempt otherwise to copy, modify, sublicense, link with, or
6478 distribute the Library is void, and will automatically terminate
6479 your rights under this License. However, parties who have
6480 received copies, or rights, from you under this License will not
6481 have their licenses terminated so long as such parties remain in
6484 9. You are not required to accept this License, since you have not
6485 signed it. However, nothing else grants you permission to modify
6486 or distribute the Library or its derivative works. These actions
6487 are prohibited by law if you do not accept this License.
6488 Therefore, by modifying or distributing the Library (or any work
6489 based on the Library), you indicate your acceptance of this
6490 License to do so, and all its terms and conditions for copying,
6491 distributing or modifying the Library or works based on it.
6493 10. Each time you redistribute the Library (or any work based on the
6494 Library), the recipient automatically receives a license from the
6495 original licensor to copy, distribute, link with or modify the
6496 Library subject to these terms and conditions. You may not impose
6497 any further restrictions on the recipients' exercise of the rights
6498 granted herein. You are not responsible for enforcing compliance
6499 by third parties with this License.
6501 11. If, as a consequence of a court judgment or allegation of patent
6502 infringement or for any other reason (not limited to patent
6503 issues), conditions are imposed on you (whether by court order,
6504 agreement or otherwise) that contradict the conditions of this
6505 License, they do not excuse you from the conditions of this
6506 License. If you cannot distribute so as to satisfy simultaneously
6507 your obligations under this License and any other pertinent
6508 obligations, then as a consequence you may not distribute the
6509 Library at all. For example, if a patent license would not permit
6510 royalty-free redistribution of the Library by all those who
6511 receive copies directly or indirectly through you, then the only
6512 way you could satisfy both it and this License would be to refrain
6513 entirely from distribution of the Library.
6515 If any portion of this section is held invalid or unenforceable
6516 under any particular circumstance, the balance of the section is
6517 intended to apply, and the section as a whole is intended to apply
6518 in other circumstances.
6520 It is not the purpose of this section to induce you to infringe any
6521 patents or other property right claims or to contest validity of
6522 any such claims; this section has the sole purpose of protecting
6523 the integrity of the free software distribution system which is
6524 implemented by public license practices. Many people have made
6525 generous contributions to the wide range of software distributed
6526 through that system in reliance on consistent application of that
6527 system; it is up to the author/donor to decide if he or she is
6528 willing to distribute software through any other system and a
6529 licensee cannot impose that choice.
6531 This section is intended to make thoroughly clear what is believed
6532 to be a consequence of the rest of this License.
6534 12. If the distribution and/or use of the Library is restricted in
6535 certain countries either by patents or by copyrighted interfaces,
6536 the original copyright holder who places the Library under this
6537 License may add an explicit geographical distribution limitation
6538 excluding those countries, so that distribution is permitted only
6539 in or among countries not thus excluded. In such case, this
6540 License incorporates the limitation as if written in the body of
6543 13. The Free Software Foundation may publish revised and/or new
6544 versions of the Lesser General Public License from time to time.
6545 Such new versions will be similar in spirit to the present version,
6546 but may differ in detail to address new problems or concerns.
6548 Each version is given a distinguishing version number. If the
6549 Library specifies a version number of this License which applies
6550 to it and "any later version", you have the option of following
6551 the terms and conditions either of that version or of any later
6552 version published by the Free Software Foundation. If the Library
6553 does not specify a license version number, you may choose any
6554 version ever published by the Free Software Foundation.
6556 14. If you wish to incorporate parts of the Library into other free
6557 programs whose distribution conditions are incompatible with these,
6558 write to the author to ask for permission. For software which is
6559 copyrighted by the Free Software Foundation, write to the Free
6560 Software Foundation; we sometimes make exceptions for this. Our
6561 decision will be guided by the two goals of preserving the free
6562 status of all derivatives of our free software and of promoting
6563 the sharing and reuse of software generally.
6566 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
6567 WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE
6568 LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
6569 HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT
6570 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
6571 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
6572 FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
6573 QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE
6574 LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
6575 SERVICING, REPAIR OR CORRECTION.
6577 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
6578 WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
6579 MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE
6580 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
6581 INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
6582 INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
6583 DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
6584 OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY
6585 OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
6586 ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
6588 END OF TERMS AND CONDITIONS
6589 How to Apply These Terms to Your New Libraries
6590 ==============================================
6592 If you develop a new library, and you want it to be of the greatest
6593 possible use to the public, we recommend making it free software that
6594 everyone can redistribute and change. You can do so by permitting
6595 redistribution under these terms (or, alternatively, under the terms of
6596 the ordinary General Public License).
6598 To apply these terms, attach the following notices to the library.
6599 It is safest to attach them to the start of each source file to most
6600 effectively convey the exclusion of warranty; and each file should have
6601 at least the "copyright" line and a pointer to where the full notice is
6604 ONE LINE TO GIVE THE LIBRARY'S NAME AND AN IDEA OF WHAT IT DOES.
6605 Copyright (C) YEAR NAME OF AUTHOR
6607 This library is free software; you can redistribute it and/or modify it
6608 under the terms of the GNU Lesser General Public License as published by
6609 the Free Software Foundation; either version 2.1 of the License, or (at
6610 your option) any later version.
6612 This library is distributed in the hope that it will be useful, but
6613 WITHOUT ANY WARRANTY; without even the implied warranty of
6614 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6615 Lesser General Public License for more details.
6617 You should have received a copy of the GNU Lesser General Public
6618 License along with this library; if not, write to the Free Software
6619 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
6622 Also add information on how to contact you by electronic and paper
6625 You should also get your employer (if you work as a programmer) or
6626 your school, if any, to sign a "copyright disclaimer" for the library,
6627 if necessary. Here is a sample; alter the names:
6629 Yoyodyne, Inc., hereby disclaims all copyright interest in the library
6630 `Frob' (a library for tweaking knobs) written by James Random Hacker.
6632 SIGNATURE OF TY COON, 1 April 1990
6633 Ty Coon, President of Vice
6635 That's all there is to it!