#include "hdm_allowlist.h"
#include "ICredentials.h"

int32_t get_app_name(Object credentials, char* app_name, size_t app_name_buf_sz, size_t* app_name_sz) {
  return ICredentials_getValueByName(credentials, "n", 1, app_name, app_name_buf_sz, app_name_sz);
}

uint32_t check_ta_cmd_permission(char* caller_ta_name, size_t caller_ta_name_len) {
  uint32_t ret = HDM_PERMISSION_DENIED;
  size_t i = 0;

  for (i = 0; i < (sizeof(hdm_ta_allowlist) / sizeof(hdm_ta_allowlist_t)); i++) {
    if (strlen(hdm_ta_allowlist[i].ta_name) == caller_ta_name_len) {
      if (!strncmp(hdm_ta_allowlist[i].ta_name, caller_ta_name, caller_ta_name_len)) {
          HDM_LOG("TA %s allowed", caller_ta_name);
          ret = HDM_STATUS_SUCCESS;
          break;
      }
    }
  }

exit:
  return ret;
}