gpgme (6 files)
cvs user marcus
cvs at cvs.gnupg.org
Fri Jun 3 02:20:55 CEST 2005
Date: Friday, June 3, 2005 @ 02:42:08
Author: marcus
Path: /cvs/gpgme/gpgme
Modified: NEWS doc/ChangeLog doc/gpgme.texi gpgme/ChangeLog
gpgme/decrypt.c gpgme/gpgme.h
doc/
2005-06-03 Marcus Brinkmann <marcus at g10code.de>
* gpgme.texi (Decrypt): Add gpgme_recipient_t.
gpgme/
2005-06-03 Marcus Brinkmann <marcus at g10code.de>
* gpgme.h (struct _gpgme_recipient): New structure.
(gpgme_recipient_t): New type.
(struct _gpgme_op_decrypt_result): Add member recipients.
* decrypt.c (op_data_t): New member last_recipient_p.
(_gpgme_op_decrypt_init_result): Initialize last_recipient_p.
(parse_enc_to): New function.
(_gpgme_decrypt_status_handler): Handle status ENC_TO and
NO_SECKEY.
-----------------+
NEWS | 5 ++
doc/ChangeLog | 4 ++
doc/gpgme.texi | 34 ++++++++++++++++++
gpgme/ChangeLog | 9 ++++
gpgme/decrypt.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
gpgme/gpgme.h | 21 +++++++++++
6 files changed, 167 insertions(+), 4 deletions(-)
Index: gpgme/NEWS
diff -u gpgme/NEWS:1.141 gpgme/NEWS:1.142
--- gpgme/NEWS:1.141 Fri Jun 3 00:01:58 2005
+++ gpgme/NEWS Fri Jun 3 02:42:08 2005
@@ -13,12 +13,17 @@
Because the default changes, this is a slight change of the API
semantics. We consider it to be a bug fix.
+ * Information about the recipients of an encrypted text is now
+ available at decryption time.
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gpgme_set_engine_info NEW
gpgme_ctx_get_engine_info NEW
gpgme_ctx_set_engine_info NEW
gpgme_set_include_certs CHANGED DEFAULT
GPGME_INCLUDE_CERTS_DEFAULT NEW
+gpgme_recipient_t NEW
+gpgme_decrypt_result_t EXTENDED: New field recipients.
GPGME_STATUS_SIG_SUBPACKET NEW
GPGME_STATUS_NEED_PASSPHRASE_PIN NEW
GPGME_STATUS_SC_OP_FAILURE NEW
Index: gpgme/doc/ChangeLog
diff -u gpgme/doc/ChangeLog:1.137 gpgme/doc/ChangeLog:1.138
--- gpgme/doc/ChangeLog:1.137 Sat May 28 22:09:20 2005
+++ gpgme/doc/ChangeLog Fri Jun 3 02:42:08 2005
@@ -1,3 +1,7 @@
+2005-06-03 Marcus Brinkmann <marcus at g10code.de>
+
+ * gpgme.texi (Decrypt): Add gpgme_recipient_t.
+
2005-05-28 Marcus Brinkmann <marcus at g10code.de>
* gpgme.texi (Key Listing Mode): Fix return type of
Index: gpgme/doc/gpgme.texi
diff -u gpgme/doc/gpgme.texi:1.139 gpgme/doc/gpgme.texi:1.140
--- gpgme/doc/gpgme.texi:1.139 Sat May 28 22:09:20 2005
+++ gpgme/doc/gpgme.texi Fri Jun 3 02:42:07 2005
@@ -3622,9 +3622,38 @@
if @var{cipher} or @var{plain} is not a valid pointer.
@end deftypefun
+ at deftp {Data type} {gpgme_recipient_t}
+This is a pointer to a structure used to store information about the
+recipient of an encrypted text which is decrypted in a
+ at code{gpgme_op_decrypt} operation. This information (except for the
+status field) is even available before the operation finished
+successfully, for example in a passphrase callback. The structure
+contains the following members:
+
+ at table @code
+ at item gpgme_recipient_t next
+This is a pointer to the next recipient structure in the linked list,
+or @code{NULL} if this is the last element.
+
+ at item gpgme_pubkey_algo_t
+The public key algorithm used in the encryption.
+
+ at item unsigned int wrong_key_usage : 1
+This is true if the key was not used according to its policy.
+
+ at item char *keyid
+This is the key ID of the key (in hexadecimal digits) used as
+recipient.
+
+ at item gpgme_error_t status
+This is an error number with the error code GPG_ERR_NO_SECKEY if the
+secret key for this recipient is not available, and 0 otherwise.
+ at end table
+ at end deftp
+
@deftp {Data type} {gpgme_decrypt_result_t}
This is a pointer to a structure used to store the result of a
- at code{gpgme_op_decrypt} operation. After successfully encrypting
+ at code{gpgme_op_decrypt} operation. After successfully decrypting
data, you can retrieve the pointer to the result with
@code{gpgme_op_decrypt_result}. The structure contains the following
members:
@@ -3636,6 +3665,9 @@
@item unsigned int wrong_key_usage : 1
This is true if the key was not used according to its policy.
+
+ at item gpgme_recipient_t recipient
+This is a linked list of recipients to which this message was encrypted.
@end table
@end deftp
Index: gpgme/gpgme/ChangeLog
diff -u gpgme/gpgme/ChangeLog:1.405 gpgme/gpgme/ChangeLog:1.406
--- gpgme/gpgme/ChangeLog:1.405 Fri Jun 3 00:59:41 2005
+++ gpgme/gpgme/ChangeLog Fri Jun 3 02:42:07 2005
@@ -1,5 +1,14 @@
2005-06-03 Marcus Brinkmann <marcus at g10code.de>
+ * gpgme.h (struct _gpgme_recipient): New structure.
+ (gpgme_recipient_t): New type.
+ (struct _gpgme_op_decrypt_result): Add member recipients.
+ * decrypt.c (op_data_t): New member last_recipient_p.
+ (_gpgme_op_decrypt_init_result): Initialize last_recipient_p.
+ (parse_enc_to): New function.
+ (_gpgme_decrypt_status_handler): Handle status ENC_TO and
+ NO_SECKEY.
+
* wait-global.c (gpgme_wait): Break out of the fd processing loop
after an error.
Reported by Igor Belyi <gpgme at katehok.ac93.org>.
Index: gpgme/gpgme/decrypt.c
diff -u gpgme/gpgme/decrypt.c:1.42 gpgme/gpgme/decrypt.c:1.43
--- gpgme/gpgme/decrypt.c:1.42 Tue Dec 7 22:13:36 2004
+++ gpgme/gpgme/decrypt.c Fri Jun 3 02:42:07 2005
@@ -38,6 +38,11 @@
int okay;
int failed;
+
+ /* A pointer to the next pointer of the last recipient in the list.
+ This makes appending new invalid signers painless while
+ preserving the order. */
+ gpgme_recipient_t *last_recipient_p;
} *op_data_t;
@@ -67,6 +72,60 @@
}
+static gpgme_error_t
+parse_enc_to (char *args, gpgme_recipient_t *recp)
+{
+ gpgme_recipient_t rec;
+ char *tail;
+ int i;
+
+ rec = malloc (sizeof (*rec));
+ if (!rec)
+ return gpg_error_from_errno (errno);
+
+ rec->next = NULL;
+ rec->keyid = rec->_keyid;
+ rec->status = 0;
+
+ for (i = 0; i < sizeof (rec->_keyid) - 1; i++)
+ {
+ if (args[i] == '\0' || args[i] == ' ')
+ break;
+
+ rec->_keyid[i] = args[i];
+ }
+ rec->_keyid[i] = '\0';
+
+ args = &args[i];
+ if (*args != '\0' && *args != ' ')
+ {
+ free (rec);
+ return gpg_error (GPG_ERR_INV_ENGINE);
+ }
+
+ while (*args == ' ')
+ args++;
+
+ if (*args)
+ {
+ errno = 0;
+ rec->pubkey_algo = strtol (args, &tail, 0);
+ if (errno || args == tail || *tail != ' ')
+ {
+ /* The crypto backend does not behave. */
+ free (rec);
+ return gpg_error (GPG_ERR_INV_ENGINE);
+ }
+ }
+
+ /* FIXME: The key length is always 0 right now, so no need to parse
+ it. */
+
+ *recp = rec;
+ return 0;
+}
+
+
gpgme_error_t
_gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
char *args)
@@ -151,7 +210,33 @@
}
}
break;
-
+
+ case GPGME_STATUS_ENC_TO:
+ err = parse_enc_to (args, opd->last_recipient_p);
+ if (err)
+ return err;
+
+ opd->last_recipient_p = &(*opd->last_recipient_p)->next;
+ break;
+
+ case GPGME_STATUS_NO_SECKEY:
+ {
+ gpgme_recipient_t rec = opd->result.recipients;
+
+ while (rec)
+ {
+ if (!strcmp (rec->keyid, args))
+ {
+ rec->status = gpg_error (GPG_ERR_NO_SECKEY);
+ break;
+ }
+ }
+ /* FIXME: Is this ok? */
+ if (!rec)
+ return gpg_error (GPG_ERR_INV_ENGINE);
+ }
+ break;
+
default:
break;
}
@@ -175,11 +260,18 @@
gpgme_error_t
_gpgme_op_decrypt_init_result (gpgme_ctx_t ctx)
{
+ gpgme_error_t err;
void *hook;
op_data_t opd;
- return _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, &hook,
- sizeof (*opd), release_op_data);
+ err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, &hook,
+ sizeof (*opd), release_op_data);
+ opd = hook;
+ if (err)
+ return err;
+
+ opd->last_recipient_p = &opd->result.recipients;
+ return 0;
}
Index: gpgme/gpgme/gpgme.h
diff -u gpgme/gpgme/gpgme.h:1.155 gpgme/gpgme/gpgme.h:1.156
--- gpgme/gpgme/gpgme.h:1.155 Thu Jun 2 13:22:14 2005
+++ gpgme/gpgme/gpgme.h Fri Jun 3 02:42:07 2005
@@ -1080,6 +1080,25 @@
/* Decryption. */
+
+struct _gpgme_recipient
+{
+ struct _gpgme_recipient *next;
+
+ /* The key ID of key for which the text was encrypted. */
+ char *keyid;
+
+ /* Internal to GPGME, do not use. */
+ char _keyid[16 + 1];
+
+ /* The public key algorithm of the recipient key. */
+ gpgme_pubkey_algo_t pubkey_algo;
+
+ /* The status of the recipient. */
+ gpgme_error_t status;
+};
+typedef struct _gpgme_recipient *gpgme_recipient_t;
+
struct _gpgme_op_decrypt_result
{
char *unsupported_algorithm;
@@ -1089,6 +1108,8 @@
/* Internal to GPGME, do not use. */
int _unused : 31;
+
+ gpgme_recipient_t recipients;
};
typedef struct _gpgme_op_decrypt_result *gpgme_decrypt_result_t;
More information about the Gnupg-commits
mailing list