Extend attribute setting routines to support non-string types.
This commit is contained in:
parent
8ab9025e31
commit
1ad90a916b
@ -77,9 +77,36 @@ void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
|
|||||||
ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
|
ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
|
||||||
}
|
}
|
||||||
a->type=type;
|
a->type=type;
|
||||||
a->value.ptr=value;
|
if (type == V_ASN1_BOOLEAN)
|
||||||
|
a->value.boolean = value ? 0xff : 0;
|
||||||
|
else
|
||||||
|
a->value.ptr=value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
|
||||||
|
{
|
||||||
|
if (!value || (type == V_ASN1_BOOLEAN))
|
||||||
|
{
|
||||||
|
ASN1_TYPE_set(a, type, (void *)value);
|
||||||
|
}
|
||||||
|
else if (type == V_ASN1_OBJECT)
|
||||||
|
{
|
||||||
|
ASN1_OBJECT *odup;
|
||||||
|
odup = OBJ_dup(value);
|
||||||
|
if (!odup)
|
||||||
|
return 0;
|
||||||
|
ASN1_TYPE_set(a, type, odup);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ASN1_STRING *sdup;
|
||||||
|
sdup = ASN1_STRING_dup(sdup);
|
||||||
|
if (!sdup)
|
||||||
|
return 0;
|
||||||
|
ASN1_TYPE_set(a, type, sdup);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
IMPLEMENT_STACK_OF(ASN1_TYPE)
|
IMPLEMENT_STACK_OF(ASN1_TYPE)
|
||||||
IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
|
IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
|
||||||
|
@ -759,6 +759,7 @@ DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
|
|||||||
|
|
||||||
int ASN1_TYPE_get(ASN1_TYPE *a);
|
int ASN1_TYPE_get(ASN1_TYPE *a);
|
||||||
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
|
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
|
||||||
|
int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
|
||||||
int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b);
|
int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b);
|
||||||
|
|
||||||
ASN1_OBJECT * ASN1_OBJECT_new(void );
|
ASN1_OBJECT * ASN1_OBJECT_new(void );
|
||||||
|
@ -281,16 +281,22 @@ int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *dat
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
atype = stmp->type;
|
atype = stmp->type;
|
||||||
} else {
|
} else if (len != -1){
|
||||||
if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err;
|
if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err;
|
||||||
if(!ASN1_STRING_set(stmp, data, len)) goto err;
|
if(!ASN1_STRING_set(stmp, data, len)) goto err;
|
||||||
atype = attrtype;
|
atype = attrtype;
|
||||||
}
|
}
|
||||||
if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
|
if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
|
||||||
if(!(ttmp = ASN1_TYPE_new())) goto err;
|
if(!(ttmp = ASN1_TYPE_new())) goto err;
|
||||||
|
if (len == -1)
|
||||||
|
{
|
||||||
|
if (!ASN1_TYPE_set1(ttmp, attrtype, data))
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ASN1_TYPE_set(ttmp, atype, stmp);
|
||||||
if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err;
|
if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err;
|
||||||
attr->single = 0;
|
attr->single = 0;
|
||||||
ASN1_TYPE_set(ttmp, atype, stmp);
|
|
||||||
return 1;
|
return 1;
|
||||||
err:
|
err:
|
||||||
X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE);
|
X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user