Define OpenPGP constants and use them rather than magic numbers
[onak.git] / keydb_dynamic.c
index fa4b13b9fb6f9c01039e3246ad27360c7aad8c9f..ae2b8056870dba7a2a27c75c37ac5193fd275490 100644 (file)
@@ -19,6 +19,7 @@
 #include "mem.h"
 #include "merge.h"
 #include "onak-conf.h"
+#include "openpgp.h"
 #include "parsekey.h"
 #include "sendsync.h"
 
@@ -198,6 +199,23 @@ static int dynamic_fetch_key_text(const char *search,
        return -1;
 }
 
+static int dynamic_fetch_key_skshash(const struct skshash *hash,
+               struct openpgp_publickey **publickey)
+{
+       if (loaded_backend == NULL) {
+               load_backend();
+       }
+       
+       if (loaded_backend != NULL) {
+               if (loaded_backend->fetch_key_skshash != NULL) {
+                       return loaded_backend->fetch_key_skshash(hash,
+                                                               publickey);
+               }
+       }
+
+       return -1;
+}
+
 static int dynamic_iterate_keys(void (*iterfunc)(void *ctx,
                struct openpgp_publickey *key), void *ctx)
 {
@@ -238,7 +256,7 @@ static char *dynamic_keyid2uid(uint64_t keyid)
        if (dynamic_fetch_key(keyid, &publickey, false) && publickey != NULL) {
                curuid = publickey->uids;
                while (curuid != NULL && buf[0] == 0) {
-                       if (curuid->packet->tag == 13) {
+                       if (curuid->packet->tag == OPENPGP_PACKET_UID) {
                                snprintf(buf, 1023, "%.*s",
                                                (int) curuid->packet->length,
                                                curuid->packet->data);
@@ -487,6 +505,7 @@ struct dbfuncs keydb_dynamic_funcs = {
        .endtrans               = dynamic_endtrans,
        .fetch_key              = dynamic_fetch_key,
        .fetch_key_text         = dynamic_fetch_key_text,
+       .fetch_key_skshash      = dynamic_fetch_key_skshash,
        .store_key              = dynamic_store_key,
        .update_keys            = dynamic_update_keys,
        .delete_key             = dynamic_delete_key,