1 \input texinfo @c -*- Texinfo -*-
2 @setfilename gpgme.info
3 @settitle The `GnuPG Made Easy' Reference Manual
5 @dircategory GNU Libraries
7 * @acronym{GPGME}: (gpgme) Adding support for cryptography to your program.
12 @c Unify some of the indices.
17 This file documents the @acronym{GPGME} library.
19 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
20 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
23 Copyright @copyright{} 2002 g10 Code GmbH.
25 Permission is granted to copy, distribute and/or modify this document
26 under the terms of the GNU Free Documentation License, Version 1.1 or
27 any later version published by the Free Software Foundation; with the
28 Invariant Sections being ``Free Software Needs Free Documentation'' and
29 ``GNU Lesser General Public License'', the Front-Cover texts being (a)
30 (see below), and with the Back-Cover Texts being (b) (see below). A
31 copy of the license is included in the section entitled ``GNU Free
32 Documentation License''.
37 @shorttitlepage The `GnuPG Made Easy' Reference Manual
40 @center @titlefont{The `GnuPG Made Easy'}
42 @center @titlefont{Reference Manual}
44 @center Edition @value{EDITION}
46 @center last updated @value{UPDATED}
48 @center for version @value{VERSION}
50 @vskip 0pt plus 1filll
51 Copyright @copyright{} 2002 g10 Code GmbH.
53 Permission is granted to copy, distribute and/or modify this document
54 under the terms of the GNU Free Documentation License, Version 1.1 or
55 any later version published by the Free Software Foundation; with the
56 Invariant Sections being ``Free Software Needs Free Documentation'' and
57 ``GNU Lesser General Public License'', the Front-Cover texts being (a)
58 (see below), and with the Back-Cover Texts being (b) (see below). A
59 copy of the license is included in the section entitled ``GNU Free
60 Documentation License''.
67 This is Edition @value{EDITION}, last updated @value{UPDATED}, of
68 @cite{The `GnuPG Made Easy' Reference Manual}, for Version
69 @value{VERSION} of the @acronym{GPGME} library.
73 * Introduction:: How to use this manual.
74 * Preparation:: What you should do before using the library.
75 * Protocols and Engines:: Supported crypto protocols.
76 * Error Handling:: Error numbers and their meanings.
77 * Exchanging Data:: Passing data to and from @acronym{GPGME}.
78 * Contexts:: Handling @acronym{GPGME} contexts.
82 * Copying:: The GNU General Public License says how you
83 can copy and share `GnuPG Made Easy'.
84 * Free Documentation License:: This manual is under the GNU Free
85 Documentation License.
89 * Concept Index:: Index of concepts and programs.
90 * Function and Data Index:: Index of functions, variables and data types.
94 --- The Detailed Node Listing ---
98 * Getting Started:: Purpose of the manual, and how to use it.
99 * Features:: Reasons to install and use @acronym{GPGME}.
100 * Overview:: Basic architecture of the @acronym{GPGME} library.
104 * Header:: What header file you need to include.
105 * Building the Source:: Compiler options to be used.
106 * Library Version Check:: Getting and verifying the library version.
108 Protocols and Engines
110 * Engine Version Check:: Verifying the engine version.
111 * Engine Information:: Obtaining more information about the engines.
112 * OpenPGP:: Support for the OpenPGP protocol.
113 * Cryptographic Message Syntax:: Support for the CMS.
117 * Error Values:: A list of all error values used.
118 * Error Strings:: How to get a descriptive string from a value.
122 * Creating Data Buffers:: Creating new data buffers.
123 * Destroying Data Buffers:: Releasing data buffers.
124 * Manipulating Data Buffers:: Operations on data buffers.
128 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
129 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
130 * Context Attributes:: Setting properties of a context.
131 * Key Management:: Managing keys with @acronym{GPGME}.
132 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
133 * Crypto Operations:: Using a context for cryptography.
134 * Run Control:: Controlling how operations are run.
138 * Protocol Selection:: Selecting the protocol used by a context.
139 * @acronym{ASCII} Armor:: Requesting @acronym{ASCII} armored output.
140 * Text Mode:: Choosing canonical text mode.
141 * Included Certificates:: Including a number of certificates.
142 * Key Listing Mode:: Selecting key listing mode.
143 * Passphrase Callback:: Getting the passphrase from the user.
144 * Progress Meter Callback:: Being informed about the progress.
148 * Listing Keys:: Browsing the list of available keys.
149 * Information About Keys:: Requesting detailed information about keys.
150 * Manipulating Keys:: Operations on keys.
151 * Generating Keys:: Creating new key pairs.
152 * Exporting Keys:: Retrieving key data from the key ring.
153 * Importing Keys:: Adding keys to the key ring.
154 * Deleting Keys:: Removing keys from the key ring.
156 Trust Item Management
158 * Listing Trust Items:: Browsing the list of available trust items.
159 * Information About Trust Items:: Requesting detailed information about trust items.
160 * Manipulating Trust Items:: Operations on trust items.
164 * Decrypt:: Decrypting a ciphertext.
165 * Verify:: Verifying a signature.
166 * Decrypt and Verify:: Decrypting a signed ciphertext.
167 * Sign:: Creating a signature.
168 * Encrypt:: Encrypting a plaintext.
169 * Detailed Results:: How to obtain more info about the operation.
173 * Selecting Signers:: How to choose the keys to sign with.
174 * Creating a Signature:: How to create a signature.
178 * Selecting Recipients:: How to choose the recipients.
179 * Encrypting a Plaintext:: How to encrypt a plaintext.
183 * Waiting For Completion:: Waiting until an operation is completed.
184 * Cancelling an Operation:: Interrupting a running operation.
185 * Hooking Up Into Idle Time:: Doing something when nothing has to be done.
191 @chapter Introduction
193 `GnuPG Made Easy' (@acronym{GPGME}) is a C language library that
194 allows to add support for cryptography to a program. It is designed
195 to make access to crypto engines like GnuPG or GpgSM easier for
196 applications. @acronym{GPGME} provides a high-level crypto API for
197 encryption, decryption, signing, signature verification and key
200 @acronym{GPGME} uses GnuPG and GpgSM as its backends to support
201 OpenPGP and the Cryptographic Message Syntax (CMS).
204 * Getting Started:: Purpose of the manual, and how to use it.
205 * Features:: Reasons to install and use @acronym{GPGME}.
206 * Overview:: Basic architecture of the @acronym{GPGME} library.
210 @node Getting Started
211 @section Getting Started
213 This library documents the @acronym{GPGME} library programming
214 interface. All functions and data types provided by the library are
217 The reader is assumed to possess basic knowledge about cryptography in
218 general, and public key cryptography in particular. The underlying
219 cryptographic engines that are used by the library are not explained,
220 but where necessary, special features or requirements by an engine are
221 mentioned as far as they are relevant to @acronym{GPGME} or its users.
223 This manual can be used in several ways. If read from the beginning
224 to the end, it gives a good introduction into the library and how it
225 can be used in an application. Forward references are included where
226 necessary. Later on, the manual can be used as a reference manual to
227 get just the information needed about any particular interface of the
228 library. Experienced programmers might want to start looking at the
229 examples at the end of the manual, and then only read up those parts
230 of the interface which are unclear.
236 @acronym{GPGME} has a couple of advantages over other libraries doing
237 a similar job, and over implementing support for GnuPG or other crypto
238 engines into your application directly.
241 @item it's free software
242 Anybody can use, modify, and redistribute it under the terms of the GNU
243 General Public License (@pxref{Copying}).
246 @acronym{GPGME} provides transparent support for several cryptographic
247 protocols by different engines. Currently, @acronym{GPGME} supports
248 the OpenPGP protocol using GnuPG as the backend, and the Cryptographic
249 Message Syntax using GpgSM as the backend.
252 @acronym{GPGME} hides the differences between the protocols and
253 engines from the programmer behind an easy-to-use interface. This way
254 the programmer can focus on the other parts of the program, and still
255 integrate strong cryptography in his application. Once support for
256 @acronym{GPGME} has been added to a program, it is easy to add support
257 for other crypto protocols once @acronym{GPGME} backends provide them.
264 @acronym{GPGME} provides a data abstraction that is used to pass data
265 to the crypto engine, and receive returned data from it. Data can be
266 read from memory or from files, but it can also be provided by a
269 The actual cryptographic operations are always set within a context.
270 A context provides configuration parameters that define the behaviour
271 of all operations performed within it. Only one operation per context
272 is allowed at any time, but when one operation is finished, you can
273 run the next operation in the same context. There can be more than
274 one context, and all can run different operations at the same time.
276 Furthermore, @acronym{GPGME} has rich key management facilities
277 including listing keys, querying their attributes, generating,
278 importing, exporting and deleting keys, and acquiring information
279 about the trust path.
281 @cindex thread-safeness
282 @cindex multi-threading
283 @strong{Caution:} The @acronym{GPGME} library is not thread-safe. It
284 will be to some extent in the future, but currently great care has to
285 be taken if @acronym{GPGME} is used in a multi-threaded environment.
291 To use @acronym{GPGME}, you have to perform some changes to your
292 sources and the build system. The necessary changes are small and
293 explained in the following sections. At the end of this chapter, it
294 is described how the library is initialized, and how the requirements
295 of the library are verified.
298 * Header:: What header file you need to include.
299 * Building the Source:: Compiler options to be used.
300 * Library Version Check:: Getting and verifying the library version.
309 All interfaces (data types and functions) of the library are defined
310 in the header file `gpgme.h'. You must include this in all programs
311 using the library, either directly or through some other header file,
318 The name space of @acronym{GPGME} is @code{gpgme_*} for function
319 names, @code{Gpgme*} for data types and @code{GPGME_*} for other
323 @node Building the Source
324 @section Building the Source
325 @cindex compiler options
326 @cindex compiler flags
328 If you want to compile a source file including the `gpgme.h' header
329 file, you must make sure that the compiler can find it in the
330 directory hierarchy. This is accomplished by adding the path to the
331 directory in which the header file is located to the compilers include
332 file search path (via the @option{-I} option).
334 However, the path to the include file is determined at the time the
335 source is configured. To solve this problem, gpgme ships with a small
336 helper program @command{gpgme-config} that knows about the path to the
337 include file and other configuration options. The options that need
338 to be added to the compiler invocation at compile time are output by
339 the @option{--cflags} option to @command{gpgme-config}. The following
340 example shows how it can be used at the command line:
343 gcc -c foo.c `gpgme-config --cflags`
346 Adding the output of @samp{gpgme-config --cflags} to the compilers
347 command line will ensure that the compiler can find the @acronym{GPGME} header
350 A similar problem occurs when linking the program with the library.
351 Again, the compiler has to find the library files. For this to work,
352 the path to the library files has to be added to the library search
353 path (via the @option{-L} option). For this, the option
354 @option{--libs} to @command{gpgme-config} can be used. For
355 convenience, this option also outputs all other options that are
356 required to link the program with @acronym{GPGME} (in particular, the
357 @samp{-lgpgme} option). The example shows how to link @file{foo.o}
358 with the @acronym{GPGME} library to a program @command{foo}.
361 gcc -o foo foo.o `gpgme-config --libs`
364 Of course you can also combine both examples to a single command by
365 specifying both options to @command{gpgme-config}:
368 gcc -o foo foo.c `gpgme-config --cflags --libs`
372 @node Library Version Check
373 @section Library Version Check
374 @cindex version check, of the library
376 @deftypefun {const char *} gpgme_check_version (@w{const char *@var{required_version}})
377 The function @code{gpgme_check_version} has three purposes. It can be
378 used to retrieve the version number of the library. In addition it
379 can verify that the version number is higher than a certain required
380 version number. In either case, the function initializes some
381 sub-systems, and for this reason alone it must be invoked early in
382 your program, before you make use of the other functions in
385 If @var{required_version} is @code{NULL}, the function returns a
386 pointer to a statically allocated string containing the version number
389 If @var{required_version} is not @code{NULL}, it should point to a
390 string containing a version number, and the function checks that the
391 version of the library is at least as high as the version number
392 provided. In this case, the function returns a pointer to a
393 statically allocated string containing the version number of the
394 library. If @var{REQUIRED_VERSION} is not a valid version number, or
395 if the version requirement is not met, the function returns
398 If you use a version of a library that is backwards compatible with
399 older releases, but contains additional interfaces which your program
400 uses, this function provides a run-time check if the necessary
401 features are provided by the installed version of the library.
405 @node Protocols and Engines
406 @chapter Protocols and Engines
409 @cindex crypto engine
411 @cindex crypto backend
413 @acronym{GPGME} supports several cryptographic protocols, however, it
414 does not implement them. Rather it uses backends (also called
415 engines) which implement the protocol. @acronym{GPGME} uses
416 inter-process communication to pass data back and forth between the
417 application and the backend, but the details of the communication
418 protocol and invocation of the backends is completely hidden by the
419 interface. All complexity is handled by @acronym{GPGME}. Where an
420 exchange of information between the application and the backend is
421 necessary, @acronym{GPGME} provides the necessary callback function
422 hooks and further interfaces.
424 @deftp {Data type} {enum GpgmeProtocol}
425 @tindex GpgmeProtocol
426 The @code{GpgmeProtocol} type specifies the set of possible protocol
427 values that are supported by @acronym{GPGME}. The following protocols
431 @item GPGME_PROTOCOL_OpenPGP
432 This specifies the OpenPGP protocol.
433 @item GPGME_PROTOCOL_CMS
434 This specifies the Cryptographic Message Syntax.
439 * Engine Version Check:: Verifying the engine version.
440 * Engine Information:: Obtaining more information about the engines.
441 * OpenPGP:: Support for the OpenPGP protocol.
442 * Cryptographic Message Syntax:: Support for the CMS.
446 @node Engine Version Check
447 @section Engine Version Check
448 @cindex version check, of the engines
450 @deftypefun GpgmeError gpgme_engine_check_version (@w{GpgmeProtocol @var{protocol}})
451 The function @code{gpgme_engine_check_version} verifies that the
452 engine implementing the protocol @var{PROTOCOL} is installed in the
453 expected path and meets the version requirement of @acronym{GPGME}.
455 This function returns @code{GPGME_No_Error} if the engine is available
456 and @code{GPGME_Invalid_Engine} if it is not.
459 @deftypefun GpgmeError gpgme_check_engine (void)
460 The function @code{gpgme_check_engine} is equivalent to
463 gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
466 This function is deprecated and provided for backwards compatibility
467 only. It is obsoleted by @code{gpgme_engine_check_version}.
471 @node Engine Information
472 @section Engine Information
473 @cindex engine, information about
475 @deftypefun {const char *} gpgme_get_engine_info (void)
476 The function @code{gpgme_get_engine_info} returns an @acronym{XML}
477 string containing information about the available protocols and the
478 engine which implement them. The following information is returned
483 The name of the protocol.
485 The version of the engine.
487 The path to the engine binary.
490 A string is always returned. If an error occurs, the string will
491 contain an @samp{<error>} tag with a description of the failure.
494 Here is the example output of what @code{gpgme_get_engine_info} might
495 return on your system:
500 <protocol>OpenPGP</protocol>
501 <version>1.0.6</version>
502 <path>/usr/bin/gpg</path>
505 <protocol>CMS</protocol>
506 <version>0.0.0</version>
507 <path>/usr/bin/gpgsm</path>
517 @cindex protocol, GnuPG
518 @cindex engine, GnuPG
520 OpenPGP is implemented by GnuPG, the @acronym{GNU} Privacy Guard.
521 This is the first protocol that was supported by @acronym{GPGME}.
523 The OpenPGP protocol is specified by @code{GPGME_PROTOCOL_OpenPGP}.
526 @node Cryptographic Message Syntax
527 @section Cryptographic Message Syntax
529 @cindex cryptographic message syntax
531 @cindex protocol, CMS
532 @cindex engine, GpgSM
534 @cindex protocol, S/MIME
536 @acronym{CMS} is implemented by GpgSM, the S/MIME implementation for
539 The @acronym{CMS} protocol is specified by @code{GPGME_PROTOCOL_CMS}.
543 @chapter Error Handling
544 @cindex error handling
546 Many functions in @acronym{GPGME} can return an error if they fail.
547 For this reason, the application should always catch the error
548 condition and take appropriate measures, for example by releasing the
549 resources and passing the error up to the caller, or by displaying a
550 descriptive message to the user and cancelling the operation.
552 Some error values do not indicate a system error or an error in the
553 operation, but the result of an operation that failed properly. For
554 example, if you try to decrypt a tempered message, the decryption will
555 fail. Another error value actually means that the end of a data
556 buffer or list has been reached. The following descriptions explain
557 what each error message means in general. Some error values have
558 specific meanings if returned by a specific function. Such cases are
559 described in the documentation of those functions.
562 * Error Values:: A list of all error values used.
563 * Error Strings:: How to get a descriptive string from a value.
568 @section Error Values
569 @cindex error values, list of
571 @deftp {Data type} {enum GpgmeError}
573 The @code{GpgmeError} type specifies the set of all error values that
574 are used by @acronym{GPGME}. Possible values are:
578 This value indicates the end of a list, buffer or file.
581 This value indicates success. The value of this error is @code{0}.
583 @item GPGME_General_Error
584 This value means that something went wrong, but either there is not
585 enough information about the problem to return a more useful error
586 value, or there is no separate error value for this type of problem.
588 @item GPGME_Out_Of_Core
589 This value means that an out-of-memory condition occurred.
591 @item GPGME_Invalid_Value
592 This value means that some user provided data was out of range. This
593 can also refer to objects. For example, if an empty @code{GpgmeData}
594 object was expected, but one containing data was provided, this error
598 This value is returned if you try to start a new operation in a
599 context that is already busy with some earlier operation which was not
600 cancelled or finished yet.
602 @item GPGME_No_Request
603 This value is in some sense the opposite of @code{GPGME_Busy}. There
604 is no pending operation, but it is required for the function to
607 @item GPGME_Exec_Error
608 This value means that an error occurred when trying to spawn a child
611 @item GPGME_Too_Many_Procs
612 This value means that there are too many active backend processes.
614 @item GPGME_Pipe_Error
615 This value means that the creation of a pipe failed.
617 @item GPGME_No_Recipients
618 This value means that no valid recipients for a message have been set.
620 @item GPGME_Invalid_Recipients
621 This value means that some, but not all, recipients for a message have
625 This value means that a @code{GpgmeData} object which was expected to
626 have content was found empty.
629 This value means that a conflict of some sort occurred.
631 @item GPGME_Not_Implemented
632 This value indicates that the specific function (or operation) is not
633 implemented. This error should never happen. It can only occur if
634 you use certain values or configuration options which do not work,
635 but for which we think that they should work at some later time.
637 @item GPGME_Read_Error
638 This value means that an I/O read operation failed.
640 @item GPGME_Write_Error
641 This value means that an I/O write operation failed.
643 @item GPGME_Invalid_Type
644 This value means that a user provided object was of a wrong or
645 incompatible type. Usually this refers to the type of a
646 @code{GpgmeData} object.
648 @item GPGME_Invalid_Mode
649 This value means that a @code{GpgmeData} object has an incorrect mode
650 of operation (for example, doesn't support output although it is
651 attempted to use it as an output buffer).
653 @item GPGME_File_Error
654 This value means that a file I/O operation failed. The value of
655 @code{errno} contains the system error value.
657 @item GPGME_Decryption_Failed
658 This value indicates that a decryption operation was unsuccessful.
660 @item GPGME_No_Passphrase
661 This value means that the user did not provide a passphrase when
665 This value means that the operation was canceled.
667 @item GPGME_Invalid_Key
668 This value means that a key was invalid.
670 @item GPGME_Invalid_Engine
671 This value means that the engine that implements the desired protocol
672 is currently not available. This can either be because the sources
673 were configured to exclude support for this engine, or because the
674 engine is not installed properly.
680 @section Error Strings
681 @cindex error values, printing of
682 @cindex error strings
684 @deftypefun {const char *} gpgme_strerror (@w{GpgmeError @var{err}})
685 The function @code{gpgme_strerror} returns a pointer to a statically
686 allocated string containing a description of the error with the error
687 value @var{err}. This string can be used to output a diagnostic
690 The following example illustrates the use of @code{gpgme_strerror}:
694 GpgmeError err = gpgme_new (&ctx);
697 fprintf (stderr, "%s: creating GpgME context failed: %s\n",
698 argv[0], gpgme_strerror (err));
705 @node Exchanging Data
706 @chapter Exchanging Data
707 @cindex data, exchanging
709 A lot of data has to be exchanged between the user and the crypto
710 engine, like plaintext messages, ciphertext, signatures and
711 information about the keys. The technical details about exchanging
712 the data information are completely abstracted by @acronym{GPGME}.
713 The user provides and receives the data via @code{GpgmeData} objects,
714 regardless of the communication protocol between @acronym{GPGME} and
715 the crypto engine in use.
717 @deftp {Data type} {GpgmeData}
718 The @code{GpgmeData} type is a handle for a container for generic
719 data, which is used by @acronym{GPGME} to exchange data with the user.
723 * Creating Data Buffers:: Creating new data buffers.
724 * Destroying Data Buffers:: Releasing data buffers.
725 * Manipulating Data Buffers:: Operations on data buffers.
729 @node Creating Data Buffers
730 @section Creating Data Buffers
731 @cindex data buffer, creation
733 @deftypefun GpgmeError gpgme_data_new (@w{GpgmeData *@var{dh}})
734 The function @code{gpgme_data_new} creates a new @code{GpgmeData}
735 object and returns a handle for it in @var{dh}. The data object is
738 The function returns @code{GPGME_No_Error} if the data object was
739 successfully created, @code{GPGME_Invalid_Value} if @var{dh} is not a
740 valid pointer, and @code{GPGME_Out_Of_Core} if not enough memory is
744 @deftypefun GpgmeError gpgme_data_new_from_mem (@w{GpgmeData *@var{dh}}, @w{const char *@var{buffer}}, @w{size_t @var{size}}, @w{int @var{copy}})
745 The function @code{gpgme_data_new_from_mem} creates a new
746 @code{GpgmeData} object and fills it with @var{size} bytes starting
749 If @var{copy} is not zero, a private copy of the data is made. If
750 @var{copy} is zero, the data is taken from the specified buffer as
751 needed, and the user has to ensure that the buffer remains valid for
752 the whole life span of the data object.
754 The function returns @code{GPGME_No_Error} if the data object was
755 successfully created, @code{GPGME_Invalid_Value} if @var{dh} or
756 @var{buffer} is not a valid pointer, and @code{GPGME_Out_Of_Core} if
757 not enough memory is available.
760 @deftypefun GpgmeError gpgme_data_new_from_file (@w{GpgmeData *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}})
761 The function @code{gpgme_data_new_from_file} creates a new
762 @code{GpgmeData} object and fills it with the content of the file
765 If @var{copy} is not zero, the whole file is read in at initialization
766 time and the file is not used anymore after that. This is the only
767 mode supported currently. Later, a value of zero for @var{copy} might
768 cause all reads to be delayed until the data is needed, but this is
771 The function returns @code{GPGME_No_Error} if the data object was
772 successfully created, @code{GPGME_Invalid_Value} if @var{dh} or
773 @var{filename} is not a valid pointer, @code{GPGME_File_Error} if an
774 I/O operation fails, @code{GPGME_Not_Implemented} if @var{code} is
775 zero, and @code{GPGME_Out_Of_Core} if not enough memory is available.
778 @deftypefun GpgmeError gpgme_data_new_from_filepart (@w{GpgmeData *@var{dh}}, @w{const char *@var{filename}}, @w{FILE *@var{fp}}, @w{off_t @var{offset}}, @w{size_t @var{length}})
779 The function @code{gpgme_data_new_from_filepart} creates a new
780 @code{GpgmeData} object and fills it with a part of the file specified
781 by @var{filename} or @var{fp}.
783 Exactly one of @var{filename} and @var{fp} must be non-zero, the other
784 must be zero. The argument that is not zero specifies the file from
785 which @var{length} bytes are read into the data object, starting from
788 The function returns @code{GPGME_No_Error} if the data object was
789 successfully created, @code{GPGME_Invalid_Value} if @var{dh} and
790 exactly one of @var{filename} and @var{fp} is not a valid pointer,
791 @code{GPGME_File_Error} if an I/O operation fails, and
792 @code{GPGME_Out_Of_Core} if not enough memory is available.
795 @deftypefun GpgmeError gpgme_data_new_with_read_cb (@w{GpgmeData *@var{dh}}, @w{int (*@var{readfunc})} (@w{void *@var{hook}}, @w{char *@var{buffer}}, @w{size_t @var{count}}, @w{size_t *@var{nread}}), @w{void *@var{hook_value}})
796 The function @code{gpgme_data_new_with_read_cb} creates a new
797 @code{GpgmeData} object and uses the callback function @var{readfunc}
798 to retrieve the data on demand. As the callback function can supply
799 the data in any way it wants, this is the most flexible data type
800 @acronym{GPGME} provides. However, it can not be used to write data.
802 The callback function receives @var{hook_value} as its first argument
803 whenever it is invoked. It should return up to @var{count} bytes in
804 @var{buffer}, and return the number of bytes actually read in
805 @var{nread}. It may return @code{0} in @var{nread} if no data is
806 currently available. To indicate @code{EOF} the function should
807 return with an error code of @code{-1} and set @var{nread} to
808 @code{0}. The callback function may support to reset its internal
809 read pointer if it is invoked with @var{buffer} and @var{nread} being
810 @code{NULL} and @var{count} being @code{0}.
812 The function returns @code{GPGME_No_Error} if the data object was
813 successfully created, @code{GPGME_Invalid_Value} if @var{dh} or
814 @var{readfunc} is not a valid pointer, and @code{GPGME_Out_Of_Core} if
815 not enough memory is available.
819 @node Destroying Data Buffers
820 @section Destroying Data Buffers
821 @cindex data buffer, destruction
823 @deftypefun void gpgme_data_release (@w{GpgmeData @var{dh}})
824 The function @code{gpgme_data_release} destroys the data object with
825 the handle @var{dh}. It releases all associated resources that were
826 not provided by the user in the first place.
829 @deftypefun {char *} gpgme_data_release_and_get_mem (@w{GpgmeData @var{dh}}, @w{size_t *@var{length}})
830 The function @code{gpgme_data_release_and_get_mem} is like
831 @code{gpgme_data_release}, except that it returns the data buffer and
832 its length that was provided by the object.
834 The user has to release the buffer with @code{free}. In case the user
835 provided the data buffer in non-copy mode, a copy will be made for
838 In case an error returns, or there is no suitable data buffer that can
839 be returned to the user, the function will return @code{NULL}.
843 @node Manipulating Data Buffers
844 @section Manipulating Data Buffers
845 @cindex data buffere, manipulation
847 @deftypefun GpgmeError gpgme_data_read (@w{GpgmeData @var{dh}}, @w{char *@var{buffer}}, @w{size_t @var{length}}, @w{size_t *@var{nread}})
848 The function @code{gpgme_data_read} reads up to @var{length} bytes
849 from the data object with the handle @var{dh} into the space starting
850 at @var{buffer}. The actual amount read is returned in @var{nread}.
852 If @var{buffer} is @code{NULL}, the function returns the amount of
853 bytes available in @var{nread} without changing the read pointer.
854 This is not supported by all types of data objects. If this function
855 is not supported, @code{GPGME_Invalid_Type} is returned.
857 If the end of the data object is reached, the function returns
858 @code{GPGME_EOF} and sets @var{nread} to zero.
860 In all other cases, the function returns @code{GPGME_No_Error} if the
861 operation was successfully performed and @code{GPGME_Invalid_Value} if
862 @var{dh} is not a valid pointer.
865 @deftypefun GpgmeError gpgme_data_rewind (@w{GpgmeData @var{dh}})
866 The function @code{gpgme_data_rewind} resets the read pointer of the
867 data object with the handle @var{dh}, so that a subsequent
868 @code{gpgme_data_read} operation starts at the beginning of the data.
870 The function returns @code{GPGME_No_Error} if the operation was
871 successfully performed, @code{GPGME_Not_Implemented} if the operation
872 is not supported (for example, by a read callback function supplied by
873 the user) and @code{GPGME_Invalid_Value} if @var{dh} is not a valid
877 @deftypefun GpgmeError gpgme_data_write (@w{GpgmeData @var{dh}}, @w{const char *@var{buffer}}, @w{size_t @var{length}})
878 The function @code{gpgme_data_write} writes @var{length} bytes
879 starting from @var{buffer} into the data object with the handle
880 @var{dh} at the current write position.
882 The function returns @code{GPGME_No_Error} if the operation was
883 successfully performed, @code{GPGME_Invalid_Value} if @var{dh} or
884 @var{buffer} is not a valid pointer, @code{GPGME_Invalid_Type} or
885 @code{GPGME_Invalid_Mode} if the data object type does not support
886 writing, and @code{GPGME_Out_Of_Core} if not enough memory is
890 @deftp {Data type} {enum GpgmeDataType}
891 @tindex GpgmeDataType
892 The @code{GpgmeDataType} type specifies the type of a @code{GpgmeData} object.
893 The following data types are available:
896 @item GPGME_DATA_TYPE_NONE
897 This specifies that the type is not yet determined.
899 @item GPGME_DATA_TYPE_MEM
900 This specifies that the data is stored in memory.
902 @item GPGME_DATA_TYPE_FD
903 This type is not implemented.
905 @item GPGME_DATA_TYPE_FILE
906 This type is not implemented.
908 @item GPGME_DATA_TYPE_CB
909 This type specifies that the data is provided by a callback function
910 implemented by the user.
914 @deftypefun GpgmeDataType gpgme_data_get_type (@w{GpgmeData @var{dh}})
915 The function @code{gpgme_data_get_type} returns the type of the data
916 object with the handle @var{dh}. If @var{dh} is not a valid pointer,
917 @code{GPGME_DATA_TYPE_NONE} is returned.
925 All cryptographic operations in @acronym{GPGME} are performed within a
926 context, which contains the internal state of the operation as well as
927 configuration parameters. By using several contexts you can run
928 several cryptographic operations in parallel, with different
931 @deftp {Data type} {GpgmeCtx}
932 The @code{GpgmeCtx} type is a handle for a @acronym{GPGME} context,
933 which is used to hold the configuration, status and result of
934 cryptographic operations.
938 * Creating Contexts:: Creating new @acronym{GPGME} contexts.
939 * Destroying Contexts:: Releasing @acronym{GPGME} contexts.
940 * Context Attributes:: Setting properties of a context.
941 * Key Management:: Managing keys with @acronym{GPGME}.
942 * Trust Item Management:: Managing trust items with @acronym{GPGME}.
943 * Crypto Operations:: Using a context for cryptography.
944 * Run Control:: Controlling how operations are run.
948 @node Creating Contexts
949 @section Creating Contexts
950 @cindex context, creation
952 @deftypefun GpgmeError gpgme_new (@w{GpgmeCtx *@var{ctx}})
953 The function @code{gpgme_data_new} creates a new @code{GpgmeCtx}
954 object and returns a handle for it in @var{ctx}.
956 The function returns @code{GPGME_No_Error} if the context was
957 successfully created, @code{GPGME_Invalid_Value} if @var{ctx} is not a
958 valid pointer, and @code{GPGME_Out_Of_Core} if not enough memory is
963 @node Destroying Contexts
964 @section Destroying Contexts
965 @cindex context, destruction
967 @deftypefun void gpgme_release (@w{GpgmeCtx @var{ctx}})
968 The function @code{gpgme_release} destroys the context with the handle
969 @var{ctx} and releases all associated resources.
973 @node Context Attributes
974 @section Context Attributes
975 @cindex context, attributes
978 * Protocol Selection:: Selecting the protocol used by a context.
979 * @acronym{ASCII} Armor:: Requesting @acronym{ASCII} armored output.
980 * Text Mode:: Choosing canonical text mode.
981 * Included Certificates:: Including a number of certificates.
982 * Key Listing Mode:: Selecting key listing mode.
983 * Passphrase Callback:: Getting the passphrase from the user.
984 * Progress Meter Callback:: Being informed about the progress.
988 @node Protocol Selection
989 @subsection Protocol Selection
990 @cindex context, selecting protocol
991 @cindex protocol, selecting
993 @deftypefun GpgmeError gpgme_set_protocol (@w{GpgmeCtx @var{ctx}}, @w{GpgmeProtocol @var{proto}})
994 The function @code{gpgme_set_protocol} sets the protocol used within
995 the context @var{ctx} to @var{proto}. All crypto operations will be
996 performed by the crypto engine configured for that protocol.
997 @xref{Protocols and Engines}.
999 Setting the protocol with @code{gpgme_set_protocol} does not check if
1000 the crypto engine for that protocol is available and installed
1001 correctly. @xref{Engine Version Check}.
1003 The function returns @code{GPGME_No_Error} if the protocol could be
1004 set successfully, and @code{GPGME_Invalid_Value} if @var{protocol} is
1005 not a valid protocol.
1009 @node @acronym{ASCII} Armor
1010 @subsection @acronym{ASCII} Armor
1011 @cindex context, armor mode
1012 @cindex @acronym{ASCII} armor
1015 @deftypefun void gpgme_set_armor (@w{GpgmeCtx @var{ctx}}, @w{int @var{yes}})
1016 The function @code{gpgme_set_armor} specifies if the output should be
1017 @acronym{ASCII} armored. By default, output is not @acronym{ASCII}
1020 @acronym{ASCII} armored output is disabled if @var{yes} is zero, and
1024 @deftypefun int gpgme_get_armor (@w{GpgmeCtx @var{ctx}})
1025 The function @code{gpgme_get_armor} returns 1 if the output is
1026 @acronym{ASCII} armored, and @code{0} if it is not, or if @var{ctx} is
1027 not a valid pointer.
1032 @subsection Text Mode
1033 @cindex context, text mode
1035 @cindex canonical text mode
1037 @deftypefun void gpgme_set_textmode (@w{GpgmeCtx @var{ctx}}, @w{int @var{yes}})
1038 The function @code{gpgme_set_textmode} specifies if canonical text mode
1039 should be used. By default, text mode is not used.
1041 Text mode is for example used for the RFC2015 signatures; note that
1042 the updated RFC 3156 mandates that the mail user agent does some
1043 preparations so that text mode is not needed anymore.
1045 This option is only relevant to the OpenPGP crypto engine, and ignored
1046 by all other engines.
1048 Canonical text mode is disabled if @var{yes} is zero, and enabled
1052 @deftypefun int gpgme_get_textmode (@w{GpgmeCtx @var{ctx}})
1053 The function @code{gpgme_get_textmode} returns 1 if canonical text
1054 mode is enabled, and @code{0} if it is not, or if @var{ctx} is not a
1059 @node Included Certificates
1060 @subsection Included Certificates
1061 @cindex certificates, included
1063 @deftypefun void gpgme_set_include_certs (@w{GpgmeCtx @var{ctx}}, @w{int @var{nr_of_certs}})
1064 The function @code{gpgme_set_include_certs} specifies how many
1065 certificates should be included in an S/MIME signed message. By
1066 default, only the sender's certificate is included. The possible
1067 values of @var{nr_of_certs} are:
1071 Include all certificates except the root certificate.
1073 Include all certificates.
1075 Include no certificates.
1077 Include the sender's certificate only.
1079 Include the first n certificates of the certificates path, starting
1080 from the sender's certificate. The number @code{n} must be positive.
1083 Values of @var{nr_of_certs} smaller than -2 are undefined.
1085 This option is only relevant to the CMS crypto engine, and ignored
1086 by all other engines.
1089 @deftypefun int gpgme_get_include_certs (@w{GpgmeCtx @var{ctx}})
1090 The function @code{gpgme_get_include_certs} returns the number of
1091 certificates to include into an S/MIME signed message.
1095 @node Key Listing Mode
1096 @subsection Key Listing Mode
1097 @cindex key listing mode
1098 @cindex key listing, mode of
1100 @deftypefun void gpgme_set_keylist_mode (@w{GpgmeCtx @var{ctx}}, @w{int @var{mode}})
1101 The function @code{gpgme_set_keylist_mode} changes the default
1102 behaviour of the key listing functions. The value in @var{mode} is a
1103 bitwise-or combination of one or multiple of the following bit values:
1106 @item GPGME_KEYLIST_MODE_LOCAL
1107 The @code{GPGME_KEYLIST_MODE_LOCAL} symbol specifies that the local
1108 keyring should be searched for keys in the keylisting operation. This
1111 @item GPGME_KEYLIST_MODE_EXTERN
1112 The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external
1113 source should be should be searched for keys in the keylisting
1114 operation. The type of external source is dependant on the crypto
1115 engine used. For example, it can be a remote keyserver or LDAP
1119 At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and
1120 @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary
1121 compatibility, you should get the current mode with
1122 @code{gpgme_get_keylist_mode} and modify it by setting or clearing the
1123 appropriate bits, and then using that calulcated value in the
1124 @code{gpgme_set_keylisting_mode} operation. This will leave all other
1125 bits in the mode value intact (in particular those that are not used
1126 in the current version of the library).
1128 The function returns @code{GPGME_No_Error} if the mode could be set
1129 correctly, and @code{GPGME_Invalid_Value} if @var{ctx} is not a valid
1130 pointer or @var{mode} is not a valid mode.
1134 @deftypefun int gpgme_get_keylist_mode (@w{GpgmeCtx @var{ctx}})
1135 The function @code{gpgme_get_keylist_mode} returns the current key
1136 listing mode of the context @var{ctx}. This value can then be
1137 modified and used in a subsequent @code{gpgme_set_keylist_mode}
1138 operation to only affect the desired bits (and leave all others
1141 The function returns 0 if @var{ctx} is not a valid pointer, and the
1142 current mode otherwise. Note that 0 is not a valid mode value.
1146 @node Passphrase Callback
1147 @subsection Passphrase Callback
1148 @cindex callback, passphrase
1149 @cindex passphrase callback
1151 @deftp {Data type} {const char *(*GpgmePassphraseCb)(void *@var{hook}, const char *@var{desc}, void **@var{r_hd})}
1152 @tindex GpgmePassphraseCb
1153 The @code{GpgmePassphraseCb} type is the type of functions usable as
1154 passphrase callback function.
1156 The string @var{desc} contains a test usable to be displayed to the
1157 user of the application. The function should return a passphrase for
1158 the context when invoked with @var{desc} not being @code{NULL}.
1160 The user may store information about the resources associated with the
1161 returned passphrase in @var{*r_hd}. When the passphrase is no longer
1162 needed by @acronym{GPGME}, the passphrase callback function will be
1163 called with @var{desc} being @var{NULL}, and @var{r_hd} being the same
1164 as at the first invocation.
1167 @deftypefun void gpgme_set_passphrase_cb (@w{GpgmeCtx @var{ctx}}, @w{GpgmePassphraseCb @var{passfunc}}, @w{void *@var{hook_value}})
1168 The function @code{gpgme_set_passphrase_cb} sets the function that is
1169 used when a passphrase needs to be provided by the user to
1170 @var{passfunc}. The function @var{passfunc} needs to implemented by
1171 the user, and whenever it is called, it is called with its first
1172 argument being @var{hook_value}. By default, no passphrase callback
1175 Not all crypto engines require this callback to retrieve the
1176 passphrase. It is better if the engine retrieves the passphrase from
1177 a trusted agent (a daemon process), rather than having each user to
1178 implement their own passphrase query.
1180 The user can disable the use of a passphrase callback function by
1181 calling @code{gpgme_set_passphrase_cb} with @var{passfunc} being
1186 @node Progress Meter Callback
1187 @subsection Progress Meter Callback
1188 @cindex callback, progress meter
1189 @cindex progress meter callback
1191 @deftp {Data type} {const char *(*GpgmeProgressCb)(void *@var{hook}, const char *@var{what}, int @var{type}, int @var{current}, int @var{total})}
1192 @tindex GpgmeProgressCb
1193 The @code{GpgmeProgressCb} type is the type of functions usable as
1194 progress callback function.
1196 The arguments are specific to the crypto engine. More information
1197 about the progress information returned from the GnuPG engine can be
1198 found in the GnuPG source code in the file @file{doc/DETAILS} in the
1202 @deftypefun void gpgme_set_progress_cb (@w{GpgmeCtx @var{ctx}}, @w{GpgmeProgressCb @var{progfunc}}, @w{void *@var{hook_value}})
1203 The function @code{gpgme_set_progress_cb} sets the function that is
1204 used when progress information about a cryptographic operation is
1205 available. The function @var{progfunc} needs to implemented by the
1206 user, and whenever it is called, it is called with its first argument
1207 being @var{hook_value}. By default, no progress callback function
1210 Setting a callback function allows an interactive program to display
1211 progress information about a long operation to the user.
1213 The user can disable the use of a progress callback function by
1214 calling @code{gpgme_set_progress_cb} with @var{progfunc} being
1219 @node Key Management
1220 @section Key Management
1221 @cindex key management
1223 Some of the cryptographic operations require that recipients or
1224 signers are specified. This is always done by specifying the
1225 respective keys that should be used for the operation. The following
1226 section describes how such keys can be selected and manipulated.
1228 @deftp {Data type} GpgmeKey
1229 The @code{GpgmeKey} type is a handle for a public or secret key, and
1230 is used to select the key for operations involving it.
1232 A key can contain several user IDs and sub keys.
1236 * Listing Keys:: Browsing the list of available keys.
1237 * Information About Keys:: Requesting detailed information about keys.
1238 * Manipulating Keys:: Operations on keys.
1239 * Generating Keys:: Creating new key pairs.
1240 * Exporting Keys:: Retrieving key data from the key ring.
1241 * Importing Keys:: Adding keys to the key ring.
1242 * Deleting Keys:: Removing keys from the key ring.
1247 @subsection Listing Keys
1248 @cindex listing keys
1250 @cindex key listing, start
1251 @cindex key ring, list
1252 @cindex key ring, search
1254 @deftypefun GpgmeError gpgme_op_keylist_start (@w{GpgmeCtx @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{secret_only}})
1255 The function @code{gpgme_op_keylist_start} initiates a key listing
1256 operation inside the context @var{ctx}. It sets everything up so that
1257 subsequent invocations of @code{gpgme_op_keylist_next} return the keys
1260 If @var{pattern} is @code{NULL}, all available keys are returned.
1261 Otherwise, @var{pattern} contains an engine specific expression that
1262 is used to limit the list to all keys matching the pattern.
1264 If @var{secret_only} is not @code{0}, the list is restricted to secret
1267 The context will be busy until either all keys are received (and
1268 @code{gpgme_op_keylist_next} returns @code{GPGME_EOF}), or
1269 @code{gpgme_op_keylist_end} is called to finish the operation.
1271 The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a
1272 valid pointer, and passes through any errors that are reported by the
1273 crypto engine support routines.
1276 @deftypefun GpgmeError gpgme_op_keylist_ext_start (@w{GpgmeCtx @var{ctx}}, @w{const char *@var{pattern}[]}, @w{int @var{secret_only}}, @w{int @var{reserved}})
1277 The function @code{gpgme_op_keylist_ext_start} initiates an extended
1278 key listing operation inside the context @var{ctx}. It sets
1279 everything up so that subsequent invocations of
1280 @code{gpgme_op_keylist_next} return the keys in the list.
1282 If @var{pattern} or @var{*pattern} is @code{NULL}, all available keys
1283 are returned. Otherwise, @var{pattern} is a @code{NULL} terminated
1284 array of strings that are used to limit the list to all keys matching
1285 at least one of the patterns verbatim.
1287 If @var{secret_only} is not @code{0}, the list is restricted to secret
1290 The value of @var{reserved} must be @code{0}.
1292 The context will be busy until either all keys are received (and
1293 @code{gpgme_op_keylist_next} returns @code{GPGME_EOF}), or
1294 @code{gpgme_op_keylist_end} is called to finish the operation.
1296 The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a
1297 valid pointer, and passes through any errors that are reported by the
1298 crypto engine support routines.
1301 @deftypefun GpgmeError gpgme_op_keylist_next (@w{GpgmeCtx @var{ctx}}, @w{GpgmeKey *@var{r_key}})
1302 The function @code{gpgme_op_keylist_next} returns the next key in the
1303 list created by a previous @code{gpgme_op_keylist_start} operation in
1304 the context @var{ctx}. The key will have one reference for the user.
1305 @xref{Manipulating Keys}.
1307 This is the only way to get at @code{GpgmeKey} objects in
1310 If the last key in the list has already been returned,
1311 @code{gpgme_op_keylist_next} returns @code{GPGME_EOF}.
1313 The function returns @code{GPGME_Invalid_Value} if @var{ctx} or
1314 @var{r_key} is not a valid pointer, @code{GPGME_No_Request} if there
1315 is no pending operation, @code{GPGME_Out_Of_Core} if there is not
1316 enough memory for the operation.
1319 @deftypefun GpgmeError gpgme_op_keylist_end (@w{GpgmeCtx @var{ctx}})
1320 The function @code{gpgme_op_keylist_next} ends a pending key list
1321 operation in the context @var{ctx}.
1323 The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a
1324 valid pointer, @code{GPGME_No_Request} if there is no pending
1325 operation, @code{GPGME_Out_Of_Core} if at some time during the
1326 operation there was not enough memory available.
1329 The following example illustrates how all keys containing a certain
1330 string (@code{g10code}) can be listed with their key ID and the name
1331 and e-mail address of the main user ID:
1335 GpgmeError err = gpgme_new (&ctx);
1339 err = gpgme_op_keylist_start (ctx, "g10code", 0);
1340 while (!err && (err = gpgme_op_keylist_next (ctx, &key)) != GPGME_EOF)
1342 printf ("%s: %s <%s>\n",
1343 gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, 0, 0),
1344 gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, 0, 0),
1345 gpgme_key_get_string_attr (key, GPGME_ATTR_EMAIL, 0, 0));
1346 gpgme_key_release (key);
1348 gpgme_release (ctx);
1352 fprintf (stderr, "%s: can not list keys: %s\n",
1353 argv[0], gpgme_strerror (err));
1359 @node Information About Keys
1360 @subsection Information About Keys
1361 @cindex key, information about
1362 @cindex key, attributes
1363 @cindex attributes, of a key
1365 @deftypefun {char *} gpgme_key_get_as_xml (@w{GpgmeKey @var{key}})
1366 The function @code{gpgme_key_get_as_xml} returns a string in
1367 @acronym{XML} format describing the key @var{key}. The user has to
1368 release the string with @code{free}.
1370 The function returns @code{NULL} if @var{key} is not a valid pointer,
1371 or there is not enough memory available.
1374 @deftp {Data type} GpgmeAttr
1375 The @code{GpgmeAttr} type is used to specify a key or trust item
1376 attribute. The following attributes are defined:
1379 @item GPGME_ATTR_KEYID
1380 This is the key ID of a sub key. It is representable as a string.
1382 For trust items, the trust item refers to the key with this ID.
1384 @item GPGME_ATTR_FPR
1385 This is the fingerprint of a sub key. It is representable as a
1388 @item GPGME_ATTR_ALGO
1389 This is the crypto algorithm for which the sub key can be used. It
1390 is representable as a string and as a number. The numbers correspond
1391 to the @code{enum gcry_pk_algos} values in the gcrypt library.
1393 @item GPGME_ATTR_LEN
1394 This is the key length of a sub key. It is representable as a
1397 @item GPGME_ATTR_CREATED
1398 This is the timestamp at creation time of a sub key. It is
1399 representable as a number.
1401 @item GPGME_ATTR_EXPIRE
1402 This is the expiration time of a sub key. It is representable as a
1405 @item GPGME_ATTR_OTRUST
1406 XXX FIXME (also for trust items)
1408 @item GPGME_ATTR_USERID
1409 This is a user ID. There can be more than one user IDs in a
1410 @var{GpgmeKey} object. The first one (with index 0) is the primary
1411 user ID. The user ID is representable as a number.
1413 For trust items, this is the user ID associated with this trust item.
1415 @item GPGME_ATTR_NAME
1416 This is the name belonging to a user ID. It is representable as a string.
1418 @item GPGME_ATTR_EMAIL
1419 This is the email address belonging to a user ID. It is representable
1422 @item GPGME_ATTR_COMMENT
1423 This is the comment belonging to a user ID. It is representable as a
1426 @item GPGME_ATTR_VALIDITY
1427 This is the validity belonging to a user ID. It is representable as a
1428 string and as a number. See below for a list of available validities.
1430 For trust items, this is the validity that is associated with this
1433 @item GPGME_ATTR_UID_REVOKED
1434 This specifies if a user ID is revoked. It is representable as a
1435 number, and is @code{1} if the user ID is revoked, and @code{0}
1438 @item GPGME_ATTR_UID_INVALID
1439 This specifies if a user ID is invalid. It is representable as a
1440 number, and is @code{1} if the user ID is invalid, and @code{0}
1443 @item GPGME_ATTR_LEVEL
1444 This is the trust level of a trust item.
1446 @item GPGME_ATTR_TYPE
1447 This is the type of a trust item.
1449 @item GPGME_ATTR_IS_SECRET
1450 This specifies if the key is a secret key. It is representable as a
1451 string or a number. If the key is a secret key, the representation is
1452 ``1'' or @code{1}, otherwise it is @code{NULL} or @code{0}.
1454 @item GPGME_ATTR_KEY_REVOKED
1455 This specifies if a sub key is revoked. It is representable as a
1456 number, and is @code{1} if the key is revoked, and @code{0} otherwise.
1458 @item GPGME_ATTR_KEY_INVALID
1459 This specifies if a sub key is invalid. It is representable as a
1460 number, and is @code{1} if the key is invalid, and @code{0} otherwise.
1462 @item GPGME_ATTR_KEY_EXPIRED
1463 This specifies if a sub key is expired. It is representable as a
1464 number, and is @code{1} if the key is expired, and @code{0} otherwise.
1466 @item GPGME_ATTR_KEY_DISABLED
1467 This specifies if a sub key is disabled. It is representable as a
1468 number, and is @code{1} if the key is disabled, and @code{0} otherwise.
1470 @item GPGME_ATTR_KEY_CAPS
1471 This is a description of the capabilities of a sub key. It is
1472 representable as a string. The string contains the letter ``e'' if
1473 the key can be used for encryption, ``s'' if the key can be used for
1474 signatures, and ``c'' if the key can be used for certifications.
1476 @item GPGME_ATTR_CAN_ENCRYPT
1477 This specifies if a sub key can be used for encryption. It is
1478 representable as a number, and is @code{1} if the sub key can be used
1479 for encryption, and @code{0} otherwise.
1481 @item GPGME_ATTR_CAN_SIGN
1482 This specifies if a sub key can be used for signatures. It is
1483 representable as a number, and is @code{1} if the sub key can be used
1484 for signatures, and @code{0} otherwise.
1486 @item GPGME_ATTR_CAN_CERTIFY
1487 This specifies if a sub key can be used for certifications. It is
1488 representable as a number, and is @code{1} if the sub key can be used
1489 for certifications, and @code{0} otherwise.
1493 @deftp {Data type} GpgmeValidity
1494 The @code{GpgmeValidity} type is used to specify the validity of a user ID
1495 in a key. The following validities are defined:
1498 @item GPGME_VALIDITY_UNKNOWN
1499 The user ID is of unknown validity. The string representation of this
1502 @item GPGME_VALIDITY_UNDEFINED
1503 The validity of the user ID is undefined. The string representation of this
1506 @item GPGME_VALIDITY_NEVER
1507 The user ID is never valid. The string representation of this
1510 @item GPGME_VALIDITY_MARGINAL
1511 The user ID is marginally valid. The string representation of this
1514 @item GPGME_VALIDITY_FULL
1515 The user ID is fully valid. The string representation of this
1518 @item GPGME_VALIDITY_ULTIMATE
1519 The user ID is ultimately valid. The string representation of this
1524 @deftypefun {const char *} gpgme_key_get_string_attr (@w{GpgmeKey @var{key}}, @w{GpgmeAttr @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
1525 The function @code{gpgme_key_get_string_attr} returns the value of the
1526 string-representable attribute @var{what} of key @var{key}. If the
1527 attribute occurs more than once in the key, the index is specified by
1528 @var{idx}. This applies to attributes of sub keys and user IDs. The
1529 argument @var{reserved} is reserved for later use and should be
1532 The string returned is only valid as long as the key is valid.
1534 The function returns @code{0} if an attribute can't be returned as a
1535 string, @var{key} is not a valid pointer, @var{idx} out of range,
1536 or @var{reserved} not @code{NULL}.
1539 @deftypefun {unsigned long} gpgme_key_get_ulong_attr (@w{GpgmeKey @var{key}}, @w{GpgmeAttr @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
1540 The function @code{gpgme_key_get_ulong_attr} returns the value of the
1541 number-representable attribute @var{what} of key @var{key}. If the
1542 attribute occurs more than once in the key, the index is specified by
1543 @var{idx}. This applies to attributes of sub keys and user IDs. The
1544 argument @var{reserved} is reserved for later use and should be
1547 The function returns @code{0} if the attribute can't be returned as a
1548 number, @var{key} is not a valid pointer, @var{idx} out of range,
1549 or @var{reserved} not @code{NULL}.
1553 @node Manipulating Keys
1554 @subsection Manipulating Keys
1555 @cindex key, manipulation
1557 @deftypefun void gpgme_key_ref (@w{GpgmeKey @var{key}})
1558 The function @code{gpgme_key_ref} acquires an additional reference for
1562 @deftypefun void gpgme_key_unref (@w{GpgmeKey @var{key}})
1563 @deftypefunx void gpgme_key_release (@w{GpgmeKey @var{key}})
1564 The function @code{gpgme_key_ref} releases a reference for the key
1565 @var{key}. If this was the last reference, the key will be destroyed
1566 and all resources associated to it will be released.
1568 The function @code{gpgme_key_release} is an alias for
1569 @code{gpgme_key_unref}.
1573 @node Generating Keys
1574 @subsection Generating Keys
1575 @cindex key, creation
1576 @cindex key ring, add
1578 @deftypefun GpgmeError gpgme_op_genkey (@w{GpgmeCtx @var{ctx}}, @w{const char *@var{parms}}, @w{GpgmeData @var{pubkey}}, @w{GpgmeData @var{seckey}})
1579 The function @code{gpgme_op_genkey} generates a new key pair in the
1580 context @var{ctx} and puts it into the standard key ring if both
1581 @var{pubkey} and @var{seckey} are @code{NULL}. In this case the
1582 function returns immediately after starting the operation, and does
1583 not wait for it to complete. If @var{pubkey} is not @code{NULL} it
1584 should be the handle for an empty (newly created) data object, and
1585 upon successful completion the data object will contain the public
1586 key. If @var{seckey} is not @code{NULL} it should be the handle for
1587 an empty (newly created) data object, and upon successful completion
1588 the data object will contain the secret key.
1590 Note that not all crypto engines support this interface equally.
1591 GnuPG does not support @var{pubkey} and @var{subkey}, they should be
1592 both @code{NULL}, and the key pair will be added to the standard key
1593 ring. GpgSM does only support @var{pubkey}, the secret key will be
1594 stored by @command{gpg-agent}. GpgSM expects @var{pubkey} being not
1597 The argument @var{parms} specifies parameters for the key in an XML
1598 string. The details about the format of @var{parms} are specific to
1599 the crypto engine used by @var{ctx}. Here is an example for GnuPG as
1603 <GnupgKeyParms format="internal">
1608 Name-Real: Joe Tester
1609 Name-Comment: with stupid passphrase
1610 Name-Email: joe@@foo.bar
1616 Here is an example for GpgSM as the crypto engine:
1618 <GnupgKeyParms format="internal">
1621 Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester
1622 Name-Email: joe@@foo.bar
1626 Strings should be given in UTF-8 encoding. The only format supported
1627 for now is ``internal''. The content of the @code{GnupgKeyParms}
1628 container is passed verbatim to GnuPG. Control statements are not
1631 The function returns @code{GPGME_No_Error} if the operation could be
1632 started successfully, @code{GPGME_Invalid_Value} if @var{parms} is not
1633 a valid XML string, @code{GPGME_Not_Supported} if @var{pubkey} or
1634 @var{seckey} is not valid, and @code{GPGME_General_Error} if no key
1635 was created by the backend.
1638 @deftypefun GpgmeError gpgme_op_genkey_start (@w{GpgmeCtx @var{ctx}}, @w{const char *@var{parms}}, @w{GpgmeData @var{pubkey}}, @w{GpgmeData @var{seckey}})
1639 The function @code{gpgme_op_genkey_start} initiates a
1640 @code{gpgme_op_genkey} operation. It can be completed by calling
1641 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
1643 The function returns @code{GPGME_No_Error} if the operation could be
1644 started successfully, @code{GPGME_Invalid_Value} if @var{parms} is not
1645 a valid XML string, and @code{GPGME_Not_Supported} if @var{pubkey} or
1646 @var{seckey} is not @code{NULL}.
1650 @node Exporting Keys
1651 @subsection Exporting Keys
1653 @cindex key ring, export from
1655 @deftypefun GpgmeError gpgme_op_export (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{recipients}}, @w{GpgmeData @var{keydata}})
1656 The function @code{gpgme_op_export} extracts the public keys of the
1657 user IDs in @var{recipients} and returns them in the data buffer
1658 @var{keydata}. The type of the public keys returned is determined by
1659 the @acronym{ASCII} armor attribute set for the context @var{ctx}.
1661 The function returns @code{GPGME_No_Error} if the operation completed
1662 successfully, @code{GPGME_Invalid_Value} if @var{recipients} is
1663 @code{NULL} or @var{keydata} is not a valid empty data buffer, and
1664 passes through any errors that are reported by the crypto engine
1668 @deftypefun GpgmeError gpgme_op_export_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{recipients}}, @w{GpgmeData @var{keydata}})
1669 The function @code{gpgme_op_export_start} initiates a
1670 @code{gpgme_op_export} operation. It can be completed by calling
1671 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
1673 The function returns @code{GPGME_No_Error} if the operation could be
1674 started successfully, and @code{GPGME_Invalid_Value} if
1675 @var{recipients} is @code{NULL} or @var{keydata} is not a valid empty
1680 @node Importing Keys
1681 @subsection Importing Keys
1683 @cindex key ring, import to
1685 @deftypefun GpgmeError gpgme_op_import (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{keydata}})
1686 The function @code{gpgme_op_import} adds the keys in the data buffer
1687 @var{keydata} to the key ring of the crypto engine used by @var{ctx}.
1688 The format of @var{keydata} can be @var{ASCII} armored, for example,
1689 but the details are specific to the crypto engine.
1691 More information about the import is available with
1692 @code{gpgme_get_op_info}. @xref{Detailed Results}.
1694 The function returns @code{GPGME_No_Error} if the import was completed
1695 successfully, @code{GPGME_Invalid_Value} if @var{keydata} if @var{ctx}
1696 or @var{keydata} is not a valid pointer, and @code{GPGME_No_Data} if
1697 @var{keydata} is an empty data buffer.
1700 @deftypefun GpgmeError gpgme_op_import_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{keydata}})
1701 The function @code{gpgme_op_import_start} initiates a
1702 @code{gpgme_op_import} operation. It can be completed by calling
1703 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
1705 The function returns @code{GPGME_No_Error} if the import could be
1706 started successfully, @code{GPGME_Invalid_Value} if @var{keydata} if
1707 @var{ctx} or @var{keydata} is not a valid pointer, and
1708 @code{GPGME_No_Data} if @var{keydata} is an empty data buffer.
1713 @subsection Deleting Keys
1715 @cindex key ring, delete from
1717 @deftypefun GpgmeError gpgme_op_delete (@w{GpgmeCtx @var{ctx}}, @w{const GpgmeKey @var{key}}, @w{int @var{allow_secret}})
1718 The function @code{gpgme_op_delete} deletes the key @var{key} from the
1719 key ring of the crypto engine used by @var{ctx}. If
1720 @var{allow_secret} is @code{0}, only public keys are deleted,
1721 otherwise secret keys are deleted as well.
1723 The function returns @code{GPGME_No_Error} if the key was deleted
1724 successfully, @code{GPGME_Invalid_Value} if @var{ctx} or @var{key} is
1725 not a valid pointer, @code{GPGME_Invalid_Key} if @var{key} could not
1726 be found in the keyring, and @code{GPGME_Conflict} if the secret key
1727 for @var{key} is available, but @var{allow_secret} is zero.
1730 @deftypefun GpgmeError gpgme_op_delete_start (@w{GpgmeCtx @var{ctx}}, @w{const GpgmeKey @var{key}}, @w{int @var{allow_secret}})
1731 The function @code{gpgme_op_delete_start} initiates a
1732 @code{gpgme_op_delete} operation. It can be completed by calling
1733 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
1735 The function returns @code{GPGME_No_Error} if the operation was
1736 started successfully, and @code{GPGME_Invalid_Value} if @var{ctx} or
1737 @var{key} is not a valid pointer.
1741 @node Trust Item Management
1742 @section Trust Item Management
1745 @strong{Caution:} The trust items interface is experimental.
1747 @deftp {Data type} GpgmeTrustItem
1748 The @code{GpgmeTrustItem} type is a handle for a trust item.
1752 * Listing Trust Items:: Browsing the list of available trust items.
1753 * Information About Trust Items:: Requesting detailed information about trust items.
1754 * Manipulating Trust Items:: Operations on trust items.
1758 @node Listing Trust Items
1759 @subsection Listing Trust Items
1760 @cindex trust item list
1762 @deftypefun GpgmeError gpgme_op_trustlist_start (@w{GpgmeCtx @var{ctx}}, @w{const char *@var{pattern}}, @w{int @var{max_level}})
1763 The function @code{gpgme_op_trustlist_start} initiates a trust item
1764 listing operation inside the context @var{ctx}. It sets everything up
1765 so that subsequent invocations of @code{gpgme_op_trustlist_next} return
1766 the trust items in the list.
1768 The string @var{pattern} contains an engine specific expression that
1769 is used to limit the list to all trust items matching the pattern. It
1770 can not be the empty string.
1772 The argument @var{max_level} is currently ignored.
1774 The context will be busy until either all trust items are received
1775 (and @code{gpgme_op_trustlist_next} returns @code{GPGME_EOF}), or
1776 @code{gpgme_op_trustlist_end} is called to finish the operation.
1778 The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a
1779 valid pointer, and passes through any errors that are reported by the
1780 crypto engine support routines.
1783 @deftypefun GpgmeError gpgme_op_trustlist_next (@w{GpgmeCtx @var{ctx}}, @w{GpgmeTrustItem *@var{r_item}})
1784 The function @code{gpgme_op_trustlist_next} returns the next trust
1785 item in the list created by a previous @code{gpgme_op_trustlist_start}
1786 operation in the context @var{ctx}. The trust item can be destroyed
1787 with @code{gpgme_trust_item_release}. @xref{Manipulating Trust Items}.
1789 This is the only way to get at @code{GpgmeTrustItem} objects in
1792 If the last trust item in the list has already been returned,
1793 @code{gpgme_op_trustlist_next} returns @code{GPGME_EOF}.
1795 The function returns @code{GPGME_Invalid_Value} if @var{ctx} or
1796 @var{r_item} is not a valid pointer, @code{GPGME_No_Request} if there
1797 is no pending operation, @code{GPGME_Out_Of_Core} if there is not
1798 enough memory for the operation.
1801 @deftypefun GpgmeError gpgme_op_trustlist_end (@w{GpgmeCtx @var{ctx}})
1802 The function @code{gpgme_op_trustlist_next} ends a pending key list
1803 operation in the context @var{ctx}.
1805 The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a
1806 valid pointer, @code{GPGME_No_Request} if there is no pending
1807 operation, @code{GPGME_Out_Of_Core} if at some time during the
1808 operation there was not enough memory available.
1812 @node Information About Trust Items
1813 @subsection Information About Trust Items
1814 @cindex trust item, information about
1815 @cindex trust item, attributes
1816 @cindex attributes, of a trust item
1818 Trust items have attributes which can be queried using the interfaces
1819 below. The attribute identifiers are shared with those for key
1820 attributes. @xref{Information About Keys}.
1822 @deftypefun {const char *} gpgme_trust_item_get_string_attr (@w{GpgmeTrustItem @var{item}}, @w{GpgmeAttr @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
1823 The function @code{gpgme_trust_item_get_string_attr} returns the value
1824 of the string-representable attribute @var{what} of trust item
1825 @var{item}. If the attribute occurs more than once in the trust
1826 items, the index is specified by @var{idx}. However, currently no
1827 such attributes exists, so @var{idx} should be @code{0}. The argument
1828 @var{reserved} is reserved for later use and should be @code{NULL}.
1830 The string returned is only valid as long as the key is valid.
1832 The function returns @code{0} if an attribute can't be returned as a
1833 string, @var{key} is not a valid pointer, @var{idx} out of range,
1834 or @var{reserved} not @code{NULL}.
1837 @deftypefun int gpgme_trust_item_get_int_attr (@w{GpgmeTrustItem @var{item}}, @w{GpgmeAttr @var{what}}, @w{const void *@var{reserved}}, @w{int @var{idx}})
1838 The function @code{gpgme_trust_item_get_int_attr} returns the value of
1839 the number-representable attribute @var{what} of trust item
1840 @var{item}. If the attribute occurs more than once in the trust item,
1841 the index is specified by @var{idx}. However, currently no such
1842 attribute exists, so @var{idx} should be @code{0}. The argument
1843 @var{reserved} is reserved for later use and should be @code{NULL}.
1845 The function returns @code{0} if the attribute can't be returned as a
1846 number, @var{key} is not a valid pointer, @var{idx} out of range,
1847 or @var{reserved} not @code{NULL}.
1851 @node Manipulating Trust Items
1852 @subsection Manipulating Trust Items
1853 @cindex trust item, manipulation
1855 @deftypefun void gpgme_trust_item_release (@w{GpgmeTrustItem @var{item}})
1856 The function @code{gpgme_trust_item_release} destroys a
1857 @code{GpgmeTrustItem} object and releases all associated resources.
1860 @node Crypto Operations
1861 @section Crypto Operations
1862 @cindex cryptographic operation
1865 * Decrypt:: Decrypting a ciphertext.
1866 * Verify:: Verifying a signature.
1867 * Decrypt and Verify:: Decrypting a signed ciphertext.
1868 * Sign:: Creating a signature.
1869 * Encrypt:: Encrypting a plaintext.
1870 * Detailed Results:: How to obtain more info about the operation.
1877 @cindex cryptographic operation, decryption
1879 @deftypefun GpgmeError gpgme_op_decrypt (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{cipher}}, @w{GpgmeData @var{plain}})
1880 The function @code{gpgme_op_decrypt} decrypts the ciphertext in the
1881 data object @var{cipher} and stores it into the data object
1884 The function returns @code{GPGME_No_Error} if the ciphertext could be
1885 decrypted successfully, @code{GPGME_Invalid_Value} if @var{ctx},
1886 @var{cipher} or @var{plain} is not a valid pointer,
1887 @code{GPGME_No_Data} if @var{cipher} does not contain any data to
1888 decrypt, @code{GPGME_Decryption_Failed} if @var{cipher} is not a valid
1889 cipher text, @code{GPGME_No_Passphrase} if the passphrase for the
1890 secret key could not be retrieved, and passes through any errors that
1891 are reported by the crypto engine support routines.
1894 @deftypefun GpgmeError gpgme_op_decrypt_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{cipher}}, @w{GpgmeData @var{plain}})
1895 The function @code{gpgme_op_decrypt_start} initiates a
1896 @code{gpgme_op_decrypt} operation. It can be completed by calling
1897 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
1899 The function returns @code{GPGME_No_Error} if the operation could be
1900 started successfully, and @code{GPGME_Invalid_Value} if @var{cipher}
1901 or @var{plain} is not a valid pointer.
1907 @cindex verification
1908 @cindex signature, verification
1909 @cindex cryptographic operation, verification
1910 @cindex cryptographic operation, signature check
1911 @cindex signature, status
1913 @deftp {Data type} {enum GpgmeSigStat}
1914 @tindex GpgmeSigStat
1915 The @code{GpgmeSigStat} type holds the result of a signature check, or
1916 the combined result of all signatures. The following results are
1920 @item GPGME_SIG_STAT_NONE
1921 This status should not occur in normal operation.
1923 @item GPGME_SIG_STAT_GOOD
1924 This status indicates that the signature is valid. For the combined
1925 result this status means that all signatures are valid.
1927 @item GPGME_SIG_STAT_BAD
1928 This status indicates that the signature is invalid. For the combined
1929 result this status means that all signatures are invalid.
1931 @item GPGME_SIG_STAT_NOKEY
1932 This status indicates that the signature could not be verified due to
1933 a missing key. For the combined result this status means that all
1934 signatures could not be checked due to missing keys.
1936 @item GPGME_SIG_STAT_NOSIG
1937 This status indicates that the signature data provided was not a real
1940 @item GPGME_SIG_STAT_ERROR
1941 This status indicates that there was some other error which prevented
1942 the signature verification.
1944 @item GPGME_SIG_STAT_DIFF
1945 For the combined result this status means that at least two signatures
1946 have a different status. You can get each key's status with
1947 @code{gpgme_get_sig_status}.
1951 @deftypefun GpgmeError gpgme_op_verify (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{sig}}, @w{GpgmeData @var{plain}}, @w{GpgmeSigStat *@var{r_stat}})
1952 The function @code{gpgme_op_verify} verifies that the signature in the
1953 data object @var{sig} is a valid signature. If @var{plain} is
1954 initialized with plaintext data, it is assumed that @var{sig} is a
1955 detached signature, and its validity for the plaintext given in
1956 @var{plain} is verified. If @var{plain} is an uninitialized data
1957 object, it is assumed that @var{sig} is a normal (or cleartext)
1958 signature, and the plaintext is available in @var{plain} after
1959 successful verification.
1961 The combined status of all signatures is returned in @var{r_stat}.
1962 The results of the individual signature verifications can be retrieved
1963 with @code{gpgme_get_sig_status} and @code{gpgme_get_sig_key}.
1965 The function returns @code{GPGME_No_Error} if the operation could be
1966 completed successfully, @code{GPGME_Invalid_Value} if @var{ctx},
1967 @var{sig}, @var{plain} or @var{r_stat} is not a valid pointer,
1968 @code{GPGME_No_Data} if @var{sig} does not contain any data to verify,
1969 and passes through any errors that are reported by the crypto engine
1973 @deftypefun GpgmeError gpgme_op_verify_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{sig}}, @w{GpgmeData @var{plain}})
1974 The function @code{gpgme_op_verify_start} initiates a
1975 @code{gpgme_op_verify} operation. It can be completed by calling
1976 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
1978 The function returns @code{GPGME_No_Error} if the operation could be
1979 started successfully, @code{GPGME_Invalid_Value} if @var{ctx},
1980 @var{sig}, @var{plain} or @var{r_stat} is not a valid pointer, and
1981 @code{GPGME_No_Data} if @var{sig} or @var{plain} does not contain any
1985 @deftypefun {const char *} gpgme_get_sig_status (@w{GpgmeCtx @var{ctx}}, @w{int @var{idx}}, @w{GpgmeSigStat *@var{r_stat}}, @w{time_t *@var{r_created}})
1986 The function @code{gpgme_get_sig_status} receives information about a
1987 signature after the @code{gpgme_op_verify} or
1988 @code{gpgme_op_verify_decrypt} operation. A single detached signature
1989 can contain signatures by more than one key. The @var{idx} specifies
1990 which signature's information should be retrieved, starting from
1993 The status of the signature will be returned in @var{r_stat} if it is
1994 not @code{NULL}. The creation time stamp of the signature will be
1995 returned in @var{r_created} if it is not @var{NULL}.
1997 The function returns a statically allocated string that contains the
1998 fingerprint of the key which signed the plaintext, or @code{NULL} if
1999 @var{ctx} is not a valid pointer, the operation is still pending, or
2000 no verification could be performed.
2003 @deftypefun {const char *} gpgme_get_sig_key (@w{GpgmeCtx @var{ctx}}, @w{int @var{idx}}, @w{GpgmeSigKey *@var{r_stat}})
2004 The function @code{gpgme_get_sig_status} receives a @code{GpgmeKey}
2005 object for the key which was used to verify the signature after the
2006 @code{gpgme_op_verify} or @code{gpgme_op_verify_decrypt} operation. A
2007 single detached signature can contain signatures by more than one key.
2008 The @var{idx} specifies which signature's information should be
2009 retrieved, starting from @var{0}. The key will have on reference for
2012 The function is a convenient way to retrieve the keys belonging to the
2013 fingerprints returned by @code{gpgme_get_sig_status}.
2015 The function returns @code{GPGME_No_Error} if the key could be
2016 returned, @code{GPGME_Invalid_Value} if @var{r_key} is not a valid
2017 pointer, @code{GPGME_Invalid_Key} if the fingerprint is not valid,
2018 @code{GPGME_EOF} if @var{idx} is too large, or some other error value
2019 if a problem occurred requesting the key.
2022 @deftypefun {char *} gpgme_get_notation (@w{GpgmeCtx @var{ctx}})
2023 The function @code{gpgme_get_notation} can be used to retrieve
2024 notation data from the last signature check in the context @var{ctx}.
2026 If there is notation data available from the last signature check,
2027 this function may be used to return this notation data as a string.
2028 The string is an XML representation of that data embedded in a
2029 <notation> container. The user has to release the string with
2032 The function returns a string if the notation data is available or
2033 @code{NULL} if there is no such data available.
2037 @node Decrypt and Verify
2038 @subsection Decrypt and Verify
2039 @cindex decryption and verification
2040 @cindex verification and decryption
2041 @cindex signature check
2042 @cindex cryptographic operation, decryption and verification
2044 @deftypefun GpgmeError gpgme_op_decrypt_verify (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{cipher}}, @w{GpgmeData @var{plain}}, @w{GpgmeSigStat *@var{r_stat}})
2045 The function @code{gpgme_op_decrypt_verify} decrypts the ciphertext in
2046 the data object @var{cipher} and stores it into the data object
2047 @var{plain}. If @var{cipher} contains signatures, they will be
2048 verified and their combined status will be returned in @var{r_stat}.
2050 After the operation completed, @code{gpgme_op_get_sig_status} and
2051 @code{gpgme_op_get_sig_key} can be used to retrieve more information
2052 about the signatures.
2054 The function returns @code{GPGME_No_Error} if the ciphertext could be
2055 decrypted successfully, @code{GPGME_Invalid_Value} if @var{ctx},
2056 @var{cipher}, @var{plain} or @var{r_stat} is not a valid pointer,
2057 @code{GPGME_No_Data} if @var{cipher} does not contain any data to
2058 decrypt, @code{GPGME_Decryption_Failed} if @var{cipher} is not a valid
2059 cipher text, @code{GPGME_No_Passphrase} if the passphrase for the
2060 secret key could not be retrieved, and passes through any errors that
2061 are reported by the crypto engine support routines.
2064 @deftypefun GpgmeError gpgme_op_decrypt_verify (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{cipher}}, @w{GpgmeData @var{plain}})
2065 The function @code{gpgme_op_decrypt_verify_start} initiates a
2066 @code{gpgme_op_decrypt_verify} operation. It can be completed by
2067 calling @code{gpgme_wait} on the context. @xref{Waiting For
2070 The function returns @code{GPGME_No_Error} if the operation could be
2071 started successfully, @code{GPGME_Invalid_Value} if @var{ctx},
2072 @var{cipher}, @var{plain} or @var{r_stat} is not a valid pointer, and
2073 @code{GPGME_No_Data} if @var{cipher} does not contain any data to
2080 @cindex signature, creation
2082 @cindex cryptographic operation, signing
2084 A signature can contain signatures by one or more keys. The set of
2085 keys used to create a signatures is contained in a context, and is
2086 applied to all following signing operations in this context (until the
2090 * Selecting Signers:: How to choose the keys to sign with.
2091 * Creating a Signature:: How to create a signature.
2095 @node Selecting Signers
2096 @subsubsection Selecting Signers
2097 @cindex signature, selecting signers
2098 @cindex signers, selecting
2100 @deftypefun void gpgme_signers_clear (@w{GpgmeCtx @var{ctx}})
2101 The function @code{gpgme_signers_clear} releases a reference for each
2102 key on the signers list and removes the list of signers from the
2105 Every context starts with an empty list.
2108 @deftypefun GpgmeError gpgme_signers_add (@w{GpgmeCtx @var{ctx}}, @w{const GpgmeKey @var{key}})
2109 The function @code{gpgme_signers_add} adds the key @var{key} to the
2110 list of signers in the context @var{ctx}.
2112 One reference for the key is consumed.
2115 @deftypefun GpgmeKey gpgme_signers_enum (@w{const GpgmeCtx @var{ctx}}, @w{int @var{seq}})
2116 The function @code{gpgme_signers_enum} returns the @var{seq}th key in
2117 the list of signers in the context @var{ctx}. An additional reference
2118 is acquired for the user.
2120 If @var{seq} is out of range, @code{NULL} is returned.
2124 @node Creating a Signature
2125 @subsubsection Creating a Signature
2127 @deftp {Data type} {enum GpgmeSigMode}
2128 @tindex GpgmeSigMode
2129 The @code{GpgmeSigMode} type is used to specify the desired type of a
2130 signature. The following modes are available:
2133 @item GPGME_SIG_MODE_NORMAL
2134 A normal signature is made, the output includes the plaintext and the
2137 @item GPGME_SIG_MODE_DETACH
2138 A detached signature is made.
2140 @item GPGME_SIG_MODE_CLEAR
2141 A clear text signature is made. The @acronym{ASCII} armor and text
2142 mode settings of the context are ignored.
2146 @deftypefun GpgmeError gpgme_op_sign (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{sig}}, @w{GpgmeSigMode @var{mode}})
2147 The function @code{gpgme_op_sign} creates a signature for the text in
2148 the data object @var{plain} and returns it in the data object
2149 @var{sig}. The type of the signature created is determined by the
2150 @acronym{ASCII} armor and text mode attributes set for the context
2151 @var{ctx} and the requested signature mode @var{mode}.
2153 More information about the signatures is available with
2154 @code{gpgme_get_op_info}. @xref{Detailed Results}.
2156 If an S/MIME signed message is created using the CMS crypto engine,
2157 the number of certificates to include in the message can be specified
2158 with @code{gpgme_set_include_certs}. @xref{Included Certificates}.
2160 The function returns @code{GPGME_No_Error} if the signature could be
2161 created successfully, @code{GPGME_Invalid_Value} if @var{ctx},
2162 @var{plain} or @var{sig} is not a valid pointer, @code{GPGME_No_Data}
2163 if the signature could not be created, @code{GPGME_No_Passphrase} if
2164 the passphrase for the secret key could not be retrieved, and passes
2165 through any errors that are reported by the crypto engine support
2169 @deftypefun GpgmeError gpgme_op_sign (@w{GpgmeCtx @var{ctx}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{sig}}, @w{GpgmeSigMode @var{mode}})
2170 The function @code{gpgme_op_sign_start} initiates a
2171 @code{gpgme_op_sign} operation. It can be completed by calling
2172 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
2174 The function returns @code{GPGME_No_Error} if the operation could be
2175 started successfully, and @code{GPGME_Invalid_Value} if @var{ctx},
2176 @var{plain} or @var{sig} is not a valid pointer.
2183 @cindex cryptographic operation, encryption
2185 One plaintext can be encrypted for several recipients at the same
2186 time. The list of recipients is created independently of any context,
2187 and then passed to the encryption operation.
2190 * Selecting Recipients:: How to choose the recipients.
2191 * Encrypting a Plaintext:: How to encrypt a plaintext.
2195 @node Selecting Recipients
2196 @subsubsection Selecting Recipients
2197 @cindex encryption, selecting recipients
2200 @deftp {Data type} GpgmeRecipients
2201 The @code{GpgmeRecipients} type is a handle for a set of recipients
2202 that can be used in an encryption process.
2205 @deftypefun GpgmeError gpgme_recipients_new (@w{GpgmeRecipients *@var{r_rset}})
2206 The function @code{gpgme_recipients_new} creates a new, empty set of
2207 recipients and returns a handle for it in @var{r_rset}.
2209 The function returns @code{GPGME_No_Error} if the recipient set could
2210 be created successfully, and @code{GPGME_Out_Of_Core} if not enough
2211 memory was available.
2214 @deftypefun void gpgme_recipients_release (@w{GpgmeRecipients @var{rset}})
2215 The function @code{gpgme_recipients_release} destroys the set of
2216 recipients @var{rset} and releases all associated resources.
2219 @deftypefun GpgmeError gpgme_recipients_add_name (@w{GpgmeRecipients @var{rset}}, @w{const char *@var{name}})
2220 The function @code{gpgme_recipients_add_name} adds the recipient
2221 @var{name} to the set of recipients @var{rset}. This is equivalent to
2222 @code{gpgme_recipients_add_name_with_validity} with a validity of
2223 @code{GPGME_VALIDITY_UNKNOWN}.
2225 The function returns @code{GPGME_No_Error} if the recipient was added
2226 successfully, @code{GPGME_Invalid_Value} if @var{rset} or @var{name}
2227 is not a valid pointer, and @code{GPGME_Out_Of_Core} if not enough
2228 memory is available.
2231 @deftypefun GpgmeError gpgme_recipients_add_name_with_validity (@w{GpgmeRecipients @var{rset}}, @w{const char *@var{name}}, @w{GpgmeValidity @var{val}})
2232 The function @code{gpgme_recipients_add_name_with_validity} adds the
2233 recipient @var{name} with the validity @var{val} to the set of
2234 recipients @var{rset}. If the validity is not known, the function
2235 @code{gpgme_recipients_add_name} can be used.
2236 @xref{Information About Keys}, for the possible values for @var{val}.
2238 The function returns @code{GPGME_No_Error} if the recipient was added
2239 successfully, @code{GPGME_Invalid_Value} if @var{rset} or @var{name}
2240 is not a valid pointer, and @code{GPGME_Out_Of_Core} if not enough
2241 memory is available.
2244 @deftypefun {unsigned int} gpgme_recipients_count (@w{const @var{GpgmeRecipients rset}})
2245 The function @code{gpgme_recipients_count} returns the number of
2246 recipients in the set @var{rset}.
2249 @deftypefun GpgmeError gpgme_recipients_enum_open (@w{const GpgmeRecipients @var{rset}}, @w{void **@var{iter}})
2250 The function @code{gpgme_recipients_enum_open} creates a new iterator
2251 @var{iter} that can be used to walk through the set of recipients in
2252 @var{rset}, using @code{gpgme_recipients_enum_read}.
2254 If the iterator is not needed anymore, it can be closed with
2255 @code{gpgme_recipients_enum_close}.
2257 The function returns @code{GPGME_No_Error} if the enumerator was
2258 successfully created and @code{GPGME_Invalid_Value} if @var{rset} or
2259 @var{iter} is not a valid pointer.
2262 @deftypefun {const char *} gpgme_recipients_enum_read (@w{const GpgmeRecipients @var{rset}}, @w{void **@var{iter}})
2263 The function @code{gpgme_recipients_enum_read} returns a string
2264 containing the name of the next recipient in the set @var{rset} for
2265 the iterator @var{iter}. The string is valid as long as @var{rset} is
2266 valid or the function is called the next time with the same recipient
2267 set and iterator, whatever is earlier.
2270 @deftypefun GpgmeError gpgme_recipients_enum_close (@w{const GpgmeRecipients @var{rset}}, @w{void **@var{iter}})
2271 The function @code{gpgme_recipients_enum_close} releases the iterator
2272 @var{iter} for the recipient set @var{rset}.
2276 @node Encrypting a Plaintext
2277 @subsubsection Encrypting a Plaintext
2279 @deftypefun GpgmeError gpgme_op_encrypt (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{rset}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{cipher}})
2280 The function @code{gpgme_op_encrypt} encrypts the plaintext in the data
2281 object @var{plain} for the recipients @var{rset} and stores the
2282 ciphertext in the data object @var{cipher}. The type of the
2283 ciphertext created is determined by the @acronym{ASCII} armor and text
2284 mode attributes set for the context @var{ctx}.
2286 If @code{GPGME_Invalid_Recipients} is returned, some recipients in
2287 @var{rset} are invalid, but not all. In this case the plaintext is
2288 encrypted for all valid recipients and returned in @var{cipher}. More
2289 information about the invalid recipients is available with
2290 @code{gpgme_get_op_info}. @xref{Detailed Results}.
2292 If @var{recp} is @code{NULL}, symmetric rather than public key
2293 encryption is performed. Symmetrically encrypted cipher text can be
2294 deciphered with @code{gpgme_op_decrypt}. Note that in this case the
2295 crypto backend needs to retrieve a passphrase from the user.
2296 Symmetric encryption is currently only supported for the OpenPGP
2299 The function returns @code{GPGME_No_Error} if the ciphertext could be
2300 created successfully, @code{GPGME_Invalid_Value} if @var{ctx},
2301 @var{rset}, @var{plain} or @var{cipher} is not a valid pointer,
2302 @code{GPGME_No_Recipients} if @var{rset} does not contain any valid
2303 recipients, @code{GPGME_Invalid_Recipients} if @var{rset} contains
2304 some invalid recipients, @code{GPGME_No_Passphrase} if the passphrase
2305 for the secret key could not be retrieved, and passes through any
2306 errors that are reported by the crypto engine support routines.
2309 @deftypefun GpgmeError gpgme_op_encrypt_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{rset}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{cipher}})
2310 The function @code{gpgme_op_encrypt_start} initiates a
2311 @code{gpgme_op_encrypt} operation. It can be completed by calling
2312 @code{gpgme_wait} on the context. @xref{Waiting For Completion}.
2314 The function returns @code{GPGME_No_Error} if the operation could be
2315 started successfully, @code{GPGME_Invalid_Value} if @var{ctx},
2316 @var{rset}, @var{plain} or @var{cipher} is not a valid pointer, and
2317 @code{GPGME_No_Recipients} if @var{rset} does not contain any valid
2322 @deftypefun GpgmeError gpgme_op_encrypt_sign (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{rset}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{cipher}})
2323 The function @code{gpgme_op_encrypt_sign} does a combined encrypt and
2324 sign operation. It is used like @code{gpgme_op_encrypt}, but the
2325 ciphertext also contains signatures for the signers listed in
2328 The combined encrypt and sign operation is currently only available
2329 for the OpenPGP crypto engine.
2332 @deftypefun GpgmeError gpgme_op_encrypt_sign_start (@w{GpgmeCtx @var{ctx}}, @w{GpgmeRecipients @var{rset}}, @w{GpgmeData @var{plain}}, @w{GpgmeData @var{cipher}})
2333 The function @code{gpgme_op_encrypt_sign_start} initiates a
2334 @code{gpgme_op_encrypt_sign} operation. It can be completed by
2335 calling @code{gpgme_wait} on the context. @xref{Waiting For
2338 The function returns @code{GPGME_No_Error} if the operation could be
2339 started successfully, @code{GPGME_Invalid_Value} if @var{ctx},
2340 @var{rset}, @var{plain} or @var{cipher} is not a valid pointer, and
2341 @code{GPGME_No_Recipients} if @var{rset} does not contain any valid
2346 @node Detailed Results
2347 @subsection Detailed Results
2348 @cindex cryptographic operation, detailed results
2350 @deftypefun {char *} gpgme_get_op_info (@w{GpgmeCtx @var{ctx}}, @w{int @var{reserved}})
2351 The function @code{gpgme_get_op_info} retrieves more information about
2352 the last crypto operation.
2354 The function returns a string in the XML format. The user has to
2355 release the string with @code{free}.
2357 Here is a sample of the information that might be returned:
2359 <GnupgOperationInfo>
2361 <detached/> <!-- or cleartext or standard -->
2363 <hashalgo>2</hashalgo>
2364 <micalg>pgp-sha1</micalg>
2365 <sigclass>01</sigclass>
2366 <created>9222222</created>
2367 <fpr>121212121212121212</fpr>
2369 </GnupgOperationInfo>
2372 Currently, the only operations that return additional information are
2373 encrypt, sign and import. @xref{Encrypt}, @xref{Sign}, @xref(Importing Keys}.
2375 The function returns a string or @code{NULL} if no such data is
2381 @section Run Control
2383 @cindex cryptographic operation, running
2385 Some basic support for running operations asynchronously is available
2386 in @acronym{GPGME}. You can use it to set up a context completely up
2387 to initiating the desired operation, but delay performing it to a
2391 * Waiting For Completion:: Waiting until an operation is completed.
2392 * Cancelling an Operation:: Interrupting a running operation.
2393 * Hooking Up Into Idle Time:: Doing something when nothing has to be done.
2397 @node Waiting For Completion
2398 @subsection Waiting For Completion
2399 @cindex cryptographic operation, wait for
2400 @cindex wait for completion
2402 @deftypefun GpgmeCtx gpgme_wait (@w{GpgmeCtx @var{ctx}}, @w{GpgmeError *@var{status}}, @w{int @var{hang}})
2403 The function @code{gpgme_wait} does continue the pending operation
2404 within the context @var{ctx}. In particular, it ensures the data
2405 exchange between @acronym{GPGME} and the crypto backend and watches
2406 over the run time status of the backend process.
2408 If @var{hang} is true, the function does not return until the
2409 operation is completed or cancelled. Otherwise the function will not
2410 block for a long time.
2412 The error status of the finished operation is returned in
2415 The @var{ctx} argument can be @code{NULL}. In that case,
2416 @code{gpgme_wait} waits for any context to complete its operation.
2418 The function returns the @var{ctx} of the context which has finished
2423 @node Cancelling an Operation
2424 @subsection Cancelling an Operation
2425 @cindex cancellation
2426 @cindex cryptographic operation, cancel
2428 @deftypefun void gpgme_cancel (@w{GpgmeCtx @var{ctx}})
2429 The function @code{gpgme_cancel} tries to cancel the pending
2430 operation. The function @code{gpgme_wait} might notice the
2431 cancellation flag and return. It is currently not guaranteed to work
2432 under all circumstances. It's current primary purpose is to prevent
2433 asking for a passphrase again in the passphrase callback.
2437 @node Hooking Up Into Idle Time
2438 @subsection Hooking Up Into Idle Time
2440 @cindex idle function
2442 @deftp {Data type} {void (*GpgmeIdleFunc) (void)}
2443 @tindex GpgmeIdleFunc
2444 The @code{GpgmeIdleFunc} type is the type of functions usable as
2445 an idle function that can be registered with @code{gpgme_register_idle}.
2448 @deftypefun GpgmeIdleFunc gpgme_register_idle (@w{GpgmeIdleFunc @var{idle}})
2449 The function @code{gpgme_register_idle} can be used to register
2450 @var{idle} as the idle function.
2452 @var{idle} will be called whenever @acronym{GPGME} thinks that it is
2453 idle and time can better be spent elsewhere. Setting @var{idle} to
2454 @code{NULL} disables use of the idle function (this is the default).
2456 The function returns the old idle function, or @code{NULL} if none was
2468 @unnumbered Concept Index
2473 @node Function and Data Index
2474 @unnumbered Function and Data Index