[gcr/ecc: 3/10] WIP egg_asn1x_data_to_usg()



commit 5f01334db20e675c86f176fd0dc83c10799cb074
Author: Stef Walter <stefw redhat com>
Date:   Thu Apr 17 07:09:34 2014 +0200

    WIP egg_asn1x_data_to_usg()

 egg/egg-asn1x.c |   34 ++++++++++++++++++++++------------
 egg/egg-asn1x.h |    3 +++
 2 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index 0daf2ef..55135be 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -2910,23 +2910,18 @@ egg_asn1x_get_integer_as_raw (GNode *node)
 }
 
 GBytes *
-egg_asn1x_get_integer_as_usg (GNode *node)
+egg_asn1x_data_to_usg (GBytes *data,
+                       gboolean already_unsigned)
 {
-       const guchar *p;
-       Anode *an;
+       const guint8 *p;
        gboolean sign;
        gsize len;
 
-       g_return_val_if_fail (node != NULL, FALSE);
-       g_return_val_if_fail (anode_def_type (node) == EGG_ASN1X_INTEGER, FALSE);
-
-       an = node->data;
-       if (an->value == NULL)
-               return NULL;
+       g_return_val_if_fail (data != NULL, NULL);
 
-       p = g_bytes_get_data (an->value, &len);
+       p = g_bytes_get_data (data, &len);
 
-       if (!an->guarantee_unsigned) {
+       if (!already_unsigned) {
                sign = !!(p[0] & 0x80);
                if (sign) {
                        g_warning ("invalid two's complement integer"); /* UNREACHABLE: */
@@ -2945,7 +2940,22 @@ egg_asn1x_get_integer_as_usg (GNode *node)
 
        return g_bytes_new_with_free_func (p, len,
                                           (GDestroyNotify)g_bytes_unref,
-                                          g_bytes_ref (an->value));
+                                          g_bytes_ref (data));
+}
+
+GBytes *
+egg_asn1x_get_integer_as_usg (GNode *node)
+{
+       Anode *an;
+
+       g_return_val_if_fail (node != NULL, NULL);
+       g_return_val_if_fail (anode_def_type (node) == EGG_ASN1X_INTEGER, NULL);
+
+       an = node->data;
+       if (an->value == NULL)
+               return NULL;
+
+       return egg_asn1x_data_to_usg (an->value, an->guarantee_unsigned);
 }
 
 void
diff --git a/egg/egg-asn1x.h b/egg/egg-asn1x.h
index 0cda783..04e5fea 100644
--- a/egg/egg-asn1x.h
+++ b/egg/egg-asn1x.h
@@ -265,6 +265,9 @@ gconstpointer       egg_asn1x_element_content        (const guchar *data,
                                                       gsize n_data,
                                                       gsize *n_content);
 
+GBytes *            egg_asn1x_data_to_usg            (GBytes *data,
+                                                             gboolean already_unsigned);
+
 #define             egg_asn1x_assert(expr, node) \
        do { if G_LIKELY(expr) ; else \
                g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]