Skip to content

Commit

Permalink
fix: introduce init method and use for enroll namespace list
Browse files Browse the repository at this point in the history
  • Loading branch information
srieteja committed Dec 18, 2024
1 parent e6fb8de commit acdc3ea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 1 addition & 2 deletions packages/atauth/src/auth_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ int main(int argc, char *argv[]) {
*/
// 3.1 Initialize and populate enrollment params structs
atcommons_enroll_namespace_list_t *ns_list = malloc(sizeof(atcommons_enroll_namespace_list_t));
if (ns_list == NULL) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Could not allocate memory for namespace list\n");
if((ret = atcommmons_init_enroll_namespace_list(ns_list)) != 0) {
goto enc_pub_key_exit;
}

Expand Down
9 changes: 9 additions & 0 deletions packages/atcommons/include/atcommons/enroll_namespace.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef ATCOMMONS_ENROLL_NAMESPACE_H
#define ATCOMMONS_ENROLL_NAMESPACE_H

#include <atlogger/atlogger.h>
#include <stddef.h>

typedef struct {
Expand All @@ -13,6 +14,14 @@ typedef struct {
atcommons_enroll_namespace_t *namespaces[];
} atcommons_enroll_namespace_list_t;

/**
* @brief intializes the provided atcommons_enroll_namespace_list_t struc
*
* @param ns_list pointer to the namespace list struct that needs to be initialized
* @return int 0 on success, non-zero int on failure
*/
int atcommmons_init_enroll_namespace_list(atcommons_enroll_namespace_list_t *ns_list);

/**
* @brief serializes enroll_namespace struct to JSON string
*
Expand Down
13 changes: 12 additions & 1 deletion packages/atcommons/src/enroll_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@

#define TAG "enroll_namespace"

int atcommmons_init_enroll_namespace_list(atcommons_enroll_namespace_list_t *ns_list) {
if(ns_list == NULL) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Memory not allocated for namespace list struct\n");
return -1;
}

memset(ns_list, 0, sizeof(atcommons_enroll_namespace_list_t));

return 0;
}

int atcommons_enroll_namespace_list_append(atcommons_enroll_namespace_list_t **ns_list,
atcommons_enroll_namespace_t *ns) {
if (ns == NULL) {
Expand Down Expand Up @@ -134,4 +145,4 @@ int atcommons_enroll_namespace_list_from_string(atcommons_enroll_namespace_list_
pos += strlen(json_str + pos) + 1;
}
exit: { return ret; }
}
}

0 comments on commit acdc3ea

Please sign in to comment.