More ASN1 reformat/tidy.
This commit is contained in:
parent
8845420f4e
commit
f3f52d7f45
@ -84,16 +84,23 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
|
|||||||
const ASN1_AUX *aux = it->funcs;
|
const ASN1_AUX *aux = it->funcs;
|
||||||
ASN1_aux_cb *asn1_cb;
|
ASN1_aux_cb *asn1_cb;
|
||||||
int i;
|
int i;
|
||||||
if(!pval) return;
|
if (!pval)
|
||||||
if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return;
|
return;
|
||||||
if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
|
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
|
||||||
else asn1_cb = 0;
|
return;
|
||||||
|
if (aux && aux->asn1_cb)
|
||||||
|
asn1_cb = aux->asn1_cb;
|
||||||
|
else
|
||||||
|
asn1_cb = 0;
|
||||||
|
|
||||||
switch(it->itype) {
|
switch(it->itype)
|
||||||
|
{
|
||||||
|
|
||||||
case ASN1_ITYPE_PRIMITIVE:
|
case ASN1_ITYPE_PRIMITIVE:
|
||||||
if(it->templates) ASN1_template_free(pval, it->templates);
|
if (it->templates)
|
||||||
else ASN1_primitive_free(pval, it);
|
ASN1_template_free(pval, it->templates);
|
||||||
|
else
|
||||||
|
ASN1_primitive_free(pval, it);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN1_ITYPE_MSTRING:
|
case ASN1_ITYPE_MSTRING:
|
||||||
@ -101,20 +108,26 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN1_ITYPE_CHOICE:
|
case ASN1_ITYPE_CHOICE:
|
||||||
if(asn1_cb) {
|
if (asn1_cb)
|
||||||
|
{
|
||||||
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
|
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
|
||||||
if(i == 2) return;
|
if (i == 2)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
i = asn1_get_choice_selector(pval, it);
|
i = asn1_get_choice_selector(pval, it);
|
||||||
if(asn1_cb) asn1_cb(ASN1_OP_FREE_PRE, pval, it);
|
if (asn1_cb)
|
||||||
if((i >= 0) && (i < it->tcount)) {
|
asn1_cb(ASN1_OP_FREE_PRE, pval, it);
|
||||||
|
if ((i >= 0) && (i < it->tcount))
|
||||||
|
{
|
||||||
ASN1_VALUE **pchval;
|
ASN1_VALUE **pchval;
|
||||||
tt = it->templates + i;
|
tt = it->templates + i;
|
||||||
pchval = asn1_get_field_ptr(pval, tt);
|
pchval = asn1_get_field_ptr(pval, tt);
|
||||||
ASN1_template_free(pchval, tt);
|
ASN1_template_free(pchval, tt);
|
||||||
}
|
}
|
||||||
if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
|
if (asn1_cb)
|
||||||
if(!combine) {
|
asn1_cb(ASN1_OP_FREE_POST, pval, it);
|
||||||
|
if (!combine)
|
||||||
|
{
|
||||||
OPENSSL_free(*pval);
|
OPENSSL_free(*pval);
|
||||||
*pval = NULL;
|
*pval = NULL;
|
||||||
}
|
}
|
||||||
@ -122,20 +135,25 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
|
|||||||
|
|
||||||
case ASN1_ITYPE_COMPAT:
|
case ASN1_ITYPE_COMPAT:
|
||||||
cf = it->funcs;
|
cf = it->funcs;
|
||||||
if(cf && cf->asn1_free) cf->asn1_free(*pval);
|
if (cf && cf->asn1_free)
|
||||||
|
cf->asn1_free(*pval);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN1_ITYPE_EXTERN:
|
case ASN1_ITYPE_EXTERN:
|
||||||
ef = it->funcs;
|
ef = it->funcs;
|
||||||
if(ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it);
|
if (ef && ef->asn1_ex_free)
|
||||||
|
ef->asn1_ex_free(pval, it);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN1_ITYPE_NDEF_SEQUENCE:
|
case ASN1_ITYPE_NDEF_SEQUENCE:
|
||||||
case ASN1_ITYPE_SEQUENCE:
|
case ASN1_ITYPE_SEQUENCE:
|
||||||
if(asn1_do_lock(pval, -1, it) > 0) return;
|
if (asn1_do_lock(pval, -1, it) > 0)
|
||||||
if(asn1_cb) {
|
return;
|
||||||
|
if (asn1_cb)
|
||||||
|
{
|
||||||
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
|
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
|
||||||
if(i == 2) return;
|
if (i == 2)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
asn1_enc_free(pval, it);
|
asn1_enc_free(pval, it);
|
||||||
/* If we free up as normal we will invalidate any
|
/* If we free up as normal we will invalidate any
|
||||||
@ -144,15 +162,19 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
|
|||||||
* free up in reverse order.
|
* free up in reverse order.
|
||||||
*/
|
*/
|
||||||
tt = it->templates + it->tcount - 1;
|
tt = it->templates + it->tcount - 1;
|
||||||
for(i = 0; i < it->tcount; tt--, i++) {
|
for (i = 0; i < it->tcount; tt--, i++)
|
||||||
|
{
|
||||||
ASN1_VALUE **pseqval;
|
ASN1_VALUE **pseqval;
|
||||||
seqtt = asn1_do_adb(pval, tt, 0);
|
seqtt = asn1_do_adb(pval, tt, 0);
|
||||||
if(!seqtt) continue;
|
if (!seqtt)
|
||||||
|
continue;
|
||||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||||
ASN1_template_free(pseqval, seqtt);
|
ASN1_template_free(pseqval, seqtt);
|
||||||
}
|
}
|
||||||
if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
|
if (asn1_cb)
|
||||||
if(!combine) {
|
asn1_cb(ASN1_OP_FREE_POST, pval, it);
|
||||||
|
if (!combine)
|
||||||
|
{
|
||||||
OPENSSL_free(*pval);
|
OPENSSL_free(*pval);
|
||||||
*pval = NULL;
|
*pval = NULL;
|
||||||
}
|
}
|
||||||
@ -163,45 +185,61 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
|
|||||||
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if(tt->flags & ASN1_TFLG_SK_MASK) {
|
if (tt->flags & ASN1_TFLG_SK_MASK)
|
||||||
|
{
|
||||||
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
|
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
|
||||||
for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
for (i = 0; i < sk_ASN1_VALUE_num(sk); i++)
|
||||||
|
{
|
||||||
ASN1_VALUE *vtmp;
|
ASN1_VALUE *vtmp;
|
||||||
vtmp = sk_ASN1_VALUE_value(sk, i);
|
vtmp = sk_ASN1_VALUE_value(sk, i);
|
||||||
asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0);
|
asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item),
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
sk_ASN1_VALUE_free(sk);
|
sk_ASN1_VALUE_free(sk);
|
||||||
*pval = NULL;
|
*pval = NULL;
|
||||||
} else asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
|
}
|
||||||
|
else
|
||||||
|
asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
|
||||||
tt->flags & ASN1_TFLG_COMBINE);
|
tt->flags & ASN1_TFLG_COMBINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||||
{
|
{
|
||||||
int utype;
|
int utype;
|
||||||
if(it) {
|
if (it)
|
||||||
|
{
|
||||||
const ASN1_PRIMITIVE_FUNCS *pf;
|
const ASN1_PRIMITIVE_FUNCS *pf;
|
||||||
pf = it->funcs;
|
pf = it->funcs;
|
||||||
if(pf && pf->prim_free) {
|
if (pf && pf->prim_free)
|
||||||
|
{
|
||||||
pf->prim_free(pval, it);
|
pf->prim_free(pval, it);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Special case: if 'it' is NULL free contents of ASN1_TYPE */
|
/* Special case: if 'it' is NULL free contents of ASN1_TYPE */
|
||||||
if(!it) {
|
if (!it)
|
||||||
|
{
|
||||||
ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
|
ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
|
||||||
utype = typ->type;
|
utype = typ->type;
|
||||||
pval = (ASN1_VALUE **)&typ->value.ptr;
|
pval = (ASN1_VALUE **)&typ->value.ptr;
|
||||||
if(!*pval) return;
|
if (!*pval)
|
||||||
} else if(it->itype == ASN1_ITYPE_MSTRING) {
|
return;
|
||||||
|
}
|
||||||
|
else if (it->itype == ASN1_ITYPE_MSTRING)
|
||||||
|
{
|
||||||
utype = -1;
|
utype = -1;
|
||||||
if(!*pval) return;
|
if (!*pval)
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
utype = it->utype;
|
utype = it->utype;
|
||||||
if((utype != V_ASN1_BOOLEAN) && !*pval) return;
|
if ((utype != V_ASN1_BOOLEAN) && !*pval)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(utype) {
|
switch(utype)
|
||||||
|
{
|
||||||
case V_ASN1_OBJECT:
|
case V_ASN1_OBJECT:
|
||||||
ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
|
ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
|
||||||
break;
|
break;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* project 2000.
|
* project 2000.
|
||||||
*/
|
*/
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
|
* Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -64,7 +64,8 @@
|
|||||||
#include <openssl/asn1t.h>
|
#include <openssl/asn1t.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
|
static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||||
|
int combine);
|
||||||
static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||||
static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
||||||
void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||||
@ -72,7 +73,8 @@ void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
|||||||
ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
|
ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
|
||||||
{
|
{
|
||||||
ASN1_VALUE *ret = NULL;
|
ASN1_VALUE *ret = NULL;
|
||||||
if(ASN1_item_ex_new(&ret, it) > 0) return ret;
|
if (ASN1_item_ex_new(&ret, it) > 0)
|
||||||
|
return ret;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +85,8 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
|||||||
return asn1_item_ex_combine_new(pval, it, 0);
|
return asn1_item_ex_combine_new(pval, it, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
|
static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||||
|
int combine)
|
||||||
{
|
{
|
||||||
const ASN1_TEMPLATE *tt = NULL;
|
const ASN1_TEMPLATE *tt = NULL;
|
||||||
const ASN1_COMPAT_FUNCS *cf;
|
const ASN1_COMPAT_FUNCS *cf;
|
||||||
@ -92,20 +95,25 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int
|
|||||||
ASN1_aux_cb *asn1_cb;
|
ASN1_aux_cb *asn1_cb;
|
||||||
ASN1_VALUE **pseqval;
|
ASN1_VALUE **pseqval;
|
||||||
int i;
|
int i;
|
||||||
if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
|
if (aux && aux->asn1_cb)
|
||||||
else asn1_cb = 0;
|
asn1_cb = aux->asn1_cb;
|
||||||
|
else
|
||||||
|
asn1_cb = 0;
|
||||||
|
|
||||||
if (!combine) *pval = NULL;
|
if (!combine) *pval = NULL;
|
||||||
|
|
||||||
#ifdef CRYPTO_MDEBUG
|
#ifdef CRYPTO_MDEBUG
|
||||||
if(it->sname) CRYPTO_push_info(it->sname);
|
if (it->sname)
|
||||||
|
CRYPTO_push_info(it->sname);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch(it->itype) {
|
switch(it->itype)
|
||||||
|
{
|
||||||
|
|
||||||
case ASN1_ITYPE_EXTERN:
|
case ASN1_ITYPE_EXTERN:
|
||||||
ef = it->funcs;
|
ef = it->funcs;
|
||||||
if(ef && ef->asn1_ex_new) {
|
if (ef && ef->asn1_ex_new)
|
||||||
|
{
|
||||||
if (!ef->asn1_ex_new(pval, it))
|
if (!ef->asn1_ex_new(pval, it))
|
||||||
goto memerr;
|
goto memerr;
|
||||||
}
|
}
|
||||||
@ -115,18 +123,19 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int
|
|||||||
cf = it->funcs;
|
cf = it->funcs;
|
||||||
if (cf && cf->asn1_new) {
|
if (cf && cf->asn1_new) {
|
||||||
*pval = cf->asn1_new();
|
*pval = cf->asn1_new();
|
||||||
if(!*pval) goto memerr;
|
if (!*pval)
|
||||||
|
goto memerr;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN1_ITYPE_PRIMITIVE:
|
case ASN1_ITYPE_PRIMITIVE:
|
||||||
if(it->templates) {
|
if (it->templates)
|
||||||
|
{
|
||||||
if (!ASN1_template_new(pval, it->templates))
|
if (!ASN1_template_new(pval, it->templates))
|
||||||
goto memerr;
|
goto memerr;
|
||||||
} else {
|
|
||||||
if(!ASN1_primitive_new(pval, it))
|
|
||||||
goto memerr;
|
|
||||||
}
|
}
|
||||||
|
else if (!ASN1_primitive_new(pval, it))
|
||||||
|
goto memerr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN1_ITYPE_MSTRING:
|
case ASN1_ITYPE_MSTRING:
|
||||||
@ -135,19 +144,25 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN1_ITYPE_CHOICE:
|
case ASN1_ITYPE_CHOICE:
|
||||||
if(asn1_cb) {
|
if (asn1_cb)
|
||||||
|
{
|
||||||
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
|
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
|
||||||
if(!i) goto auxerr;
|
if (!i)
|
||||||
if(i==2) {
|
goto auxerr;
|
||||||
|
if (i==2)
|
||||||
|
{
|
||||||
#ifdef CRYPTO_MDEBUG
|
#ifdef CRYPTO_MDEBUG
|
||||||
if(it->sname) CRYPTO_pop_info();
|
if (it->sname)
|
||||||
|
CRYPTO_pop_info();
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!combine) {
|
if (!combine)
|
||||||
|
{
|
||||||
*pval = OPENSSL_malloc(it->size);
|
*pval = OPENSSL_malloc(it->size);
|
||||||
if(!*pval) goto memerr;
|
if (!*pval)
|
||||||
|
goto memerr;
|
||||||
memset(*pval, 0, it->size);
|
memset(*pval, 0, it->size);
|
||||||
}
|
}
|
||||||
asn1_set_choice_selector(pval, -1, it);
|
asn1_set_choice_selector(pval, -1, it);
|
||||||
@ -157,26 +172,34 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int
|
|||||||
|
|
||||||
case ASN1_ITYPE_NDEF_SEQUENCE:
|
case ASN1_ITYPE_NDEF_SEQUENCE:
|
||||||
case ASN1_ITYPE_SEQUENCE:
|
case ASN1_ITYPE_SEQUENCE:
|
||||||
if(asn1_cb) {
|
if (asn1_cb)
|
||||||
|
{
|
||||||
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
|
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
|
||||||
if(!i) goto auxerr;
|
if (!i)
|
||||||
if(i==2) {
|
goto auxerr;
|
||||||
|
if (i==2)
|
||||||
|
{
|
||||||
#ifdef CRYPTO_MDEBUG
|
#ifdef CRYPTO_MDEBUG
|
||||||
if(it->sname) CRYPTO_pop_info();
|
if (it->sname)
|
||||||
|
CRYPTO_pop_info();
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!combine) {
|
if (!combine)
|
||||||
|
{
|
||||||
*pval = OPENSSL_malloc(it->size);
|
*pval = OPENSSL_malloc(it->size);
|
||||||
if(!*pval) goto memerr;
|
if (!*pval)
|
||||||
|
goto memerr;
|
||||||
memset(*pval, 0, it->size);
|
memset(*pval, 0, it->size);
|
||||||
asn1_do_lock(pval, 0, it);
|
asn1_do_lock(pval, 0, it);
|
||||||
asn1_enc_init(pval, it);
|
asn1_enc_init(pval, it);
|
||||||
}
|
}
|
||||||
for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
|
||||||
|
{
|
||||||
pseqval = asn1_get_field_ptr(pval, tt);
|
pseqval = asn1_get_field_ptr(pval, tt);
|
||||||
if(!ASN1_template_new(pseqval, tt)) goto memerr;
|
if (!ASN1_template_new(pseqval, tt))
|
||||||
|
goto memerr;
|
||||||
}
|
}
|
||||||
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
|
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
|
||||||
goto auxerr;
|
goto auxerr;
|
||||||
@ -208,7 +231,8 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
|||||||
{
|
{
|
||||||
const ASN1_EXTERN_FUNCS *ef;
|
const ASN1_EXTERN_FUNCS *ef;
|
||||||
|
|
||||||
switch(it->itype) {
|
switch(it->itype)
|
||||||
|
{
|
||||||
|
|
||||||
case ASN1_ITYPE_EXTERN:
|
case ASN1_ITYPE_EXTERN:
|
||||||
ef = it->funcs;
|
ef = it->funcs;
|
||||||
@ -243,24 +267,29 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
|||||||
{
|
{
|
||||||
const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
|
const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
|
||||||
int ret;
|
int ret;
|
||||||
if(tt->flags & ASN1_TFLG_OPTIONAL) {
|
if (tt->flags & ASN1_TFLG_OPTIONAL)
|
||||||
|
{
|
||||||
asn1_template_clear(pval, tt);
|
asn1_template_clear(pval, tt);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* If ANY DEFINED BY nothing to do */
|
/* If ANY DEFINED BY nothing to do */
|
||||||
|
|
||||||
if(tt->flags & ASN1_TFLG_ADB_MASK) {
|
if (tt->flags & ASN1_TFLG_ADB_MASK)
|
||||||
|
{
|
||||||
*pval = NULL;
|
*pval = NULL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#ifdef CRYPTO_MDEBUG
|
#ifdef CRYPTO_MDEBUG
|
||||||
if(tt->field_name) CRYPTO_push_info(tt->field_name);
|
if (tt->field_name)
|
||||||
|
CRYPTO_push_info(tt->field_name);
|
||||||
#endif
|
#endif
|
||||||
/* If SET OF or SEQUENCE OF, its a STACK */
|
/* If SET OF or SEQUENCE OF, its a STACK */
|
||||||
if(tt->flags & ASN1_TFLG_SK_MASK) {
|
if (tt->flags & ASN1_TFLG_SK_MASK)
|
||||||
|
{
|
||||||
STACK_OF(ASN1_VALUE) *skval;
|
STACK_OF(ASN1_VALUE) *skval;
|
||||||
skval = sk_ASN1_VALUE_new_null();
|
skval = sk_ASN1_VALUE_new_null();
|
||||||
if(!skval) {
|
if (!skval)
|
||||||
|
{
|
||||||
ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
|
ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto done;
|
goto done;
|
||||||
@ -273,7 +302,8 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
|||||||
ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
|
ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
|
||||||
done:
|
done:
|
||||||
#ifdef CRYPTO_MDEBUG
|
#ifdef CRYPTO_MDEBUG
|
||||||
if(it->sname) CRYPTO_pop_info();
|
if (it->sname)
|
||||||
|
CRYPTO_pop_info();
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -288,8 +318,8 @@ static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* NB: could probably combine most of the real XXX_new() behaviour and junk all the old
|
/* NB: could probably combine most of the real XXX_new() behaviour and junk
|
||||||
* functions.
|
* all the old functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||||
@ -298,10 +328,16 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
|||||||
int utype;
|
int utype;
|
||||||
const ASN1_PRIMITIVE_FUNCS *pf;
|
const ASN1_PRIMITIVE_FUNCS *pf;
|
||||||
pf = it->funcs;
|
pf = it->funcs;
|
||||||
if(pf && pf->prim_new) return pf->prim_new(pval, it);
|
|
||||||
if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
|
if (pf && pf->prim_new)
|
||||||
else utype = it->utype;
|
return pf->prim_new(pval, it);
|
||||||
switch(utype) {
|
|
||||||
|
if (!it || (it->itype == ASN1_ITYPE_MSTRING))
|
||||||
|
utype = -1;
|
||||||
|
else
|
||||||
|
utype = it->utype;
|
||||||
|
switch(utype)
|
||||||
|
{
|
||||||
case V_ASN1_OBJECT:
|
case V_ASN1_OBJECT:
|
||||||
*pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
|
*pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
|
||||||
return 1;
|
return 1;
|
||||||
@ -319,7 +355,8 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
|||||||
|
|
||||||
case V_ASN1_ANY:
|
case V_ASN1_ANY:
|
||||||
typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
|
typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
|
||||||
if(!typ) return 0;
|
if (!typ)
|
||||||
|
return 0;
|
||||||
typ->value.ptr = NULL;
|
typ->value.ptr = NULL;
|
||||||
typ->type = -1;
|
typ->type = -1;
|
||||||
*pval = (ASN1_VALUE *)typ;
|
*pval = (ASN1_VALUE *)typ;
|
||||||
@ -329,7 +366,8 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
|||||||
*pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
|
*pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(*pval) return 1;
|
if (*pval)
|
||||||
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,15 +376,18 @@ void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
|||||||
int utype;
|
int utype;
|
||||||
const ASN1_PRIMITIVE_FUNCS *pf;
|
const ASN1_PRIMITIVE_FUNCS *pf;
|
||||||
pf = it->funcs;
|
pf = it->funcs;
|
||||||
if(pf) {
|
if (pf)
|
||||||
|
{
|
||||||
if (pf->prim_clear)
|
if (pf->prim_clear)
|
||||||
pf->prim_clear(pval, it);
|
pf->prim_clear(pval, it);
|
||||||
else
|
else
|
||||||
*pval = NULL;
|
*pval = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
|
if (!it || (it->itype == ASN1_ITYPE_MSTRING))
|
||||||
else utype = it->utype;
|
utype = -1;
|
||||||
|
else
|
||||||
|
utype = it->utype;
|
||||||
if (utype == V_ASN1_BOOLEAN)
|
if (utype == V_ASN1_BOOLEAN)
|
||||||
*(ASN1_BOOLEAN *)pval = it->size;
|
*(ASN1_BOOLEAN *)pval = it->size;
|
||||||
else *pval = NULL;
|
else *pval = NULL;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* project 2000.
|
* project 2000.
|
||||||
*/
|
*/
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
|
* Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -103,11 +103,14 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
|
|||||||
const ASN1_AUX *aux;
|
const ASN1_AUX *aux;
|
||||||
int *lck, ret;
|
int *lck, ret;
|
||||||
if ((it->itype != ASN1_ITYPE_SEQUENCE)
|
if ((it->itype != ASN1_ITYPE_SEQUENCE)
|
||||||
&& (it->itype != ASN1_ITYPE_NDEF_SEQUENCE)) return 0;
|
&& (it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
|
||||||
|
return 0;
|
||||||
aux = it->funcs;
|
aux = it->funcs;
|
||||||
if(!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) return 0;
|
if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
|
||||||
|
return 0;
|
||||||
lck = offset2ptr(*pval, aux->ref_offset);
|
lck = offset2ptr(*pval, aux->ref_offset);
|
||||||
if(op == 0) {
|
if (op == 0)
|
||||||
|
{
|
||||||
*lck = 1;
|
*lck = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -125,9 +128,11 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
|
|||||||
static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||||
{
|
{
|
||||||
const ASN1_AUX *aux;
|
const ASN1_AUX *aux;
|
||||||
if(!pval || !*pval) return NULL;
|
if (!pval || !*pval)
|
||||||
|
return NULL;
|
||||||
aux = it->funcs;
|
aux = it->funcs;
|
||||||
if(!aux || !(aux->flags & ASN1_AFLG_ENCODING)) return NULL;
|
if (!aux || !(aux->flags & ASN1_AFLG_ENCODING))
|
||||||
|
return NULL;
|
||||||
return offset2ptr(*pval, aux->enc_offset);
|
return offset2ptr(*pval, aux->enc_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +140,8 @@ void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
|||||||
{
|
{
|
||||||
ASN1_ENCODING *enc;
|
ASN1_ENCODING *enc;
|
||||||
enc = asn1_get_enc_ptr(pval, it);
|
enc = asn1_get_enc_ptr(pval, it);
|
||||||
if(enc) {
|
if (enc)
|
||||||
|
{
|
||||||
enc->enc = NULL;
|
enc->enc = NULL;
|
||||||
enc->len = 0;
|
enc->len = 0;
|
||||||
enc->modified = 1;
|
enc->modified = 1;
|
||||||
@ -146,23 +152,29 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
|
|||||||
{
|
{
|
||||||
ASN1_ENCODING *enc;
|
ASN1_ENCODING *enc;
|
||||||
enc = asn1_get_enc_ptr(pval, it);
|
enc = asn1_get_enc_ptr(pval, it);
|
||||||
if(enc) {
|
if (enc)
|
||||||
if(enc->enc) OPENSSL_free(enc->enc);
|
{
|
||||||
|
if (enc->enc)
|
||||||
|
OPENSSL_free(enc->enc);
|
||||||
enc->enc = NULL;
|
enc->enc = NULL;
|
||||||
enc->len = 0;
|
enc->len = 0;
|
||||||
enc->modified = 1;
|
enc->modified = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it)
|
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
|
||||||
|
const ASN1_ITEM *it)
|
||||||
{
|
{
|
||||||
ASN1_ENCODING *enc;
|
ASN1_ENCODING *enc;
|
||||||
enc = asn1_get_enc_ptr(pval, it);
|
enc = asn1_get_enc_ptr(pval, it);
|
||||||
if(!enc) return 1;
|
if (!enc)
|
||||||
|
return 1;
|
||||||
|
|
||||||
if(enc->enc) OPENSSL_free(enc->enc);
|
if (enc->enc)
|
||||||
|
OPENSSL_free(enc->enc);
|
||||||
enc->enc = OPENSSL_malloc(inlen);
|
enc->enc = OPENSSL_malloc(inlen);
|
||||||
if(!enc->enc) return 0;
|
if (!enc->enc)
|
||||||
|
return 0;
|
||||||
memcpy(enc->enc, in, inlen);
|
memcpy(enc->enc, in, inlen);
|
||||||
enc->len = inlen;
|
enc->len = inlen;
|
||||||
enc->modified = 0;
|
enc->modified = 0;
|
||||||
@ -170,16 +182,20 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const A
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it)
|
int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
|
||||||
|
const ASN1_ITEM *it)
|
||||||
{
|
{
|
||||||
ASN1_ENCODING *enc;
|
ASN1_ENCODING *enc;
|
||||||
enc = asn1_get_enc_ptr(pval, it);
|
enc = asn1_get_enc_ptr(pval, it);
|
||||||
if(!enc || enc->modified) return 0;
|
if (!enc || enc->modified)
|
||||||
if(out) {
|
return 0;
|
||||||
|
if (out)
|
||||||
|
{
|
||||||
memcpy(*out, enc->enc, enc->len);
|
memcpy(*out, enc->enc, enc->len);
|
||||||
*out += enc->len;
|
*out += enc->len;
|
||||||
}
|
}
|
||||||
if(len) *len = enc->len;
|
if (len)
|
||||||
|
*len = enc->len;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +203,8 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN
|
|||||||
ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
||||||
{
|
{
|
||||||
ASN1_VALUE **pvaltmp;
|
ASN1_VALUE **pvaltmp;
|
||||||
if(tt->flags & ASN1_TFLG_COMBINE) return pval;
|
if (tt->flags & ASN1_TFLG_COMBINE)
|
||||||
|
return pval;
|
||||||
pvaltmp = offset2ptr(*pval, tt->offset);
|
pvaltmp = offset2ptr(*pval, tt->offset);
|
||||||
/* NOTE for BOOLEAN types the field is just a plain
|
/* NOTE for BOOLEAN types the field is just a plain
|
||||||
* int so we can't return int **, so settle for
|
* int so we can't return int **, so settle for
|
||||||
@ -200,14 +217,16 @@ ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
|
|||||||
* the relevant ASN1_TEMPLATE in the table and return it.
|
* the relevant ASN1_TEMPLATE in the table and return it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
|
const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
|
||||||
|
int nullerr)
|
||||||
{
|
{
|
||||||
const ASN1_ADB *adb;
|
const ASN1_ADB *adb;
|
||||||
const ASN1_ADB_TABLE *atbl;
|
const ASN1_ADB_TABLE *atbl;
|
||||||
long selector;
|
long selector;
|
||||||
ASN1_VALUE **sfld;
|
ASN1_VALUE **sfld;
|
||||||
int i;
|
int i;
|
||||||
if(!(tt->flags & ASN1_TFLG_ADB_MASK)) return tt;
|
if (!(tt->flags & ASN1_TFLG_ADB_MASK))
|
||||||
|
return tt;
|
||||||
|
|
||||||
/* Else ANY DEFINED BY ... get the table */
|
/* Else ANY DEFINED BY ... get the table */
|
||||||
adb = ASN1_ADB_ptr(tt->item);
|
adb = ASN1_ADB_ptr(tt->item);
|
||||||
@ -216,8 +235,10 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int
|
|||||||
sfld = offset2ptr(*pval, adb->offset);
|
sfld = offset2ptr(*pval, adb->offset);
|
||||||
|
|
||||||
/* Check if NULL */
|
/* Check if NULL */
|
||||||
if(!sfld) {
|
if (!sfld)
|
||||||
if(!adb->null_tt) goto err;
|
{
|
||||||
|
if (!adb->null_tt)
|
||||||
|
goto err;
|
||||||
return adb->null_tt;
|
return adb->null_tt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,16 +260,20 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++)
|
for (atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++)
|
||||||
if(atbl->value == selector) return &atbl->tt;
|
if (atbl->value == selector)
|
||||||
|
return &atbl->tt;
|
||||||
|
|
||||||
/* FIXME: need to search application table too */
|
/* FIXME: need to search application table too */
|
||||||
|
|
||||||
/* No match, return default type */
|
/* No match, return default type */
|
||||||
if(!adb->default_tt) goto err;
|
if (!adb->default_tt)
|
||||||
|
goto err;
|
||||||
return adb->default_tt;
|
return adb->default_tt;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
/* FIXME: should log the value or OID of unsupported type */
|
/* FIXME: should log the value or OID of unsupported type */
|
||||||
if(nullerr) ASN1err(ASN1_F_ASN1_DO_ADB, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
|
if (nullerr)
|
||||||
|
ASN1err(ASN1_F_ASN1_DO_ADB,
|
||||||
|
ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user