Add option GPGME_EXPORT_MODE_MINIMAL

This commit is contained in:
Werner Koch 2010-02-16 20:07:03 +00:00
parent 9fb8b16f88
commit 2281024d4c
7 changed files with 82 additions and 16 deletions

5
NEWS
View File

@ -3,6 +3,11 @@ Noteworthy changes in version 1.3.1 (unreleased)
* Under development. * Under development.
* Interface changes relative to the 1.3.0 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GPGME_EXPORT_MODE_MINIMAL NEW.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Noteworthy changes in version 1.3.0 (2010-01-11) Noteworthy changes in version 1.3.0 (2010-01-11)
------------------------------------------------ ------------------------------------------------

View File

@ -3402,6 +3402,12 @@ practise to not send more than a few dozens key to a keyserver at one
time. Using this flag requires that the @var{keydata} argument of the time. Using this flag requires that the @var{keydata} argument of the
export function is set to @code{NULL}. export function is set to @code{NULL}.
@item GPGME_EXPORT_MODE_MINIMAL
If this bit is set, the smallest possible key is exported. For OpenPGP
keys it removes all signatures except for the latest self-signatures.
For X.509 keys it has no effect.
@end table @end table

View File

@ -1,3 +1,12 @@
2010-02-16 Werner Koch <wk@g10code.com>
* gpgme-tool.c (spacep, has_option, skip_options): New.
(cmd_export): Implement option --minimal.
* gpgme.h.in (GPGME_EXPORT_MODE_MINIMAL): New.
* export.c (export_start, export_ext_start): Implement it.
* engine-gpg.c (export_common): Ditto.
2010-01-25 Werner Koch <wk@g10code.com> 2010-01-25 Werner Koch <wk@g10code.com>
* w32-io.c (_gpgme_io_connect): Fix return code check to make it work. * w32-io.c (_gpgme_io_connect): Fix return code check to make it work.

View File

