secret

package
v1.0.0-alpha4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2018 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDecryption    = errgo.New("decryption error")
	ErrInvalidCookie = errgo.New("invalid cookie")
)

Functions

This section is empty.

Types

type Codec

type Codec struct {
	// contains filtered or unexported fields
}

Codec is used to create an encrypted messages that will be decrypted by the same service. This should be used for cookies and other data that needs to be sent through the client but must be verifiable as originally coming from this service.

func NewCodec

func NewCodec(key *bakery.KeyPair) *Codec

NewCodec creates a new Codec using the given key.

func (*Codec) Cookie

func (c *Codec) Cookie(req *http.Request, name, verification string, v interface{}) error

Cookie decodes the cookie with the given name from the given request into v. The given verification string is used to ensure the cookie is valid.

func (*Codec) Decode

func (c *Codec) Decode(s string, v interface{}) error

Decode unmarshals a value from the given buffer that must have been marshaled with a Codec using the same key. If there was an error decrypting buf the returned error will have a cause of ErrDecryption.

func (*Codec) Encode

func (c *Codec) Encode(v interface{}) (string, error)

Encode marshals the given value in such a way that it can only be unmarshaled by a Codec using the same key. The encoded output will be in the base64 url safe alphabet.

func (*Codec) SetCookie

func (c *Codec) SetCookie(w http.ResponseWriter, name string, v interface{}) (string, error)

SetCookie encodes the given value as a session cookie with the given name. The returned value is used the verify the cookie later - it should be passed to Cookie when the cookie is retrieved.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL