2021-05-04 22:06:05 +00:00
|
|
|
package oidc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-10-20 03:21:45 +00:00
|
|
|
|
|
|
|
"github.com/go-crypt/crypt"
|
2021-05-04 22:06:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Compare compares the hash with the data and returns an error if they don't match.
|
2022-10-20 03:21:45 +00:00
|
|
|
func (h AdaptiveHasher) Compare(_ context.Context, hash, data []byte) (err error) {
|
|
|
|
var digest crypt.Digest
|
|
|
|
|
|
|
|
if digest, err = crypt.DecodeWithPlainText(string(hash)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if digest.MatchBytes(data) {
|
|
|
|
return nil
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
2022-10-20 03:21:45 +00:00
|
|
|
return errPasswordsDoNotMatch
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hash creates a new hash from data.
|
2022-10-20 03:21:45 +00:00
|
|
|
func (h AdaptiveHasher) Hash(_ context.Context, data []byte) (hash []byte, err error) {
|
2021-05-04 22:06:05 +00:00
|
|
|
return data, nil
|
|
|
|
}
|