2003-05-28  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.texi (Exporting Keys): Change argument type from
	gpgme_recipient_t to gpgme_user_id_t.
	(Encrypting a Plaintext): Likewise.
	(Selecting Recipients): Rewritten.

gpgme/
2003-05-28  Marcus Brinkmann  <marcus@g10code.de>

	* Makefile.am (libgpgme_la_SOURCES): Remove recipient.c, add
	user-id.c.
	* gpgme.h (gpgme_recipients_t): Removed.
	(gpgme_recipients_new, gpgme_recipients_release,
	gpgme_recipients_add_name,
	gpgme_recipients_add_name_with_validity, gpgme_recipients_count,
	gpgme_recipients_enum_open, gpgme_recipients_enum_read,
	gpgme_recipients_enum_close): Removed.
	(gpgme_op_encrypt, gpgme_op_encrypt_start, gpgme_op_encrypt_sign,
	gpgme_op_encrypt_sign_start, gpgme_op_export_start,
	gpgme_op_export): Change second argument to gpgme_user_id_t.
	(gpgme_user_ids_release): New prototype.
	(gpgme_user_ids_append): Likewise.
	* ops.h (_gpgme_recipients_all_valid): Remove.
	(_gpgme_user_ids_all_valid): Add.
	* context.h (struct gpgme_recipients): Removed.
	* user-id.c: New file.
	* recipient.c: Removed file.
	* rungpg.c (append_args_from_recipients): Change last arg to
	gpgme_user_id_t.  Reimplement.
	(gpg_encrypt): Change second arg to gpgme_user_id_t.
	(gpg_encrypt_sign): Likewise.
	(gpg_export): Likewise.  Rewrite user ID list code.
	* engine.c (_gpgme_engine_op_encrypt): Change second arg to
	gpgme_user_id_t.
	(_gpgme_engine_op_encrypt_sign): Likewise.
	(_gpgme_engine_op_export): Likewise.
	* engine.h (_gpgme_engine_op_encrypt, _gpgme_engine_op_encrypt_sign,
	_gpgme_engine_op_export): Likewise.
	* engine-gpgsm.c (set_recipients): Likewise.  Rewrite loop code.
	(gpgsm_encrypt): Likewise.
	(gpgsm_export): Likewise.
	* engine-backend.h (struct engine_ops): Likewise for members
	ENCRYPT, ENCRYPT_SIGN and EXPORT.
	* export.c (export_start, gpgme_op_export_start, gpgme_op_export):
	Likewise.
	* encrypt.c (encrypt_start): Likewise.  Don't check for count of
	recipients.
	(gpgme_op_encrypt_start): Likewise.
	(gpgme_op_encrypt): Likewise.
	* encrypt-sign.c (encrypt_sign_start): Likewise.
	(gpgme_op_encrypt_sign): Likewise.
	(gpgme_op_encrypt_sign_start): Likewise.

tests/
2003-05-28  Marcus Brinkmann  <marcus@g10code.de>

	* gpg/t-eventloop.c (main): Rewrite recipient management.
	* gpg/t-encrypt-sign.c (main): Likewise.
	* gpg/t-encrypt.c (main): Likewise.
	* gpg/t-export.c (main): Likewise.
This commit is contained in:
Marcus Brinkmann 2003-05-28 01:15:38 +00:00
parent d5d26aecbc
commit bade4a32b5
25 changed files with 448 additions and 502 deletions

52
NEWS
View File

@ -22,7 +22,7 @@ Noteworthy changes in version 0.4.1 (unreleased)
structs rather than by XML structs or in other ways.
Objects which used to be opaque (for example a key) are now pointers
accessible structs, so no accessor functions are necessary.
to accessible structs, so no accessor functions are necessary.
Backward compatibility is provided where it was possible without too
much effort and did not collide with the overall sanitization effort.
@ -46,7 +46,6 @@ Noteworthy changes in version 0.4.1 (unreleased)
Old name: New name:
GpgmeCtx gpgme_ctx_t
GpgmeData gpgme_data_t
GpgmeRecipients gpgme_recipients_t
GpgmeError gpgme_error_t
GpgmeDataEncoding gpgme_data_encoding_t
GpgmeSigStat gpgme_sig_stat_t
@ -96,6 +95,37 @@ Noteworthy changes in version 0.4.1 (unreleased)
The user is expected to write the response to the file descriptor,
followed by a newline.
* The recipients interface has been removed and replaced by a more
generic and light gpgme_user_ids_* interface, which only provides
two functions: gpgme_user_ids_append adds a new user ID at the end
of the linked list, and gpgme_user_ids_release releases all user
IDs in the linked list. The resulting user ID object is free for
the user to change (note however that gpgme_user_ids_release only
releases resources allocated by GPGME).
This change propagates to the prototypes of gpgme_op_encrypt,
gpgme_op_encrypt_start, gpgme_op_encrypt_sign and
gpgme_op_encrypt_sign_start. Also the prototypes of
gpgme_op_export_start and gpgme_op_export finally make sense.
Here is an example how to use the new interface:
gpgme_user_id_t rset = NULL;
gpgme_user_id_t *rset_lastp = &rset;
err = gpgme_user_ids_append (rset_lastp, "Alpha");
fail_if_err (err);
(*rset_lastp)->validity = GPGME_VALIDITY_FULL;
rset_lastp = &(*rset_lastp)->next;
err = gpgme_user_ids_append (rset_lastp, "Bob");
fail_if_err (err);
(*rset_lastp)->validity = GPGME_VALIDITY_FULL;
[...]
gpgme_user_ids_release (rset);
* gpgme_op_verify and gpgme_op_decrypt_verify don't return a status
summary anymore. Use gpgme_get_sig_status to retrieve the individual
stati.
@ -219,7 +249,6 @@ Noteworthy changes in version 0.4.1 (unreleased)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GpgmeCtx DEPRECATED: Use gpgme_ctx_t.
GpgmeData DEPRECATED: Use gpgme_data_t.
GpgmeRecipients DEPRECATED: Use gpgme_recipients_t.
GpgmeError DEPRECATED: Use gpgme_error_t.
GpgmeDataEncoding DEPRECATED: Use gpgme_data_encoding_t.
GpgmeSigStat DEPRECATED: Use gpgme_sig_stat_t.
@ -279,6 +308,23 @@ gpgme_op_decrypt_verify CHANGED: Drop R_STAT argument.
gpgme_wait CHANGED: Can return NULL even if hang is true.
GpgmeIdleFunc REMOVED
gpgme_register_idle REMOVED
GpgmeRecipients REMOVED: Use gpgme_user_id_t.
gpgme_recipients_new REMOVED: Initialize gpgme_user_id_t with NULL.
gpgme_recipients_release REMOVED: Use gpgme_user_ids_release.
gpgme_recipients_add_name REMOVED: Use gpgme_user_ids_append
gpgme_recipients_add_name_with_validity REMOVED: Set validity directly.
gpgme_recipients_count REMOVED: You can count them yourself.
gpgme_recipients_enum_open REMOVED: gpgme_user_id_t is a linked list.
gpgme_recipients_enum_read REMOVED: See gpgme_recipients_enum_open.
gpgme_recipients_enum_close REMOVED: See gpgme_recipients_enum_read.
gpgme_user_ids_append NEW
gpgme_user_ids_release NEW
gpgme_op_encrypt CHANGED: Recipients passed as gpgme_user_id_t.
gpgme_op_encrypt_start CHANGED: Recipients passed as gpgme_user_id_t.
gpgme_op_encrypt_sign CHANGED: Recipients passed as gpgme_user_id_t.
gpgme_op_encrypt_sign_start CHANGED: Recipients passed as gpgme_user_id_t.
gpgme_op_export_start CHANGED: User IDs passed as gpgme_user_id_t.
gpgme_op_export CHANGED: User IDs passed as gpgme_user_id_t.
gpgme_engine_info_t NEW
gpgme_get_engine_info CHANGED: Return info structure instead XML.
gpgme_get_protocol_name NEW

