summaryrefslogtreecommitdiff
path: root/egg/egg-dn.c
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2012-06-20 08:15:20 +0200
committerStef Walter <stefw@gnome.org>2012-06-21 16:14:59 +0200
commitae6f001f386df172f966e055516c0b968379804a (patch)
tree708427682e5ee8fe3ec44717e6876ec8442dd285 /egg/egg-dn.c
parent2fce6f29272b9e78fb047913aab8531ddec2203e (diff)
downloadgcr-ae6f001f386df172f966e055516c0b968379804a.tar.gz
egg: Rework how DER parsing works
In particular fix things like * Indefinite parsing * Encoding of defaults * Ability to read values that haven't yet been encoded * Proper handling of ANY tags
Diffstat (limited to 'egg/egg-dn.c')
-rw-r--r--egg/egg-dn.c50
1 files changed, 16 insertions, 34 deletions
diff --git a/egg/egg-dn.c b/egg/egg-dn.c
index e3b092e..43bd772 100644
--- a/egg/egg-dn.c
+++ b/egg/egg-dn.c
@@ -52,7 +52,7 @@ dn_print_hex_value (GBytes *val)
static gchar*
dn_print_oid_value_parsed (GQuark oid,
guint flags,
- GBytes *val)
+ GNode *val)
{
GNode *asn1, *node;
GBytes *value;
@@ -65,7 +65,7 @@ dn_print_oid_value_parsed (GQuark oid,
asn1 = egg_asn1x_create_quark (pkix_asn1_tab, oid);
g_return_val_if_fail (asn1, NULL);
- if (!egg_asn1x_decode (asn1, val)) {
+ if (!egg_asn1x_get_any_into (val, asn1)) {
g_message ("couldn't decode value for OID: %s: %s",
g_quark_to_string (oid), egg_asn1x_message (asn1));
egg_asn1x_destroy (asn1);
@@ -81,7 +81,7 @@ dn_print_oid_value_parsed (GQuark oid,
else
node = asn1;
- value = egg_asn1x_get_raw_value (node);
+ value = egg_asn1x_get_value_raw (node);
data = g_bytes_get_data (value, &size);
/*
@@ -108,8 +108,9 @@ dn_print_oid_value_parsed (GQuark oid,
static gchar*
dn_print_oid_value (GQuark oid,
guint flags,
- GBytes *val)
+ GNode *val)
{
+ GBytes *der;
gchar *value;
g_assert (val != NULL);
@@ -120,7 +121,11 @@ dn_print_oid_value (GQuark oid,
return value;
}
- return dn_print_hex_value (val);
+ der = egg_asn1x_get_element_raw (val);
+ value = dn_print_hex_value (der);
+ g_bytes_unref (der);
+
+ return value;
}
static gchar*
@@ -129,7 +134,7 @@ dn_parse_rdn (GNode *asn)
const gchar *name;
guint flags;
GQuark oid;
- GBytes *value;
+ GNode *value;
gchar *display;
gchar *result;
@@ -141,7 +146,7 @@ dn_parse_rdn (GNode *asn)
flags = egg_oid_get_flags (oid);
name = egg_oid_get_name (oid);
- value = egg_asn1x_get_element_raw (egg_asn1x_node (asn, "value", NULL));
+ value = egg_asn1x_node (asn, "value", NULL);
g_return_val_if_fail (value, NULL);
display = dn_print_oid_value (oid, flags, value);
@@ -149,7 +154,6 @@ dn_parse_rdn (GNode *asn)
"=", display, NULL);
g_free (display);
- g_bytes_unref (value);
return result;
}
@@ -200,11 +204,9 @@ egg_dn_read_part (GNode *asn, const gchar *match)
{
gboolean done = FALSE;
const gchar *name;
- GBytes *value;
GNode *node;
GQuark oid;
gint i, j;
- gchar *result;
g_return_val_if_fail (asn, NULL);
g_return_val_if_fail (match, NULL);
@@ -233,12 +235,7 @@ egg_dn_read_part (GNode *asn, const gchar *match)
node = egg_asn1x_node (asn, i, j, "value", NULL);
g_return_val_if_fail (node, NULL);
- value = egg_asn1x_get_element_raw (node);
- g_return_val_if_fail (value, NULL);
-
- result = dn_print_oid_value (oid, egg_oid_get_flags (oid), value);
- g_bytes_unref (value);
- return result;
+ return dn_print_oid_value (oid, egg_oid_get_flags (oid), node);
}
}
@@ -250,7 +247,6 @@ egg_dn_parse (GNode *asn, EggDnCallback callback, gpointer user_data)
{
gboolean done = FALSE;
GNode *node;
- GBytes *value;
GQuark oid;
guint i, j;
@@ -279,12 +275,8 @@ egg_dn_parse (GNode *asn, EggDnCallback callback, gpointer user_data)
break;
}
- value = egg_asn1x_get_element_raw (node);
-
if (callback)
- (callback) (i, oid, value, user_data);
-
- g_bytes_unref (value);
+ (callback) (i, oid, node, user_data);
}
}
@@ -293,7 +285,7 @@ egg_dn_parse (GNode *asn, EggDnCallback callback, gpointer user_data)
gchar *
egg_dn_print_value (GQuark oid,
- GBytes *value)
+ GNode *value)
{
g_return_val_if_fail (oid != 0, NULL);
g_return_val_if_fail (value != NULL, NULL);
@@ -336,7 +328,6 @@ egg_dn_add_string_part (GNode *asn,
GQuark oid,
const gchar *string)
{
- GBytes *bytes;
GNode *node;
GNode *value;
GNode *val;
@@ -373,15 +364,6 @@ egg_dn_add_string_part (GNode *asn,
egg_asn1x_set_string_as_utf8 (val, g_strdup (string), g_free);
- bytes = egg_asn1x_encode (value, NULL);
- if (bytes == NULL) {
- g_warning ("couldn't build dn string value: %s", egg_asn1x_message (value));
- return;
- }
-
- if (!egg_asn1x_set_element_raw (egg_asn1x_node (node, "value", NULL), bytes))
- g_return_if_reached ();
-
+ egg_asn1x_set_any_from (egg_asn1x_node (node, "value", NULL), value);
egg_asn1x_destroy (value);
- g_bytes_unref (bytes);
}