From 9cd467e9968f25ae37ad31757cbcfa7bc31708ae Mon Sep 17 00:00:00 2001 From: Todd Date: Tue, 16 Apr 2024 22:00:51 +0000 Subject: [PATCH] backport of commit ce35e2209047c4ec7114a4db789d32ce64a0e923 --- internal/perms/grants.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/internal/perms/grants.go b/internal/perms/grants.go index de73502d0d..fa8a061356 100644 --- a/internal/perms/grants.go +++ b/internal/perms/grants.go @@ -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