Skip to content

Commit

Permalink
Merge ce35e22 into backport/alanknight_alias_listresolvable/willingly…
Browse files Browse the repository at this point in the history
…-flowing-gator
  • Loading branch information
hc-github-team-secure-boundary authored Apr 18, 2024
2 parents 54374bd + ce35e22 commit 243f3c2
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions internal/perms/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,21 @@ type GrantTuples []GrantTuple
// GrantsHash returns a stable hash of all the grants in the GrantTuples.
func (g GrantTuples) GrantHash(ctx context.Context) ([]byte, error) {
const op = "perms.(GrantTuples).GrantHash"
// TODO: Should this return an error when the GrantTuples is empty?
var values []string
for _, grant := range g {
values = append(values, grant.Grant, grant.RoleId, grant.ScopeId)
}
// Sort for deterministic output
slices.Sort(values)
hashVal, err := hashStrings(ctx, values...)
hashVal, err := hashStrings(values...)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
}
return binary.LittleEndian.AppendUint64(make([]byte, 0, 4), hashVal), nil
}

func hashStrings(ctx context.Context, s ...string) (uint64, error) {
const op = "perms.hashStrings"
if len(s) == 0 {
return 0, errors.New(ctx, errors.InvalidParameter, op, "no strings provided")
}
func hashStrings(s ...string) (uint64, error) {
hasher := fnv.New64()
var h uint64
var err error
Expand Down

0 comments on commit 243f3c2

Please sign in to comment.