Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions tuf/encoding/targets_asn1_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,10 @@ def set_asn_targets(json_signed, targetsMetadata):
if customkey == 'ecu_serial':
# ecu_serial field name currently goes from ecu_serial to ecuIdentifier
custom['ecuIdentifier'] = filemeta['custom'][customkey]
# TODO: Include other cases specific to Uptane here (release counter
# and hardware identifier.)
# elif customkey == 'release_counter':
# pass
# elif customkey == 'hardware_identifier':
# pass
elif customkey == 'release_counter':
custom['releaseCounter'] = filemeta['custom'][customkey]
elif customkey == 'hardware_id':
custom['hardwareIdentifier'] = filemeta['custom'][customkey]
else:
custom[customkey] = filemeta['custom'][customkey] # Will probably break.

Expand Down Expand Up @@ -360,9 +358,28 @@ def set_json_targets(json_signed, targetsMetadata):
# Optional bit.
custom = targetAndCustom['custom']
if custom:
json_custom = {
'ecu_serial': str(custom['ecuIdentifier'])
}
json_custom = dict()
for customkey in custom:
if customkey == 'ecuIdentifier':
# ecu_serial field name currently goes from ecu_serial to ecuIdentifier
# try to get enteries corresponding to the various keys in custom metedata
# and if the enteries are empty, ignore and move forward
# When there are no enteries corresponding to a certain key,
# pyasn1 raises an exception.
try:
json_custom['ecu_serial'] = str(custom[customkey])
except:
pass
elif customkey == 'releaseCounter':
try:
json_custom['release_counter'] = str(custom[customkey])
except:
pass
elif customkey == 'hardwareIdentifier':
try:
json_custom['hardware_id'] = str(custom[customkey])
except:
pass
filemeta['custom'] = json_custom

json_targets[filename] = filemeta
Expand Down