Example #1
0
// Sign signs the given data and returns the data plus the signature
// as a string. See Signer documentation for the characteristics of
// the returned string.
func (s *Signer) Sign(data []byte) (string, error) {
	signature, err := s.sign(data)
	if err != nil {
		return "", err
	}
	return base64.Encode(data) + ":" + base64.Encode(signature), nil
}
Example #2
0
// SetOpts works like Set(), but accepts an Options parameter.
func (c *Cookies) SetOpts(name string, value interface{}, o *Options) error {
	data, err := c.c.Encode(value)
	if err != nil {
		return err
	}
	return c.set(name, base64.Encode(data), o)
}
Example #3
0
func profileHeader(ctx *Context) string {
	data, _ := json.Marshal(getProfileInfo(ctx))
	var buf bytes.Buffer
	w, _ := flate.NewWriter(&buf, flate.DefaultCompression)
	w.Write(data)
	w.Close()
	return base64.Encode(buf.Bytes())
}
Example #4
0
func (c *Cookies) encode(value interface{}, t transformer) (string, error) {
	data, err := c.c.Encode(value)
	if err != nil {
		return "", err
	}
	if t != nil {
		data, err = t(data)
		if err != nil {
			return "", err
		}
	}
	return base64.Encode(data), nil
}