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
- func Base64Decode(b []byte) ([]byte, error)
- func Base64Encode(b []byte) []byte
- func NewURLToken() []byte
- func RandomPassword() []byte
- type AuthToken
- func (a AuthToken) Equal(a2 AuthToken) bool
- func (a AuthToken) Marshal() ([]byte, error)
- func (a AuthToken) MarshalJSON() ([]byte, error)
- func (a AuthToken) MarshalTo(data []byte) (int, error)
- func (a AuthToken) Size() int
- func (a *AuthToken) Unmarshal(data []byte) error
- func (a *AuthToken) UnmarshalJSON(data []byte) error
- type Salt
- type SessionID
- func (s SessionID) Equal(s2 SessionID) bool
- func (s SessionID) Marshal() ([]byte, error)
- func (s SessionID) MarshalJSON() ([]byte, error)
- func (s SessionID) MarshalTo(data []byte) (int, error)
- func (s SessionID) Size() int
- func (s *SessionID) Unmarshal(data []byte) error
- func (s *SessionID) UnmarshalJSON(data []byte) error
Constants ¶
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 ¶
Base64Decode decodes the provided []byte using the padded and URL-safe base64 scheme.
func Base64Encode ¶
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 (AuthToken) MarshalJSON ¶
func (*AuthToken) UnmarshalJSON ¶
type SessionID ¶
type SessionID [SessionIDLength]byte
SessionID is a base-64 encoded array used to identify a particular session.
func NewPopulatedSessionID ¶
func NewSessionID ¶
func NewSessionID() SessionID
NewSessionID creates a cryptographically-secure session identifier.