diff --git a/NEWS b/NEWS index e811e5e0..4e37693c 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,9 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gpgme_get_passphrase_cb NEW gpgme_get_progress_cb NEW +GpgmeDataEncoding NEW +gpgme_data_set_encoding NEW +gpgme_data_get_encoding NEW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Noteworthy changes in version 0.3.5 (2002-04-01) diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index cfcdb8da..ff04df80 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,10 @@ +2002-04-27 Werner Koch + + * gpgme.h (GpgmeData_Encoding): New. + * data.c (gpgme_data_get_encoding,gpgme_data_set_encoding): New. + * engine-gpgsm.c (map_input_enc): New. Use it in all local + functions where the INPUT command gets send. + 2002-04-27 Marcus Brinkmann * engine-gpgsm.c (_gpgme_gpgsm_op_verify): Close the output diff --git a/gpgme/context.h b/gpgme/context.h index 8ecdaf18..34ca9d49 100644 --- a/gpgme/context.h +++ b/gpgme/context.h @@ -107,6 +107,7 @@ struct gpgme_data_s { const char *data; GpgmeDataType type; GpgmeDataMode mode; + GpgmeDataEncoding encoding; int (*read_cb)( void *, char *, size_t, size_t *); void *read_cb_value; diff --git a/gpgme/data.c b/gpgme/data.c index 1805d58f..ac827576 100644 --- a/gpgme/data.c +++ b/gpgme/data.c @@ -465,6 +465,24 @@ gpgme_data_get_type (GpgmeData dh) return dh->type; } +/* Get the current encoding meta information. */ +GpgmeDataEncoding +gpgme_data_get_encoding (GpgmeData dh) +{ + return dh? dh->encoding : GPGME_DATA_ENCODING_NONE; +} + +/* Set the encoding meta information for DB to ENC */ +GpgmeError +gpgme_data_set_encoding (GpgmeData dh, GpgmeDataEncoding enc) +{ + if (!dh) + return GPGME_Invalid_Value; + if (enc < 0 || enc > GPGME_DATA_ENCODING_ARMOR) + return GPGME_Invalid_Value; + dh->encoding = enc; + return 0; +} void _gpgme_data_set_mode (GpgmeData dh, GpgmeDataMode mode) diff --git a/gpgme/engine-gpgsm.c b/gpgme/engine-gpgsm.c index aa1b09f5..a4675ac0 100644 --- a/gpgme/engine-gpgsm.c +++ b/gpgme/engine-gpgsm.c @@ -503,6 +503,21 @@ gpgsm_set_fd (ASSUAN_CONTEXT ctx, const char *which, int fd, const char *opt) } +static const char * +map_input_enc (GpgmeData d) +{ + switch (gpgme_data_get_encoding (d)) + { + case GPGME_DATA_ENCODING_NONE: break; + case GPGME_DATA_ENCODING_BINARY: return "--binary"; + case GPGME_DATA_ENCODING_BASE64: return "--base64"; + case GPGME_DATA_ENCODING_ARMOR: return "--armor"; + } + + return NULL; +} + + GpgmeError _gpgme_gpgsm_op_decrypt (GpgsmObject gpgsm, GpgmeData ciph, GpgmeData plain) { @@ -516,7 +531,8 @@ _gpgme_gpgsm_op_decrypt (GpgsmObject gpgsm, GpgmeData ciph, GpgmeData plain) return mk_error (Out_Of_Core); gpgsm->input_data = ciph; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_data)); if (err) return mk_error (General_Error); /* FIXME */ gpgsm->output_data = plain; @@ -607,7 +623,8 @@ _gpgme_gpgsm_op_encrypt (GpgsmObject gpgsm, GpgmeRecipients recp, return mk_error (Out_Of_Core); gpgsm->input_data = plain; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_data)); if (err) return err; gpgsm->output_data = ciph; @@ -648,7 +665,8 @@ _gpgme_gpgsm_op_genkey (GpgsmObject gpgsm, GpgmeData help_data, int use_armor, return mk_error (Out_Of_Core); gpgsm->input_data = help_data; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_data)); if (err) return err; gpgsm->output_data = pubkey; @@ -675,7 +693,8 @@ _gpgme_gpgsm_op_import (GpgsmObject gpgsm, GpgmeData keydata) return mk_error (Out_Of_Core); gpgsm->input_data = keydata; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_data)); if (err) return err; _gpgme_io_close (gpgsm->output_fd); @@ -834,7 +853,8 @@ _gpgme_gpgsm_op_sign (GpgsmObject gpgsm, GpgmeData in, GpgmeData out, return err; gpgsm->input_data = in; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_data)); if (err) return err; gpgsm->output_data = out; @@ -869,7 +889,8 @@ _gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, GpgmeData text) return mk_error (Out_Of_Core); gpgsm->input_data = sig; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_data)); if (err) return err; if (_gpgme_data_get_mode (text) == GPGME_DATA_MODE_IN) diff --git a/gpgme/gpgme.c b/gpgme/gpgme.c index e91e2fb1..21578cad 100644 --- a/gpgme/gpgme.c +++ b/gpgme/gpgme.c @@ -140,7 +140,7 @@ gpgme_get_notation (GpgmeCtx ctx) * @c: the context * @reserved: * - * Return information about the last information. The caller has to + * Return information about the last operation. The caller has to * free the string. NULL is returned if there is not previous * operation available or the operation has not yet finished. * diff --git a/gpgme/gpgme.h b/gpgme/gpgme.h index 65615645..079b88ab 100644 --- a/gpgme/gpgme.h +++ b/gpgme/gpgme.h @@ -112,6 +112,16 @@ typedef enum } GpgmeDataType; +/* The possible encoding mode of GpgmeData objects. */ +typedef enum + { + GPGME_DATA_ENCODING_NONE = 0, /* i.e. not specified */ + GPGME_DATA_ENCODING_BINARY = 1, + GPGME_DATA_ENCODING_BASE64 = 2, + GPGME_DATA_ENCODING_ARMOR = 3 /* Either PEM or OpenPGP Armor */ + } +GpgmeDataEncoding; + /* The possible signature stati. */ typedef enum { @@ -374,6 +384,12 @@ char *gpgme_data_release_and_get_mem (GpgmeData dh, size_t *r_len); /* Return the type of the data buffer DH. */ GpgmeDataType gpgme_data_get_type (GpgmeData dh); +/* Return the encoding attribute of the data buffer DH */ +GpgmeDataEncoding gpgme_data_get_encoding (GpgmeData dh); + +/* Set the encoding attribute of data buffer DH to ENC */ +GpgmeError gpgme_data_set_encoding (GpgmeData dh, GpgmeDataEncoding enc); + /* Reset the read pointer in DH. */ GpgmeError gpgme_data_rewind (GpgmeData dh);