chiark / gitweb /
privcache: Reorganise private key loading
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 Dec 2019 13:57:09 +0000 (13:57 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:50 +0000 (21:56 +0000)
Now that we only call one sigscheme's entry point, we should
restructure this so it doesn't look like we call scheme->loadpriv in a
loop.

No functional change.

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

index b8dc2adee323ce23b2625ac6fe9a313901d0b388..790281df61fa4e48608fceb7f9335f135a7116db 100644 (file)
@@ -73,37 +73,36 @@ static struct sigprivkey_if *uncached_get(struct privcache *st,
     fclose(f); f=0;
 
     struct sigprivkey_if *sigpriv=0;
-    for (const struct sigscheme_info *scheme=sigschemes;
+    const struct sigscheme_info *scheme;
+    for (scheme=sigschemes;
         scheme->name;
-        scheme++) {
-       if (scheme->algid != id->b[GRPIDSZ])
-           continue;
-
-       st->databuf.start=st->databuf.base;
-       st->databuf.size=got;
-       struct cloc loc = { .file=st->path.buffer, .line=0 };
-       ok=scheme->loadpriv(scheme, &st->databuf, &sigpriv, log, loc);
-       if (ok) {
-           if (sigpriv->sethash) {
-               if (!st->defhash) {
-                   slilog(log,M_ERR,
+        scheme++)
+       if (scheme->algid == id->b[GRPIDSZ])
+           goto found;
+
+    slilog(log,M_ERR,"private key file %s not loaded (unknown algid)",
+          st->path.buffer);
+    goto out;
+
+ found:
+    st->databuf.start=st->databuf.base;
+    st->databuf.size=got;
+    struct cloc loc = { .file=st->path.buffer, .line=0 };
+    ok=scheme->loadpriv(scheme, &st->databuf, &sigpriv, log, loc);
+    if (!ok) goto out; /* loadpriv will have logged */
+
+    if (sigpriv->sethash) {
+       if (!st->defhash) {
+           slilog(log,M_ERR,
  "private key %s requires `hash' config key for privcache to load",
-                          st->path.buffer);
-                   sigpriv->dispose(sigpriv->st);
-                   sigpriv=0;
-                   goto out;
-               }
-               sigpriv->sethash(sigpriv->st,st->defhash);
-           }
+                  st->path.buffer);
+           sigpriv->dispose(sigpriv->st);
+           sigpriv=0;
            goto out;
        }
-       /* loadpriv will have logged */
-       goto out;
+       sigpriv->sethash(sigpriv->st,st->defhash);
     }
 
-    slilog(log,M_ERR,"private key file %s not loaded (unknown algid)",
-          st->path.buffer);
-
   out:
     if (f) fclose(f);
     return ok ? sigpriv : 0;