@ -1727,12 +1727,18 @@ static gpgme_error_t
export_common (engine_gpg_t gpg, gpgme_export_mode_t mode, export_common (engine_gpg_t gpg, gpgme_export_mode_t mode,
gpgme_data_t keydata, int use_armor) gpgme_data_t keydata, int use_armor)
{ {
gpgme_error_t err; gpgme_error_t err = 0;
if ((mode & ~GPGME_EXPORT_MODE_EXTERN)) if ((mode & ~(GPGME_EXPORT_MODE_EXTERN
|GPGME_EXPORT_MODE_MINIMAL)))
return gpg_error (GPG_ERR_NOT_SUPPORTED); return gpg_error (GPG_ERR_NOT_SUPPORTED);
if ((mode & GPGME_EXPORT_MODE_EXTERN)) if ((mode & GPGME_EXPORT_MODE_MINIMAL))
err = add_arg (gpg, "--export-options=export-minimal");
if (err)
;
else if ((mode & GPGME_EXPORT_MODE_EXTERN))
{ {
err = add_arg (gpg, "--send-keys"); err = add_arg (gpg, "--send-keys");
} }

View File

@ -1,6 +1,6 @@
/* export.c - Export a key. /* export.c - Export a key.
Copyright (C) 2000 Werner Koch (dd9jn) Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH Copyright (C) 2001, 2002, 2003, 2004, 2010 g10 Code GmbH
This file is part of GPGME. This file is part of GPGME.
@ -15,9 +15,8 @@
Lesser General Public License for more details. Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software License along with this program; if not, see <http://www.gnu.org/licenses/>.
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA */
02111-1307, USA. */
#if HAVE_CONFIG_H #if HAVE_CONFIG_H
#include <config.h> #include <config.h>
@ -44,7 +43,8 @@ export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern,
{ {
gpgme_error_t err; gpgme_error_t err;
if ((mode & ~(GPGME_EXPORT_MODE_EXTERN))) if ((mode & ~(GPGME_EXPORT_MODE_EXTERN
|GPGME_EXPORT_MODE_MINIMAL)))
return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */ return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */
@ -107,7 +107,8 @@ export_ext_start (gpgme_ctx_t ctx, int synchronous, const char *pattern[],
{ {
gpgme_error_t err; gpgme_error_t err;
if ((mode & ~(GPGME_EXPORT_MODE_EXTERN))) if ((mode & ~(GPGME_EXPORT_MODE_EXTERN
|GPGME_EXPORT_MODE_MINIMAL)))
return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */ return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */
if ((mode & GPGME_EXPORT_MODE_EXTERN)) if ((mode & GPGME_EXPORT_MODE_EXTERN))

View File

@ -468,6 +468,9 @@ argp_parse (const struct argp *argp, int argc,
FILE *log_stream; FILE *log_stream;
char *program_name = "gpgme-tool"; char *program_name = "gpgme-tool";
#define spacep(p) (*(p) == ' ' || *(p) == '\t')
void log_error (int status, gpg_error_t errnum, void log_error (int status, gpg_error_t errnum,
const char *fmt, ...) GT_GCC_A_PRINTF(3,4); const char *fmt, ...) GT_GCC_A_PRINTF(3,4);
@ -497,6 +500,35 @@ log_error (int status, gpg_error_t errnum, const char *fmt, ...)
} }
/* Check whether the option NAME appears in LINE. */
static int
has_option (const char *line, const char *name)
{
const char *s;
int n = strlen (name);
s = strstr (line, name);
return (s && (s == line || spacep (s-1)) && (!s[n] || spacep (s+n)));
}
/* Skip over options. It is assumed that leading spaces have been
removed (this is the case for lines passed to a handler from
assuan). Blanks after the options are also removed. */
static char *
skip_options (char *line)
{
while ( *line == '-' && line[1] == '-' )
{
while (*line && !spacep (line))
line++;
while (spacep (line))
line++;
}
return line;
}
typedef gpg_error_t (*result_xml_write_cb_t) (void *hook, const void *buf, typedef gpg_error_t (*result_xml_write_cb_t) (void *hook, const void *buf,
size_t len); size_t len);
@ -2334,6 +2366,11 @@ cmd_import (assuan_context_t ctx, char *line)
} }
static const char hlp_export[] =
"EXPORT [--extern] [--minimal] [<pattern>]\n"
"\n"
"Export the keys described by PATTERN. Write the\n"
"the output to the object set by the last OUTPUT command.";
static gpg_error_t static gpg_error_t
cmd_export (assuan_context_t ctx, char *line) cmd_export (assuan_context_t ctx, char *line)
{ {
@ -2343,7 +2380,6 @@ cmd_export (assuan_context_t ctx, char *line)
gpgme_data_t out_data; gpgme_data_t out_data;
gpgme_export_mode_t mode = 0; gpgme_export_mode_t mode = 0;
const char *pattern[2]; const char *pattern[2];
const char optstr[] = "--extern ";
out_fd = assuan_get_output_fd (ctx); out_fd = assuan_get_output_fd (ctx);
if (out_fd == ASSUAN_INVALID_FD) if (out_fd == ASSUAN_INVALID_FD)
@ -2352,11 +2388,13 @@ cmd_export (assuan_context_t ctx, char *line)
if (err) if (err)
return err; return err;
if (strncasecmp (line, optstr, strlen (optstr))) if (has_option (line, "--extern"))
{
mode |= GPGME_EXPORT_MODE_EXTERN; mode |= GPGME_EXPORT_MODE_EXTERN;
line += strlen (optstr); if (has_option (line, "--minimal"))
} mode |= GPGME_EXPORT_MODE_MINIMAL;
line = skip_options (line);
pattern[0] = line; pattern[0] = line;
pattern[1] = NULL; pattern[1] = NULL;
@ -2695,7 +2733,7 @@ register_commands (assuan_context_t ctx)
{ "SIGN", cmd_sign }, { "SIGN", cmd_sign },
{ "VERIFY", cmd_verify }, { "VERIFY", cmd_verify },
{ "IMPORT", cmd_import }, { "IMPORT", cmd_import },
{ "EXPORT", cmd_export }, { "EXPORT", cmd_export, hlp_export },
{ "GENKEY", cmd_genkey }, { "GENKEY", cmd_genkey },
{ "DELETE", cmd_delete }, { "DELETE", cmd_delete },
/* TODO: EDIT, CARD_EDIT (with INQUIRE) */ /* TODO: EDIT, CARD_EDIT (with INQUIRE) */

View File

@ -348,6 +348,7 @@ typedef unsigned int gpgme_keylist_mode_t;
/* The available export mode flags. */ /* The available export mode flags. */
#define GPGME_EXPORT_MODE_EXTERN 2 #define GPGME_EXPORT_MODE_EXTERN 2
#define GPGME_EXPORT_MODE_MINIMAL 4
typedef unsigned int gpgme_export_mode_t; typedef unsigned int gpgme_export_mode_t;