token

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: AGPL-3.0 Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmpty          = errors.New("token storage is empty")
	ErrNoZone         = errors.New("no zone specified")
	ErrTokenInvalid   = errors.New("token is invalid")
	ErrTokenMalformed = errors.New("token malformed")
	ErrTokenUsed      = errors.New("token already used")
	ErrZoneMismatch   = errors.New("zone mismatch")
	ErrZoneTaken      = errors.New("zone taken")
	ErrZoneUnknown    = errors.New("zone unknown")
)

Functions

func HandleSetupRequest

func HandleSetupRequest(request *SetupRequest) (*RequestHandlingState, *SetupResponse, error)

func ProcessIssuedTokens

func ProcessIssuedTokens(response *IssuedTokens) error

func RegisterPBlindHandler

func RegisterPBlindHandler(h *PBlindHandler) error

func RegisterScrambleHandler

func RegisterScrambleHandler(h *ScrambleHandler) error

func ResetRegistry

func ResetRegistry()

func VerifyToken

func VerifyToken(token *Token) error

Types

type Handler

type Handler interface {
	// Zone returns the zone name.
	Zone() string

	// ShouldRequest returns whether the new tokens should be requested.
	ShouldRequest() bool

	// Amount returns the current amount of tokens in this handler.
	Amount() int

	// IsFallback returns whether this handler should only be used as a fallback.
	IsFallback() bool

	// GetToken returns a token.
	GetToken() (token *Token, err error)

	// Verify verifies the given token.
	Verify(token *Token) error

	// Save serializes and returns the current tokens.
	Save() ([]byte, error)

	// Load loads the given tokens into the handler.
	Load(data []byte) error

	// Clear clears all the tokens in the handler.
	Clear()
}

Handler represents a token handling system.

func GetHandler

func GetHandler(zone string) (handler Handler, ok bool)

type IssuedPBlindTokens

type IssuedPBlindTokens struct {
	Msgs []*pblind.Message3
}

type IssuedScrambleTokens

type IssuedScrambleTokens struct {
	Tokens []*ScrambleToken
}

type IssuedTokens

type IssuedTokens struct {
	PBlind   map[string]*IssuedPBlindTokens   `json:"PB,omitempty"`
	Scramble map[string]*IssuedScrambleTokens `json:"SC,omitempty"`
}

func IssueTokens

func IssueTokens(state *RequestHandlingState, request *TokenRequest) (response *IssuedTokens, err error)

type PBlindHandler

type PBlindHandler struct {
	sync.Mutex

	Storage []*PBlindToken
	// contains filtered or unexported fields
}

func NewPBlindHandler

func NewPBlindHandler(opts PBlindOptions) (*PBlindHandler, error)

func (*PBlindHandler) Amount

func (pbh *PBlindHandler) Amount() int

Amount returns the current amount of tokens in this handler.

func (*PBlindHandler) Clear added in v0.3.9

func (pbh *PBlindHandler) Clear()

Clear clears all the tokens in the handler.

func (*PBlindHandler) CreateSetup

func (pbh *PBlindHandler) CreateSetup() (state *PBlindSignerState, setupResponse *PBlindSetupResponse, err error)

CreateSetup sets up signers for a request.

func (*PBlindHandler) CreateTokenRequest

func (pbh *PBlindHandler) CreateTokenRequest(requestSetup *PBlindSetupResponse) (request *PBlindTokenRequest, err error)

CreateTokenRequest creates a token request to be sent to the token server.

func (*PBlindHandler) GetToken

func (pbh *PBlindHandler) GetToken() (token *Token, err error)

GetToken returns a token.

func (*PBlindHandler) IsFallback

func (pbh *PBlindHandler) IsFallback() bool

IsFallback returns whether this handler should only be used as a fallback.

func (*PBlindHandler) IssueTokens

func (pbh *PBlindHandler) IssueTokens(state *PBlindSignerState, request *PBlindTokenRequest) (response *IssuedPBlindTokens, err error)

IssueTokens sign the requested tokens.

func (*PBlindHandler) Load

func (pbh *PBlindHandler) Load(data []byte) error

Load loads the given tokens into the handler.

func (*PBlindHandler) ProcessIssuedTokens

func (pbh *PBlindHandler) ProcessIssuedTokens(issuedTokens *IssuedPBlindTokens) error

ProcessIssuedTokens processes the issued token from the server.

func (*PBlindHandler) Save

func (pbh *PBlindHandler) Save() ([]byte, error)

Save serializes and returns the current tokens.

func (*PBlindHandler) ShouldRequest

func (pbh *PBlindHandler) ShouldRequest() bool

ShouldRequest returns whether the new tokens should be requested.

func (*PBlindHandler) Verify

func (pbh *PBlindHandler) Verify(token *Token) error

Verify verifies the given token.

func (*PBlindHandler) Zone

func (pbh *PBlindHandler) Zone() string

Zone returns the zone name.

type PBlindOptions

type PBlindOptions struct {
	Zone                  string
	CurveName             string
	Curve                 elliptic.Curve
	PublicKey             string
	PrivateKey            string
	UseSerials            bool
	BatchSize             int
	RandomizeOrder        bool
	SignalShouldRequest   func(Handler)
	DoubleSpendProtection func([]byte) error
	Fallback              bool
}

