[Help-gnutls] Re: Getting keys for my own crtypto functions (opencdk)
Mario Lenz
mario.lenz at gmx.net
Wed Jan 10 19:39:54 CET 2007
Hi!
> This approach seems acceptable, and if you implement it (or some
> variant of this), I'd be happy to make that part of the official API.
Would you please have a look at these functions? If you think they're ok
I'll do some tests:
/**
* cdk_pubkey_to_sexp:
* @pk:
* @sexp:
* @len: where to store the length of sexp (may be NULL)
*
* Convert a public key to an S- expression. sexp is allocated
* by this function, so you have to cdk_free() the memory when you don't
* need it any more.
**/
int
cdk_pubkey_to_sexp (cdk_pkt_pubkey_t pk, char **sexp, size_t * len)
{
int rc;
char *buf;
size_t sexp_len;
gcry_sexp_t pk_sexp;
if (!pk || !sexp)
return CDK_Inv_Value;
rc = pubkey_to_sexp (&pk_sexp, pk);
if (rc)
return rc;
sexp_len = gcry_sexp_sprint (pk_sexp, GCRYSEXP_FMT_CANON, NULL, 0);
if (!sexp_len)
{
gcry_sexp_release (pk_sexp);
return CDK_Gcry_Error;
}
buf = (char *) cdk_malloc (sexp_len);
if (!buf)
{
gcry_sexp_release (pk_sexp);
return CDK_Out_Of_Core;
}
sexp_len =
gcry_sexp_sprint (pk_sexp, GCRYSEXP_FMT_CANON, pk_sexp, sexp_len);
gcry_sexp_release (pk_sexp);
if (!sexp_len)
{
cdk_free (buf);
return CDK_Gcry_Error;
}
if (len)
*len = sexp_len;
*sexp = buf;
return 0;
}
/**
* cdk_seckey_to_sexp:
* @sk:
* @sexp:
* @len: where to store the length of sexp (may be NULL)
*
* Convert a secret key to an S- expression. sexp is allocated
* by this function, so you have to cdk_free() the memory when you don't
* need it any more.
**/
int
cdk_seckey_to_sexp (cdk_pkt_seckey_t sk, char **sexp, size_t * len)
{
int rc;
char *buf;
size_t sexp_len;
gcry_sexp_t sk_sexp;
if (!sk || !sexp)
return CDK_Inv_Value;
rc = seckey_to_sexp (&sk_sexp, sk);
if (rc)
return rc;
sexp_len = gcry_sexp_sprint (sk_sexp, GCRYSEXP_FMT_CANON, NULL, 0);
if (!sexp_len)
{
gcry_sexp_release (sk_sexp);
return CDK_Gcry_Error;
}
buf = (char *) cdk_malloc (sexp_len);
if (!buf)
{
gcry_sexp_release (sk_sexp);
return CDK_Out_Of_Core;
}
sexp_len =
gcry_sexp_sprint (sk_sexp, GCRYSEXP_FMT_CANON, sk_sexp, sexp_len);
gcry_sexp_release (sk_sexp);
if (!sexp_len)
{
cdk_free (buf);
return CDK_Gcry_Error;
}
if (len)
*len = sexp_len;
*sexp = buf;
return 0;
}
cu
Mario
--
Wieners, in buns, no condiments. It's Hank's way. Anything else is
wrong.
More information about the Gnutls-help
mailing list