Skip to content

Commit b1d22cc

Browse files
committed
Clean up succinct hashed bin code
Remove unnecessary or duplicate code in response to feedback on the pr. This also removes the existance check in add_delegated_role so that the value passed will replace any existing delegation. This allows the caller to replace an outdated role using this function. Signed-off-by: marinamoore <[email protected]>
1 parent e53998d commit b1d22cc

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

tuf/repository_tool.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,7 @@ def load_signing_key_succinct_delegations(self, key):
18131813

18141814
# Ensure the private portion of the key is available, otherwise signatures
18151815
# cannot be generated when the metadata file is written to disk.
1816-
if 'private' not in key['keyval'] or not len(key['keyval']['private']):
1816+
if not key['keyval'].get('private'):
18171817
raise securesystemslib.exceptions.Error('This is not a private key.')
18181818

18191819
# Has the key, with the private portion included, been added to the keydb?
@@ -1881,17 +1881,10 @@ def add_delegated_role(self, rolename, targets_object, succinct=False):
18811881
' not a Targets object.')
18821882

18831883
if succinct:
1884-
if rolename in self._succinct_delegations:
1885-
logger.debug(repr(rolename) + ' already exists.')
1886-
else:
1887-
self._succinct_delegations[rolename] = targets_object
1884+
self._succinct_delegations[rolename] = targets_object
18881885

18891886
else:
1890-
if rolename in self._delegated_roles:
1891-
logger.debug(repr(rolename) + ' already exists.')
1892-
1893-
else:
1894-
self._delegated_roles[rolename] = targets_object
1887+
self._delegated_roles[rolename] = targets_object
18951888

18961889

18971890

@@ -2685,10 +2678,7 @@ def delegate_hashed_bins(self, list_of_targets, keys_of_hashed_bins,
26852678
# be created, but they will not all be listed in the delegation
26862679
role = {"name":name,
26872680
"keyids": keyids,
2688-
"threshold": 1,
2689-
"terminating": False,
26902681
"target_paths": []}
2691-
ordered_roles.append(role)
26922682
else:
26932683
target_hash_prefixes = []
26942684
for idy in range((idx*prefix_count), (idx*prefix_count)+bin_size):
@@ -2749,14 +2739,6 @@ def delegate_hashed_bins(self, list_of_targets, keys_of_hashed_bins,
27492739
'terminating': False,
27502740
'path_hash_prefixes': bin_role['target_hash_prefixes']}
27512741
delegated_roleinfos.append(roleinfo)
2752-
else:
2753-
roleinfo = {'name': bin_role['name'],
2754-
'keyids': keyids,
2755-
'signing_keyids': [],
2756-
'version':1,
2757-
'threshold': 1,
2758-
'terminating': False,
2759-
'paths': []}
27602742

27612743
# Add the new delegation to the top-level 'targets' role object (i.e.,
27622744
# 'repository.targets()').

0 commit comments

Comments
 (0)