import "github.com/daaku/hmacsigner"
Documentation: https://godoc.org/github.com/daaku/hmacsigner
Package hmacsigner provides signed blobs.
It:
- Includes a version.
- Includes 8 byte nanosecond unix timestamp.
- Includes 8 byte salt.
- Requires a Secret of at least 32 bytes.
- Does not encrypt the payload.
- Enforces HMAC-SHA256 signatures.
- Outputs URL safe Base64 encoding.
var (
// ErrTooShort indicates the data to parse is too short to be valid.
ErrTooShort = errors.New("hmacsigner: too short")
// ErrInvalidVersion indicates the version was invalid.
ErrInvalidVersion = errors.New("hmacsigner: invalid version")
// ErrInvalidEncoding indicates the encoding is invalid.
ErrInvalidEncoding = errors.New("hmacsigner: invalid encoding")
// ErrTimestampExpired indicates the timestamp has expired.
ErrTimestampExpired = errors.New("hmacsigner: timestamp expired")
// ErrSignatureMismatch indicates the signature is not as expected.
ErrSignatureMismatch = errors.New("hmacsigner: signature mismatch")
)
type Signer struct {
Secret []byte // Secret must be at least 32 bytes.
TTL time.Duration // TTL must be non zero.
}
Signer handles generating and parsing signed data.
func (s *Signer) Gen(payload []byte) []byte
Gen returns the signed payload.
func (s *Signer) Parse(b []byte) ([]byte, error)
Parse returns the original payload. It verifies the signature and ensures the TTL is respected.