chiark / gitweb /
rsa: sharing load_ctx: Code motion
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 23 Nov 2019 11:16:06 +0000 (11:16 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:49 +0000 (21:56 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
rsa.c

diff --git a/rsa.c b/rsa.c
index be803b1161acaa4c5d1f41f4a0da4b7389279e2f..e4d62ad10f2c4b13ad60a5ad8ed63e1a7821cc5d 100644 (file)
--- a/rsa.c
+++ b/rsa.c
@@ -45,6 +45,38 @@ struct rsacommon {
     uint8_t *hashbuf;
 };
 
+struct rsapriv_load_ctx {
+    void (*verror)(struct rsapriv_load_ctx *l,
+                  FILE *maybe_f, bool_t unsup,
+                  const char *message, va_list args);
+    bool_t (*postreadcheck)(struct rsapriv_load_ctx *l, FILE *f);
+    union {
+       struct {
+           struct cloc loc;
+       } apply;
+       struct {
+           struct log_if *log;
+       } tryload;
+    } u;
+};
+
+FORMAT(printf,4,0)
+static void verror_tryload(struct rsapriv_load_ctx *l,
+                          FILE *maybe_f, bool_t unsup,
+                          const char *message, va_list args)
+{
+    int class=unsup ? M_DEBUG : M_ERR;
+    slilog_part(l->u.tryload.log,class,"rsa1priv load: ");
+    vslilog(l->u.tryload.log,class,message,args);
+}
+
+static void verror_cfgfatal(struct rsapriv_load_ctx *l,
+                           FILE *maybe_f, bool_t unsup,
+                           const char *message, va_list args)
+{
+    vcfgfatal_maybefile(maybe_f,l->u.apply.loc,"rsa-private",message,args);
+}
+
 struct rsapriv {
     closure_t cl;
     struct sigprivkey_if ops;
@@ -328,20 +360,14 @@ static list_t *rsapub_apply(closure_t *self, struct cloc loc, dict_t *context,
     return new_closure(&st->cl);
 }
 
-struct rsapriv_load_ctx {
-    void (*verror)(struct rsapriv_load_ctx *l,
-                  FILE *maybe_f, bool_t unsup,
-                  const char *message, va_list args);
-    bool_t (*postreadcheck)(struct rsapriv_load_ctx *l, FILE *f);
-    union {
-       struct {
-           struct cloc loc;
-       } apply;
-       struct {
-           struct log_if *log;
-       } tryload;
-    } u;
-};
+static void load_error(struct rsapriv_load_ctx *l, FILE *maybe_f,
+                      bool_t unsup, const char *fmt, ...)
+{
+    va_list al;
+    va_start(al,fmt);
+    l->verror(l,maybe_f,unsup,fmt,al);
+    va_end(al);
+}
 
 #define LDFATAL(...)      ({ load_error(l,0,0,__VA_ARGS__); goto error_out; })
 #define LDUNSUP(...)      ({ load_error(l,0,1,__VA_ARGS__); goto error_out; })
@@ -372,15 +398,6 @@ static uint16_t keyfile_get_16(struct rsapriv_load_ctx *l, FILE *f)
     return r;
 }
 
-static void load_error(struct rsapriv_load_ctx *l, FILE *maybe_f,
-                      bool_t unsup, const char *fmt, ...)
-{
-    va_list al;
-    va_start(al,fmt);
-    l->verror(l,maybe_f,unsup,fmt,al);
-    va_end(al);
-}
-
 static void rsapriv_dispose(void *sst)
 {
     struct rsapriv *st=sst;
@@ -621,16 +638,6 @@ error_out:
     goto out;
 }
 
-FORMAT(printf,4,0)
-static void verror_tryload(struct rsapriv_load_ctx *l,
-                          FILE *maybe_f, bool_t unsup,
-                          const char *message, va_list args)
-{
-    int class=unsup ? M_DEBUG : M_ERR;
-    slilog_part(l->u.tryload.log,class,"rsa1priv load: ");
-    vslilog(l->u.tryload.log,class,message,args);
-}
-
 static bool_t postreadcheck_tryload(struct rsapriv_load_ctx *l, FILE *f)
 {
     assert(!ferror(f));
@@ -674,13 +681,6 @@ bool_t rsa1_loadpriv(const struct sigscheme_info *algo,
     return True;
 }
 
-static void verror_cfgfatal(struct rsapriv_load_ctx *l,
-                           FILE *maybe_f, bool_t unsup,
-                           const char *message, va_list args)
-{
-    vcfgfatal_maybefile(maybe_f,l->u.apply.loc,"rsa-private",message,args);
-}
-
 static bool_t postreadcheck_apply(struct rsapriv_load_ctx *l, FILE *f)
 {
     cfgfile_postreadcheck(l->u.apply.loc,f);