diff options
author | Dmitry Baryshkov <dbaryshkov@gmail.com> | 2020-01-29 13:39:34 +0300 |
---|---|---|
committer | Dmitry Baryshkov <dbaryshkov@gmail.com> | 2020-01-29 20:18:37 +0300 |
commit | 1c39b8a05f64393c70f2e68bb08c8a47284b2055 (patch) | |
tree | 5f7b50592099f2324f08d6f2e3fff03309f06810 /egg | |
parent | 4ec5842e59df71b83379be1cb2d4c2dfc3483284 (diff) | |
download | gcr-1c39b8a05f64393c70f2e68bb08c8a47284b2055.tar.gz |
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>
Diffstat (limited to 'egg')
-rw-r--r-- | egg/egg-asn1x.c | 55 | ||||
-rw-r--r-- | egg/egg-asn1x.h | 7 |
2 files changed, 62 insertions, 0 deletions
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); |