[gcr/ecc: 3/16] asn1: Handle choices wrapped in explicit tags correctly



commit 4d49037b630eaf5586fb1a77eae188ceb510e592
Author: Stef Walter <stefw gnome org>
Date:   Fri Apr 18 10:35:42 2014 +0200

    asn1: Handle choices wrapped in explicit tags correctly
    
    This results in a tag surrounding the chosen choice. Used in
    EC private keys.

 egg/egg-asn1x.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index 0daf2ef..b64bca9 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -964,10 +964,24 @@ static gboolean
 anode_decode_choice (GNode *node,
                      Atlv *tlv)
 {
+       gint flags = anode_def_flags (node);
        gboolean have = FALSE;
        GNode *child;
+       gulong tag;
        Anode *an;
 
+       /* An explicit, wrapped tag */
+       if (flags & FLAG_TAG) {
+               tag = anode_calc_tag_for_flags (node, flags);
+               if ((tlv->cls & ASN1_CLASS_CONTEXT_SPECIFIC) == 0)
+                       return anode_failure (node, "choice missing context specific tag");
+               if (tag != tlv->tag)
+                       return anode_failure (node, "choice tag did not match");
+               if (tlv->child == NULL)
+                       return anode_failure (node, "choice missing context specific child");
+               tlv = tlv->child;
+       }
+
        for (child = node->children; child; child = child->next) {
                an = (Anode*)child->data;
                if (anode_decode_one (child, tlv)) {


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