3cff8ccd64
* Rewrite the code handling basic auth to make it easier to extend for other types of auth. * The behaviour of the existing code is maintained. * No changes to how basic auth is configured from a user's perspective. https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/-/merge_requests/89
18 lines
262 B
Go
18 lines
262 B
Go
package auth
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
)
|
|
|
|
func hash(data []byte) []byte {
|
|
if len(data) == 0 {
|
|
return []byte{}
|
|
}
|
|
b := sha256.Sum256(data)
|
|
return b[:]
|
|
}
|
|
|
|
func HashString(data string) string {
|
|
return hex.EncodeToString(hash([]byte(data)))
|
|
}
|