token

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package token provides a way to serialize/un-serialize data structures in an encrypted token.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(payload map[string]interface{}, privateKey *rsa.PrivateKey) []byte

Generate generates a signed token for a payload.

func ParseAndValidate

func ParseAndValidate(token []byte, publicKey *rsa.PublicKey) (map[string]interface{}, error)

ParseAndValidate parses a token and validates its signature and date.

func UnmarshalDependingOnItemPlatform

func UnmarshalDependingOnItemPlatform(
	store *database.DataStore,
	itemID int64,
	target interface{},
	token []byte,
	tokenFieldName string,
) (platformHasKey bool, err error)

UnmarshalDependingOnItemPlatform unmarshals a token from JSON representation using a platform's public key for given itemID. The function returns nil (success) if the platform doesn't use tokens.

Types

type Answer

type Answer payloads.AnswerToken

Answer represents an answer token.

func (*Answer) MarshalJSON

func (tt *Answer) MarshalJSON() ([]byte, error)

MarshalJSON marshals the answer token into JSON.

func (*Answer) MarshalString

func (tt *Answer) MarshalString() (string, error)

MarshalString marshals the answer token into a string.

func (*Answer) Sign

func (tt *Answer) Sign(privateKey *rsa.PrivateKey) (string, error)

Sign returns a signed token as a string.

func (*Answer) UnmarshalJSON

func (tt *Answer) UnmarshalJSON(raw []byte) error

UnmarshalJSON unmarshals the answer token from JSON.

func (*Answer) UnmarshalString

func (tt *Answer) UnmarshalString(raw string) error

UnmarshalString unmarshals the task token from a string.

type Config

type Config struct {
	PublicKey    *rsa.PublicKey
	PrivateKey   *rsa.PrivateKey
	PlatformName string
}

Config contains parsed keys and PlatformName.

func Initialize

func Initialize(config *viper.Viper) (tokenConfig *Config, err error)

Initialize loads keys from the config and resolves the platform name.

type Hint

type Hint payloads.HintToken

Hint represents a hint token.

func (*Hint) MarshalJSON

func (tt *Hint) MarshalJSON() ([]byte, error)

MarshalJSON marshals the answer token into JSON.

func (*Hint) MarshalString

func (tt *Hint) MarshalString() (string, error)

MarshalString marshals the hint token into a string.

func (*Hint) Sign

func (tt *Hint) Sign(privateKey *rsa.PrivateKey) (string, error)

Sign returns a signed token as a string.

func (*Hint) UnmarshalJSON

func (tt *Hint) UnmarshalJSON(raw []byte) error

UnmarshalJSON unmarshals the answer token from JSON.

func (*Hint) UnmarshalString

func (tt *Hint) UnmarshalString(raw string) error

UnmarshalString unmarshals the task token from a string.

type MarshalStringer

type MarshalStringer interface {
	MarshalString() (string, error)
}

MarshalStringer is the interface implemented by types that can marshal themselves into a string. For example, a token's string description is `{ENCODED_TOKEN}` while a token's JSON description is `"{ENCODED_TOKEN}"`.

type Score

type Score payloads.ScoreToken

Score represents a score token.

func (*Score) MarshalJSON

func (tt *Score) MarshalJSON() ([]byte, error)

MarshalJSON marshals the score token into JSON.

func (*Score) MarshalString

func (tt *Score) MarshalString() (string, error)

MarshalString marshals the score token into a string.

func (*Score) Sign

func (tt *Score) Sign(privateKey *rsa.PrivateKey) (string, error)

Sign returns a signed score token as a string.

func (*Score) UnmarshalJSON

func (tt *Score) UnmarshalJSON(raw []byte) error

UnmarshalJSON unmarshals the score token from JSON.

func (*Score) UnmarshalString

func (tt *Score) UnmarshalString(raw string) error

UnmarshalString unmarshals the score token from a string.

type Signer

type Signer interface {
	Sign(*rsa.PrivateKey) (string, error)
}

Signer is the interface implemented by types that can sign themselves returning a token in a string.

type Task

type Task payloads.TaskToken

Task represents a task token.

func (*Task) MarshalJSON

func (tt *Task) MarshalJSON() ([]byte, error)

MarshalJSON marshals the task token into JSON.

func (*Task) MarshalString

func (tt *Task) MarshalString() (string, error)

MarshalString marshals the task token into a string.

func (*Task) Sign

func (tt *Task) Sign(privateKey *rsa.PrivateKey) (string, error)

Sign returns a signed token as a string.

func (*Task) UnmarshalJSON

func (tt *Task) UnmarshalJSON(raw []byte) error

UnmarshalJSON unmarshals the task token from JSON.

func (*Task) UnmarshalString

func (tt *Task) UnmarshalString(raw string) error

UnmarshalString unmarshals the task token from a string.

type Thread added in v1.9.0

type Thread payloads.ThreadToken

Thread represents a thread token.

func (*Thread) MarshalJSON added in v1.9.0

func (tt *Thread) MarshalJSON() ([]byte, error)

MarshalJSON marshals the answer token into JSON.

func (*Thread) MarshalString added in v1.9.0

func (tt *Thread) MarshalString() (string, error)

MarshalString marshals the answer token into a string.

func (*Thread) Sign added in v1.9.0

func (tt *Thread) Sign(privateKey *rsa.PrivateKey) (string, error)

Sign returns a signed token as a string.

func (*Thread) UnmarshalJSON added in v1.9.0

func (tt *Thread) UnmarshalJSON(raw []byte) error

UnmarshalJSON unmarshals the answer token from JSON.

func (*Thread) UnmarshalString added in v1.9.0

func (tt *Thread) UnmarshalString(raw string) error

UnmarshalString unmarshals the task token from a string.

type UnmarshalStringer

type UnmarshalStringer interface {
	UnmarshalString(string) error
}

UnmarshalStringer is the interface implemented by types that can unmarshal a string description of themselves. For example, a token's string description is `{ENCODED_TOKEN}` while a token's JSON description is `"{ENCODED_TOKEN}"`.

Jump to

Keyboard shortcuts

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