Move base64 implementation to own file.
[paraslash.git] / gcrypt.c
index 45a1c67d20da0b6d229180de92be10644a63d082..8e73b3b2696f0aee501c6a317280067b885e3011 100644 (file)
--- a/gcrypt.c
+++ b/gcrypt.c
@@ -15,6 +15,7 @@
 #include "crypt.h"
 #include "crypt_backend.h"
 #include "fd.h"
+#include "base64.h"
 
 //#define GCRYPT_DEBUG 1
 
@@ -212,7 +213,7 @@ static int decode_key(const char *key_file, const char *header_str,
 
        ret = mmap_full_file(key_file, O_RDONLY, &map, &map_size, NULL);
        if (ret < 0)
-               return ret;
+               goto out;
        ret = -E_KEY_MARKER;
        if (strncmp(map, header_str, strlen(header_str)))
                goto unmap;
@@ -257,6 +258,7 @@ unmap:
                free(blob);
                blob = NULL;
        }
+out:
        *result = blob;
        return ret;
 }
@@ -781,6 +783,9 @@ int priv_decrypt(const char *key_file, unsigned char *outbuf,
        gcry_sexp_t in, out, priv_key;
        size_t nbytes;
 
+       ret = check_key_file(key_file, true);
+       if (ret < 0)
+               return ret;
        PARA_INFO_LOG("decrypting %d byte input\n", inlen);
        /* key_file -> asymmetric key priv */
        ret = get_private_key(key_file, &priv);