type PBlindSetupResponse

type PBlindSetupResponse struct {
	Msgs []*pblind.Message1
}

type PBlindSignerState

type PBlindSignerState struct {
	// contains filtered or unexported fields
}

type PBlindStorage

type PBlindStorage struct {
	Storage []*PBlindToken
}

type PBlindToken

type PBlindToken struct {
	Serial    int               `json:"N,omitempty"`
	Token     []byte            `json:"T,omitempty"`
	Signature *pblind.Signature `json:"S,omitempty"`
}

func UnpackPBlindToken

func UnpackPBlindToken(token []byte) (*PBlindToken, error)

func (*PBlindToken) Pack

func (pbt *PBlindToken) Pack() ([]byte, error)

type PBlindTokenRequest

type PBlindTokenRequest struct {
	Msgs []*pblind.Message2
}

type RequestHandlingState

type RequestHandlingState struct {
	SessionID string
	PBlind    map[string]*PBlindSignerState
}

type RequestState

type RequestState struct {
	Token []byte
	State *pblind.StateRequester
}

type ScrambleHandler

type ScrambleHandler struct {
	sync.Mutex

	Storage []*ScrambleToken
	// contains filtered or unexported fields
}

func NewScrambleHandler

func NewScrambleHandler(opts ScrambleOptions) (*ScrambleHandler, error)

func (*ScrambleHandler) Amount

func (sh *ScrambleHandler) Amount() int

Amount returns the current amount of tokens in this handler.

func (*ScrambleHandler) Clear added in v0.3.9

func (sh *ScrambleHandler) Clear()

Clear clears all the tokens in the handler.

func (*ScrambleHandler) CreateTokenRequest

func (sh *ScrambleHandler) CreateTokenRequest() (request *ScrambleTokenRequest)

CreateTokenRequest creates a token request to be sent to the token server.

func (*ScrambleHandler) GetToken

func (sh *ScrambleHandler) GetToken() (*Token, error)

GetToken returns a token.

func (*ScrambleHandler) IsFallback

func (sh *ScrambleHandler) IsFallback() bool

IsFallback returns whether this handler should only be used as a fallback.

func (*ScrambleHandler) IssueTokens

func (sh *ScrambleHandler) IssueTokens(request *ScrambleTokenRequest) (response *IssuedScrambleTokens, err error)

IssueTokens sign the requested tokens.

func (*ScrambleHandler) Load

func (sh *ScrambleHandler) Load(data []byte) error

Load loads the given tokens into the handler.

func (*ScrambleHandler) ProcessIssuedTokens

func (sh *ScrambleHandler) ProcessIssuedTokens(issuedTokens *IssuedScrambleTokens) error

ProcessIssuedTokens processes the issued token from the server.

func (*ScrambleHandler) Save

func (sh *ScrambleHandler) Save() ([]byte, error)

Save serializes and returns the current tokens.

func (*ScrambleHandler) ShouldRequest

func (sh *ScrambleHandler) ShouldRequest() bool

ShouldRequest returns whether the new tokens should be requested.

func (*ScrambleHandler) Verify

func (sh *ScrambleHandler) Verify(token *Token) error

Verify verifies the given token.

func (*ScrambleHandler) Zone

func (sh *ScrambleHandler) Zone() string

Zone returns the zone name.

type ScrambleOptions

type ScrambleOptions struct {
	Zone             string
	Algorithm        lhash.Algorithm
	InitialTokens    []string
	InitialVerifiers []string
	Fallback         bool
}

type ScrambleStorage

type ScrambleStorage struct {
	Storage []*ScrambleToken
}

type ScrambleToken

type ScrambleToken struct {
	Token []byte
}

func UnpackScrambleToken

func UnpackScrambleToken(token []byte) (*ScrambleToken, error)

func (*ScrambleToken) Pack

func (pbt *ScrambleToken) Pack() ([]byte, error)

type ScrambleTokenRequest

type ScrambleTokenRequest struct {
}

type SetupRequest

type SetupRequest struct {
	PBlind map[string]struct{} `json:"PB,omitempty"`
}

func CreateSetupRequest

func CreateSetupRequest() (request *SetupRequest, setupRequired bool)

type SetupResponse

type SetupResponse struct {
	SessionID string                          `json:"ID,omitempty"`
	PBlind    map[string]*PBlindSetupResponse `json:"PB,omitempty"`
}

type Token

type Token struct {
	Zone string
	Data []byte
}

func GetToken

func GetToken(zone string) (*Token, error)

func ParseRawToken

func ParseRawToken(code []byte) (*Token, error)

func ParseToken

func ParseToken(code string) (*Token, error)

func (*Token) Raw

func (c *Token) Raw() []byte

func (*Token) String

func (c *Token) String() string

type TokenRequest

type TokenRequest struct {
	SessionID string                           `json:"ID,omitempty"`
	PBlind    map[string]*PBlindTokenRequest   `json:"PB,omitempty"`
	Scramble  map[string]*ScrambleTokenRequest `json:"S,omitempty"`
}

func CreateTokenRequest

func CreateTokenRequest(setup *SetupResponse) (request *TokenRequest, requestRequired bool, err error)

Jump to

Keyboard shortcuts

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