Documentation
¶
Overview ¶
Package http has helpers for HTTP servers, such as signed cookies.
Index ¶
Constants ¶
const MinCookieKeyLength = 32
MinCookieKeyLength is the shortest key NewCookieSigner accepts.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CookieSigner ¶
type CookieSigner struct {
// contains filtered or unexported fields
}
CookieSigner keeps small values in cookies signed with HMAC-SHA256, so a server can trust what comes back without keeping a store. Values are signed but not encrypted: the client can read them, but not change them.
The signature covers the cookie's name as well as its value, so a value sealed for one cookie is not accepted for another.
func NewCookieSigner ¶
func NewCookieSigner(key []byte) (*CookieSigner, error)
NewCookieSigner returns a CookieSigner using key, which must be at least MinCookieKeyLength bytes. Changing the key invalidates every value sealed with the old one.
func (*CookieSigner) Open ¶
func (s *CookieSigner) Open(name, value string, v any) bool
Open checks that value was sealed for the cookie called name and decodes it into v. It reports false if the signature or encoding is wrong, in which case v may have been partly written.