Add assert on crypto_pk_write_private_key,and macros to make sure we have real keys

svn:r1694
This commit is contained in:
Nick Mathewson 2004-04-25 19:21:44 +00:00
parent 0fca143ea1
commit 70bbd0cafa

View File

@ -53,6 +53,9 @@
#define RETURN_SSL_OUTCOME(exp) return !(exp)
#endif
#define PUBLIC_KEY_OK(k) ((k) && (k)->key && (k)->key->n)
#define PRIVATE_KEY_OK(k) ((k) && (k)->key && (k)->key->p)
struct crypto_pk_env_t
{
int refs; /* reference counting; so we don't have to copy keys */
@ -373,6 +376,8 @@ crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env,
char *s;
int r;
assert(PRIVATE_KEY_OK(env));
if (!(bio = BIO_new(BIO_s_mem())))
return -1;
if (PEM_write_bio_RSAPrivateKey(bio, env->key, NULL,NULL,0,NULL,NULL)