776 } |
780 } |
777 } |
781 } |
778 |
782 |
779 return repo; |
783 return repo; |
780 } |
784 } |
|
785 |
|
786 int dav_config_keytype(DavCfgKeyType type) { |
|
787 switch(type) { |
|
788 default: break; |
|
789 case DAV_KEY_TYPE_AES256: return DAV_KEY_AES256; |
|
790 case DAV_KEY_TYPE_AES128: return DAV_KEY_AES128; |
|
791 } |
|
792 return 0; |
|
793 } |
|
794 |
|
795 int dav_config_register_keys(DavConfig *config, DavContext *ctx, dav_loadkeyfile_func loadkey) { |
|
796 for(DavCfgKey *key=config->keys;key;key=key->next) { |
|
797 char *file = cx_strdup_m(key->file.value).ptr; |
|
798 cxmutstr keycontent = loadkey(file); |
|
799 free(file); |
|
800 |
|
801 // TODO: check key length |
|
802 |
|
803 if(!keycontent.ptr) { |
|
804 return 1; |
|
805 } |
|
806 |
|
807 DavKey *davkey = calloc(1, sizeof(DavKey)); |
|
808 davkey->name = cx_strdup_m(key->name.value).ptr; |
|
809 davkey->type = dav_config_keytype(key->type); |
|
810 davkey->data = keycontent.ptr; |
|
811 davkey->length = keycontent.length; |
|
812 |
|
813 dav_context_add_key(ctx, davkey); |
|
814 } |
|
815 return 0; |
|
816 } |