13
TODO
View File

@ -1,7 +1,7 @@
Hey Emacs, this is -*- outline -*- mode!
* ABI's to break:
** Change gpgme_recipient_t stuff to gpgme_user_id_t (encrypt, export, ...).
** Use libgpg-error.
** Compatibility interfaces that can be removed in future versions:
*** gpgme_data_new_from_filepart
*** gpgme_data_new_from_file
@ -108,14 +108,3 @@ Hey Emacs, this is -*- outline -*- mode!
* Build suite
** Make sure everything is cleaned correctly (esp. test area).
Bugs reported by Stephane Corthesy:
> In GpgmeRecipients, would it be possible to provide a function which
> would return the validity assigned to a name contained in the
> GpgmeRecipients instance?
> passphrase callback. If I use the same GpgmeContext as the one which
> is currently asking for a passphrase, my app crashes: the r_hd in
> the
> callback has become invalid; if I use a brand new one, the callback
> is called recursively, when I ask to enumerate keys.

View File

@ -1,3 +1,10 @@
2003-05-28 Marcus Brinkmann <marcus@g10code.de>
* gpgme.texi (Exporting Keys): Change argument type from
gpgme_recipient_t to gpgme_user_id_t.
(Encrypting a Plaintext): Likewise.
(Selecting Recipients): Rewritten.
2003-05-27 Marcus Brinkmann <marcus@g10code.de>
* gpgme.texi (Protocol Selection): Do not use @acronym in @node

View File

