imgtool: Assert "measurement value" is last in boot_record.py

'Measurement Value' added the 'properties' list initially,
rather than adding it separately later.
Added an assertion to ensure 'Measurement Value' remains as
the last item in the 'properties' list

Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: I106059c6c903c3d560477d5114d866f48590ad7e
This commit is contained in:
Rustam Ismayilov 2023-12-13 12:33:49 +01:00 committed by Dávid Vincze
parent 36f8bf3085
commit d16a613f6d
1 changed files with 10 additions and 10 deletions

View File

@ -1,4 +1,4 @@
# Copyright (c) 2019-2021, Arm Limited. # Copyright (c) 2019-2024, Arm Limited.
# Copyright (c) 2020, Linaro Limited # Copyright (c) 2020, Linaro Limited
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
@ -22,6 +22,7 @@ try:
except ImportError: except ImportError:
from cbor import dumps from cbor import dumps
class SwComponent(int, Enum): class SwComponent(int, Enum):
""" """
Software component property IDs specified by Software component property IDs specified by
@ -36,17 +37,16 @@ class SwComponent(int, Enum):
def create_sw_component_data(sw_type, sw_version, sw_measurement_description, def create_sw_component_data(sw_type, sw_version, sw_measurement_description,
sw_measurement_value, sw_signer_id): sw_measurement_value, sw_signer_id):
# List of software component properties (Key ID + value) # List of software component properties (Key ID + value)
properties = { properties = {SwComponent.TYPE: sw_type,
SwComponent.TYPE: sw_type,
SwComponent.VERSION: sw_version, SwComponent.VERSION: sw_version,
SwComponent.SIGNER_ID: sw_signer_id, SwComponent.SIGNER_ID: sw_signer_id,
SwComponent.MEASUREMENT_DESCRIPTION: sw_measurement_description, SwComponent.MEASUREMENT_DESCRIPTION: sw_measurement_description,
SwComponent.MEASUREMENT_VALUE: sw_measurement_value,
} }
# Note: The measurement value must be the last item of the property # Note: The measurement value must be the last item of the property
# list because later it will be modified by the bootloader. # list because later it will be modified by the bootloader.
properties[SwComponent.MEASUREMENT_VALUE] = sw_measurement_value last_key = list(properties.keys())[-1]
assert SwComponent.MEASUREMENT_VALUE == last_key, 'Measurement value is not the last item of the property list'
return dumps(properties) return dumps(properties)