--- a/libidav/config.c Sat Sep 30 16:33:47 2023 +0200 +++ b/libidav/config.c Sat Sep 30 17:26:00 2023 +0200 @@ -160,6 +160,10 @@ return config; } +void dav_config_free(DavConfig *config) { + cxMempoolDestroy(config->mp); +} + CxBuffer* dav_config2buf(DavConfig *config) { xmlChar* xmlText = NULL; int textLen = 0; @@ -778,3 +782,35 @@ return repo; } + +int dav_config_keytype(DavCfgKeyType type) { + switch(type) { + default: break; + case DAV_KEY_TYPE_AES256: return DAV_KEY_AES256; + case DAV_KEY_TYPE_AES128: return DAV_KEY_AES128; + } + return 0; +} + +int dav_config_register_keys(DavConfig *config, DavContext *ctx, dav_loadkeyfile_func loadkey) { + for(DavCfgKey *key=config->keys;key;key=key->next) { + char *file = cx_strdup_m(key->file.value).ptr; + cxmutstr keycontent = loadkey(file); + free(file); + + // TODO: check key length + + if(!keycontent.ptr) { + return 1; + } + + DavKey *davkey = calloc(1, sizeof(DavKey)); + davkey->name = cx_strdup_m(key->name.value).ptr; + davkey->type = dav_config_keytype(key->type); + davkey->data = keycontent.ptr; + davkey->length = keycontent.length; + + dav_context_add_key(ctx, davkey); + } + return 0; +}