@ -2649,27 +2649,27 @@ operation is started on the context.
@cindex key, export
@cindex key ring, export from
@deftypefun gpgme_error_t gpgme_op_export (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_recipients_t @var{recipients}}, @w{gpgme_data_t @var{keydata}})
@deftypefun gpgme_error_t gpgme_op_export (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_user_id_t @var{uids}}, @w{gpgme_data_t @var{keydata}})
The function @code{gpgme_op_export} extracts the public keys of the
user IDs in @var{recipients} and returns them in the data buffer
user IDs in @var{uids} and returns them in the data buffer
@var{keydata}. The type of the public keys returned is determined by
the @acronym{ASCII} armor attribute set for the context @var{ctx}.
The function returns @code{GPGME_No_Error} if the operation completed
successfully, @code{GPGME_Invalid_Value} if @var{recipients} is
successfully, @code{GPGME_Invalid_Value} if @var{uids} is
@code{NULL} or @var{keydata} is not a valid empty data buffer, and
passes through any errors that are reported by the crypto engine
support routines.
@end deftypefun
@deftypefun gpgme_error_t gpgme_op_export_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_recipients_t @var{recipients}}, @w{gpgme_data_t @var{keydata}})
@deftypefun gpgme_error_t gpgme_op_export_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_user_id_t @var{uids}}, @w{gpgme_data_t @var{keydata}})
The function @code{gpgme_op_export_start} initiates a
@code{gpgme_op_export} operation. It can be completed by calling
@code{gpgme_wait} on the context. @xref{Waiting For Completion}.
The function returns @code{GPGME_No_Error} if the operation could be
started successfully, and @code{GPGME_Invalid_Value} if
@var{recipients} is @code{NULL} or @var{keydata} is not a valid empty
@var{uids} is @code{NULL} or @var{keydata} is not a valid empty
data buffer.
@end deftypefun
@ -3756,86 +3756,59 @@ and then passed to the encryption operation.
@cindex encryption, selecting recipients
@cindex recipients
@deftp {Data type} gpgme_recipients_t
The @code{gpgme_recipients_t} type is a handle for a set of recipients
that can be used in an encryption process.
@end deftp
@deftypefun gpgme_error_t gpgme_user_ids_append (@w{gpgme_user_id_t *@var{rset_p}}, @w{const char *@var{name}})
The function @code{gpgme_user_ids_append} creates a new
@code{gpgme_user_id_t} object, initializes its @code{uid} member with
a copy of the string pointed to by @var{name}, initializes its
@code{name}, @code{email}, @code{comment} members to the empty string,
its @code{validity} member to @code{GPGME_VALIDITY_UNKNOWN} and leaves
all other fields to 0.
@deftypefun gpgme_error_t gpgme_recipients_new (@w{gpgme_recipients_t *@var{r_rset}})
The function @code{gpgme_recipients_new} creates a new, empty set of
recipients and returns a handle for it in @var{r_rset}.
It then appends the user ID at the end of the linked list of user IDs
that starts at *@var{rset_p}, or it returns it in *@var{rset_p} if
that is @code{NULL}. You can then update for example the validity
information in the user ID directly.
We recommend that you keep a pointer to the last element in your
linked list. This is faster and allows you to easily update the
fields of the last user ID. Here is an example how to create a linked
list of user IDs in @var{rset} with full validity from a
@code{NULL}-terminated array of names:
@example
const char *names[] = @{ "Alpha", "Bob", NULL @};
gpgme_error_t err;
gpgme_user_id_t rset = NULL;
gpgme_user_id_t *rset_lastp = &rset;
do
@{
err = gpgme_user_ids_append (rset_lastp, *(names++));
if (!err)
@{
(*rset_lastp)->validity = GPGME_VALIDITY_FULL;
rset_lastp = &(*rset_lastp)->next;
@}
@}
while (!err && *names);
@end example
The function returns @code{GPGME_No_Error} if the recipient set could
be created successfully, and @code{GPGME_Out_Of_Core} if not enough
memory was available.
@end deftypefun
@deftypefun void gpgme_recipients_release (@w{gpgme_recipients_t @var{rset}})
The function @code{gpgme_recipients_release} destroys the set of
recipients @var{rset} and releases all associated resources.
@end deftypefun
@deftypefun gpgme_error_t gpgme_recipients_add_name (@w{gpgme_recipients_t @var{rset}}, @w{const char *@var{name}})
The function @code{gpgme_recipients_add_name} adds the recipient
@var{name} to the set of recipients @var{rset}. This is equivalent to
@code{gpgme_recipients_add_name_with_validity} with a validity of
@code{GPGME_VALIDITY_UNKNOWN}.
The function returns @code{GPGME_No_Error} if the recipient was added
successfully, @code{GPGME_Invalid_Value} if @var{rset} or @var{name}
is not a valid pointer, and @code{GPGME_Out_Of_Core} if not enough
memory is available.
@end deftypefun
@deftypefun gpgme_error_t gpgme_recipients_add_name_with_validity (@w{gpgme_recipients_t @var{rset}}, @w{const char *@var{name}}, @w{gpgme_validity_t @var{val}})
The function @code{gpgme_recipients_add_name_with_validity} adds the
recipient @var{name} with the validity @var{val} to the set of
recipients @var{rset}. If the validity is not known, the function
@code{gpgme_recipients_add_name} can be used.
@xref{Information About Keys}, for the possible values for @var{val}.
The function returns @code{GPGME_No_Error} if the recipient was added
successfully, @code{GPGME_Invalid_Value} if @var{rset} or @var{name}
is not a valid pointer, and @code{GPGME_Out_Of_Core} if not enough
memory is available.
@end deftypefun
@deftypefun {unsigned int} gpgme_recipients_count (@w{const @var{gpgme_recipients_t rset}})
The function @code{gpgme_recipients_count} returns the number of
recipients in the set @var{rset}.
@end deftypefun
@deftypefun gpgme_error_t gpgme_recipients_enum_open (@w{const gpgme_recipients_t @var{rset}}, @w{void **@var{iter}})
The function @code{gpgme_recipients_enum_open} creates a new iterator
@var{iter} that can be used to walk through the set of recipients in
@var{rset}, using @code{gpgme_recipients_enum_read}.
If the iterator is not needed anymore, it can be closed with
@code{gpgme_recipients_enum_close}.
The function returns @code{GPGME_No_Error} if the enumerator was
successfully created and @code{GPGME_Invalid_Value} if @var{rset} or
@var{iter} is not a valid pointer.
@end deftypefun
@deftypefun {const char *} gpgme_recipients_enum_read (@w{const gpgme_recipients_t @var{rset}}, @w{void **@var{iter}})
The function @code{gpgme_recipients_enum_read} returns a string
containing the name of the next recipient in the set @var{rset} for
the iterator @var{iter}. The string is valid as long as @var{rset} is
valid or the function is called the next time with the same recipient
set and iterator, whatever is earlier.
@end deftypefun
@deftypefun gpgme_error_t gpgme_recipients_enum_close (@w{const gpgme_recipients_t @var{rset}}, @w{void **@var{iter}})
The function @code{gpgme_recipients_enum_close} releases the iterator
@var{iter} for the recipient set @var{rset}.
@deftypefun void gpgme_user_ids_release (@w{gpgme_user_id_t @var{uids}})
The function @code{gpgme_user_ids_release} destroys the linked list of
user IDs @var{uids} and releases all associated resources allocated by
@acronym{GPGME}..
@end deftypefun
@node Encrypting a Plaintext
@subsubsection Encrypting a Plaintext
@deftypefun gpgme_error_t gpgme_op_encrypt (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_recipients_t @var{rset}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
@deftypefun gpgme_error_t gpgme_op_encrypt (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_user_id_t @var{rset}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
The function @code{gpgme_op_encrypt} encrypts the plaintext in the data
object @var{plain} for the recipients @var{rset} and stores the
ciphertext in the data object @var{cipher}. The type of the
@ -3865,7 +3838,7 @@ the secret key could not be retrieved, and passes through any errors
that are reported by the crypto engine support routines.
@end deftypefun
@deftypefun gpgme_error_t gpgme_op_encrypt_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_recipients_t @var{rset}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
@deftypefun gpgme_error_t gpgme_op_encrypt_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_user_id_t @var{rset}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
The function @code{gpgme_op_encrypt_start} initiates a
@code{gpgme_op_encrypt} operation. It can be completed by calling
@code{gpgme_wait} on the context. @xref{Waiting For Completion}.
@ -3902,7 +3875,7 @@ next operation is started on the context.
@end deftypefun
@deftypefun gpgme_error_t gpgme_op_encrypt_sign (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_recipients_t @var{rset}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
@deftypefun gpgme_error_t gpgme_op_encrypt_sign (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_user_id_t @var{rset}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
The function @code{gpgme_op_encrypt_sign} does a combined encrypt and
sign operation. It is used like @code{gpgme_op_encrypt}, but the
ciphertext also contains signatures for the signers listed in
@ -3912,7 +3885,7 @@ The combined encrypt and sign operation is currently only available
for the OpenPGP crypto engine.
@end deftypefun
@deftypefun gpgme_error_t gpgme_op_encrypt_sign_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_recipients_t @var{rset}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
@deftypefun gpgme_error_t gpgme_op_encrypt_sign_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_user_id_t @var{rset}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}})
The function @code{gpgme_op_encrypt_sign_start} initiates a
@code{gpgme_op_encrypt_sign} operation. It can be completed by
calling @code{gpgme_wait} on the context. @xref{Waiting For

View File

@ -1,3 +1,49 @@
2003-05-28 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am (libgpgme_la_SOURCES): Remove recipient.c, add
user-id.c.
* gpgme.h (gpgme_recipients_t): Removed.
(gpgme_recipients_new, gpgme_recipients_release,
gpgme_recipients_add_name,
gpgme_recipients_add_name_with_validity, gpgme_recipients_count,
gpgme_recipients_enum_open, gpgme_recipients_enum_read,
gpgme_recipients_enum_close): Removed.
(gpgme_op_encrypt, gpgme_op_encrypt_start, gpgme_op_encrypt_sign,
gpgme_op_encrypt_sign_start, gpgme_op_export_start,
gpgme_op_export): Change second argument to gpgme_user_id_t.
(gpgme_user_ids_release): New prototype.
(gpgme_user_ids_append): Likewise.
* ops.h (_gpgme_recipients_all_valid): Remove.
(_gpgme_user_ids_all_valid): Add.
* context.h (struct gpgme_recipients): Removed.
* user-id.c: New file.
* recipient.c: Removed file.
* rungpg.c (append_args_from_recipients): Change last arg to
gpgme_user_id_t. Reimplement.
(gpg_encrypt): Change second arg to gpgme_user_id_t.
(gpg_encrypt_sign): Likewise.
(gpg_export): Likewise. Rewrite user ID list code.
* engine.c (_gpgme_engine_op_encrypt): Change second arg to
gpgme_user_id_t.
(_gpgme_engine_op_encrypt_sign): Likewise.
(_gpgme_engine_op_export): Likewise.
* engine.h (_gpgme_engine_op_encrypt, _gpgme_engine_op_encrypt_sign,
_gpgme_engine_op_export): Likewise.
* engine-gpgsm.c (set_recipients): Likewise. Rewrite loop code.
(gpgsm_encrypt): Likewise.
(gpgsm_export): Likewise.
* engine-backend.h (struct engine_ops): Likewise for members
ENCRYPT, ENCRYPT_SIGN and EXPORT.
* export.c (export_start, gpgme_op_export_start, gpgme_op_export):
Likewise.
* encrypt.c (encrypt_start): Likewise. Don't check for count of
recipients.
(gpgme_op_encrypt_start): Likewise.
(gpgme_op_encrypt): Likewise.
* encrypt-sign.c (encrypt_sign_start): Likewise.
(gpgme_op_encrypt_sign): Likewise.
(gpgme_op_encrypt_sign_start): Likewise.
2003-05-27 Marcus Brinkmann <marcus@g10code.de>
* gpgme.h (struct _gpgme_op_import_result): Add skipped_new_keys.

View File

@ -72,7 +72,7 @@ libgpgme_la_SOURCES = \
gpgme.h util.h conversion.c context.h ops.h \
data.h data.c data-fd.c data-stream.c data-mem.c data-user.c \
data-compat.c \
recipient.c signers.c \
user-id.c signers.c \
wait.c wait-global.c wait-private.c wait-user.c wait.h \
op-support.c \
encrypt.c encrypt-sign.c decrypt.c decrypt-verify.c verify.c \

View File

@ -37,6 +37,7 @@ typedef enum
OPDATA_VERIFY, OPDATA_TRUSTLIST
} ctx_op_data_type;
struct ctx_op_data
{
/* The next element in the linked list, or NULL if this is the last
@ -102,12 +103,4 @@ struct gpgme_context
struct gpgme_io_cbs io_cbs;
};
/* A recipient is defined by a user ID, but we define it as an opaque
type for the user. */
struct gpgme_recipients
{
gpgme_user_id_t list;
};
#endif /* CONTEXT_H */

View File

@ -37,7 +37,7 @@ encrypt_sign_status_handler (void *priv, gpgme_status_code_t code, char *args)
static gpgme_error_t
encrypt_sign_start (gpgme_ctx_t ctx, int synchronous, gpgme_recipients_t recp,
encrypt_sign_start (gpgme_ctx_t ctx, int synchronous, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t cipher)
{
gpgme_error_t err;
@ -80,7 +80,7 @@ encrypt_sign_start (gpgme_ctx_t ctx, int synchronous, gpgme_recipients_t recp,
store the resulting ciphertext in CIPHER. Also sign the ciphertext
with the signers in CTX. */
gpgme_error_t
gpgme_op_encrypt_sign_start (gpgme_ctx_t ctx, gpgme_recipients_t recp,
gpgme_op_encrypt_sign_start (gpgme_ctx_t ctx, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t cipher)
{
return encrypt_sign_start (ctx, 0, recp, plain, cipher);
@ -91,7 +91,7 @@ gpgme_op_encrypt_sign_start (gpgme_ctx_t ctx, gpgme_recipients_t recp,
store the resulting ciphertext in CIPHER. Also sign the ciphertext
with the signers in CTX. */
gpgme_error_t
gpgme_op_encrypt_sign (gpgme_ctx_t ctx, gpgme_recipients_t recp,
gpgme_op_encrypt_sign (gpgme_ctx_t ctx, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t cipher)
{
gpgme_error_t err = encrypt_sign_start (ctx, 1, recp, plain, cipher);

View File

@ -148,7 +148,7 @@ _gpgme_op_encrypt_init_result (gpgme_ctx_t ctx)
static gpgme_error_t
encrypt_start (gpgme_ctx_t ctx, int synchronous, gpgme_recipients_t recp,
encrypt_start (gpgme_ctx_t ctx, int synchronous, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t cipher)
{
gpgme_error_t err;
@ -164,8 +164,6 @@ encrypt_start (gpgme_ctx_t ctx, int synchronous, gpgme_recipients_t recp,
if (!recp)
symmetric = 1;
else if (gpgme_recipients_count (recp) == 0)
return GPGME_No_UserID;
if (!plain)
return GPGME_No_Data;
@ -193,7 +191,7 @@ encrypt_start (gpgme_ctx_t ctx, int synchronous, gpgme_recipients_t recp,
gpgme_error_t
gpgme_op_encrypt_start (gpgme_ctx_t ctx, gpgme_recipients_t recp,
gpgme_op_encrypt_start (gpgme_ctx_t ctx, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t cipher)
{
return encrypt_start (ctx, 0, recp, plain, cipher);
@ -203,7 +201,7 @@ gpgme_op_encrypt_start (gpgme_ctx_t ctx, gpgme_recipients_t recp,
/* Encrypt plaintext PLAIN within CTX for the recipients RECP and
store the resulting ciphertext in CIPHER. */
gpgme_error_t
gpgme_op_encrypt (gpgme_ctx_t ctx, gpgme_recipients_t recp,
gpgme_op_encrypt (gpgme_ctx_t ctx, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t cipher)
{
gpgme_error_t err = encrypt_start (ctx, 1, recp, plain, cipher);

View File

@ -49,13 +49,13 @@ struct engine_ops
gpgme_error_t (*delete) (void *engine, gpgme_key_t key, int allow_secret);
gpgme_error_t (*edit) (void *engine, gpgme_key_t key, gpgme_data_t out,
gpgme_ctx_t ctx /* FIXME */);
gpgme_error_t (*encrypt) (void *engine, gpgme_recipients_t recp,
gpgme_error_t (*encrypt) (void *engine, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t ciph,
int use_armor);
gpgme_error_t (*encrypt_sign) (void *engine, gpgme_recipients_t recp,
gpgme_error_t (*encrypt_sign) (void *engine, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t ciph,
int use_armor, gpgme_ctx_t ctx /* FIXME */);
gpgme_error_t (*export) (void *engine, gpgme_recipients_t recp,
gpgme_error_t (*export) (void *engine, gpgme_user_id_t uids,
gpgme_data_t keydata, int use_armor);
gpgme_error_t (*genkey) (void *engine, gpgme_data_t help_data, int use_armor,
gpgme_data_t pubkey, gpgme_data_t seckey);

View File

@ -936,13 +936,12 @@ gpgsm_delete (void *engine, gpgme_key_t key, int allow_secret)
static gpgme_error_t
set_recipients (GpgsmObject gpgsm, gpgme_recipients_t recp)
set_recipients (GpgsmObject gpgsm, gpgme_user_id_t uid)
{
gpgme_error_t err;
ASSUAN_CONTEXT ctx = gpgsm->assuan_ctx;
char *line;
int linelen;
gpgme_user_id_t uid;
int invalid_recipients = 0;
linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */
@ -950,7 +949,7 @@ set_recipients (GpgsmObject gpgsm, gpgme_recipients_t recp)
if (!line)
return GPGME_Out_Of_Core;
strcpy (line, "RECIPIENT ");
for (uid = recp->list; uid; uid = uid->next)
while (uid)
{
int newlen = 11 + strlen (uid->uid);
if (linelen < newlen)
@ -975,6 +974,7 @@ set_recipients (GpgsmObject gpgsm, gpgme_recipients_t recp)
free (line);
return err;
}
uid = uid->next;
}
free (line);
return invalid_recipients ? GPGME_Invalid_UserID : 0;
@ -982,7 +982,7 @@ set_recipients (GpgsmObject gpgsm, gpgme_recipients_t recp)
static gpgme_error_t
gpgsm_encrypt (void *engine, gpgme_recipients_t recp, gpgme_data_t plain,
gpgsm_encrypt (void *engine, gpgme_user_id_t recp, gpgme_data_t plain,
gpgme_data_t ciph, int use_armor)
{
GpgsmObject gpgsm = engine;
@ -1015,7 +1015,7 @@ gpgsm_encrypt (void *engine, gpgme_recipients_t recp, gpgme_data_t plain,
static gpgme_error_t
gpgsm_export (void *engine, gpgme_recipients_t recp, gpgme_data_t keydata,
gpgsm_export (void *engine, gpgme_user_id_t uid, gpgme_data_t keydata,
int use_armor)
{
GpgsmObject gpgsm = engine;
@ -1033,36 +1033,27 @@ gpgsm_export (void *engine, gpgme_recipients_t recp, gpgme_data_t keydata,
strcpy (cmd, "EXPORT");
cmdi = 6;
if (recp)
while (!err && uid)
{
void *ec;
const char *s;
err = gpgme_recipients_enum_open (recp, &ec);
while (!err && (s = gpgme_recipients_enum_read (recp, &ec)))
int uidlen = strlen (uid->uid);
/* New string is old string + ' ' + s + '\0'. */
if (cmdlen < cmdi + 1 + uidlen + 1)
{
int slen = strlen (s);
/* New string is old string + ' ' + s + '\0'. */
if (cmdlen < cmdi + 1 + slen + 1)
char *newcmd = realloc (cmd, cmdlen * 2);
if (!newcmd)
{
char *newcmd = realloc (cmd, cmdlen * 2);
if (!newcmd)
{
free (cmd);
return GPGME_Out_Of_Core;
}
cmd = newcmd;
cmdlen *= 2;
free (cmd);
return GPGME_Out_Of_Core;
}
cmd[cmdi++] = ' ';
strcpy (cmd + cmdi, s);
cmdi += slen;
cmd = newcmd;
cmdlen *= 2;
}
if (!err)
err = gpgme_recipients_enum_close (recp, &ec);
if (err)
return err;
cmd[cmdi++] = ' ';
strcpy (cmd + cmdi, uid->uid);
cmdi += uidlen;
}
if (err)
return err;
gpgsm->output_cb.data = keydata;
err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server,

View File

@ -289,7 +289,7 @@ _gpgme_engine_op_edit (EngineObject engine, gpgme_key_t key, gpgme_data_t out,
gpgme_error_t
_gpgme_engine_op_encrypt (EngineObject engine, gpgme_recipients_t recp,
_gpgme_engine_op_encrypt (EngineObject engine, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t ciph, int use_armor)
{
if (!engine)
@ -304,7 +304,7 @@ _gpgme_engine_op_encrypt (EngineObject engine, gpgme_recipients_t recp,
gpgme_error_t
_gpgme_engine_op_encrypt_sign (EngineObject engine, gpgme_recipients_t recp,
_gpgme_engine_op_encrypt_sign (EngineObject engine, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t ciph,
int use_armor, gpgme_ctx_t ctx /* FIXME */)
{
@ -320,7 +320,7 @@ _gpgme_engine_op_encrypt_sign (EngineObject engine, gpgme_recipients_t recp,
gpgme_error_t
_gpgme_engine_op_export (EngineObject engine, gpgme_recipients_t recp,
_gpgme_engine_op_export (EngineObject engine, gpgme_user_id_t uids,
gpgme_data_t keydata, int use_armor)
{
if (!engine)
@ -329,8 +329,7 @@ _gpgme_engine_op_export (EngineObject engine, gpgme_recipients_t recp,
if (!engine->ops->export)
return GPGME_Not_Implemented;
return (*engine->ops->export) (engine->engine, recp, keydata,
use_armor);
return (*engine->ops->export) (engine->engine, uids, keydata, use_armor);
}

View File

@ -57,17 +57,17 @@ gpgme_error_t _gpgme_engine_op_edit (EngineObject engine, gpgme_key_t key,
gpgme_data_t out,
gpgme_ctx_t ctx /* FIXME */);
gpgme_error_t _gpgme_engine_op_encrypt (EngineObject engine,
gpgme_recipients_t recp,
gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t ciph,
int use_armor);
gpgme_error_t _gpgme_engine_op_encrypt_sign (EngineObject engine,
gpgme_recipients_t recp,
gpgme_user_id_t recp,
gpgme_data_t plain,
gpgme_data_t ciph,
int use_armor,
gpgme_ctx_t ctx /* FIXME */);
gpgme_error_t _gpgme_engine_op_export (EngineObject engine,
gpgme_recipients_t recp,
gpgme_user_id_t uids,
gpgme_data_t keydata, int use_armor);
gpgme_error_t _gpgme_engine_op_genkey (EngineObject engine,
gpgme_data_t help_data,

View File

@ -36,11 +36,11 @@ export_status_handler (void *priv, gpgme_status_code_t code, char *args)
static gpgme_error_t
export_start (gpgme_ctx_t ctx, int synchronous,
gpgme_recipients_t recp, gpgme_data_t keydata)
gpgme_user_id_t uids, gpgme_data_t keydata)
{
gpgme_error_t err;
if (!keydata || !recp)
if (!keydata || !uids)
return GPGME_Invalid_Value;
err = _gpgme_op_reset (ctx, synchronous);
@ -49,24 +49,24 @@ export_start (gpgme_ctx_t ctx, int synchronous,
_gpgme_engine_set_status_handler (ctx->engine, export_status_handler, ctx);
return _gpgme_engine_op_export (ctx->engine, recp, keydata, ctx->use_armor);
return _gpgme_engine_op_export (ctx->engine, uids, keydata, ctx->use_armor);
}
/* Export the keys listed in RECP into KEYDATA. */
gpgme_error_t
gpgme_op_export_start (gpgme_ctx_t ctx, gpgme_recipients_t recp,
gpgme_op_export_start (gpgme_ctx_t ctx, gpgme_user_id_t uids,
gpgme_data_t keydata)
{
return export_start (ctx, 0, recp, keydata);
return export_start (ctx, 0, uids, keydata);
}
/* Export the keys listed in RECP into KEYDATA. */
gpgme_error_t
gpgme_op_export (gpgme_ctx_t ctx, gpgme_recipients_t recipients, gpgme_data_t keydata)
gpgme_op_export (gpgme_ctx_t ctx, gpgme_user_id_t uids, gpgme_data_t keydata)
{
gpgme_error_t err = export_start (ctx, 1, recipients, keydata);
gpgme_error_t err = export_start (ctx, 1, uids, keydata);
if (!err)
err = _gpgme_wait_one (ctx);
return err;

View File

@ -75,10 +75,6 @@ typedef struct gpgme_context *gpgme_ctx_t;
struct gpgme_data;
typedef struct gpgme_data *gpgme_data_t;
/* A list of recipients to be used in an encryption operation. */
struct gpgme_recipients;
typedef struct gpgme_recipients *gpgme_recipients_t;
/* Public data types provided by GPGME. */
@ -542,6 +538,14 @@ struct _gpgme_user_id
};
typedef struct _gpgme_user_id *gpgme_user_id_t;
/* Release the user IDs in the list UID. */
void gpgme_user_ids_release (gpgme_user_id_t uid);
/* Add the name NAME to the user ID list *UIDS_P (with unknown
validity). */
gpgme_error_t gpgme_user_ids_append (gpgme_user_id_t *uids_p,
const char *name);
/* A key from the keyring. */
struct _gpgme_key
@ -793,40 +797,6 @@ void gpgme_get_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs);
the pending operation to finish. */
gpgme_ctx_t gpgme_wait (gpgme_ctx_t ctx, gpgme_error_t *status, int hang);
/* Functions to handle recipients. */
/* Create a new recipients set and return it in R_RSET. */
gpgme_error_t gpgme_recipients_new (gpgme_recipients_t *r_rset);
/* Release the recipients set RSET. */
void gpgme_recipients_release (gpgme_recipients_t rset);
/* Add NAME to the recipients set RSET. */
gpgme_error_t gpgme_recipients_add_name (gpgme_recipients_t rset, const char *name);
/* Add NAME with validity AL to the recipients set RSET. */
gpgme_error_t gpgme_recipients_add_name_with_validity (gpgme_recipients_t rset,
const char *name,
gpgme_validity_t val);
/* Return the number of recipients in RSET. */
unsigned int gpgme_recipients_count (const gpgme_recipients_t rset);
/* Create a new enumeration handle for the recipients set RSET and
return it in ITER. */
gpgme_error_t gpgme_recipients_enum_open (const gpgme_recipients_t rset,
void **iter);
/* Return the next recipient from the recipient set RSET in the
enumerator ITER. */
const char *gpgme_recipients_enum_read (const gpgme_recipients_t rset,
void **iter);
/* Destroy the enumerator ITER for the recipient set RSET. */
gpgme_error_t gpgme_recipients_enum_close (const gpgme_recipients_t rset,
void **iter);
/* Functions to handle data objects. */
@ -1011,19 +981,19 @@ gpgme_encrypt_result_t gpgme_op_encrypt_result (gpgme_ctx_t ctx);
/* Encrypt plaintext PLAIN within CTX for the recipients RECP and
store the resulting ciphertext in CIPHER. */
gpgme_error_t gpgme_op_encrypt_start (gpgme_ctx_t ctx, gpgme_recipients_t recp,
gpgme_error_t gpgme_op_encrypt_start (gpgme_ctx_t ctx, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t cipher);
gpgme_error_t gpgme_op_encrypt (gpgme_ctx_t ctx, gpgme_recipients_t recp,
gpgme_error_t gpgme_op_encrypt (gpgme_ctx_t ctx, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t cipher);
/* Encrypt plaintext PLAIN within CTX for the recipients RECP and
store the resulting ciphertext in CIPHER. Also sign the ciphertext
with the signers in CTX. */
gpgme_error_t gpgme_op_encrypt_sign_start (gpgme_ctx_t ctx,
gpgme_recipients_t recp,
gpgme_user_id_t recp,
gpgme_data_t plain,
gpgme_data_t cipher);
gpgme_error_t gpgme_op_encrypt_sign (gpgme_ctx_t ctx, gpgme_recipients_t recp,
gpgme_error_t gpgme_op_encrypt_sign (gpgme_ctx_t ctx, gpgme_user_id_t recp,
gpgme_data_t plain, gpgme_data_t cipher);
@ -1261,10 +1231,10 @@ gpgme_error_t gpgme_op_import_ext (gpgme_ctx_t ctx, gpgme_data_t keydata,
int *nr) _GPGME_DEPRECATED;
/* Export the keys listed in RECP into KEYDATA. */
gpgme_error_t gpgme_op_export_start (gpgme_ctx_t ctx, gpgme_recipients_t recp,
/* Export the keys listed in UIDS into KEYDATA. */
gpgme_error_t gpgme_op_export_start (gpgme_ctx_t ctx, gpgme_user_id_t uids,
gpgme_data_t keydata);
gpgme_error_t gpgme_op_export (gpgme_ctx_t ctx, gpgme_recipients_t recp,
gpgme_error_t gpgme_op_export (gpgme_ctx_t ctx, gpgme_user_id_t uids,
gpgme_data_t keydata);
@ -1442,7 +1412,6 @@ gpgme_error_t gpgme_engine_check_version (gpgme_protocol_t proto);
/* Deprecated types. */
typedef gpgme_ctx_t GpgmeCtx _GPGME_DEPRECATED;
typedef gpgme_data_t GpgmeData _GPGME_DEPRECATED;
typedef gpgme_recipients_t GpgmeRecipients _GPGME_DEPRECATED;
typedef gpgme_error_t GpgmeError _GPGME_DEPRECATED;
typedef gpgme_data_encoding_t GpgmeDataEncoding _GPGME_DEPRECATED;
typedef gpgme_pubkey_algo_t GpgmePubKeyAlgo _GPGME_DEPRECATED;

View File

@ -33,8 +33,9 @@ void _gpgme_release_result (gpgme_ctx_t ctx);
gpgme_error_t _gpgme_wait_one (gpgme_ctx_t ctx);
gpgme_error_t _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond);
/* From recipient.c. */
int _gpgme_recipients_all_valid ( const gpgme_recipients_t rset );
/* From user-id.c. */
int _gpgme_user_ids_all_valid (gpgme_user_id_t uid);
/* From data.c. */
@ -144,5 +145,4 @@ const char *_gpgme_compare_versions (const char *my_version,
const char *req_version);
char *_gpgme_get_program_version (const char *const path);
#endif /* OPS_H */

View File

@ -1,163 +0,0 @@
/* recipient.c - mainatin recipient sets
Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2002, 2003 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GPGME; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "context.h"
/* Create a new uninitialized recipient object and return it in R_RSET. */
gpgme_error_t
gpgme_recipients_new (gpgme_recipients_t *r_rset)
{
gpgme_recipients_t rset;
rset = calloc (1, sizeof *rset);
if (!rset)
return GPGME_Out_Of_Core;
*r_rset = rset;
return 0;
}
/* Release the recipient object RSET. */
void
gpgme_recipients_release (gpgme_recipients_t rset)
{
gpgme_user_id_t uid = rset->list;
while (uid)
{
gpgme_user_id_t next_uid = uid->next;
free (uid);
uid = next_uid;
}
free (rset);
}
/* Add the name NAME to the recipient set RSET with the given key
validity VALIDITY. */
gpgme_error_t
gpgme_recipients_add_name_with_validity (gpgme_recipients_t rset,
const char *name,
gpgme_validity_t validity)
{
gpgme_user_id_t uid;
if (!name || !rset)
return GPGME_Invalid_Value;
uid = malloc (sizeof (*uid) + strlen (name) + 1);
if (!uid)
return GPGME_Out_Of_Core;
uid->validity = validity;
uid->name = "";
uid->email = "";
uid->comment = "";
uid->uid = ((char *) uid) + sizeof (*uid);
strcpy (uid->uid, name);
uid->next = rset->list;
rset->list = uid;
return 0;
}
/* Add the name NAME to the recipient set RSET. Same as
gpgme_recipients_add_name_with_validity with validitiy
GPGME_VALIDITY_UNKNOWN. */
gpgme_error_t
gpgme_recipients_add_name (gpgme_recipients_t rset, const char *name)
{
return gpgme_recipients_add_name_with_validity (rset, name,
GPGME_VALIDITY_UNKNOWN);
}
/* Return the number of recipients in the set. */
unsigned int
gpgme_recipients_count (const gpgme_recipients_t rset)
{
gpgme_user_id_t uid = rset->list;
unsigned int count = 0;
while (uid)
{
count++;
uid = uid->next;
}
return count;
}
/* Start an enumeration on the recipient set RSET. The caller must
pass the address of a void pointer which is used as the iterator
object. */
gpgme_error_t
gpgme_recipients_enum_open (const gpgme_recipients_t rset, void **iter)
{
*iter = rset->list;
return 0;
}
/* Return the name of the next recipient in the set RSET. */
const char *
gpgme_recipients_enum_read (const gpgme_recipients_t rset, void **iter)
{
gpgme_user_id_t uid;
uid = *iter;
if (!uid)
return NULL;
*iter = uid->next;
return uid->name;
}
/* Release the iterator for this object. */
gpgme_error_t
gpgme_recipients_enum_close (const gpgme_recipients_t rset, void **iter)
{
/* Not really needed, but might catch the occasional mistake. */
*iter = NULL;
return 0;
}
int
_gpgme_recipients_all_valid (const gpgme_recipients_t rset)
{
gpgme_user_id_t uid = rset->list;
while (uid)
{
if (uid->validity != GPGME_VALIDITY_FULL
&& uid->validity != GPGME_VALIDITY_ULTIMATE )
return 0;
uid = uid->next;
}
return 1;
}

View File

@ -1235,26 +1235,25 @@ gpg_edit (void *engine, gpgme_key_t key, gpgme_data_t out,
static gpgme_error_t
append_args_from_recipients (GpgObject gpg, const gpgme_recipients_t rset)
append_args_from_recipients (GpgObject gpg, gpgme_user_id_t uid)
{
gpgme_error_t err = 0;
gpgme_user_id_t uid;
assert (rset);
for (uid = rset->list; uid; uid = uid->next)
while (uid)
{
err = add_arg (gpg, "-r");
if (!err)
err = add_arg (gpg, uid->uid);
if (err)
break;
uid = uid->next;
}
return err;
}
static gpgme_error_t
gpg_encrypt (void *engine, gpgme_recipients_t recp, gpgme_data_t plain,
gpg_encrypt (void *engine, gpgme_user_id_t recp, gpgme_data_t plain,
gpgme_data_t ciph, int use_armor)
{
GpgObject gpg = engine;
@ -1270,7 +1269,7 @@ gpg_encrypt (void *engine, gpgme_recipients_t recp, gpgme_data_t plain,
{
/* If we know that all recipients are valid (full or ultimate trust)
we can suppress further checks. */
if (!err && !symmetric && _gpgme_recipients_all_valid (recp))
if (!err && !symmetric && _gpgme_user_ids_all_valid (recp))
err = add_arg (gpg, "--always-trust");
if (!err)
@ -1297,7 +1296,7 @@ gpg_encrypt (void *engine, gpgme_recipients_t recp, gpgme_data_t plain,
static gpgme_error_t
gpg_encrypt_sign (void *engine, gpgme_recipients_t recp, gpgme_data_t plain,
gpg_encrypt_sign (void *engine, gpgme_user_id_t recp, gpgme_data_t plain,
gpgme_data_t ciph, int use_armor,
gpgme_ctx_t ctx /* FIXME */)
{
@ -1312,7 +1311,7 @@ gpg_encrypt_sign (void *engine, gpgme_recipients_t recp, gpgme_data_t plain,
/* If we know that all recipients are valid (full or ultimate trust)
* we can suppress further checks */
if (!err && _gpgme_recipients_all_valid (recp))
if (!err && _gpgme_user_ids_all_valid (recp))
err = add_arg (gpg, "--always-trust");
if (!err)
@ -1341,7 +1340,7 @@ gpg_encrypt_sign (void *engine, gpgme_recipients_t recp, gpgme_data_t plain,
static gpgme_error_t
gpg_export (void *engine, gpgme_recipients_t recp, gpgme_data_t keydata,
gpg_export (void *engine, gpgme_user_id_t uids, gpgme_data_t keydata,
int use_armor)
{
GpgObject gpg = engine;
@ -1355,16 +1354,10 @@ gpg_export (void *engine, gpgme_recipients_t recp, gpgme_data_t keydata,
if (!err)
err = add_arg (gpg, "--");
if (!err)
while (!err && uids)
{
void *ec;
const char *s;
err = gpgme_recipients_enum_open (recp, &ec);
while (!err && (s = gpgme_recipients_enum_read (recp, &ec)))
err = add_arg (gpg, s);
if (!err)
err = gpgme_recipients_enum_close (recp, &ec);
err = add_arg (gpg, uids->uid);
uids = uids->next;
}
if (!err)

View File

@ -29,10 +29,7 @@
#include "util.h"
#include "context.h"
/* The signers are directly stored in the context. So this is quite
different to a recipient set. */
/* Delete all signers from CTX. */
void
gpgme_signers_clear (gpgme_ctx_t ctx)

91
gpgme/user-id.c Normal file
View File

@ -0,0 +1,91 @@
/* user-id.c - Managing user IDs.
Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2002, 2003 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GPGME; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <gpgme.h>
/* Release the user IDs in the list UID. */
void
gpgme_user_ids_release (gpgme_user_id_t uid)
{
while (uid)
{
gpgme_user_id_t next_uid = uid->next;
free (uid);
uid = next_uid;
}
}
/* Add the name NAME to the user ID list *UIDS_P (with unknown
validity). */
gpgme_error_t
gpgme_user_ids_append (gpgme_user_id_t *uids_p, const char *name)
{
gpgme_user_id_t uids;
gpgme_user_id_t uid;
if (!name || !uids_p)
return GPGME_Invalid_Value;
uid = calloc (1, sizeof (*uid) + strlen (name) + 1);
if (!uid)
return GPGME_Out_Of_Core;
uid->uid = ((char *) uid) + sizeof (*uid);
strcpy (uid->uid, name);
uid->name = uid->uid + strlen (name);
uid->email = uid->name;
uid->comment = uid->name;
uid->validity = GPGME_VALIDITY_UNKNOWN;
uids = *uids_p;
if (uids)
{
while (uids->next)
uids = uids->next;
uids->next = uid;
}
else
*uids_p = uid;
return 0;
}
int
_gpgme_user_ids_all_valid (gpgme_user_id_t uid)
{
while (uid)
{
if (uid->validity != GPGME_VALIDITY_FULL
&& uid->validity != GPGME_VALIDITY_ULTIMATE)
return 0;
uid = uid->next;
}
return 1;
}

View File

@ -1,3 +1,10 @@
2003-05-28 Marcus Brinkmann <marcus@g10code.de>
* gpg/t-eventloop.c (main): Rewrite recipient management.
* gpg/t-encrypt-sign.c (main): Likewise.
* gpg/t-encrypt.c (main): Likewise.
* gpg/t-export.c (main): Likewise.
2003-05-27 Marcus Brinkmann <marcus@g10code.de>
* gpg/Makefile.am (TESTS): Order t-keylist and t-keylist-sig after

View File

@ -117,7 +117,8 @@ main (int argc, char **argv)
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_recipients_t rset;
gpgme_user_id_t rset = NULL;
gpgme_user_id_t *rset_lastp = &rset;
gpgme_encrypt_result_t result;
gpgme_sign_result_t sign_result;
char *agent_info;
@ -139,15 +140,15 @@ main (int argc, char **argv)
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_recipients_new (&rset);
err = gpgme_user_ids_append (rset_lastp, "Alpha");
fail_if_err (err);
err = gpgme_recipients_add_name_with_validity (rset, "Bob",
GPGME_VALIDITY_FULL);
fail_if_err (err);
err = gpgme_recipients_add_name_with_validity (rset, "Alpha",
GPGME_VALIDITY_FULL);
(*rset_lastp)->validity = GPGME_VALIDITY_FULL;
rset_lastp = &(*rset_lastp)->next;
err = gpgme_user_ids_append (rset_lastp, "Bob");
fail_if_err (err);
(*rset_lastp)->validity = GPGME_VALIDITY_FULL;
err = gpgme_op_encrypt_sign (ctx, rset, in, out);
fail_if_err (err);
@ -162,11 +163,9 @@ main (int argc, char **argv)
check_result (sign_result, GPGME_SIG_MODE_NORMAL);
print_data (out);
gpgme_recipients_release (rset);
gpgme_user_ids_release (rset);
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);
return 0;
}

View File

@ -60,7 +60,8 @@ main (int argc, char **argv)
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_recipients_t rset;
gpgme_user_id_t rset = NULL;
gpgme_user_id_t *rset_lastp = &rset;
gpgme_encrypt_result_t result;
err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
@ -76,14 +77,14 @@ main (int argc, char **argv)
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_recipients_new (&rset);
err = gpgme_user_ids_append (rset_lastp, "Alpha");
fail_if_err (err);
err = gpgme_recipients_add_name_with_validity (rset, "Bob",
GPGME_VALIDITY_FULL);
fail_if_err (err);
err = gpgme_recipients_add_name_with_validity (rset, "Alpha",
GPGME_VALIDITY_FULL);
(*rset_lastp)->validity = GPGME_VALIDITY_FULL;
rset_lastp = &(*rset_lastp)->next;
err = gpgme_user_ids_append (rset_lastp, "Bob");
fail_if_err (err);
(*rset_lastp)->validity = GPGME_VALIDITY_FULL;
err = gpgme_op_encrypt (ctx, rset, in, out);
fail_if_err (err);
@ -96,7 +97,7 @@ main (int argc, char **argv)
}
print_data (out);
gpgme_recipients_release (rset);
gpgme_user_ids_release (rset);
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);

View File

@ -27,11 +27,18 @@
#include <gpgme.h>
#define fail_if_err(a) do { if(a) { \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror(a)); \
exit (1); } \
} while(0)
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
@ -114,6 +121,7 @@ io_event (void *data, gpgme_event_io_t type, void *type_data)
}
}
int
do_select (void)
{
@ -166,6 +174,7 @@ my_wait (void)
return 0;
}
struct gpgme_io_cbs io_cbs =
{
add_io_cb,
@ -175,13 +184,15 @@ struct gpgme_io_cbs io_cbs =
&op_result
};
int
main (int argc, char *argv[])
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t in, out;
gpgme_recipients_t rset;
gpgme_user_id_t rset = NULL;
gpgme_user_id_t *rset_lastp = &rset;
int i;
for (i = 0; i < FDLIST_MAX; i++)
@ -190,49 +201,43 @@ main (int argc, char *argv[])
err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
fail_if_err (err);
do
{
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_armor (ctx, 1);
gpgme_set_io_cbs (ctx, &io_cbs);
op_result.done = 0;
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_armor (ctx, 1);
gpgme_set_io_cbs (ctx, &io_cbs);
op_result.done = 0;
err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
fail_if_err (err);
err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_recipients_new (&rset);
fail_if_err (err);
err = gpgme_recipients_add_name_with_validity (rset, "Bob",
GPGME_VALIDITY_FULL);
fail_if_err (err);
err = gpgme_recipients_add_name_with_validity (rset, "Alpha",
GPGME_VALIDITY_FULL);
fail_if_err (err);
err = gpgme_user_ids_append (rset_lastp, "Alpha");
fail_if_err (err);
(*rset_lastp)->validity = GPGME_VALIDITY_FULL;
err = gpgme_op_encrypt_start (ctx, rset, in, out);
fail_if_err (err);
rset_lastp = &(*rset_lastp)->next;
err = gpgme_user_ids_append (rset_lastp, "Bob");
fail_if_err (err);
(*rset_lastp)->validity = GPGME_VALIDITY_FULL;
my_wait ();
fail_if_err (op_result.err);
fail_if_err (err);
err = gpgme_op_encrypt_start (ctx, rset, in, out);
fail_if_err (err);
fflush (NULL);
fputs ("Begin Result:\n", stdout);
print_data (out);
fputs ("End Result.\n", stdout);
my_wait ();
fail_if_err (op_result.err);
fail_if_err (err);
fflush (NULL);
fputs ("Begin Result:\n", stdout);
print_data (out);
fputs ("End Result.\n", stdout);
gpgme_recipients_release (rset);
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);
}
while (argc > 1 && !strcmp (argv[1], "--loop"));
gpgme_user_ids_release (rset);
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);
return 0;
}

View File

@ -1,23 +1,22 @@
/* t-export.c - regression test
* Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* t-export.c - Regression test.
Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2003 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GPGME; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
@ -26,11 +25,17 @@
#include <gpgme.h>
#define fail_if_err(a) do { if(a) { \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror(a)); \
exit (1); } \
} while(0)
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
@ -48,43 +53,43 @@ print_data (gpgme_data_t dh)
fail_if_err (GPGME_File_Error);
}
int
main (int argc, char **argv )
main (int argc, char **argv)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t out;
gpgme_recipients_t rset;
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t out;
gpgme_user_id_t uids = NULL;
gpgme_user_id_t *uids_lastp = &uids;
do {
err = gpgme_new (&ctx);
fail_if_err (err);
err = gpgme_new (&ctx);
fail_if_err (err);
err = gpgme_data_new ( &out );
fail_if_err (err);
err = gpgme_data_new (&out);
fail_if_err (err);
err = gpgme_recipients_new (&rset);
fail_if_err (err);
err = gpgme_recipients_add_name (rset, "Bob");
fail_if_err (err);
err = gpgme_recipients_add_name (rset, "Alpha");
fail_if_err (err);
err = gpgme_user_ids_append (uids_lastp, "Alpha");
fail_if_err (err);
uids_lastp = &(*uids_lastp)->next;
gpgme_set_armor (ctx, 1 );
err = gpgme_op_export (ctx, rset, out );
fail_if_err (err);
err = gpgme_user_ids_append (uids_lastp, "Bob");
fail_if_err (err);
fflush (NULL);
fputs ("Begin Result:\n", stdout );
print_data (out);
fputs ("End Result.\n", stdout );
gpgme_set_armor (ctx, 1);
err = gpgme_op_export (ctx, uids, out);
fail_if_err (err);
fflush (NULL);
fputs ("Begin Result:\n", stdout);
print_data (out);
fputs ("End Result.\n", stdout);
gpgme_recipients_release (rset);
gpgme_data_release (out);
gpgme_release (ctx);
} while ( argc > 1 && !strcmp( argv[1], "--loop" ) );
gpgme_user_ids_release (uids);
gpgme_data_release (out);
gpgme_release (ctx);
return 0;
return 0;
}