From 07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d Mon Sep 17 00:00:00 2001 From: tedu <> Date: Fri, 18 Apr 2014 00:10:08 +0000 Subject: putting most of the braces in the right column is the very least we can do. --- src/lib/libcrypto/asn1/tasn_dec.c | 468 +++++++++++++++++++------------------- 1 file changed, 234 insertions(+), 234 deletions(-) (limited to 'src/lib/libcrypto/asn1/tasn_dec.c') diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c index c594db9140..0df42a4a93 100644 --- a/src/lib/libcrypto/asn1/tasn_dec.c +++ b/src/lib/libcrypto/asn1/tasn_dec.c @@ -103,13 +103,13 @@ B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */ B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */ B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */ B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */ - }; +}; unsigned long ASN1_tag2bit(int tag) - { +{ if ((tag < 0) || (tag > 30)) return 0; return tag2bit[tag]; - } +} /* Macro to initialize and invalidate the cache */ @@ -127,7 +127,7 @@ unsigned long ASN1_tag2bit(int tag) ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it) - { +{ ASN1_TLC c; ASN1_VALUE *ptmpval = NULL; if (!pval) @@ -136,15 +136,15 @@ ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0) return *pval; return NULL; - } +} int ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_TEMPLATE *tt) - { +{ ASN1_TLC c; asn1_tlc_clear_nc(&c); return asn1_template_ex_d2i(pval, in, len, tt, 0, &c); - } +} /* Decode an item, taking care of IMPLICIT tagging, if any. @@ -154,7 +154,7 @@ int ASN1_template_d2i(ASN1_VALUE **pval, int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx) - { +{ const ASN1_TEMPLATE *tt, *errtt = NULL; const ASN1_COMPAT_FUNCS *cf; const ASN1_EXTERN_FUNCS *ef; @@ -176,10 +176,10 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, else asn1_cb = 0; switch(it->itype) - { + { case ASN1_ITYPE_PRIMITIVE: if (it->templates) - { + { /* tagging or OPTIONAL is currently illegal on an item * template because the flags can't get passed down. * In practice this isn't a problem: we include the @@ -187,14 +187,14 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, * template itself. */ if ((tag != -1) || opt) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); goto err; - } + } return asn1_template_ex_d2i(pval, in, len, it->templates, opt, ctx); - } + } return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt, ctx); break; @@ -205,31 +205,31 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, &p, len, -1, 0, 1, ctx); if (!ret) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; - } + } /* Must be UNIVERSAL class */ if (oclass != V_ASN1_UNIVERSAL) - { + { /* If OPTIONAL, assume this is OK */ if (opt) return -1; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL); goto err; - } + } /* Check tag matches bit map */ if (!(ASN1_tag2bit(otag) & it->utype)) - { + { /* If OPTIONAL, assume this is OK */ if (opt) return -1; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_WRONG_TAG); goto err; - } + } return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx); @@ -245,7 +245,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, /* If OPTIONAL see if it is there */ if (opt) - { + { int exptag; p = *in; if (tag == -1) @@ -257,14 +257,14 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, &p, len, exptag, aclass, 1, ctx); if (!ret) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; - } + } if (ret == -1) return -1; - } + } /* This is the old style evil hack IMPLICIT handling: * since the underlying code is expecting a tag and @@ -282,18 +282,18 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, */ if (tag != -1) - { + { wp = *(unsigned char **)in; imphack = *wp; if (p == NULL) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; - } + } *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | it->utype); - } + } ptmpval = cf->asn1_d2i(pval, in, len); @@ -313,15 +313,15 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, /* Allocate structure */ if (!*pval && !ASN1_item_ex_new(pval, it)) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; - } + } /* CHOICE type, try each possibility in turn */ p = *in; for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) - { + { pchptr = asn1_get_field_ptr(pval, tt); /* We mark field as OPTIONAL so its absence * can be recognised. @@ -338,22 +338,22 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; - } + } /* Did we fall off the end without reading anything? */ if (i == it->tcount) - { + { /* If OPTIONAL, this is OK */ if (opt) - { + { /* Free and zero it */ ASN1_item_ex_free(pval, it); return -1; - } + } ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE); goto err; - } + } asn1_set_choice_selector(pval, i, it); *in = p; @@ -368,48 +368,48 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ if (tag == -1) - { + { tag = V_ASN1_SEQUENCE; aclass = V_ASN1_UNIVERSAL; - } + } /* Get SEQUENCE length and update len, p */ ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, &p, len, tag, aclass, opt, ctx); if (!ret) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; - } + } else if (ret == -1) return -1; if (aux && (aux->flags & ASN1_AFLG_BROKEN)) - { + { len = tmplen - (p - *in); seq_nolen = 1; - } + } /* If indefinite we don't do a length check */ else seq_nolen = seq_eoc; if (!cst) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED); goto err; - } + } if (!*pval && !ASN1_item_ex_new(pval, it)) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; - } + } if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) goto auxerr; /* Get each field entry */ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) - { + { const ASN1_TEMPLATE *seqtt; ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 1); @@ -421,18 +421,18 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, break; q = p; if (asn1_check_eoc(&p, len)) - { + { if (!seq_eoc) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC); goto err; - } + } len -= p - q; seq_eoc = 0; q = p; break; - } + } /* This determines the OPTIONAL flag value. The field * cannot be omitted if it is the last of a SEQUENCE * and there is still data to be read. This isn't @@ -448,60 +448,60 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx); if (!ret) - { + { errtt = seqtt; goto err; - } + } else if (ret == -1) - { + { /* OPTIONAL component absent. * Free and zero the field. */ ASN1_template_free(pseqval, seqtt); continue; - } + } /* Update length */ len -= p - q; - } + } /* Check for EOC if expecting one */ if (seq_eoc && !asn1_check_eoc(&p, len)) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); goto err; - } + } /* Check all data read */ if (!seq_nolen && len) - { + { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH); goto err; - } + } /* If we get here we've got no more data in the SEQUENCE, * however we may not have read all fields so check all * remaining are OPTIONAL and clear any that are. */ for (; i < it->tcount; tt++, i++) - { + { const ASN1_TEMPLATE *seqtt; seqtt = asn1_do_adb(pval, tt, 1); if (!seqtt) goto err; if (seqtt->flags & ASN1_TFLG_OPTIONAL) - { + { ASN1_VALUE **pseqval; pseqval = asn1_get_field_ptr(pval, seqtt); ASN1_template_free(pseqval, seqtt); - } + } else - { + { errtt = seqtt; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING); goto err; - } } + } /* Save encoding */ if (!asn1_enc_save(pval, *in, p - *in, it)) goto auxerr; @@ -512,7 +512,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, default: return 0; - } + } auxerr: ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); err: @@ -523,7 +523,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, else ERR_add_error_data(2, "Type=", it->sname); return 0; - } +} /* Templates are handled with two separate functions. * One handles any EXPLICIT tag and the other handles the rest. @@ -533,7 +533,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long inlen, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx) - { +{ int flags, aclass; int ret; long len; @@ -548,7 +548,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, /* Check if EXPLICIT tag expected */ if (flags & ASN1_TFLG_EXPTAG) - { + { char cst; /* Need to work out amount of data available to the inner * content and where it starts: so read in EXPLICIT header to @@ -558,51 +558,51 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, &p, inlen, tt->tag, aclass, opt, ctx); q = p; if (!ret) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; - } + } else if (ret == -1) return -1; if (!cst) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED); return 0; - } + } /* We've found the field so it can't be OPTIONAL now */ ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); if (!ret) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; - } + } /* We read the field in OK so update length */ len -= p - q; if (exp_eoc) - { + { /* If NDEF we must have an EOC here */ if (!asn1_check_eoc(&p, len)) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_MISSING_EOC); goto err; - } } + } else - { + { /* Otherwise we must hit the EXPLICIT tag end or its * an error */ if (len) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_LENGTH_MISMATCH); goto err; - } } } + } else return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx); @@ -613,13 +613,13 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, err: ASN1_template_free(val, tt); return 0; - } +} static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx) - { +{ int flags, aclass; int ret; const unsigned char *p, *q; @@ -632,128 +632,128 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, q = p; if (flags & ASN1_TFLG_SK_MASK) - { + { /* SET OF, SEQUENCE OF */ int sktag, skaclass; char sk_eoc; /* First work out expected inner tag value */ if (flags & ASN1_TFLG_IMPTAG) - { + { sktag = tt->tag; skaclass = aclass; - } + } else - { + { skaclass = V_ASN1_UNIVERSAL; if (flags & ASN1_TFLG_SET_OF) sktag = V_ASN1_SET; else sktag = V_ASN1_SEQUENCE; - } + } /* Get the tag */ ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, &p, len, sktag, skaclass, opt, ctx); if (!ret) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; - } + } else if (ret == -1) return -1; if (!*val) *val = (ASN1_VALUE *)sk_new_null(); else - { + { /* We've got a valid STACK: free up any items present */ STACK_OF(ASN1_VALUE) *sktmp = (STACK_OF(ASN1_VALUE) *)*val; ASN1_VALUE *vtmp; while(sk_ASN1_VALUE_num(sktmp) > 0) - { + { vtmp = sk_ASN1_VALUE_pop(sktmp); ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item)); - } } + } if (!*val) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_MALLOC_FAILURE); goto err; - } + } /* Read as many items as we can */ while(len > 0) - { + { ASN1_VALUE *skfield; q = p; /* See if EOC found */ if (asn1_check_eoc(&p, len)) - { + { if (!sk_eoc) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_UNEXPECTED_EOC); goto err; - } + } len -= p - q; sk_eoc = 0; break; - } + } skfield = NULL; if (!ASN1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; - } + } len -= p - q; if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_MALLOC_FAILURE); goto err; - } } + } if (sk_eoc) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC); goto err; - } } + } else if (flags & ASN1_TFLG_IMPTAG) - { + { /* IMPLICIT tagging */ ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx); if (!ret) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; - } + } else if (ret == -1) return -1; - } + } else - { + { /* Nothing special */ ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, opt, ctx); if (!ret) - { + { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; - } + } else if (ret == -1) return -1; - } + } *in = p; return 1; @@ -761,13 +761,13 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, err: ASN1_template_free(val, tt); return 0; - } +} static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long inlen, const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx) - { +{ int ret = 0, utype; long plen; char cst, inf, free_cont = 0; @@ -776,100 +776,100 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char *cont = NULL; long len; if (!pval) - { + { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); return 0; /* Should never happen */ - } + } if (it->itype == ASN1_ITYPE_MSTRING) - { + { utype = tag; tag = -1; - } + } else utype = it->utype; if (utype == V_ASN1_ANY) - { + { /* If type is ANY need to figure out type from tag */ unsigned char oclass; if (tag >= 0) - { + { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_TAGGED_ANY); return 0; - } + } if (opt) - { + { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_OPTIONAL_ANY); return 0; - } + } p = *in; ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, &p, inlen, -1, 0, 0, ctx); if (!ret) - { + { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); return 0; - } + } if (oclass != V_ASN1_UNIVERSAL) utype = V_ASN1_OTHER; - } + } if (tag == -1) - { + { tag = utype; aclass = V_ASN1_UNIVERSAL; - } + } p = *in; /* Check header */ ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, &p, inlen, tag, aclass, opt, ctx); if (!ret) - { + { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); return 0; - } + } else if (ret == -1) return -1; ret = 0; /* SEQUENCE, SET and "OTHER" are left in encoded form */ if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) - { + { /* Clear context cache for type OTHER because the auto clear * when we have a exact match wont work */ if (utype == V_ASN1_OTHER) - { + { asn1_tlc_clear(ctx); - } + } /* SEQUENCE and SET must be constructed */ else if (!cst) - { + { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_TYPE_NOT_CONSTRUCTED); return 0; - } + } cont = *in; /* If indefinite length constructed find the real end */ if (inf) - { + { if (!asn1_find_end(&p, plen, inf)) goto err; len = p - cont; - } + } else - { + { len = p - cont + plen; p += plen; buf.data = NULL; - } } + } else if (cst) - { + { buf.length = 0; buf.max = 0; buf.data = NULL; @@ -880,28 +880,28 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, * for UNIVERSAL class and ignore the tag. */ if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) - { + { free_cont = 1; goto err; - } + } len = buf.length; /* Append a final null to string */ if (!BUF_MEM_grow_clean(&buf, len + 1)) - { + { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE); return 0; - } + } buf.data[len] = 0; cont = (const unsigned char *)buf.data; free_cont = 1; - } + } else - { + { cont = p; len = plen; p += plen; - } + } /* We now have content length and type: translate into a structure */ if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) @@ -912,13 +912,13 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, err: if (free_cont && buf.data) free(buf.data); return ret; - } +} /* Translate ASN1 content octets into a structure */ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it) - { +{ ASN1_VALUE **opval = NULL; ASN1_STRING *stmp; ASN1_TYPE *typ = NULL; @@ -931,14 +931,14 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, return pf->prim_c2i(pval, cont, len, utype, free_cont, it); /* If ANY type clear type and set pointer to internal value */ if (it->utype == V_ASN1_ANY) - { + { if (!*pval) - { + { typ = ASN1_TYPE_new(); if (typ == NULL) goto err; *pval = (ASN1_VALUE *)typ; - } + } else typ = (ASN1_TYPE *)*pval; @@ -946,9 +946,9 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, ASN1_TYPE_set(typ, utype, NULL); opval = pval; pval = &typ->value.asn1_value; - } + } switch(utype) - { + { case V_ASN1_OBJECT: if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) goto err; @@ -956,27 +956,27 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, case V_ASN1_NULL: if (len) - { + { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_NULL_IS_WRONG_LENGTH); goto err; - } + } *pval = (ASN1_VALUE *)1; break; case V_ASN1_BOOLEAN: if (len != 1) - { + { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_BOOLEAN_IS_WRONG_LENGTH); goto err; - } + } else - { + { ASN1_BOOLEAN *tbool; tbool = (ASN1_BOOLEAN *)pval; *tbool = *cont; - } + } break; case V_ASN1_BIT_STRING: @@ -1014,56 +1014,56 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, case V_ASN1_SEQUENCE: default: if (utype == V_ASN1_BMPSTRING && (len & 1)) - { + { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_BMPSTRING_IS_WRONG_LENGTH); goto err; - } + } if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) - { + { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH); goto err; - } + } /* All based on ASN1_STRING and handled the same */ if (!*pval) - { + { stmp = ASN1_STRING_type_new(utype); if (!stmp) - { + { ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); goto err; - } - *pval = (ASN1_VALUE *)stmp; } + *pval = (ASN1_VALUE *)stmp; + } else - { + { stmp = (ASN1_STRING *)*pval; stmp->type = utype; - } + } /* If we've already allocated a buffer use it */ if (*free_cont) - { + { if (stmp->data) free(stmp->data); stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ stmp->length = len; *free_cont = 0; - } + } else - { + { if (!ASN1_STRING_set(stmp, cont, len)) - { + { ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); ASN1_STRING_free(stmp); *pval = NULL; goto err; - } } - break; } + break; + } /* If ASN1_ANY and NULL type fix up value */ if (typ && (utype == V_ASN1_NULL)) typ->value.ptr = NULL; @@ -1071,13 +1071,13 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, ret = 1; err: if (!ret) - { + { ASN1_TYPE_free(typ); if (opval) *opval = NULL; - } - return ret; } + return ret; +} /* This function finds the end of an ASN1 structure when passed its maximum @@ -1087,16 +1087,16 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, */ static int asn1_find_end(const unsigned char **in, long len, char inf) - { +{ int expected_eoc; long plen; const unsigned char *p = *in, *q; /* If not indefinite length constructed just add length */ if (inf == 0) - { + { *in += len; return 1; - } + } expected_eoc = 1; /* Indefinite length constructed form. Find the end when enough EOCs * are found. If more indefinite length constructed headers @@ -1104,37 +1104,37 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) * skip to the end of the data. */ while (len > 0) - { + { if(asn1_check_eoc(&p, len)) - { + { expected_eoc--; if (expected_eoc == 0) break; len -= 2; continue; - } + } q = p; /* Just read in a header: only care about the length */ if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, -1, 0, 0, NULL)) - { + { ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); return 0; - } + } if (inf) expected_eoc++; else p += plen; len -= p - q; - } + } if (expected_eoc) - { + { ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC); return 0; - } + } *in = p; return 1; - } +} /* This function collects the asn1 data from a constructred string * type into a buffer. The values of 'in' and 'len' should refer * to the contents of the constructed type and 'inf' should be set @@ -1153,7 +1153,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, char inf, int tag, int aclass, int depth) - { +{ const unsigned char *p, *q; long plen; char cst, ininf; @@ -1162,92 +1162,92 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, /* If no buffer and not indefinite length constructed just pass over * the encoded data */ if (!buf && !inf) - { + { *in += len; return 1; - } + } while(len > 0) - { + { q = p; /* Check for EOC */ if (asn1_check_eoc(&p, len)) - { + { /* EOC is illegal outside indefinite length * constructed form */ if (!inf) - { + { ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_UNEXPECTED_EOC); return 0; - } + } inf = 0; break; - } + } if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, len, tag, aclass, 0, NULL)) - { + { ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); return 0; - } + } /* If indefinite length constructed update max length */ if (cst) - { + { if (depth >= ASN1_MAX_STRING_NEST) - { + { ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_NESTED_ASN1_STRING); return 0; - } + } if (!asn1_collect(buf, &p, plen, ininf, tag, aclass, depth + 1)) return 0; - } + } else if (plen && !collect_data(buf, &p, plen)) return 0; len -= p - q; - } + } if (inf) - { + { ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); return 0; - } + } *in = p; return 1; - } +} static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) - { +{ int len; if (buf) - { + { len = buf->length; if (!BUF_MEM_grow_clean(buf, len + plen)) - { + { ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); return 0; - } - memcpy(buf->data + len, *p, plen); } + memcpy(buf->data + len, *p, plen); + } *p += plen; return 1; - } +} /* Check for ASN1 EOC and swallow it if found */ static int asn1_check_eoc(const unsigned char **in, long len) - { +{ const unsigned char *p; if (len < 2) return 0; p = *in; if (!p[0] && !p[1]) - { + { *in += 2; return 1; - } - return 0; } + return 0; +} /* Check an ASN1 tag and length: a bit like ASN1_get_object * but it sets the length for indefinite length constructed @@ -1261,7 +1261,7 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, const unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx) - { +{ int i; int ptag, pclass; long plen; @@ -1270,18 +1270,18 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, q = p; if (ctx && ctx->valid) - { + { i = ctx->ret; plen = ctx->plen; pclass = ctx->pclass; ptag = ctx->ptag; p += ctx->hdrlen; - } + } else - { + { i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); if (ctx) - { + { ctx->ret = i; ctx->plen = plen; ctx->pclass = pclass; @@ -1292,25 +1292,25 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, * header can't exceed total amount of data available. */ if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) - { + { ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG); asn1_tlc_clear(ctx); return 0; - } } } + } if (i & 0x80) - { + { ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); asn1_tlc_clear(ctx); return 0; - } + } if (exptag >= 0) - { + { if ((exptag != ptag) || (expclass != pclass)) - { + { /* If type is OPTIONAL, not an error: * indicate missing type. */ @@ -1318,11 +1318,11 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, asn1_tlc_clear(ctx); ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG); return 0; - } + } /* We have a tag and class match: * assume we are going to do something with it */ asn1_tlc_clear(ctx); - } + } if (i & 1) plen = len - (p - q); @@ -1344,4 +1344,4 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, *in = p; return 1; - } +} -- cgit v1.2.3-55-g6feb