diff --git a/inc/csuit/suit_common.h b/inc/csuit/suit_common.h index 513f9aa..1f7bdb0 100644 --- a/inc/csuit/suit_common.h +++ b/inc/csuit/suit_common.h @@ -595,7 +595,6 @@ typedef struct suit_parameters { bool boolean; bool isNull; suit_digest_t digest; - suit_version_match_t version_match; } value; } suit_parameters_t; diff --git a/inc/csuit/suit_manifest_decode.h b/inc/csuit/suit_manifest_decode.h index b7dc21e..07d7a9a 100644 --- a/inc/csuit/suit_manifest_decode.h +++ b/inc/csuit/suit_manifest_decode.h @@ -67,17 +67,16 @@ suit_err_t suit_decode_dependencies_from_item(suit_decode_mode_t mode, bool next, suit_dependencies_t *dependencies); -suit_err_t suit_decode_version_match(QCBORDecodeContext *context, - QCBORItem *item, - bool next, - suit_version_match_t *version_match); - suit_err_t suit_decode_wait_event_from_item(QCBORDecodeContext *context, QCBORItem *item, bool next, suit_wait_event_t *wait_event); +suit_err_t suit_decode_version_match(const suit_buf_t *buf, + suit_version_match_t *version_match); suit_err_t suit_decode_wait_event(const suit_buf_t *buf, suit_wait_event_t *wait_event); +suit_err_t suit_decode_component_metadata(const suit_buf_t *buf, + suit_component_metadata_t *component_metadata); #ifdef __cplusplus } diff --git a/src/suit_manifest_decode.c b/src/suit_manifest_decode.c index 205f6f3..a2de9f4 100644 --- a/src/suit_manifest_decode.c +++ b/src/suit_manifest_decode.c @@ -127,21 +127,14 @@ suit_err_t suit_decode_version_match_from_item(QCBORDecodeContext *context, return SUIT_SUCCESS; } -suit_err_t suit_decode_version_match_from_bstr(QCBORDecodeContext *context, - QCBORItem *item, - bool next, - suit_version_match_t *version_match) +suit_err_t suit_decode_version_match(const suit_buf_t *buf, + suit_version_match_t *version_match) { - suit_err_t result = suit_qcbor_get(context, item, next, QCBOR_TYPE_BYTE_STRING); - QCBORDecodeContext version_context; - /* NOTE: SUIT_Text_Map may contain component-identifier key, - so we parse as QCBOR_DECODE_MODE_MAP_AS_ARRAY - to prevent invalid CBOR Map */ - QCBORDecode_Init(&version_context, - (UsefulBufC){item->val.string.ptr, item->val.string.len}, - QCBOR_DECODE_MODE_MAP_AS_ARRAY); - result = suit_decode_version_match_from_item(&version_context, item, true, version_match); - QCBORError error = QCBORDecode_Finish(&version_context); + QCBORDecodeContext version_match_context; + QCBORItem item; + QCBORDecode_Init(&version_match_context, (UsefulBufC){buf->ptr, buf->len}, QCBOR_DECODE_MODE_NORMAL); + suit_err_t result = suit_decode_version_match_from_item(&version_match_context, &item, true, version_match); + QCBORError error = QCBORDecode_Finish(&version_match_context); if (error != QCBOR_SUCCESS && result == SUIT_SUCCESS) { result = suit_error_from_qcbor_error(error); } @@ -237,6 +230,211 @@ suit_err_t suit_decode_wait_event(const suit_buf_t *buf, } #endif /* !LIBCSUIT_DISABLE_PARAMETER_WAIT_INFO */ +#if !defined(LIBCSUIT_DISABLE_PARAMETER_COMPONENT_METADATA) +suit_err_t suit_decode_actor_id_from_item(QCBORDecodeContext *context, + QCBORItem *item, + bool next, + bool from_label, + suit_actor_id_t *actor_id) +{ + // UUID_Tagged, bstr, tstr, int + suit_err_t result = suit_qcbor_get(context, item, next, QCBOR_TYPE_ANY); + if (result != SUIT_SUCCESS) { + return result; + } + if (from_label) { + switch (item->uLabelType) { + case QCBOR_TYPE_BYTE_STRING: + if (item->uTags[0] == 37) { + // UUID_Tagged + actor_id->type = SUIT_ACTOR_TYPE_UUID_TAGGED; + } + else if (item->uTags[0] != 0) { + // invalid + return SUIT_ERR_INVALID_VALUE; + } + else { + actor_id->type = SUIT_ACTOR_TYPE_BSTR; + } + actor_id->actor_id_str.ptr = (uint8_t *)item->label.string.ptr; + actor_id->actor_id_str.len = item->label.string.len; + break; + case QCBOR_TYPE_TEXT_STRING: + actor_id->type = SUIT_ACTOR_TYPE_TSTR; + actor_id->actor_id_str.ptr = (uint8_t *)item->label.string.ptr; + actor_id->actor_id_str.len = item->label.string.len; + break; + case QCBOR_TYPE_INT64: + actor_id->type = SUIT_ACTOR_TYPE_INT; + actor_id->actor_id_i64 = item->label.int64; + break; + default: + return SUIT_ERR_INVALID_TYPE_OF_KEY; + } + } + else { + switch (item->uDataType) { + case QCBOR_TYPE_BYTE_STRING: + if (item->uTags[0] == 37) { + // UUID_Tagged + actor_id->type = SUIT_ACTOR_TYPE_UUID_TAGGED; + } + else if (item->uTags[0] != 0) { + // invalid + return SUIT_ERR_INVALID_VALUE; + } + else { + actor_id->type = SUIT_ACTOR_TYPE_BSTR; + } + actor_id->actor_id_str.ptr = (uint8_t *)item->val.string.ptr; + actor_id->actor_id_str.len = item->val.string.len; + break; + case QCBOR_TYPE_TEXT_STRING: + actor_id->type = SUIT_ACTOR_TYPE_TSTR; + actor_id->actor_id_str.ptr = (uint8_t *)item->val.string.ptr; + actor_id->actor_id_str.len = item->val.string.len; + break; + case QCBOR_TYPE_INT64: + actor_id->type = SUIT_ACTOR_TYPE_INT; + actor_id->actor_id_i64 = item->val.int64; + break; + default: + return SUIT_ERR_INVALID_TYPE_OF_KEY; + } + } + return result; +} + +suit_err_t suit_decode_actor_id_from_item_label(QCBORDecodeContext *context, + QCBORItem *item, + bool next, + suit_actor_id_t *actor_id) +{ + return suit_decode_actor_id_from_item(context, item, next, true, actor_id); +} + +suit_err_t suit_decode_actor_id_from_item_value(QCBORDecodeContext *context, + QCBORItem *item, + bool next, + suit_actor_id_t *actor_id) +{ + return suit_decode_actor_id_from_item(context, item, next, false, actor_id); +} + +suit_err_t suit_decode_permissions(QCBORDecodeContext *context, + QCBORItem *item, + suit_permissions_t *permissions) +{ + suit_err_t result = suit_qcbor_get_next_uint(context, item); + if (result != SUIT_SUCCESS) { + return result; + } + permissions->val = item->val.uint64; + return SUIT_SUCCESS; +} + +suit_err_t suit_decode_permission_map(QCBORDecodeContext *context, + QCBORItem *item, + bool next, + suit_permission_map_t *permissions) +{ + suit_err_t result = suit_qcbor_get(context, item, next, QCBOR_TYPE_MAP); + if (result != SUIT_SUCCESS) { + return result; + } + permissions->len = item->val.uCount; + if (permissions->len > SUIT_MAX_ARGS_LENGTH) { + return SUIT_ERR_NO_MEMORY; + } + + for (size_t i = 0; i < permissions->len; i++) { + result = suit_decode_permissions(context, item, &permissions->permission_map[i].permissions); + if (result != SUIT_SUCCESS) { + return result; + } + result = suit_decode_actor_id_from_item_label(context, item, false, &permissions->permission_map[i].actor); + if (result != SUIT_SUCCESS) { + return result; + } + } + return SUIT_SUCCESS; +} + +suit_err_t suit_decode_component_metadata_from_item(QCBORDecodeContext *context, + QCBORItem *item, + bool next, + suit_component_metadata_t *component_metadata) +{ + suit_err_t result = suit_qcbor_get(context, item, next, QCBOR_TYPE_MAP); + if (result != SUIT_SUCCESS) { + return result; + } + size_t map_count = item->val.uCount; + + for (size_t i = 0; i < map_count; i++) { + QCBORDecode_PeekNext(context, item); + if (item->uLabelType != QCBOR_TYPE_INT64) { + return SUIT_ERR_INVALID_TYPE_OF_KEY; + } + switch (item->label.int64) { + /* int */ + case SUIT_META_DEFAULT_PERMISSIONS: + component_metadata->exists |= SUIT_META_CONTAINS_DEFAULT_PERMISSIONS; + result = suit_decode_permissions(context, item, &component_metadata->default_permissions); + break; + case SUIT_META_USER_PERMISSIONS: + component_metadata->exists |= SUIT_META_CONTAINS_USER_PERMISSIONS; + result = suit_decode_permission_map(context, item, true, &component_metadata->user_permissions); + break; + case SUIT_META_GROUP_PERMISSIONS: + component_metadata->exists |= SUIT_META_CONTAINS_GROUP_PERMISSIONS; + result = suit_decode_permission_map(context, item, true, &component_metadata->group_permissions); + break; + case SUIT_META_ROLE_PERMISSIONS: + component_metadata->exists |= SUIT_META_CONTAINS_ROLE_PERMISSIONS; + result = suit_decode_permission_map(context, item, true, &component_metadata->role_permissions); + break; + case SUIT_META_FILE_TYPE: + component_metadata->exists |= SUIT_META_CONTAINS_FILE_TYPE; + QCBORDecode_GetInt64(context, &component_metadata->filetype); + break; + case SUIT_META_MODIFICATION_TIME: + component_metadata->exists |= SUIT_META_CONTAINS_MODIFICATION_TIME; + QCBORDecode_GetInt64(context, &component_metadata->modification_time); + break; + case SUIT_META_CREATION_TIME: + component_metadata->exists |= SUIT_META_CONTAINS_CREATION_TIME; + QCBORDecode_GetInt64(context, &component_metadata->creation_time); + break; + case SUIT_META_CREATOR: + component_metadata->exists |= SUIT_META_CONTAINS_CREATOR; + result = suit_decode_actor_id_from_item_value(context, item, true, &component_metadata->creator); + break; + default: + return SUIT_ERR_NOT_IMPLEMENTED; + } + if (result != SUIT_SUCCESS) { + return result; + } + } + return SUIT_SUCCESS; +} + +suit_err_t suit_decode_component_metadata(const suit_buf_t *buf, + suit_component_metadata_t *component_metadata) +{ + QCBORDecodeContext component_metadata_context; + QCBORItem item; + QCBORDecode_Init(&component_metadata_context, (UsefulBufC){buf->ptr, buf->len}, QCBOR_DECODE_MODE_NORMAL); + suit_err_t result = suit_decode_component_metadata_from_item(&component_metadata_context, &item, true, component_metadata); + QCBORError error = QCBORDecode_Finish(&component_metadata_context); + if (error != QCBOR_SUCCESS && result == SUIT_SUCCESS) { + result = suit_error_from_qcbor_error(error); + } + return result; +} +#endif /* !LIBCSUIT_DISABLE_PARAMETER_COMPONENT_METADATA */ + suit_err_t suit_decode_parameters_list_from_item(const suit_decode_mode_t mode, QCBORDecodeContext *context, QCBORItem *item, @@ -335,10 +533,19 @@ suit_err_t suit_decode_parameters_list_from_item(const suit_decode_mode_t mode, case SUIT_PARAMETER_ENCRYPTION_INFO: #endif - /* bstr .cbor SUIT_Wait_Event */ /* draft-ietf-suit-update-management */ +#if !defined(LIBCSUIT_DISABLE_PARAMETER_VERSION) + /* bstr .cbor SUIT_Parameter_Version_Match */ + case SUIT_PARAMETER_VERSION: +#endif + #if !defined(LIBCSUIT_DISABLE_PARAMETER_WAIT_INFO) + /* bstr .cbor SUIT_Wait_Event */ case SUIT_PARAMETER_WAIT_INFO: +#endif +#if !defined(LIBCSUIT_DISABLE_PARAMETER_COMPONENT_METADATA) + /* bstr .cbor SUIT_Component_Metadata */ + case SUIT_PARAMETER_COMPONENT_METADATA: #endif if (item->uDataType != QCBOR_TYPE_BYTE_STRING) { result = SUIT_ERR_INVALID_TYPE_OF_VALUE; @@ -374,12 +581,6 @@ suit_err_t suit_decode_parameters_list_from_item(const suit_decode_mode_t mode, result = suit_decode_digest_from_bstr(mode, context, item, false, ¶ms_list->params[i].value.digest); break; - /* SUIT_Parameter_Version_Match */ -#if !defined(LIBCSUIT_DISABLE_PARAMETER_VERSION) - case SUIT_PARAMETER_VERSION: - result = suit_decode_version_match_from_bstr(context, item, false, ¶ms_list->params[i].value.version_match); - break; -#endif default: result = SUIT_ERR_NOT_IMPLEMENTED; diff --git a/src/suit_manifest_encode.c b/src/suit_manifest_encode.c index 0a0c0b3..abc5270 100644 --- a/src/suit_manifest_encode.c +++ b/src/suit_manifest_encode.c @@ -265,14 +265,24 @@ suit_err_t suit_append_directive_override_parameters(const suit_parameters_list_ #if !defined(LIBCSUIT_DISABLE_PARAMETER_FETCH_ARGS) case SUIT_PARAMETER_FETCH_ARGS: #endif + /* draft-ietf-suit-firmware-encryption */ #if !defined(LIBCSUIT_DISABLE_PARAMETER_ENCRYPTION_INFO) case SUIT_PARAMETER_ENCRYPTION_INFO: #endif + /* draft-ietf-suit-update-management */ - /* bstr .cbor SUIT_Wait_Event */ +#if !defined(LIBCSUIT_DISABLE_PARAMETER_VERSION) + /* bstr .cbor SUIT_Parameter_Version_Match */ + case SUIT_PARAMETER_VERSION: +#endif #if !defined(LIBCSUIT_DISABLE_PARAMETER_WAIT_INFO) + /* bstr .cbor SUIT_Wait_Event */ case SUIT_PARAMETER_WAIT_INFO: +#endif +#if !defined(LIBCSUIT_DISABLE_PARAMETER_COMPONENT_INDEX) + /* bstr .cbor SUIT_Component_Metadata */ + case SUIT_PARAMETER_COMPONENT_METADATA: #endif QCBOREncode_AddBytesToMapN(context, param->label, (UsefulBufC){.ptr = param->value.string.ptr, .len = param->value.string.len}); break; @@ -297,22 +307,6 @@ suit_err_t suit_append_directive_override_parameters(const suit_parameters_list_ QCBOREncode_CloseBstrWrap(context, NULL); break; - /* SUIT_Parameter_Version_Match */ -#if !defined(LIBCSUIT_DISABLE_CONDITION_VERSION) - case SUIT_PARAMETER_VERSION: - QCBOREncode_BstrWrapInMapN(context, param->label); - QCBOREncode_OpenArray(context); - QCBOREncode_AddInt64(context, param->value.version_match.type); - QCBOREncode_OpenArray(context); - for (size_t j = 0; j < param->value.version_match.value.len; j++) { - QCBOREncode_AddInt64(context, param->value.version_match.value.int64[j]); - } - QCBOREncode_CloseArray(context); - QCBOREncode_CloseArray(context); - QCBOREncode_CloseBstrWrap(context, NULL); - break; -#endif /* !LIBCSUIT_DISABLE_CONDITION_VERSION */ - default: result = SUIT_ERR_NOT_IMPLEMENTED; } diff --git a/src/suit_manifest_print.c b/src/suit_manifest_print.c index f044624..41a72d5 100644 --- a/src/suit_manifest_print.c +++ b/src/suit_manifest_print.c @@ -269,6 +269,8 @@ char* suit_parameter_key_to_str(suit_parameter_key_t parameter) return "soft-failure"; case SUIT_PARAMETER_IMAGE_SIZE: return "image-size"; + case SUIT_PARAMETER_FETCH_ARGS: + return "fetch-args"; case SUIT_PARAMETER_CONTENT: return "content"; case SUIT_PARAMETER_ENCRYPTION_INFO: @@ -289,8 +291,8 @@ char* suit_parameter_key_to_str(suit_parameter_key_t parameter) return "version"; case SUIT_PARAMETER_WAIT_INFO: return "wait-info"; - case SUIT_PARAMETER_FETCH_ARGS: - return "fetch-args"; + case SUIT_PARAMETER_COMPONENT_METADATA: + return "component-metadata"; case SUIT_PARAMETER_INVALID: break; } @@ -896,9 +898,9 @@ suit_err_t suit_print_encryption_info(const suit_buf_t *encryption_info, return result; } -suit_err_t suit_print_version(const suit_version_match_t *version_match, - const uint32_t indent_space, - const uint32_t indent_delta) +suit_err_t suit_print_version_match(const suit_version_match_t *version_match, + const uint32_t indent_space, + const uint32_t indent_delta) { printf("[\n"); printf("%*s/ comparison-type / %d / %s /,\n", indent_space + indent_delta, "", version_match->type, suit_version_comparison_type_to_str(version_match->type)); @@ -914,6 +916,25 @@ suit_err_t suit_print_version(const suit_version_match_t *version_match, return SUIT_SUCCESS; } +suit_err_t suit_print_version_buf(const suit_buf_t *version_match_buf, + const uint32_t indent_space, + const uint32_t indent_delta) +{ + printf("<< "); + suit_err_t result = SUIT_SUCCESS; + if (version_match_buf->ptr != NULL && version_match_buf->len > 0) { + suit_version_match_t version_match = {0}; + result = suit_decode_version_match(version_match_buf, &version_match); + if (result != SUIT_SUCCESS) { + return result; + } + result = suit_print_version_match(&version_match, indent_space, indent_delta); + } + printf(" >>"); + + return SUIT_SUCCESS; +} + suit_err_t suit_print_wait_event(const suit_wait_event_t *wait_event, const uint32_t indent_space, const uint32_t indent_delta) @@ -952,7 +973,7 @@ suit_err_t suit_print_wait_event(const suit_wait_event_t *wait_event, printf(",\n%*s/ version: / [\n", indent_space + 2 * indent_delta, ""); for (size_t i = 0; i < wait_event->other_device_version.len; i++) { printf("%*s", indent_space + 3 * indent_delta, ""); - suit_print_version(&wait_event->other_device_version.versions[i], indent_space + 4 * indent_delta, indent_delta); + suit_print_version_match(&wait_event->other_device_version.versions[i], indent_space + 4 * indent_delta, indent_delta); if (i + 1 != wait_event->other_device_version.len) { printf(","); } @@ -983,7 +1004,7 @@ suit_err_t suit_print_wait_event(const suit_wait_event_t *wait_event, printf("%*s/ day-of-week / 7: %lu", indent_space + indent_delta, "", wait_event->day_of_week); comma = true; } - printf("\n%*s} ", indent_space, ""); + printf("\n%*s}", indent_space, ""); return SUIT_SUCCESS; } @@ -998,14 +1019,267 @@ suit_err_t suit_print_wait_event_buf(const suit_buf_t *wait_event_buf, printf("<< "); suit_err_t result = SUIT_SUCCESS; if (wait_event_buf->ptr != NULL && wait_event_buf->len > 0) { - suit_wait_event_t wait_event; + suit_wait_event_t wait_event = {0}; result = suit_decode_wait_event(wait_event_buf, &wait_event); if (result != SUIT_SUCCESS) { return result; } result = suit_print_wait_event(&wait_event, indent_space, indent_delta); } - printf(">>"); + printf(" >>"); + return result; +} + +suit_err_t suit_print_permissions(const suit_permissions_t permissions) +{ + bool pipe = false; + printf("%lu / (", permissions.val); + + if (permissions.write_attr_ex) { + if (pipe) { + printf("|"); + } + printf("write_attr_ex"); + pipe = true; + } + if (permissions.read_attr_ex) { + if (pipe) { + printf("|"); + } + printf("read_attr_ex"); + pipe = true; + } + if (permissions.sync) { + if (pipe) { + printf("|"); + } + printf("sync"); + pipe = true; + } + if (permissions.delete) { + if (pipe) { + printf("|"); + } + printf("delete"); + pipe = true; + } + if (permissions.recurse_delete) { + if (pipe) { + printf("|"); + } + printf("recurse_delete"); + pipe = true; + } + if (permissions.write_attr) { + if (pipe) { + printf("|"); + } + printf("write_attr"); + pipe = true; + } + if (permissions.change_owner) { + if (pipe) { + printf("|"); + } + printf("change_owner"); + pipe = true; + } + if (permissions.change_perm) { + if (pipe) { + printf("|"); + } + printf("change_perm"); + pipe = true; + } + if (permissions.read_perm) { + if (pipe) { + printf("|"); + } + printf("read_perm"); + pipe = true; + } + if (permissions.read_attr) { + if (pipe) { + printf("|"); + } + printf("read_attr"); + pipe = true; + } + if (permissions.creatdir_append) { + if (pipe) { + printf("|"); + } + printf("creatdir_append"); + pipe = true; + } + if (permissions.list_read) { + if (pipe) { + printf("|"); + } + printf("list_read"); + pipe = true; + } + if (permissions.create_write) { + if (pipe) { + printf("|"); + } + printf("create_write"); + pipe = true; + } + if (permissions.traverse_exec) { + if (pipe) { + printf("|"); + } + printf("traverse_exec"); + pipe = true; + } + printf(") /"); + return SUIT_SUCCESS; +} + +suit_err_t suit_print_actor_id(const suit_actor_id_t *actor) +{ + switch (actor->type) { + case SUIT_ACTOR_TYPE_UUID_TAGGED: + printf("/ UUID_Tagged / 37("); + suit_print_uuid(&actor->actor_id_str); + printf(")"); + break; + case SUIT_ACTOR_TYPE_BSTR: + suit_print_hex(actor->actor_id_str.ptr, actor->actor_id_str.len); + break; + case SUIT_ACTOR_TYPE_TSTR: + suit_print_tstr((char *)actor->actor_id_str.ptr, actor->actor_id_str.len); + break; + case SUIT_ACTOR_TYPE_INT: + printf("%ld", actor->actor_id_i64); + break; + default: + return SUIT_ERR_NOT_IMPLEMENTED; + } + return SUIT_SUCCESS; +} + +suit_err_t suit_print_permission_map(const suit_permission_map_t *permission_map, + const uint32_t indent_space, + const uint32_t indent_delta) +{ + for (size_t i = 0; i < permission_map->len; i++) { + printf("%*s", indent_space, ""); + suit_print_actor_id(&permission_map->permission_map[i].actor); + printf(": "); + suit_print_permissions(permission_map->permission_map[i].permissions); + if (i + 1 != permission_map->len) { + printf(","); + } + printf("\n"); + } + return SUIT_SUCCESS; +} + +suit_err_t suit_print_component_metadata(const suit_component_metadata_t *component_metadata, + const uint32_t indent_space, + const uint32_t indent_delta) +{ + bool comma = false; + printf("{\n"); + + if (component_metadata->exists & SUIT_META_CONTAINS_DEFAULT_PERMISSIONS) { + if (comma) { + printf(",\n"); + } + printf("%*s/ default-permissions / 1: ", indent_space + indent_delta, ""); + suit_print_permissions(component_metadata->default_permissions); + comma = true; + } + if (component_metadata->exists & SUIT_META_CONTAINS_USER_PERMISSIONS) { + if (comma) { + printf(",\n"); + } + printf("%*s/ user-permissions / 2: {\n", indent_space + indent_delta, ""); + suit_print_permission_map(&component_metadata->user_permissions, indent_space + 2 * indent_delta, indent_delta); + printf("%*s}", indent_space + indent_delta, ""); + comma = true; + } + if (component_metadata->exists & SUIT_META_CONTAINS_GROUP_PERMISSIONS) { + if (comma) { + printf(",\n"); + } + printf("%*s/ group-permissions / 3: {\n", indent_space + indent_delta, ""); + suit_print_permission_map(&component_metadata->group_permissions, indent_space + 2 * indent_delta, indent_delta); + printf("%*s}", indent_space + indent_delta, ""); + comma = true; + } + if (component_metadata->exists & SUIT_META_CONTAINS_ROLE_PERMISSIONS) { + if (comma) { + printf(",\n"); + } + printf("%*s/ role-permissions / 4: {\n", indent_space + indent_delta, ""); + suit_print_permission_map(&component_metadata->role_permissions, indent_space + 2 * indent_delta, indent_delta); + printf("%*s}", indent_space + indent_delta, ""); + comma = true; + } + if (component_metadata->exists & SUIT_META_CONTAINS_FILE_TYPE) { + if (comma) { + printf(",\n"); + } + printf("%*s/ file-type / 5: ", indent_space + indent_delta, ""); + switch (component_metadata->filetype) { + case SUIT_FILETYPE_REGULAR: + printf("1 / regular /"); + break; + case SUIT_FILETYPE_DIRECTORY: + printf("2 / directory /"); + break; + case SUIT_FILETYPE_SYMBOLIC: + printf("3 / symbolic /"); + break; + } + comma = true; + } + if (component_metadata->exists & SUIT_META_CONTAINS_MODIFICATION_TIME) { + if (comma) { + printf(",\n"); + } + printf("%*s/ modification-time / 6: %ld", indent_space + indent_delta, "", component_metadata->modification_time); + } + if (component_metadata->exists & SUIT_META_CONTAINS_CREATION_TIME) { + if (comma) { + printf(",\n"); + } + printf("%*s/ creation-time / 7: %ld", indent_space + indent_delta, "", component_metadata->creation_time); + } + if (component_metadata->exists & SUIT_META_CONTAINS_CREATOR) { + if (comma) { + printf(",\n"); + } + printf("%*s/ creator / 8: ", indent_space + indent_delta, ""); + suit_print_actor_id(&component_metadata->creator); + } + + printf("\n%*s}", indent_space, ""); + + return SUIT_SUCCESS; +} + +suit_err_t suit_print_component_metadata_buf(const suit_buf_t *component_metadata_buf, + const uint32_t indent_space, + const uint32_t indent_delta) +{ + if (component_metadata_buf == NULL) { + return SUIT_ERR_FATAL; + } + printf("<< "); + suit_err_t result = SUIT_SUCCESS; + if (component_metadata_buf->ptr != NULL && component_metadata_buf->len > 0) { + suit_component_metadata_t component_metadata = {0}; + result = suit_decode_component_metadata(component_metadata_buf, &component_metadata); + if (result != SUIT_SUCCESS) { + return result; + } + result = suit_print_component_metadata(&component_metadata, indent_space, indent_delta); + } + printf(" >>"); return result; } @@ -1187,6 +1461,20 @@ suit_err_t suit_print_suit_parameters_list(const suit_parameters_list_t *params_ } break; + /* bstr .cbor SUIT_Parameter_Version_Match */ + case SUIT_PARAMETER_VERSION: + if (params_list->params[i].value.string.len > 0) { + result = suit_print_version_buf(¶ms_list->params[i].value.string, indent_space, indent_delta); + } + break; + + /* SUIT_Component_Metadata */ + case SUIT_PARAMETER_COMPONENT_METADATA: + if (params_list->params[i].value.string.len > 0) { + result = suit_print_component_metadata_buf(¶ms_list->params[i].value.string, indent_space, indent_delta); + } + break; + /* bool */ case SUIT_PARAMETER_STRICT_ORDER: case SUIT_PARAMETER_SOFT_FAILURE: @@ -1200,11 +1488,6 @@ suit_err_t suit_print_suit_parameters_list(const suit_parameters_list_t *params_ printf(" >>"); break; - /* SUIT_Parameter_Version_Match */ - case SUIT_PARAMETER_VERSION: - result = suit_print_version(¶ms_list->params[i].value.version_match, indent_space, indent_delta); - break; - default: result = SUIT_ERR_NOT_IMPLEMENTED; break; @@ -2224,7 +2507,7 @@ suit_err_t suit_print_condition(suit_condition_args_t condition_args) /* SUIT_Parameter_Version_Match */ case SUIT_CONDITION_VERSION: - suit_print_version(&condition_args.expected.version_match, 2, 2); + suit_print_version_match(&condition_args.expected.version_match, 2, 2); printf("\n"); break;