Skip to content

Commit c0df590

Browse files
committed
Remove _get_filepath_hash
Remove _get_filepath_hash and call sslib_hash.digest directly instead. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
1 parent 790b699 commit c0df590

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

tuf/api/metadata.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,13 @@ def is_in_trusted_paths(self, target_filepath: str) -> bool:
10381038
is in one of the trusted paths of DelegatedRole"""
10391039

10401040
if self.path_hash_prefixes is not None:
1041-
target_filepath_hash = _get_filepath_hash(target_filepath)
1041+
# Calculate the hash of the filepath to determine which bin
1042+
# to find the target. The client currently assumes the repository
1043+
# uses sslib's default algorithm to generate hashes.
1044+
digest_object = sslib_hash.digest()
1045+
digest_object.update(target_filepath.encode("utf-8"))
1046+
target_filepath_hash = digest_object.hexdigest()
1047+
10421048
for path_hash_prefix in self.path_hash_prefixes:
10431049
if target_filepath_hash.startswith(path_hash_prefix):
10441050
return True
@@ -1058,21 +1064,6 @@ def is_in_trusted_paths(self, target_filepath: str) -> bool:
10581064
return False
10591065

10601066

1061-
def _get_filepath_hash(target_filepath, hash_function="sha256"):
1062-
"""
1063-
Calculate the hash of the filepath to determine which bin to find the
1064-
target.
1065-
"""
1066-
# The client currently assumes the repository (i.e., repository
1067-
# tool) uses 'hash_function' to generate hashes and UTF-8.
1068-
digest_object = sslib_hash.digest(hash_function)
1069-
encoded_target_filepath = target_filepath.encode("utf-8")
1070-
digest_object.update(encoded_target_filepath)
1071-
target_filepath_hash = digest_object.hexdigest()
1072-
1073-
return target_filepath_hash
1074-
1075-
10761067
class Delegations:
10771068
"""A container object storing information about all delegations.
10781069

0 commit comments

Comments
 (0)