Documentation ¶
Overview ¶
Package token provides a way to serialize/un-serialize data structures in an encrypted token.
Index ¶
- func Generate(payload map[string]interface{}, privateKey *rsa.PrivateKey) []byte
- func ParseAndValidate(token []byte, publicKey *rsa.PublicKey) (map[string]interface{}, error)
- func UnmarshalDependingOnItemPlatform(store *database.DataStore, itemID int64, target interface{}, token []byte, ...) (platformHasKey bool, err error)
- type Answer
- type Config
- type Hint
- type MarshalStringer
- type Score
- type Signer
- type Task
- type Thread
- type UnmarshalStringer
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 ¶
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 ¶
MarshalJSON marshals the answer token into JSON.
func (*Answer) MarshalString ¶
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 ¶
UnmarshalJSON unmarshals the answer token from JSON.
func (*Answer) UnmarshalString ¶
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.
type Hint ¶
Hint represents a hint token.
func (*Hint) MarshalJSON ¶
MarshalJSON marshals the answer token into JSON.
func (*Hint) MarshalString ¶
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 ¶
UnmarshalJSON unmarshals the answer token from JSON.
func (*Hint) UnmarshalString ¶
UnmarshalString unmarshals the task token from a string.
type MarshalStringer ¶
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 ¶
MarshalJSON marshals the score token into JSON.
func (*Score) MarshalString ¶
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 ¶
UnmarshalJSON unmarshals the score token from JSON.
func (*Score) UnmarshalString ¶
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 ¶
Task represents a task token.
func (*Task) MarshalJSON ¶
MarshalJSON marshals the task token into JSON.
func (*Task) MarshalString ¶
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 ¶
UnmarshalJSON unmarshals the task token from JSON.
func (*Task) UnmarshalString ¶
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
MarshalJSON marshals the answer token into JSON.
func (*Thread) MarshalString ¶ added in v1.9.0
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
UnmarshalJSON unmarshals the answer token from JSON.
func (*Thread) UnmarshalString ¶ added in v1.9.0
UnmarshalString unmarshals the task token from a string.
type UnmarshalStringer ¶
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}"`.