mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
gpg: Move a function from import.c to export.c.
* g10/import.c (write_keyblock_to_output): Move to ... * g10/export.c (write_keyblock_to_output): here. Add arg WITH_ARMOR. Also make sure never to export ring trust packets.
This commit is contained in:
parent
3ccfd58b25
commit
0f5b105d96
57
g10/export.c
57
g10/export.c
@ -1203,6 +1203,63 @@ receive_seckey_from_agent (ctrl_t ctrl, gcry_cipher_hd_t cipherhd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Write KEYBLOCK either to stdout or to the file set with the
|
||||||
|
* --output option. */
|
||||||
|
gpg_error_t
|
||||||
|
write_keyblock_to_output (kbnode_t keyblock, int with_armor)
|
||||||
|
{
|
||||||
|
gpg_error_t err;
|
||||||
|
const char *fname;
|
||||||
|
iobuf_t out;
|
||||||
|
kbnode_t node;
|
||||||
|
armor_filter_context_t *afx = NULL;
|
||||||
|
|
||||||
|
fname = opt.outfile? opt.outfile : "-";
|
||||||
|
if (is_secured_filename (fname) )
|
||||||
|
return gpg_error (GPG_ERR_EPERM);
|
||||||
|
|
||||||
|
out = iobuf_create (fname, 0);
|
||||||
|
if (!out)
|
||||||
|
{
|
||||||
|
err = gpg_error_from_syserror ();
|
||||||
|
log_error(_("can't create '%s': %s\n"), fname, gpg_strerror (err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
if (opt.verbose)
|
||||||
|
log_info (_("writing to '%s'\n"), iobuf_get_fname_nonnull (out));
|
||||||
|
|
||||||
|
if (with_armor)
|
||||||
|
{
|
||||||
|
afx = new_armor_context ();
|
||||||
|
afx->what = 1;
|
||||||
|
push_armor_filter (afx, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (node = keyblock; node; node = node->next)
|
||||||
|
{
|
||||||
|
if (!is_deleted_kbnode (node) && node->pkt->pkttype != PKT_RING_TRUST)
|
||||||
|
{
|
||||||
|
err = build_packet (out, node->pkt);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
log_error ("build_packet(%d) failed: %s\n",
|
||||||
|
node->pkt->pkttype, gpg_strerror (err) );
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = 0;
|
||||||
|
|
||||||
|
leave:
|
||||||
|
if (err)
|
||||||
|
iobuf_cancel (out);
|
||||||
|
else
|
||||||
|
iobuf_close (out);
|
||||||
|
release_armor_context (afx);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Helper for apply_keep_uid_filter. */
|
/* Helper for apply_keep_uid_filter. */
|
||||||
static const char *
|
static const char *
|
||||||
filter_getval (void *cookie, const char *propname)
|
filter_getval (void *cookie, const char *propname)
|
||||||
|
59
g10/import.c
59
g10/import.c
@ -937,63 +937,6 @@ fix_bad_direct_key_sigs (kbnode_t keyblock, u32 *keyid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Write the keyblock either to stdin or to the file set with
|
|
||||||
* the --output option. */
|
|
||||||
static gpg_error_t
|
|
||||||
write_keyblock_to_output (kbnode_t keyblock)
|
|
||||||
{
|
|
||||||
gpg_error_t err;
|
|
||||||
const char *fname;
|
|
||||||
iobuf_t out;
|
|
||||||
kbnode_t node;
|
|
||||||
armor_filter_context_t *afx = NULL;
|
|
||||||
|
|
||||||
fname = opt.outfile? opt.outfile : "-";
|
|
||||||
if (is_secured_filename (fname) )
|
|
||||||
return gpg_error (GPG_ERR_EPERM);
|
|
||||||
|
|
||||||
out = iobuf_create (fname, 0);
|
|
||||||
if (!out)
|
|
||||||
{
|
|
||||||
err = gpg_error_from_syserror ();
|
|
||||||
log_error(_("can't create '%s': %s\n"), fname, gpg_strerror (err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
if (opt.verbose)
|
|
||||||
log_info (_("writing to '%s'\n"), iobuf_get_fname_nonnull (out));
|
|
||||||
|
|
||||||
if (opt.armor)
|
|
||||||
{
|
|
||||||
afx = new_armor_context ();
|
|
||||||
afx->what = 1;
|
|
||||||
push_armor_filter (afx, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (node = keyblock; node; node = node->next)
|
|
||||||
{
|
|
||||||
if (!is_deleted_kbnode (node))
|
|
||||||
{
|
|
||||||
err = build_packet (out, node->pkt);
|
|
||||||
if (err)
|
|
||||||
{
|
|
||||||
log_error ("build_packet(%d) failed: %s\n",
|
|
||||||
node->pkt->pkttype, gpg_strerror (err) );
|
|
||||||
goto leave;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = 0;
|
|
||||||
|
|
||||||
leave:
|
|
||||||
if (err)
|
|
||||||
iobuf_cancel (out);
|
|
||||||
else
|
|
||||||
iobuf_close (out);
|
|
||||||
release_armor_context (afx);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_import_ok (PKT_public_key *pk, unsigned int reason)
|
print_import_ok (PKT_public_key *pk, unsigned int reason)
|
||||||
{
|
{
|
||||||
@ -1387,7 +1330,7 @@ import_one (ctrl_t ctrl,
|
|||||||
merge_keys_and_selfsig (keyblock);
|
merge_keys_and_selfsig (keyblock);
|
||||||
merge_keys_done = 1;
|
merge_keys_done = 1;
|
||||||
}
|
}
|
||||||
rc = write_keyblock_to_output (keyblock);
|
rc = write_keyblock_to_output (keyblock, opt.armor);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,9 +396,12 @@ gpg_error_t export_pubkey_buffer (ctrl_t ctrl, const char *keyspec,
|
|||||||
|
|
||||||
gpg_error_t receive_seckey_from_agent (ctrl_t ctrl, gcry_cipher_hd_t cipherhd,
|
gpg_error_t receive_seckey_from_agent (ctrl_t ctrl, gcry_cipher_hd_t cipherhd,
|
||||||
int cleartext,
|
int cleartext,
|
||||||
char **cache_nonce_addr, const char *hexgrip,
|
char **cache_nonce_addr,
|
||||||
|
const char *hexgrip,
|
||||||
PKT_public_key *pk);
|
PKT_public_key *pk);
|
||||||
|
|
||||||
|
gpg_error_t write_keyblock_to_output (kbnode_t keyblock, int with_armor);
|
||||||
|
|
||||||
gpg_error_t export_ssh_key (ctrl_t ctrl, const char *userid);
|
gpg_error_t export_ssh_key (ctrl_t ctrl, const char *userid);
|
||||||
|
|
||||||
/*-- dearmor.c --*/
|
/*-- dearmor.c --*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user