Documentation ¶
Index ¶
- func Generate(payload map[string]interface{}, privateKey *rsa.PrivateKey) []byte
- func IsUnexpectedError(err error) bool
- func ParseAndValidate(token []byte, publicKey *rsa.PublicKey) (map[string]interface{}, error)
- func UnmarshalDependingOnItemPlatform(store *database.DataStore, itemID int64, target interface{}, token []byte, ...) (err error)
- type Answer
- type Config
- type Hint
- type MarshalStringer
- type Score
- type Signer
- type Task
- type UnexpectedError
- 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 IsUnexpectedError ¶
IsUnexpectedError returns true if its argument is an unexpected error
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) (err error)
UnmarshalDependingOnItemPlatform unmarshals a token from JSON representation using a platforms's public key for given itemID. The function returns 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 UnexpectedError ¶
type UnexpectedError struct {
// contains filtered or unexported fields
}
UnexpectedError represents an unexpected error so that we could differentiate it from expected errors
func (*UnexpectedError) Error ¶
func (ue *UnexpectedError) Error() string
Error returns a string representation for an unexpected error
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}"`