Another stack.

This commit is contained in:
Ben Laurie 1999-05-01 18:29:59 +00:00
parent d500de1672
commit d35ea5b00b
8 changed files with 58 additions and 51 deletions

View File

@ -1069,7 +1069,7 @@ start:
/* add object plus value */
if ((xa=X509_ATTRIBUTE_new()) == NULL)
goto err;
if ((xa->value.set=sk_new_null()) == NULL)
if ((xa->value.set=sk_ASN1_TYPE_new_null()) == NULL)
goto err;
xa->set=1;
@ -1095,7 +1095,7 @@ start:
{ BIO_printf(bio_err,"Malloc failure\n"); goto err; }
ASN1_TYPE_set(at,bs->type,(char *)bs);
sk_push(xa->value.set,(char *)at);
sk_ASN1_TYPE_push(xa->value.set,at);
bs=NULL;
at=NULL;
/* only one item per attribute */

View File

@ -344,3 +344,5 @@ static void ASN1_TYPE_component_free(ASN1_TYPE *a)
}
}
IMPLEMENT_STACK_OF(ASN1_TYPE)
IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)

View File

@ -66,6 +66,7 @@ extern "C" {
#include <time.h>
#include <openssl/bn.h>
#include <openssl/stack.h>
#include <openssl/safestack.h>
#define V_ASN1_UNIVERSAL 0x00
#define V_ASN1_APPLICATION 0x40
@ -127,6 +128,33 @@ extern "C" {
#define B_ASN1_UNKNOWN 0x1000
#define B_ASN1_UTF8STRING 0x2000
#define DECLARE_ASN1_SET_OF(type) \
int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
int (*func)(type *,unsigned char **), int ex_tag, \
int ex_class, int is_set); \
STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
long length, \
type *(*func)(type **, \
unsigned char **,long), \
void (*free_func)(type *), \
int ex_tag,int ex_class);
#define IMPLEMENT_ASN1_SET_OF(type) \
int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
int (*func)(type *,unsigned char **), int ex_tag, \
int ex_class, int is_set) \
{ return i2d_ASN1_SET((STACK *)a,pp,func,ex_tag,ex_class,is_set); } \
STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
long length, \
type *(*func)(type **, \
unsigned char **,long), \
void (*free_func)(type *), \
int ex_tag,int ex_class) \
{ return (STACK_OF(type) *)d2i_ASN1_SET((STACK **)a,pp,length, \
(char *(*)())func, \
(void (*)())free_func, \
ex_tag,ex_class); }
typedef struct asn1_ctx_st
{
unsigned char *p;/* work char pointer */
@ -233,6 +261,9 @@ typedef struct asn1_type_st
} value;
} ASN1_TYPE;
DECLARE_STACK_OF(ASN1_TYPE)
DECLARE_ASN1_SET_OF(ASN1_TYPE)
typedef struct asn1_method_st
{
int (*i2d)();
@ -553,33 +584,6 @@ STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
char *(*func)(), void (*free_func)(),
int ex_tag, int ex_class);
#define DECLARE_ASN1_SET_OF(type) \
int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
int (*func)(type *,unsigned char **), int ex_tag, \
int ex_class, int is_set); \
STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
long length, \
type *(*func)(type **, \
unsigned char **,long), \
void (*free_func)(type *), \
int ex_tag,int ex_class);
#define IMPLEMENT_ASN1_SET_OF(type) \
int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
int (*func)(type *,unsigned char **), int ex_tag, \
int ex_class, int is_set) \
{ return i2d_ASN1_SET((STACK *)a,pp,func,ex_tag,ex_class,is_set); } \
STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
long length, \
type *(*func)(type **, \
unsigned char **,long), \
void (*free_func)(type *), \
int ex_tag,int ex_class) \
{ return (STACK_OF(type) *)d2i_ASN1_SET((STACK **)a,pp,length, \
(char *(*)())func, \
(void (*)())free_func, \
ex_tag,ex_class); }
#ifdef HEADER_BIO_H
int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);

View File

@ -168,9 +168,9 @@ int X509_REQ_print(BIO *bp, X509_REQ *x)
if (a->set)
{
ii=0;
count=sk_num(a->value.set);
count=sk_ASN1_TYPE_num(a->value.set);
get_next:
at=(ASN1_TYPE *)sk_value(a->value.set,ii);
at=sk_ASN1_TYPE_value(a->value.set,ii);
type=at->type;
bs=at->value.asn1_string;
}

View File

