aboutsummaryrefslogtreecommitdiff
path: root/src/common/crypto.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-09-26 18:27:35 +0000
committerNick Mathewson <nickm@torproject.org>2003-09-26 18:27:35 +0000
commit92acbe12bc9512100b9282d7e9d61fe86b5a60bb (patch)
tree80cd3c92c91f30818c60a97842a1f106a8cb27ac /src/common/crypto.c
parent9e5cafc395397426030e8098d64b8e25625863c5 (diff)
downloadtor-92acbe12bc9512100b9282d7e9d61fe86b5a60bb.tar.gz
tor-92acbe12bc9512100b9282d7e9d61fe86b5a60bb.zip
Refactor common file code into util.c; add published to descriptors
svn:r487
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r--src/common/crypto.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index b2ddbb1735..f6c7360d53 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -472,6 +472,28 @@ int crypto_pk_read_public_key_from_string(crypto_pk_env_t *env, char *src, int l
return 0;
}
+int
+crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env,
+ const char *fname)
+{
+ BIO *bio;
+ char *cp;
+ long len;
+ int r;
+ assert(env->type == CRYPTO_PK_RSA);
+ if (!(bio = BIO_new(BIO_s_mem())))
+ return -1;
+ if (PEM_write_bio_RSAPrivateKey(bio, (RSA*)env->key, NULL,NULL,0,0,NULL)) {
+ BIO_free(bio);
+ return -1;
+ }
+ len = BIO_get_mem_data(bio, &cp);
+ assert(len == strlen(cp));
+ r = write_str_to_file(fname, cp);
+ BIO_free(bio);
+ return r;
+}
+
int crypto_pk_write_private_key_to_file(crypto_pk_env_t *env, FILE *dest)
{
assert(env && dest);