@@ -562,28 +562,30 @@ func isTargetInPathPattern(targetpath string, pathpattern string) bool {
562562
563563// GetRolesForTarget return the names and terminating status of all
564564// 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
568569 if role .Roles != nil {
569570 for _ , r := range role .Roles {
570571 ok , err := r .IsDelegatedPath (targetFilepath )
571572 if err == nil && ok {
572- res [ r .Name ] = r .Terminating
573+ res = append ( res , RoleResult { Name : r .Name , Terminating : r .Terminating })
573574 }
574575 }
575576 } else if role .SuccinctRoles != nil {
576577 // SuccinctRoles delegations
577578 res = role .SuccinctRoles .GetRolesForTarget (targetFilepath )
578579 }
580+ // We preserve the same order as the actual roles list
579581 return res
580582}
581583
582584// GetRolesForTarget calculate the name of the delegated role responsible for "targetFilepath".
583585// The target at path "targetFilepath" is assigned to a bin by casting
584586// 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 {
587589 // calculate the suffixLen value based on the total number of bins in
588590 // hex. If bit_length = 10 then numberOfBins = 1024 or bin names will
589591 // 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
604606 // add zero padding if necessary and cast to hex the suffix
605607 suffix := fmt .Sprintf ("%0*x" , suffixLen , binNumber )
606608 // 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 } }
609611}
610612
611613// GetRoles returns the names of all different delegated roles
0 commit comments