summaryrefslogtreecommitdiffstats
path: root/common/name-value.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2019-05-03 14:24:07 +0200
committerWerner Koch <wk@gnupg.org>2019-05-03 14:24:07 +0200
commitc9fa28bfad297b17e76341ffb40383ce92da5d44 (patch)
treea676da5a4220b7e2aa3f7e2a528461f9cbb2bb0e /common/name-value.c
parentgpg: Use just the addrspec from the Signer's UID. (diff)
downloadgnupg2-c9fa28bfad297b17e76341ffb40383ce92da5d44.tar.xz
gnupg2-c9fa28bfad297b17e76341ffb40383ce92da5d44.zip
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>
Diffstat (limited to 'common/name-value.c')
-rw-r--r--common/name-value.c53
1 files changed, 40 insertions, 13 deletions
diff --git a/common/name-value.c b/common/name-value.c
index 5094acd03..89fd060c8 100644
--- a/common/name-value.c
+++ b/common/name-value.c
@@ -778,29 +778,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. */
gpg_error_t
nvc_write (nvc_t pk, estream_t stream)
{
- gpg_error_t err;
+ gpg_error_t err = 0;
nve_t entry;
- strlist_t s;
+ nve_t keyentry = NULL;
for (entry = pk->first; entry; entry = entry->next)
{
- if (entry->name)
- es_fputs (entry->name, stream);
-
- err = assert_raw_value (entry);
+ 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;
-
- 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;
}