i=i2d_PublicKey(pkey,NULL);
if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err;
int X509_PUBKEY_set(x,pkey)X509_PUBKEY **x;EVP_PKEY *pkey;	{	int ok=0;	X509_PUBKEY *pk;	X509_ALGOR *a;	ASN1_OBJECT *o;	unsigned char *s,*p;	int i;	if (x == NULL) return(0);	if ((pk=X509_PUBKEY_new()) == NULL) goto err;	a=pk->algor;	/* set the algorithm id */	if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err;	ASN1_OBJECT_free(a->algorithm);	a->algorithm=o;	/* Set the parameter list */	if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA))		{		if ((a->parameter == NULL) ||			(a->parameter->type != V_ASN1_NULL))			{			ASN1_TYPE_free(a->parameter);			a->parameter=ASN1_TYPE_new();			a->parameter->type=V_ASN1_NULL;			}		}	else#ifndef NO_DSA		if (pkey->type == EVP_PKEY_DSA)		{		unsigned char *pp;		DSA *dsa;		dsa=pkey->pkey.dsa;		dsa->write_params=0;		ASN1_TYPE_free(a->parameter);		i=i2d_DSAparams(dsa,NULL);		p=(unsigned char *)Malloc(i);		pp=p;		i2d_DSAparams(dsa,&pp);		a->parameter=ASN1_TYPE_new();		a->parameter->type=V_ASN1_SEQUENCE;		a->parameter->value.sequence=ASN1_STRING_new();		ASN1_STRING_set(a->parameter->value.sequence,p,i);		Free(p);		}	else#endif		{		X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);		goto err;		}	i=i2d_PublicKey(pkey,NULL);	if ((s=(unsigned char *)Malloc(i+1)) == NULL) goto err;	p=s;	i2d_PublicKey(pkey,&p);	if (!ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err;	/* Set number of unused bits to zero */	pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);	pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;	Free(s);	CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);	pk->pkey=pkey;	if (*x != NULL)		X509_PUBKEY_free(*x);	*x=pk;	pk=NULL;	ok=1;err:	if (pk != NULL) X509_PUBKEY_free(pk);	return(ok);	}