1
0
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:
Werner Koch 2019-05-03 14:24:07 +02:00
parent dc9b242628
commit 12ad952978
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -842,16 +842,13 @@ nvc_parse_private_key (nvc_t *result, int *errlinep, estream_t stream)
} }
/* Write a representation of PK to STREAM. */ /* Helper fpr nvc_write. */
gpg_error_t static gpg_error_t
nvc_write (nvc_t pk, estream_t stream) write_one_entry (nve_t entry, estream_t stream)
{ {
gpg_error_t err; gpg_error_t err;
nve_t entry; strlist_t sl;
strlist_t s;
for (entry = pk->first; entry; entry = entry->next)
{
if (entry->name) if (entry->name)
es_fputs (entry->name, stream); es_fputs (entry->name, stream);
@ -859,12 +856,42 @@ nvc_write (nvc_t pk, estream_t stream)
if (err) if (err)
return err; return err;
for (s = entry->raw_value; s; s = s->next) for (sl = entry->raw_value; sl; sl = sl->next)
es_fputs (s->d, stream); es_fputs (sl->d, stream);
if (es_ferror (stream)) if (es_ferror (stream))
return my_error_from_syserror (); return my_error_from_syserror ();
}
return 0; return 0;
} }
/* Write a representation of PK to STREAM. */
gpg_error_t
nvc_write (nvc_t pk, estream_t stream)
{
gpg_error_t err = 0;
nve_t entry;
nve_t keyentry = NULL;
for (entry = pk->first; entry; entry = entry->next)
{
if (pk->private_key_mode
&& entry->name && !ascii_strcasecmp (entry->name, "Key:"))
{
if (!keyentry)
keyentry = entry;
continue;
}
err = write_one_entry (entry, stream);
if (err)
return err;
}
/* In private key mode we write the Key always last. */
if (keyentry)
err = write_one_entry (keyentry, stream);
return err;
}