Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move repository_lib.get_taget_hash back from sslib to tuf #909

Merged
Merged
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions tuf/repository_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import tuf.settings

import securesystemslib
import securesystemslib.hash
import securesystemslib.interface
import iso8601
import six
Expand Down Expand Up @@ -1174,6 +1175,8 @@ def get_metadata_versioninfo(rolename, repository_name):



# TODO: Is this function needed? It does not seem used, also the same
# function exists as private method in updater.Updater._get_target_hash.
def get_target_hash(target_filepath):
"""
<Purpose>
Expand All @@ -1198,9 +1201,20 @@ def get_target_hash(target_filepath):

<Returns>
The hash of 'target_filepath'.
"""

return securesystemslib.util.get_target_hash(target_filepath)
"""
securesystemslib.formats.RELPATH_SCHEMA.check_match(target_filepath)

# Calculate the hash of the filepath to determine which bin to find the
# target. The client currently assumes the repository uses
# 'tuf.settings.DEFAULT_HASH_ALGORITHM' to generate hashes and 'utf-8'.
digest_object = securesystemslib.hash.digest(
tuf.settings.DEFAULT_HASH_ALGORITHM)
encoded_target_filepath = target_filepath.encode('utf-8')
digest_object.update(encoded_target_filepath)
target_filepath_hash = digest_object.hexdigest()

return target_filepath_hash



Expand Down
5 changes: 3 additions & 2 deletions tuf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@

# A setting for the instances where a default hashing algorithm is needed.
# This setting is currently used to calculate the path hash prefixes of hashed
# bin delegations. The other instances (e.g., digest of files) that require a
# hashing algorithm rely on settings in the securesystemslib external library.
# bin delegations, and digests of targets filepaths. The other instances
# (e.g., digest of files) that require a hashing algorithm rely on settings in
# the securesystemslib external library.
DEFAULT_HASH_ALGORITHM = 'sha256'

# The client's update procedure (contained within a while-loop) can potentially
Expand Down