mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-23 10:29:58 +01:00
common: In private key mode write "Key:" always last in name-value.
* common/name-value.c (nvc_write): Take care of Key. Factor some code out to ... (write_one_entry): new. -- The key item is in general not manual editable thus we put it at the end of a file. Signed-off-by: Werner Koch <wk@gnupg.org> (cherry picked from commit c9fa28bfad297b17e76341ffb40383ce92da5d44)
This commit is contained in:
parent
dc9b242628
commit
12ad952978
@ -842,29 +842,56 @@ nvc_parse_private_key (nvc_t *result, int *errlinep, estream_t stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Helper fpr nvc_write. */
|
||||||
|
static gpg_error_t
|
||||||
|
write_one_entry (nve_t entry, estream_t stream)
|
||||||
|
{
|
||||||
|
gpg_error_t err;
|
||||||
|
strlist_t sl;
|
||||||
|
|
||||||
|
if (entry->name)
|
||||||
|
es_fputs (entry->name, stream);
|
||||||
|
|
||||||
|
err = assert_raw_value (entry);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
for (sl = entry->raw_value; sl; sl = sl->next)
|
||||||
|
es_fputs (sl->d, stream);
|
||||||
|
|
||||||
|
if (es_ferror (stream))
|
||||||
|
return my_error_from_syserror ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Write a representation of PK to STREAM. */
|
/* Write a representation of PK to STREAM. */
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
nvc_write (nvc_t pk, estream_t stream)
|
nvc_write (nvc_t pk, estream_t stream)
|
||||||
{
|
{
|
||||||
gpg_error_t err;
|
gpg_error_t err = 0;
|
||||||
nve_t entry;
|
nve_t entry;
|
||||||
strlist_t s;
|
nve_t keyentry = NULL;
|
||||||
|
|
||||||
for (entry = pk->first; entry; entry = entry->next)
|
for (entry = pk->first; entry; entry = entry->next)
|
||||||
{
|
{
|
||||||
if (entry->name)
|
if (pk->private_key_mode
|
||||||
es_fputs (entry->name, stream);
|
&& entry->name && !ascii_strcasecmp (entry->name, "Key:"))
|
||||||
|
{
|
||||||
|
if (!keyentry)
|
||||||
|
keyentry = entry;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
err = assert_raw_value (entry);
|
err = write_one_entry (entry, stream);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
for (s = entry->raw_value; s; s = s->next)
|
|
||||||
es_fputs (s->d, stream);
|
|
||||||
|
|
||||||
if (es_ferror (stream))
|
|
||||||
return my_error_from_syserror ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/* In private key mode we write the Key always last. */
|
||||||
|
if (keyentry)
|
||||||
|
err = write_one_entry (keyentry, stream);
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user