Documentation ¶
Index ¶
- Variables
- func HandleSetupRequest(request *SetupRequest) (*RequestHandlingState, *SetupResponse, error)
- func ProcessIssuedTokens(response *IssuedTokens) error
- func RegisterPBlindHandler(h *PBlindHandler) error
- func RegisterScrambleHandler(h *ScrambleHandler) error
- func RegistrySize() int
- func ResetRegistry()
- func VerifyToken(token *Token) error
- type Handler
- type IssuedPBlindTokens
- type IssuedScrambleTokens
- type IssuedTokens
- type PBlindHandler
- func (pbh *PBlindHandler) Amount() int
- func (pbh *PBlindHandler) Clear()
- func (pbh *PBlindHandler) CreateSetup() (state *PBlindSignerState, setupResponse *PBlindSetupResponse, err error)
- func (pbh *PBlindHandler) CreateTokenRequest(requestSetup *PBlindSetupResponse) (request *PBlindTokenRequest, err error)
- func (pbh *PBlindHandler) GetToken() (token *Token, err error)
- func (pbh *PBlindHandler) IsFallback() bool
- func (pbh *PBlindHandler) IssueTokens(state *PBlindSignerState, request *PBlindTokenRequest) (response *IssuedPBlindTokens, err error)
- func (pbh *PBlindHandler) Load(data []byte) error
- func (pbh *PBlindHandler) ProcessIssuedTokens(issuedTokens *IssuedPBlindTokens) error
- func (pbh *PBlindHandler) Save() ([]byte, error)
- func (pbh *PBlindHandler) ShouldRequest() bool
- func (pbh *PBlindHandler) Verify(token *Token) error
- func (pbh *PBlindHandler) Zone() string
- type PBlindOptions
- type PBlindSetupResponse
- type PBlindSignerState
- type PBlindStorage
- type PBlindToken
- type PBlindTokenRequest
- type RequestHandlingState
- type RequestState
- type ScrambleHandler
- func (sh *ScrambleHandler) Amount() int
- func (sh *ScrambleHandler) Clear()
- func (sh *ScrambleHandler) CreateTokenRequest() (request *ScrambleTokenRequest)
- func (sh *ScrambleHandler) GetToken() (*Token, error)
- func (sh *ScrambleHandler) IsFallback() bool
- func (sh *ScrambleHandler) IssueTokens(request *ScrambleTokenRequest) (response *IssuedScrambleTokens, err error)
- func (sh *ScrambleHandler) Load(data []byte) error
- func (sh *ScrambleHandler) ProcessIssuedTokens(issuedTokens *IssuedScrambleTokens) error
- func (sh *ScrambleHandler) Save() ([]byte, error)
- func (sh *ScrambleHandler) ShouldRequest() bool
- func (sh *ScrambleHandler) Verify(token *Token) error
- func (sh *ScrambleHandler) Zone() string
- type ScrambleOptions
- type ScrambleStorage
- type ScrambleToken
- type ScrambleTokenRequest
- type SetupRequest
- type SetupResponse
- type Token
- type TokenRequest
Constants ¶
This section is empty.
Variables ¶
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") )
Errors.
Functions ¶
func HandleSetupRequest ¶
func HandleSetupRequest(request *SetupRequest) (*RequestHandlingState, *SetupResponse, error)
HandleSetupRequest handles a setup request for all registered tokens.
func ProcessIssuedTokens ¶
func ProcessIssuedTokens(response *IssuedTokens) error
ProcessIssuedTokens processes issued tokens for all registered tokens.
func RegisterPBlindHandler ¶
func RegisterPBlindHandler(h *PBlindHandler) error
RegisterPBlindHandler registers a pblind handler with the registry.
func RegisterScrambleHandler ¶
func RegisterScrambleHandler(h *ScrambleHandler) error
RegisterScrambleHandler registers a scramble handler with the registry.
func RegistrySize ¶ added in v0.4.0
func RegistrySize() int
RegistrySize returns the amount of handler registered.
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 ¶
GetHandler returns the handler of the given zone.
type IssuedPBlindTokens ¶
IssuedPBlindTokens are issued pblind tokens.
type IssuedScrambleTokens ¶
type IssuedScrambleTokens struct {
Tokens []*ScrambleToken
}
IssuedScrambleTokens are issued scrambled tokens.
type IssuedTokens ¶
type IssuedTokens struct { PBlind map[string]*IssuedPBlindTokens `json:"PB,omitempty"` Scramble map[string]*IssuedScrambleTokens `json:"SC,omitempty"` }
IssuedTokens are issued tokens.
func IssueTokens ¶
func IssueTokens(state *RequestHandlingState, request *TokenRequest) (response *IssuedTokens, err error)
IssueTokens issues tokens for all registered tokens.
type PBlindHandler ¶
type PBlindHandler struct { sync.Mutex Storage []*PBlindToken // contains filtered or unexported fields }
PBlindHandler is a handler for the pblind tokens.
func NewPBlindHandler ¶
func NewPBlindHandler(opts PBlindOptions) (*PBlindHandler, error)
NewPBlindHandler creates a new pblind handler.
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.
type PBlindOptions ¶
type PBlindOptions struct { Zone string CurveName string Curve elliptic.Curve PublicKey string PrivateKey string BatchSize int UseSerials bool RandomizeOrder bool Fallback bool SignalShouldRequest func(Handler) DoubleSpendProtection func([]byte) error }
PBlindOptions are options for the PBlindHandler.
type PBlindSetupResponse ¶
PBlindSetupResponse is a setup response.
type PBlindSignerState ¶
type PBlindSignerState struct {
// contains filtered or unexported fields
}
PBlindSignerState is a signer state.
type PBlindStorage ¶
type PBlindStorage struct {
Storage []*PBlindToken
}
PBlindStorage is a storage for pblind tokens.
type PBlindToken ¶
type PBlindToken struct { Serial int `json:"N,omitempty"` Token []byte `json:"T,omitempty"` Signature *pblind.Signature `json:"S,omitempty"` }
PBlindToken is token based on the pblind library.
func UnpackPBlindToken ¶
func UnpackPBlindToken(token []byte) (*PBlindToken, error)
UnpackPBlindToken unpacks the token.
type PBlindTokenRequest ¶
PBlindTokenRequest is a token request.
type RequestHandlingState ¶
type RequestHandlingState struct { SessionID string PBlind map[string]*PBlindSignerState }
RequestHandlingState is a request handling state.
type RequestState ¶
type RequestState struct { Token []byte State *pblind.StateRequester }
RequestState is a request state.
type ScrambleHandler ¶
type ScrambleHandler struct { sync.Mutex Storage []*ScrambleToken // contains filtered or unexported fields }
ScrambleHandler is a handler for the scramble tokens.
func NewScrambleHandler ¶
func NewScrambleHandler(opts ScrambleOptions) (*ScrambleHandler, error)
NewScrambleHandler creates a new scramble handler.
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.
type ScrambleOptions ¶
type ScrambleOptions struct { Zone string Algorithm lhash.Algorithm InitialTokens []string InitialVerifiers []string Fallback bool }
ScrambleOptions are options for the ScrambleHandler.
type ScrambleStorage ¶
type ScrambleStorage struct {
Storage []*ScrambleToken
}
ScrambleStorage is a storage for scramble tokens.
type ScrambleToken ¶
type ScrambleToken struct {
Token []byte
}
ScrambleToken is token based on hashing.
func UnpackScrambleToken ¶
func UnpackScrambleToken(token []byte) (*ScrambleToken, error)
UnpackScrambleToken unpacks the token.
type ScrambleTokenRequest ¶
type ScrambleTokenRequest struct{}
ScrambleTokenRequest is a token request.
type SetupRequest ¶
type SetupRequest struct {
PBlind map[string]struct{} `json:"PB,omitempty"`
}
SetupRequest is a setup request.
func CreateSetupRequest ¶
func CreateSetupRequest() (request *SetupRequest, setupRequired bool)
CreateSetupRequest creates a combined setup request for all registered tokens, if needed.
type SetupResponse ¶
type SetupResponse struct { SessionID string `json:"ID,omitempty"` PBlind map[string]*PBlindSetupResponse `json:"PB,omitempty"` }
SetupResponse is a setup response.
type Token ¶
Token represents a token, consisting of a zone (name) and some data.
func ParseRawToken ¶
ParseRawToken parses a raw token.
func ParseToken ¶
ParseToken parses a stringified token.
type TokenRequest ¶
type TokenRequest struct { SessionID string `json:"ID,omitempty"` PBlind map[string]*PBlindTokenRequest `json:"PB,omitempty"` Scramble map[string]*ScrambleTokenRequest `json:"S,omitempty"` }
TokenRequest is a token request.
func CreateTokenRequest ¶
func CreateTokenRequest(setup *SetupResponse) (request *TokenRequest, requestRequired bool, err error)
CreateTokenRequest creates a token request for all registered tokens.