chiark / gitweb /
pubkeys: Introduce `fill' variable to make code prettier
[secnet.git] / pubkeys.fl.pl
index 43df2e16593cff2bfeda6ae9cec81cbd2d2c71bf..ec1cba60610dcbe5edd996059c9eaac1f51faeba 100755 (executable)
@@ -161,6 +161,7 @@ struct pubkeyset_context {
     /* filled in during setup: */
     struct cloc loc; /* line is runtime */
     struct log_if *log;
+    struct hash_if *defhash;
     struct buffer_if *data_buf;
     struct peer_keyset *building;
     /* runtime: */
@@ -230,13 +231,19 @@ static struct pubkeyset_context c[1];
     bool_t ok=c->scheme->loadpub(c->scheme,c->data_buf,
                                 &pubkey,c->log,c->loc);
     if (!ok) break;
-    memcpy(c->building->keys[c->building->nkeys].id.b,
-          c->grpid,
-           GRPIDSZ);
+    if (pubkey->sethash) {
+       if (!c->defhash) {
+           pubkey->dispose(pubkey->st);
+           DOSKIP("public key requires default hash to load");
+       }
+       pubkey->sethash(pubkey->st,c->defhash);
+    }
+    struct peer_pubkey *fill=&c->building->keys[c->building->nkeys];
+    memcpy(fill->id.b,c->grpid,GRPIDSZ);
     assert(ALGIDSZ==1); /* otherwise need htons or htonl or something */
-    c->building->keys[c->building->nkeys].id.b[GRPIDSZ]=
-      c->scheme->algid;
-    c->building->keys[c->building->nkeys++].pubkey=pubkey;
+    fill->id.b[GRPIDSZ]=c->scheme->algid;
+    fill->pubkey=pubkey;
+    c->building->nkeys++;
 !}
 
 !KEYWORD serial
@@ -283,9 +290,11 @@ static struct pubkeyset_context c[1];
 
 extern struct peer_keyset *
 keyset_load(const char *path, struct buffer_if *data_buf,
-           struct log_if *log, int logcl_enoent) {
+           struct log_if *log, int logcl_enoent,
+           struct hash_if *defhash) {
     assert(!c->building);
     c->log=log;
+    c->defhash=defhash;
     c->loc.file=path;
     pkyyin = fopen(path, "r");
     if (!pkyyin) {
@@ -311,10 +320,6 @@ keyset_load(const char *path, struct buffer_if *data_buf,
     int r=pkyylex();
     if (r) goto err_bad;
 
-    if (!c->had_serial) {
-       slilog(LI,M_ERR,"missing serial number in %s",path);
-       goto err_bad;
-    }
     if (!c->building->nkeys) {
        slilog(LI,M_ERR,"no useable keys in %s",path);
        goto err_bad;