mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-15 11:21:04 +01:00
28 lines
520 B
Go
28 lines
520 B
Go
|
package hmac
|
||
|
|
||
|
import (
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type TimedHMACValidator struct {
|
||
|
*TimedHMAC
|
||
|
}
|
||
|
|
||
|
func NewTimedHMACValidator(secret string, duration time.Duration) *TimedHMACValidator {
|
||
|
ta := NewTimedHMAC(secret, duration)
|
||
|
return &TimedHMACValidator{
|
||
|
ta,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a *TimedHMACValidator) Validate(credentials any) error {
|
||
|
b := credentials.([]byte)
|
||
|
c, err := unmarshalToken(b)
|
||
|
if err != nil {
|
||
|
log.Errorf("failed to unmarshal token: %s", err)
|
||
|
return err
|
||
|
}
|
||
|
return a.TimedHMAC.Validate(c)
|
||
|
}
|