Skip to content

Commit 45cc43c

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 592f098 commit 45cc43c

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

tuf/api/metadata.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,12 @@ 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
1042+
# to determine in which bin to find the target.
1043+
digest_object = sslib_hash.digest(algorithm="sha256")
1044+
digest_object.update(target_filepath.encode("utf-8"))
1045+
target_filepath_hash = digest_object.hexdigest()
1046+
10421047
for path_hash_prefix in self.path_hash_prefixes:
10431048
if target_filepath_hash.startswith(path_hash_prefix):
10441049
return True
@@ -1058,21 +1063,6 @@ def is_in_trusted_paths(self, target_filepath: str) -> bool:
10581063
return False
10591064

10601065

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-
10761066
class Delegations:
10771067
"""A container object storing information about all delegations.
10781068

0 commit comments

Comments
 (0)