diff --git a/include/dap_cert.h b/include/dap_cert.h index db212d2484a8f5d12c69929db0cc3ccab74f0e41..82ce8d4cd85904489ad77dfd9956cb11496e128c 100755 --- a/include/dap_cert.h +++ b/include/dap_cert.h @@ -59,6 +59,7 @@ dap_cert_t * dap_cert_generate_mem(const char * a_cert_name, dap_enc_key_type_t dap_cert_t * dap_cert_add_file(const char * a_cert_name,const char *a_folder_path); int dap_cert_save_to_folder(dap_cert_t * a_cert, const char *a_file_dir_path); +const char* dap_cert_get_folder(int a_n_folder_path); void dap_cert_add_folder(const char *a_folder_path); void dap_cert_dump(dap_cert_t * a_cert); dap_pkey_t * dap_cert_to_pkey(dap_cert_t * a_cert); diff --git a/include/dap_hash.h b/include/dap_hash.h index 28d3977a2b9e73bd59216e39a4c6a28fc9e46918..32edf0125e53362d7ea3871fe343d438a5e53b6b 100755 --- a/include/dap_hash.h +++ b/include/dap_hash.h @@ -26,6 +26,7 @@ #include <stddef.h> #include <stdbool.h> #include <stdint.h> +#include <assert.h> #include "dap_common.h" #include "dap_hash_keccak.h" @@ -96,12 +97,12 @@ static inline bool dap_hash_fast_is_blank( dap_chain_hash_fast_t *a_hash ) DAP_STATIC_INLINE int dap_chain_hash_fast_to_str( dap_chain_hash_fast_t *a_hash, char *a_str, size_t a_str_max ) { - (void) a_str_max; - a_str[0] = '0'; - a_str[1] = 'x'; - a_str[ DAP_CHAIN_HASH_FAST_SIZE * 2 + 2 ] = 0; - dap_htoa64( (a_str + 2), a_hash->raw, DAP_CHAIN_HASH_FAST_SIZE ); - return DAP_CHAIN_HASH_FAST_SIZE * 2 + 2; + assert(a_str_max >= (DAP_CHAIN_HASH_FAST_SIZE * 2 + 2)); + a_str[0] = '0'; + a_str[1] = 'x'; + a_str[ DAP_CHAIN_HASH_FAST_SIZE * 2 + 2] = 0; + dap_htoa64((a_str + 2), a_hash->raw, DAP_CHAIN_HASH_FAST_SIZE); + return DAP_CHAIN_HASH_FAST_SIZE * 2 + 2; } static inline char *dap_chain_hash_fast_to_str_new(dap_chain_hash_fast_t * a_hash) diff --git a/src/dap_cert.c b/src/dap_cert.c index a9fb97bfeef962c07a4392467d82ec5fa56dc520..4c00e0763cb350276663e6d035b12a6fddcd1735 100755 --- a/src/dap_cert.c +++ b/src/dap_cert.c @@ -54,6 +54,12 @@ typedef struct dap_cert_item UT_hash_handle hh; } dap_cert_item_t; +typedef struct dap_cert_folder +{ + char *name; + UT_hash_handle hh; +} dap_cert_folder_t; + typedef struct dap_cert_pvt { dap_sign_item_t *signs; @@ -63,6 +69,7 @@ typedef struct dap_cert_pvt #define PVT(a) ( ( dap_cert_pvt_t *)((a)->_pvt) ) static dap_cert_item_t * s_certs = NULL; +static dap_cert_folder_t * s_cert_folders = NULL; /** * @brief dap_cert_init @@ -444,6 +451,25 @@ void dap_cert_dump(dap_cert_t * a_cert) printf ("Certificates signatures chain size: %lu\n",dap_cert_count_cert_sign (a_cert)); } +/** + * @brief dap_cert_get_folder + * @param a_folder_path + */ +const char* dap_cert_get_folder(int a_n_folder_path) +{ + dap_cert_folder_t *l_cert_folder_item = NULL, *l_cert_folder_item_tmp = NULL; + int l_n_cur_folder_path = 0; + HASH_ITER(hh, s_cert_folders, l_cert_folder_item, l_cert_folder_item_tmp) + { + if(l_cert_folder_item) { + if(a_n_folder_path == l_n_cur_folder_path) + return l_cert_folder_item->name; + l_n_cur_folder_path++; + } + } + return NULL; +} + /** * @brief dap_cert_add_folder @@ -451,6 +477,13 @@ void dap_cert_dump(dap_cert_t * a_cert) */ void dap_cert_add_folder(const char *a_folder_path) { + // save dir + { + dap_cert_folder_t * l_cert_folder_item = DAP_NEW_Z(dap_cert_folder_t); + l_cert_folder_item->name = dap_strdup(a_folder_path); + HASH_ADD_STR(s_cert_folders, name, l_cert_folder_item); + } + DIR * l_dir = opendir(a_folder_path); if( l_dir ) { struct dirent * l_dir_entry; @@ -471,9 +504,9 @@ void dap_cert_add_folder(const char *a_folder_path) DAP_DELETE(l_cert_name); } } - } closedir(l_dir); + log_it(L_NOTICE, "Added folder %s",a_folder_path); }else log_it(L_WARNING, "Can't add folder %s to cert manager",a_folder_path);