[gnome-keyring/wip/header-order] egg: Write Proc-Type header before DEK-Info
- From: Iain Lane <iainl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring/wip/header-order] egg: Write Proc-Type header before DEK-Info
- Date: Tue, 29 Jan 2019 10:26:22 +0000 (UTC)
commit 2959cc2890d3869784e8f68fa663e06ddd2aee6a
Author: Iain Lane <iainl gnome org>
Date: Mon Jan 28 14:38:40 2019 +0000
egg: Write Proc-Type header before DEK-Info
These headers (at least for OpenSSL) must come in this order. We
shouldn't assume that `g_hash_table_foreach` is going to give a
particular ordering - it's not guaranteed, and has changed with GLib
2.59.
egg/egg-armor.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/egg/egg-armor.c b/egg/egg-armor.c
index 267cc87b..a02bb6fc 100644
--- a/egg/egg-armor.c
+++ b/egg/egg-armor.c
@@ -59,6 +59,8 @@ EGG_SECURE_DECLARE (armor);
#define ARMOR_PREF_END "-----END "
#define ARMOR_PREF_END_L 9
+static const gchar * const ORDERED_HEADERS[] = { "Proc-Type", "DEK-Info", NULL };
+
static void
parse_header_lines (const gchar *hbeg,
const gchar *hend,
@@ -336,13 +338,16 @@ egg_armor_parse (GBytes *data,
}
static void
-append_each_header (gpointer key, gpointer value, gpointer user_data)
+append_each_header (gconstpointer key, gconstpointer value, gpointer user_data)
{
GString *string = (GString*)user_data;
- g_string_append (string, (gchar*)key);
+ if (g_strv_contains (ORDERED_HEADERS, (const gchar *) key))
+ return;
+
+ g_string_append (string, (const gchar *)key);
g_string_append (string, ": ");
- g_string_append (string, (gchar*)value);
+ g_string_append (string, (const gchar *)value);
g_string_append_c (string, '\n');
}
@@ -357,6 +362,7 @@ egg_armor_write (const guchar *data,
gint state, save;
gsize i, length;
gsize n_prefix, estimate;
+ gchar *value;
g_return_val_if_fail (data || !n_data, NULL);
g_return_val_if_fail (type, NULL);
@@ -370,9 +376,19 @@ egg_armor_write (const guchar *data,
g_string_append_len (string, ARMOR_SUFF, ARMOR_SUFF_L);
g_string_append_c (string, '\n');
- /* The headers */
+ /* The headers. Some must come in a specific order. */
+ for (i = 0; ORDERED_HEADERS[i] != NULL; i++) {
+ value = g_hash_table_lookup (headers, ORDERED_HEADERS[i]);
+ if (value != NULL)
+ g_string_append_printf (string,
+ "%s: %s\n",
+ ORDERED_HEADERS[i],
+ value);
+ }
+
+ /* And the rest we output in any arbitrary order. */
if (headers && g_hash_table_size (headers) > 0) {
- g_hash_table_foreach (headers, append_each_header, string);
+ g_hash_table_foreach (headers, (GHFunc) append_each_header, string);
g_string_append_c (string, '\n');
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]