tokens

package
v0.0.0-...-b4b3d51 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2017 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Tokens is a group of useful functions for creating cryptographically-secure tokens. All functions will panic if they cannot gather the required number of bytes via rand.Read.

Sizes of the tokens are from Thomas Ptacek's gist: https://gist.github.com/tqbf/be58d2d39690c3b366ad

To use the tokens with the gogo/protobuf library, build this with the build tag "-protobuf"

Index

Constants

View Source
const (
	// AuthTokenLength is the length of an encoded AuthToken.
	AuthTokenLength = (authSizeBytes + 2) / 3 * 4

	// SessionIDLength is the length of an encoded SessionID.
	SessionIDLength = (sessionIDSizeBytes + 2) / 3 * 4

	// SaltLength is the length of encoded Salt.
	SaltLength = (saltSizeBytes + 2) / 3 * 4

	// URLTokenLength is the length of an encoded pasword ResetToken.
	URLTokenLength = (urlTokenSizeBytes + 2) / 3 * 4
)

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(b []byte) ([]byte, error)

Base64Decode decodes the provided []byte using the padded and URL-safe base64 scheme.

func Base64Encode

func Base64Encode(b []byte) []byte

Base64Encode encodes the provided []byte using the padded and URL-safe base64 scheme.

func NewURLToken

func NewURLToken() []byte

NewURLToken generates a cryptographically-secure random slice of base-64 encoded bytes suitable for use in a URL.

func RandomPassword

func RandomPassword() []byte

RandomPassword generates a cryptographically-secure slice of bytes suitable for use as a password.

Types

type AuthToken

type AuthToken [AuthTokenLength]byte

AuthToken is a base-64 encoded array suitable for use as an API key or authentication token.

func NewAuthToken

func NewAuthToken() AuthToken

NewAuthToken generates a cryptographically-secure AuthToken.

func NewPopulatedAuthToken

func NewPopulatedAuthToken(_ randy, easy ...bool) *AuthToken

func (AuthToken) Equal

func (a AuthToken) Equal(a2 AuthToken) bool

func (AuthToken) Marshal

func (a AuthToken) Marshal() ([]byte, error)

func (AuthToken) MarshalJSON

func (a AuthToken) MarshalJSON() ([]byte, error)

func (AuthToken) MarshalTo

func (a AuthToken) MarshalTo(data []byte) (int, error)

func (AuthToken) Size

func (a AuthToken) Size() int

func (*AuthToken) Unmarshal

func (a *AuthToken) Unmarshal(data []byte) error

func (*AuthToken) UnmarshalJSON

func (a *AuthToken) UnmarshalJSON(data []byte) error

type Salt

type Salt [SaltLength]byte

Salt is an array used in cryptographic functions.

func NewSalt

func NewSalt() Salt

NewSalt generates a cryptographically-secure Salt.

type SessionID

type SessionID [SessionIDLength]byte

SessionID is a base-64 encoded array used to identify a particular session.

func NewPopulatedSessionID

func NewPopulatedSessionID(_ randy, easy ...bool) *SessionID

func NewSessionID

func NewSessionID() SessionID

NewSessionID creates a cryptographically-secure session identifier.

func (SessionID) Equal

func (s SessionID) Equal(s2 SessionID) bool

func (SessionID) Marshal

func (s SessionID) Marshal() ([]byte, error)

func (SessionID) MarshalJSON

func (s SessionID) MarshalJSON() ([]byte, error)

func (SessionID) MarshalTo

func (s SessionID) MarshalTo(data []byte) (int, error)

func (SessionID) Size

func (s SessionID) Size() int

func (*SessionID) Unmarshal

func (s *SessionID) Unmarshal(data []byte) error

func (*SessionID) UnmarshalJSON

func (s *SessionID) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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