@ -84,7 +84,7 @@ int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a, unsigned char **pp)
ret+=i2d_ASN1_OBJECT(a->object,p);
if (a->set)
ret+=i2d_ASN1_SET(a->value.set,p,i2d_ASN1_TYPE,
ret+=i2d_ASN1_SET_OF_ASN1_TYPE(a->value.set,p,i2d_ASN1_TYPE,
V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
else
ret+=i2d_ASN1_TYPE(a->value.single,p);
@ -105,7 +105,8 @@ X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a, unsigned char **pp,
(M_ASN1_next == (V_ASN1_CONSTRUCTED|V_ASN1_UNIVERSAL|V_ASN1_SET)))
{
ret->set=1;
M_ASN1_D2I_get_set(ret->value.set,d2i_ASN1_TYPE,ASN1_TYPE_free);
M_ASN1_D2I_get_set_type(ASN1_TYPE,ret->value.set,d2i_ASN1_TYPE,
ASN1_TYPE_free);
}
else
{
@ -125,9 +126,9 @@ X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, char *value)
return(NULL);
ret->object=OBJ_nid2obj(nid);
ret->set=1;
if ((ret->value.set=sk_new_null()) == NULL) goto err;
if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err;
if ((val=ASN1_TYPE_new()) == NULL) goto err;
if (!sk_push(ret->value.set,(char *)val)) goto err;
if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err;
ASN1_TYPE_set(val,atrtype,value);
return(ret);
@ -155,7 +156,7 @@ void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a)
if (a == NULL) return;
ASN1_OBJECT_free(a->object);
if (a->set)
sk_pop_free(a->value.set,ASN1_TYPE_free);
sk_ASN1_TYPE_pop_free(a->value.set,ASN1_TYPE_free);
else
ASN1_TYPE_free(a->value.single);
Free((char *)a);

View File

@ -87,11 +87,11 @@ int PKCS12_add_localkeyid (PKCS12_SAFEBAG *bag, unsigned char *name,
return 0;
}
attrib->object = OBJ_nid2obj(NID_localKeyID);
if (!(attrib->value.set = sk_new(NULL))) {
if (!(attrib->value.set = sk_ASN1_TYPE_new(NULL))) {
PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
return 0;
}
sk_push (attrib->value.set, (char *)keyid);
sk_ASN1_TYPE_push (attrib->value.set,keyid);
attrib->set = 1;
if (!bag->attrib && !(bag->attrib = sk_new (NULL))) {
PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
@ -129,11 +129,11 @@ int PKCS8_add_keyusage (PKCS8_PRIV_KEY_INFO *p8, int usage)
return 0;
}
attrib->object = OBJ_nid2obj(NID_key_usage);
if (!(attrib->value.set = sk_new(NULL))) {
if (!(attrib->value.set = sk_ASN1_TYPE_new(NULL))) {
PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
return 0;
}
sk_push (attrib->value.set, (char *)keyid);
sk_ASN1_TYPE_push (attrib->value.set,keyid);
attrib->set = 1;
if (!p8->attributes && !(p8->attributes = sk_new (NULL))) {
PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
@ -194,12 +194,12 @@ int PKCS12_add_friendlyname_uni (PKCS12_SAFEBAG *bag,
return 0;
}
attrib->object = OBJ_nid2obj(NID_friendlyName);
if (!(attrib->value.set = sk_new(NULL))) {
if (!(attrib->value.set = sk_ASN1_TYPE_new(NULL))) {
PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME,
ERR_R_MALLOC_FAILURE);
return 0;
}
sk_push (attrib->value.set, (char *)fname);
sk_ASN1_TYPE_push (attrib->value.set,fname);
attrib->set = 1;
if (!bag->attrib && !(bag->attrib = sk_new (NULL))) {
PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
@ -218,9 +218,8 @@ ASN1_TYPE *PKCS12_get_attr_gen (STACK *attrs, int attr_nid)
for (i = 0; i < sk_num (attrs); i++) {
attrib = (X509_ATTRIBUTE *) sk_value (attrs, i);
if (OBJ_obj2nid (attrib->object) == attr_nid) {
if (sk_num (attrib->value.set))
return (ASN1_TYPE *)
sk_value (attrib->value.set, 0);
if (sk_ASN1_TYPE_num (attrib->value.set))
return sk_ASN1_TYPE_value(attrib->value.set, 0);
else return NULL;
}
}

View File

@ -809,8 +809,8 @@ static ASN1_TYPE *get_attribute(STACK *sk, int nid)
xa=(X509_ATTRIBUTE *)sk_value(sk,i);
if (OBJ_cmp(xa->object,o) == 0)
{
if (xa->set && sk_num(xa->value.set))
return((ASN1_TYPE *)sk_value(xa->value.set,0));
if (xa->set && sk_ASN1_TYPE_num(xa->value.set))
return(sk_ASN1_TYPE_value(xa->value.set,0));
else
return(NULL);
}
@ -831,9 +831,10 @@ ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK *sk)
if (OBJ_obj2nid(attr->object) == NID_pkcs9_messageDigest)
{
if (!attr->set) return NULL;
if (!attr->value.set ||
!sk_num (attr->value.set) ) return NULL;
astype = (ASN1_TYPE *) sk_value(attr->value.set, 0);
if (!attr->value.set
|| !sk_ASN1_TYPE_num(attr->value.set) )
return NULL;
astype = sk_ASN1_TYPE_value(attr->value.set, 0);
return astype->value.octet_string;
}
}

View File

@ -174,7 +174,7 @@ typedef struct x509_attributes_st
int set; /* 1 for a set, 0 for a single item (which is wrong) */
union {
char *ptr;
/* 1 */ STACK /* ASN1_TYPE */ *set;
/* 1 */ STACK_OF(ASN1_TYPE) *set;
/* 0 */ ASN1_TYPE *single;
} value;
} X509_ATTRIBUTE;