Skip to content

Commit

Permalink
predicates/auth: fix array conversion (#2788)
Browse files Browse the repository at this point in the history
* fix array conversion that was necessary due to golang/go#46505
* preallocate slice

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Dec 11, 2023
1 parent 2239849 commit 3dc744e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions predicates/auth/headersha256.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ func (*headerSha256Spec) Create(args []interface{}) (routing.Predicate, error) {
return nil, predicates.ErrInvalidPredicateParameters
}

var hashes [][sha256.Size]byte
for _, arg := range args[1:] {
args = args[1:]

hashes := make([][sha256.Size]byte, 0, len(args))
for _, arg := range args {
hexHash, ok := arg.(string)
if !ok {
return nil, predicates.ErrInvalidPredicateParameters
Expand All @@ -50,7 +52,7 @@ func (*headerSha256Spec) Create(args []interface{}) (routing.Predicate, error) {
if len(hash) != sha256.Size {
return nil, predicates.ErrInvalidPredicateParameters
}
hashes = append(hashes, *(*[sha256.Size]byte)(hash)) // https://github.com/golang/go/issues/46505
hashes = append(hashes, ([sha256.Size]byte)(hash))
}

return &headerSha256Predicate{name, hashes}, nil
Expand Down

0 comments on commit 3dc744e

Please sign in to comment.