[gcr: 2/5] egg-asn1x: special function to decode ANY as fooSTRING



commit 1c39b8a05f64393c70f2e68bb08c8a47284b2055
Author: Dmitry Baryshkov <dbaryshkov gmail com>
Date:   Wed Jan 29 13:39:34 2020 +0300

    egg-asn1x: special function to decode ANY as fooSTRING
    
    Newer asn1Parser does not include standard types into generated tables,
    thus making egg_asn1x_get_any_as() unusable in this case. Add special
    handler for decoding ANY is fooSTRING instead.
    
    Signed-off-by: Dmitry Baryshkov <dbaryshkov gmail com>

 egg/egg-asn1x.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 egg/egg-asn1x.h |  7 +++++++
 2 files changed, 62 insertions(+)
---
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index 9e427ee..b7d9d11 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -3081,6 +3081,61 @@ egg_asn1x_get_any_as_full (GNode *node,
        return asn;
 }
 
+GNode *
+egg_asn1x_get_any_as_string (GNode *node,
+                             EggAsn1xType type)
+{
+       g_return_val_if_fail (node != NULL, NULL);
+       g_return_val_if_fail (egg_asn1x_type (node) == EGG_ASN1X_ANY, NULL);
+
+       return egg_asn1x_get_any_as_string_full (node, type, 0);
+}
+
+static const EggAsn1xDef def_bmpstring = {
+       .type = EGG_ASN1X_BMP_STRING | FLAG_UNIVERSAL | FLAG_IMPLICIT,
+};
+
+static const EggAsn1xDef def_utf8string = {
+       .type = EGG_ASN1X_UTF8_STRING | FLAG_UNIVERSAL | FLAG_IMPLICIT,
+};
+
+static const EggAsn1xDef def_ia5string = {
+       .type = EGG_ASN1X_IA5_STRING | FLAG_UNIVERSAL | FLAG_IMPLICIT,
+};
+
+GNode *
+egg_asn1x_get_any_as_string_full (GNode *node,
+                                  EggAsn1xType type,
+                                  gint options)
+{
+       GNode *asn;
+
+       g_return_val_if_fail (node != NULL, NULL);
+       g_return_val_if_fail (egg_asn1x_type (node) == EGG_ASN1X_ANY, NULL);
+
+       switch (type) {
+       case EGG_ASN1X_BMP_STRING:
+               asn = anode_new (&def_bmpstring);
+               break;
+       case EGG_ASN1X_UTF8_STRING:
+               asn = anode_new (&def_utf8string);
+               break;
+       case EGG_ASN1X_IA5_STRING:
+               asn = anode_new (&def_ia5string);
+               break;
+       default:
+               g_return_val_if_reached (NULL);
+       }
+       g_return_val_if_fail (asn != NULL, NULL);
+
+       if (!egg_asn1x_get_any_into_full (node, asn, options)) {
+               egg_asn1x_destroy (asn);
+               return NULL;
+       }
+
+       return asn;
+}
+
 gboolean
 egg_asn1x_get_any_into  (GNode *node,
                          GNode *into)
diff --git a/egg/egg-asn1x.h b/egg/egg-asn1x.h
index 2dac1a9..aab3f4e 100644
--- a/egg/egg-asn1x.h
+++ b/egg/egg-asn1x.h
@@ -119,6 +119,13 @@ GNode *             egg_asn1x_get_any_as_full        (GNode *node,
                                                       const gchar *type,
                                                       gint options);
 
+GNode *             egg_asn1x_get_any_as_string      (GNode *node,
+                                                      EggAsn1xType type);
+
+GNode *             egg_asn1x_get_any_as_string_full (GNode *node,
+                                                      EggAsn1xType type,
+                                                      gint options);
+
 GBytes *            egg_asn1x_get_any_raw            (GNode *node,
                                                       EggAllocator allocator);
 


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