@@ -562,28 +562,30 @@ func isTargetInPathPattern(targetpath string, pathpattern string) bool {
562
562
563
563
// GetRolesForTarget return the names and terminating status of all
564
564
// delegated roles who are responsible for targetFilepath
565
- func (role * Delegations ) GetRolesForTarget (targetFilepath string ) map [string ]bool {
566
- res := map [string ]bool {}
567
- // standard delegations
565
+ // Note the result should be an ordered list, ref. https://github.com/theupdateframework/go-tuf/security/advisories/GHSA-4f8r-qqr9-fq8j
566
+ func (role * Delegations ) GetRolesForTarget (targetFilepath string ) []RoleResult {
567
+ var res []RoleResult
568
+ // Standard delegations
568
569
if role .Roles != nil {
569
570
for _ , r := range role .Roles {
570
571
ok , err := r .IsDelegatedPath (targetFilepath )
571
572
if err == nil && ok {
572
- res [ r .Name ] = r .Terminating
573
+ res = append ( res , RoleResult { Name : r .Name , Terminating : r .Terminating })
573
574
}
574
575
}
575
576
} else if role .SuccinctRoles != nil {
576
577
// SuccinctRoles delegations
577
578
res = role .SuccinctRoles .GetRolesForTarget (targetFilepath )
578
579
}
580
+ // We preserve the same order as the actual roles list
579
581
return res
580
582
}
581
583
582
584
// GetRolesForTarget calculate the name of the delegated role responsible for "targetFilepath".
583
585
// The target at path "targetFilepath" is assigned to a bin by casting
584
586
// the left-most "BitLength" of bits of the file path hash digest to
585
- // int, using it as bin index between 0 and “2**BitLength - 1“ .
586
- func (role * SuccinctRoles ) GetRolesForTarget (targetFilepath string ) map [ string ] bool {
587
+ // int, using it as bin index between 0 and “2**BitLength-1” .
588
+ func (role * SuccinctRoles ) GetRolesForTarget (targetFilepath string ) [] RoleResult {
587
589
// calculate the suffixLen value based on the total number of bins in
588
590
// hex. If bit_length = 10 then numberOfBins = 1024 or bin names will
589
591
// have a suffix between "000" and "3ff" in hex and suffixLen will be 3
@@ -604,8 +606,8 @@ func (role *SuccinctRoles) GetRolesForTarget(targetFilepath string) map[string]b
604
606
// add zero padding if necessary and cast to hex the suffix
605
607
suffix := fmt .Sprintf ("%0*x" , suffixLen , binNumber )
606
608
// we consider all succinct_roles as terminating.
607
- // for more information read TAP 15.
608
- return map [ string ] bool { fmt .Sprintf ("%s-%s" , role .NamePrefix , suffix ): true }
609
+ // for more information, read TAP 15.
610
+ return [] RoleResult {{ Name : fmt .Sprintf ("%s-%s" , role .NamePrefix , suffix ), Terminating : true } }
609
611
}
610
612
611
613
// GetRoles returns the names of all different delegated roles
0 commit comments