Skip to content

Commit d0bff72

Browse files
committed
chore: code improvements
- In Store.autogenerateHasher, avoid modifying foundVariants. - Improve comment for Hasher.HashWithSalt
1 parent 03fd45b commit d0bff72

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

authorization/storage.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,15 @@ func (s *Store) autogenerateHasher(ctx context.Context, variantName string) (*Au
256256
}
257257

258258
var decoderVariants []influxdb2_algo.Variant
259-
// Make sure we have the hasher variant we will make in there and that it is first in the list.
259+
// Make sure we have the hasher variant we will make in there and that it is first in the list,
260+
// so that it is the first one we try to lookup a given token.
260261
hasherVariant := influxdb2_algo.NewVariant(variantName)
261262
decoderVariants = append(decoderVariants, hasherVariant)
262-
delete(foundVariants, hasherVariant)
263263
for variant := range foundVariants {
264-
decoderVariants = append(decoderVariants, variant)
264+
// Avoid having 2 hasherVariant decoders.
265+
if variant != hasherVariant {
266+
decoderVariants = append(decoderVariants, variant)
267+
}
265268
}
266269

267270
hasher, err := NewAuthorizationHasher(WithHasherVariant(hasherVariant), WithDecoderVariants(decoderVariants))

pkg/crypt/algorithm/influxdb2/hasher.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ func (h *Hasher) Hash(password string) (hashed algorithm.Digest, err error) {
5959
return d, nil
6060
}
6161

62-
// HashWithSalt is an overload of plaintext.Digest that also accepts a salt.
63-
func (h *Hasher) HashWithSalt(password string, _ []byte) (hashed algorithm.Digest, err error) {
62+
// HashWithSalt is an overload of Hasher.Digest that also accepts a salt. The salt is ignored since we can't support
63+
// salted hashes because we need to lookup the auth record by the token.
64+
func (h *Hasher) HashWithSalt(password string, salt []byte) (hashed algorithm.Digest, err error) {
6465
return h.Hash(password)
6566
}
6667

0 commit comments

Comments
 (0)