Skip to content

Commit

Permalink
fix: type of parameter-vesion (bstr wrap is needed)
Browse files Browse the repository at this point in the history
  • Loading branch information
kentakayama committed Nov 21, 2024
1 parent 6e68a4c commit 4a87d8e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
33 changes: 27 additions & 6 deletions src/suit_manifest_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ suit_err_t suit_decode_digest_from_bstr(const suit_decode_mode_t mode,
}

#if !defined(LIBCSUIT_DISABLE_PARAMETER_VERSION)
suit_err_t suit_decode_version_match(QCBORDecodeContext *context,
QCBORItem *item,
bool next,
suit_version_match_t *version_match)
suit_err_t suit_decode_version_match_from_item(QCBORDecodeContext *context,
QCBORItem *item,
bool next,
suit_version_match_t *version_match)
{
if (next) {
QCBORDecode_GetNext(context, item);
Expand Down Expand Up @@ -126,6 +126,27 @@ suit_err_t suit_decode_version_match(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 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);
if (error != QCBOR_SUCCESS && result == SUIT_SUCCESS) {
result = suit_error_from_qcbor_error(error);
}
return result;
}
#endif /* !LIBCSUIT_DISABLE_PARAMETER_VERSION */

#if !defined(LIBCSUIT_DISABLE_PARAMETER_WAIT_INFO)
Expand Down Expand Up @@ -185,7 +206,7 @@ suit_err_t suit_decode_wait_event_from_item(QCBORDecodeContext *context,
QCBORDecode_EnterArray(context, item);
wait_event->other_device_version.len = item->val.uCount;
for (size_t j = 0; j < wait_event->other_device_version.len; j++) {
result = suit_decode_version_match(context, item, false, &wait_event->other_device_version.versions[j]);
result = suit_decode_version_match_from_item(context, item, false, &wait_event->other_device_version.versions[j]);
if (result != SUIT_SUCCESS) {
return result;
}
Expand Down Expand Up @@ -356,7 +377,7 @@ suit_err_t suit_decode_parameters_list_from_item(const suit_decode_mode_t mode,
/* SUIT_Parameter_Version_Match */
#if !defined(LIBCSUIT_DISABLE_PARAMETER_VERSION)
case SUIT_PARAMETER_VERSION:
result = suit_decode_version_match(context, item, false, &params_list->params[i].value.version_match);
result = suit_decode_version_match_from_bstr(context, item, false, &params_list->params[i].value.version_match);
break;
#endif

Expand Down
4 changes: 3 additions & 1 deletion src/suit_manifest_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,16 @@ suit_err_t suit_append_directive_override_parameters(const suit_parameters_list_
/* SUIT_Parameter_Version_Match */
#if !defined(LIBCSUIT_DISABLE_CONDITION_VERSION)
case SUIT_PARAMETER_VERSION:
QCBOREncode_OpenArrayInMapN(context, param->label);
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 */

Expand Down
2 changes: 2 additions & 0 deletions src/suit_manifest_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ suit_err_t suit_set_parameters(QCBORDecodeContext *context,
/* SUIT_Parameter_Version_Match */
#if !defined(LIBCSUIT_DISABLE_PARAMETER_VERSION)
case SUIT_PARAMETER_VERSION:
QCBORDecode_EnterBstrWrapped(context, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL);
QCBORDecode_EnterArray(context, &item);
for (size_t j = 0; j < suit_index->len; j++) {
uint8_t tmp_index = suit_index->index[j];
Expand All @@ -305,6 +306,7 @@ suit_err_t suit_set_parameters(QCBORDecodeContext *context,
}
}
QCBORDecode_ExitArray(context);
QCBORDecode_ExitBstrWrapped(context);
break;
#endif /* !LIBCSUIT_DISABLE_PARAMETER_VERSION */

Expand Down

0 comments on commit 4a87d8e

Please sign in to comment.