Valid reports whether got matches any accepted token. Every candidate digest is compared with subtle.ConstantTimeCompare and there is no early exit on a match.
(got string)
| 55 | // digest is compared with subtle.ConstantTimeCompare and there is no early |
| 56 | // exit on a match. |
| 57 | func (ts TokenSet) Valid(got string) bool { |
| 58 | if got == "" { |
| 59 | return false |
| 60 | } |
| 61 | gotSum := sha256.Sum256([]byte(got)) |
| 62 | match := 0 |
| 63 | for i := range ts.digests { |
| 64 | match |= subtle.ConstantTimeCompare(gotSum[:], ts.digests[i][:]) |
| 65 | } |
| 66 | return match == 1 |
| 67 | } |
| 68 | |
| 69 | // Count returns the number of accepted tokens (for operability logging only — |
| 70 | // never log the values themselves). |
no outgoing calls