Skip to content
Snippets Groups Projects
Commit 524bb296 authored by alexander.lysikov's avatar alexander.lysikov
Browse files

added dap_cert_get_folder()

parent 1688d692
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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)
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment