1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-29 08:22:11 +02:00
imgproxy/crypt.go
2017-06-27 03:38:00 +03:00

27 lines
476 B
Go

package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"errors"
)
func validatePath(token, path string) error {
messageMAC, err := base64.RawURLEncoding.DecodeString(token)
if err != nil {
return errors.New("Invalid token encoding")
}
mac := hmac.New(sha256.New, conf.Key)
mac.Write(conf.Salt)
mac.Write([]byte(path))
expectedMAC := mac.Sum(nil)
if !hmac.Equal(messageMAC, expectedMAC) {
return errors.New("Invalid token")
}
return nil
}