@@ -2588,7 +2588,7 @@ def revoke(self, rolename):
25882588
25892589
25902590 def delegate_hashed_bins (self , list_of_targets , keys_of_hashed_bins ,
2591- number_of_bins = DEFAULT_NUM_BINS , succinct = False , prefix = None ):
2591+ number_of_bins = DEFAULT_NUM_BINS , succinct = False , prefix = '' ):
25922592 """
25932593 <Purpose>
25942594 Distribute a large number of target files over multiple delegated roles
@@ -2663,13 +2663,6 @@ def delegate_hashed_bins(self, list_of_targets, keys_of_hashed_bins,
26632663 securesystemslib .formats .ANYKEYLIST_SCHEMA .check_match (keys_of_hashed_bins )
26642664 tuf .formats .NUMBINS_SCHEMA .check_match (number_of_bins )
26652665
2666- # determine the prefix for each bin. If one is not provided, use the
2667- # default prefix
2668- if prefix :
2669- name_prefix = prefix + '-'
2670- else :
2671- name_prefix = self .rolename + '.hbd-'
2672-
26732666 prefix_length , prefix_count , bin_size = repo_lib .get_bin_numbers (number_of_bins )
26742667
26752668 logger .info ('Creating hashed bin delegations.\n ' +
@@ -2685,7 +2678,7 @@ def delegate_hashed_bins(self, list_of_targets, keys_of_hashed_bins,
26852678 # to be delegated to that bin
26862679 ordered_roles = []
26872680 for idx in range (0 , number_of_bins ):
2688- name = name_prefix + "{num:0{len}x}" . format ( num = idx , len = prefix_length )
2681+ name = repo_lib . create_bin_name ( idx , prefix_length , prefix )
26892682 if succinct :
26902683 # For succinct hased bin delegations, these metadata files will still
26912684 # be created, but they will not all be listed in the delegation
@@ -2777,19 +2770,19 @@ def delegate_hashed_bins(self, list_of_targets, keys_of_hashed_bins,
27772770 if succinct :
27782771 # For succinct delegations, each bin is not added, so add a single
27792772 # succinct delegation
2780- roleinfo = {'name' : name_prefix ,
2773+ roleinfo = {'name' : prefix ,
27812774 'keyids' : keyids ,
27822775 'threshold' : 1 ,
27832776 'terminating' : False ,
27842777 'delegation_hash_prefix_len' : prefix_length ,
27852778 'paths' : []}
27862779 delegated_roleinfos .append (roleinfo )
27872780
2788- target = self ._create_delegated_target (name_prefix , keyids , 1 , [])
2781+ target = self ._create_delegated_target (prefix , keyids , 1 , [])
27892782 for key in keys_of_hashed_bins :
27902783 target .add_verification_key (key )
27912784
2792- self .add_delegated_role (name_prefix , target )
2785+ self .add_delegated_role (prefix , target )
27932786
27942787
27952788 self ._update_roledb_delegations (keydict , delegated_roleinfos )
@@ -2798,7 +2791,7 @@ def delegate_hashed_bins(self, list_of_targets, keys_of_hashed_bins,
27982791
27992792
28002793 def add_target_to_bin (self , target_filepath , number_of_bins = DEFAULT_NUM_BINS ,
2801- fileinfo = None , prefix = None ):
2794+ fileinfo = None , prefix = '' ):
28022795 """
28032796 <Purpose>
28042797 Add the fileinfo of 'target_filepath' to the expected hashed bin, if the
@@ -2824,8 +2817,7 @@ def add_target_to_bin(self, target_filepath, number_of_bins=DEFAULT_NUM_BINS,
28242817 providing full information about the file.
28252818
28262819 prefix:
2827- The filename prefix used for bin names. If None, the default of
2828- rolename.hbd-* will be used
2820+ The filename prefix used for bin names.
28292821
28302822 <Exceptions>
28312823 securesystemslib.exceptions.FormatError, if 'target_filepath' is
@@ -2852,13 +2844,9 @@ def add_target_to_bin(self, target_filepath, number_of_bins=DEFAULT_NUM_BINS,
28522844
28532845 # TODO: check target_filepath is sane
28542846
2855- if prefix :
2856- bin_name = prefix + '-'
2857- else :
2858- bin_name = self .rolename + ".hbd-"
2859-
28602847 path_hash = repo_lib .get_target_hash (target_filepath )
2861- bin_name = bin_name + repo_lib .find_bin_for_target_hash (path_hash , number_of_bins )
2848+ bin_name = repo_lib .find_bin_for_target_hash (path_hash , number_of_bins ,
2849+ prefix )
28622850
28632851 # Ensure the Targets object has delegated to hashed bins
28642852 if not self ._delegated_roles .get (bin_name , None ):
@@ -2873,7 +2861,7 @@ def add_target_to_bin(self, target_filepath, number_of_bins=DEFAULT_NUM_BINS,
28732861
28742862
28752863 def remove_target_from_bin (self , target_filepath ,
2876- number_of_bins = DEFAULT_NUM_BINS , prefix = None ):
2864+ number_of_bins = DEFAULT_NUM_BINS , prefix = '' ):
28772865 """
28782866 <Purpose>
28792867 Remove the fileinfo of 'target_filepath' from the expected hashed bin, if
@@ -2895,8 +2883,7 @@ def remove_target_from_bin(self, target_filepath,
28952883 Note: 'number_of_bins' must be a power of 2.
28962884
28972885 prefix:
2898- The filename prefix used for bin names. If None, the default of
2899- rolename.hbd-* will be used
2886+ The filename prefix used for bin names.
29002887
29012888 <Exceptions>
29022889 securesystemslib.exceptions.FormatError, if 'target_filepath' is
@@ -2923,13 +2910,9 @@ def remove_target_from_bin(self, target_filepath,
29232910
29242911 # TODO: check target_filepath is sane?
29252912
2926- if prefix :
2927- bin_name = prefix + '-'
2928- else :
2929- bin_name = self .rolename + '.hbd-'
2930-
29312913 path_hash = repo_lib .get_target_hash (target_filepath )
2932- bin_name = bin_name + repo_lib .find_bin_for_target_hash (path_hash , number_of_bins )
2914+ bin_name = repo_lib .find_bin_for_target_hash (path_hash , number_of_bins ,
2915+ prefix )
29332916
29342917 # Ensure the Targets object has delegated to hashed bins
29352918 if not self ._delegated_roles .get (bin_name , None ):
@@ -3241,8 +3224,7 @@ def load_repository(repository_directory, repository_name='default',
32413224 prefix_len = role ['delegation_hash_prefix_len' ]
32423225 num_bins = 2 ** prefix_len
32433226 for i in range (num_bins ):
3244- bin_name = "{name}{num:0{len}x}" .format (name = role ['name' ], num = i ,
3245- len = prefix_len )
3227+ bin_name = repo_lib .create_bin_name (i , prefix_len , role ['name' ])
32463228 succinct_role = {'name' : bin_name ,
32473229 'keyids' : role ['keyids' ],
32483230 'threshold' : role ['threshold' ],
0 commit comments