]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
crypt.c: Combine load_key() and get_private_key().
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 6 Jan 2017 17:52:13 +0000 (18:52 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 6 Jan 2017 19:58:41 +0000 (20:58 +0100)
Both functions are short and the former is only called by the latter.

crypt.c

diff --git a/crypt.c b/crypt.c
index 34b78798cc764451e71d1a61353e52485cbd92e0..29a1c955a8d19fc6d5691632d37eaf3f65a3d292 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -61,31 +61,24 @@ void init_random_seed_or_die(void)
        srandom(seed);
 }
 
-static EVP_PKEY *load_key(const char *file)
+static int get_private_key(const char *path, RSA **rsa)
 {
-       BIO *key;
-       EVP_PKEY *pkey = NULL;
+       EVP_PKEY *pkey;
+       BIO *bio = BIO_new(BIO_s_file());
 
-       key = BIO_new(BIO_s_file());
-       if (!key)
-               return NULL;
-       if (BIO_read_filename(key, file) > 0)
-               pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, NULL);
-       BIO_free(key);
-       return pkey;
-}
-
-static int get_private_key(const char *key_file, RSA **rsa)
-{
-       EVP_PKEY *key = load_key(key_file);
-
-       if (!key)
+       *rsa = NULL;
+       if (!bio)
                return -E_PRIVATE_KEY;
-       *rsa = EVP_PKEY_get1_RSA(key);
-       EVP_PKEY_free(key);
-       if (!*rsa)
-               return -E_RSA;
-       return RSA_size(*rsa);
+       if (BIO_read_filename(bio, path) <= 0)
+               goto bio_free;
+       pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
+       if (!pkey)
+               goto bio_free;
+       *rsa = EVP_PKEY_get1_RSA(pkey);
+       EVP_PKEY_free(pkey);
+bio_free:
+       BIO_free(bio);
+       return *rsa? RSA_size(*rsa) : -E_PRIVATE_KEY;
 }
 
 /*