File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 4949import tuf .settings
5050
5151import securesystemslib
52+ import securesystemslib .hash
5253import securesystemslib .interface
5354import iso8601
5455import six
@@ -1174,6 +1175,8 @@ def get_metadata_versioninfo(rolename, repository_name):
11741175
11751176
11761177
1178+ # TODO: Is this function needed? It does not seem used, also the same
1179+ # function exists as private method in updater.Updater._get_target_hash.
11771180def get_target_hash (target_filepath ):
11781181 """
11791182 <Purpose>
@@ -1198,9 +1201,20 @@ def get_target_hash(target_filepath):
11981201
11991202 <Returns>
12001203 The hash of 'target_filepath'.
1201- """
12021204
1203- return securesystemslib .util .get_target_hash (target_filepath )
1205+ """
1206+ securesystemslib .formats .RELPATH_SCHEMA .check_match (target_filepath )
1207+
1208+ # Calculate the hash of the filepath to determine which bin to find the
1209+ # target. The client currently assumes the repository uses
1210+ # 'tuf.settings.DEFAULT_HASH_ALGORITHM' to generate hashes and 'utf-8'.
1211+ digest_object = securesystemslib .hash .digest (
1212+ tuf .settings .DEFAULT_HASH_ALGORITHM )
1213+ encoded_target_filepath = target_filepath .encode ('utf-8' )
1214+ digest_object .update (encoded_target_filepath )
1215+ target_filepath_hash = digest_object .hexdigest ()
1216+
1217+ return target_filepath_hash
12041218
12051219
12061220
Original file line number Diff line number Diff line change 9797
9898# A setting for the instances where a default hashing algorithm is needed.
9999# This setting is currently used to calculate the path hash prefixes of hashed
100- # bin delegations. The other instances (e.g., digest of files) that require a
101- # hashing algorithm rely on settings in the securesystemslib external library.
100+ # bin delegations, and digests of targets filepaths. The other instances
101+ # (e.g., digest of files) that require a hashing algorithm rely on settings in
102+ # the securesystemslib external library.
102103DEFAULT_HASH_ALGORITHM = 'sha256'
103104
104105# The client's update procedure (contained within a while-loop) can potentially
You can’t perform that action at this time.
0 commit comments