Documentation
¶
Overview ¶
Package fst is a high-performance, low-memory library for generating and parsing Fast Signed Tokens (FST). FST provides an alternative to JSON-based tokens and allows you to store any information that can be represented as []byte. You can use FST for the same purposes as JWT.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Converter ¶
type Converter struct { NewToken func([]byte) string ParseToken func(string) ([]byte, error) // contains filtered or unexported fields }
Converter represents a token converter that can generate and parse Fast Signed Tokens.
secretKey is the secret used to sign the token.
postfix is the postfix to add to the token to more secure the token.
hashType is the hash function used to sign the token.
timeBeforeExpire is the lifetime of the token.
hmacPool and expirationTime and timeNow are needed to improve performance.
NewToken is the function used to generate the token.
ParseToken is the function used to parse the token.
func NewConverter ¶
func NewConverter(cfg *ConverterConfig) *Converter
NewConverter creates a new instance of the Converter based on the provided fst.ConverterConfig.
Example of the usage:
converter := fst.NewConverter(&fst.ConverterConfig{ SecretKey: []byte(`secret`), Postfix: nil, ExpirationTime: time.Minute * 5, HashType: sha256.New, WithExpirationTime: true, })
func (*Converter) ExpireTime ¶
ExpireTime returns the expiration time used by the Converter.
type ConverterConfig ¶
type ConverterConfig struct { // SecretKey is the secret used to sign the token. SecretKey []byte // Postfix is the postfix to add to the token to more secure the token. Postfix []byte // ExpirationTime is the expiration time of the token. ExpirationTime time.Duration // HashType is the hash function used to sign the token. HashType func() hash.Hash WithExpirationTime bool }
ConverterConfig represents the configuration options for creating a new Converter.
SecretKey is the secret used to sign the token.
Postfix is the postfix to add to the token to more secure the token.
ExpirationTime is the expiration time of the token.
HashType is the hash function used to sign the token.
WithExpirationTime is the flag to enable expiration time. By default, it is disabled.