chiark / gitweb /
privcache: Break out uncached_load_file
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Dec 2019 14:13:24 +0000 (14:13 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:54 +0000 (21:56 +0000)
We are going to want to reuse this to make a new entrypoint.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
privcache.c

index ba756ffda8d38117ff766935103e86221b501c7d..298626f2e19c4e416e3b8b7c6949684875f571dc 100644 (file)
@@ -37,19 +37,19 @@ struct privcache {
     struct hash_if *defhash;
 };
 
+static struct sigprivkey_if *uncached_load_file(
+                          const struct sigscheme_info *scheme,
+                          const char *path,
+                          struct buffer_if *databuf,
+                          struct hash_if *defhash,
+                          struct log_if *log);
+
 static struct sigprivkey_if *uncached_get(struct privcache *st,
                           const struct sigkeyid *id, struct log_if *log)
 {
-    bool_t ok=False;
-    FILE *f=0;
-
     sprintf(st->path.write_here, SIGKEYID_PR_FMT, SIGKEYID_PR_VAL(id));
 
     const char *path=st->path.buffer;
-    struct hash_if *defhash=st->defhash;
-    struct buffer_if *databuf=&st->databuf;
-
-    struct sigprivkey_if *sigpriv=0;
     const struct sigscheme_info *scheme;
     for (scheme=sigschemes;
         scheme->name;
@@ -59,9 +59,27 @@ static struct sigprivkey_if *uncached_get(struct privcache *st,
 
     slilog(log,M_ERR,"private key file %s not loaded (unknown algid)",
           path);
-    goto out;
+    return 0;
 
  found:
+    return uncached_load_file(scheme,
+                             path,
+                             &st->databuf,
+                             st->defhash,
+                             log);
+}
+
+static struct sigprivkey_if *uncached_load_file(
+                          const struct sigscheme_info *scheme,
+                          const char *path,
+                          struct buffer_if *databuf,
+                          struct hash_if *defhash,
+                          struct log_if *log)
+{
+    bool_t ok=False;
+    FILE *f=0;
+    struct sigprivkey_if *sigpriv=0;
+
     f = fopen(path,"rb");
     if (!f) {
        if (errno == ENOENT) {