Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoIssuedAt = errors.New("uciph/cutil/token: Token data does not contains CreatedAt")
var ErrTokenExpired = errors.New("uciph/cutil/token: Token data is expired")
Functions ¶
This section is empty.
Types ¶
type Base64Manager ¶
Base64Manager wraps other manager and base64 encodes them with encoding it's given.
func (*Base64Manager) IssueToken ¶
func (m *Base64Manager) IssueToken(data interface{}) (token []byte, err error)
func (*Base64Manager) LoadToken ¶
func (m *Base64Manager) LoadToken(token []byte, dst interface{}) (err error)
type CreatedAtData ¶
CreatedAtData is kind of token data, which contains time of creation of this token.
type EncryptingManager ¶
type EncryptingManager struct { Manager Manager EncFac func() enc.Encryptor DecFac func() enc.Decryptor }
EncryptingManager uses EncFac and DecFac to encrypt/decrypt marshaled data. EncFac and DecFac should use AEAD encryptors in order not to allow tampering with token contents.
func (*EncryptingManager) IssueToken ¶
func (m *EncryptingManager) IssueToken(data interface{}) (token []byte, err error)
IssueToken serializes data, and encrypts it.
func (*EncryptingManager) LoadToken ¶
func (m *EncryptingManager) LoadToken(token []byte, dst interface{}) (err error)
LoadToken decrypts data, and deserializes it.
type ExpireManager ¶
type ExpireManager struct { Manager Manager // underlying manager, has to be provided Now func() time.Time // defaults to time.Now ForceCreatedAt bool // if false, then data that does not implement CreatedAtData interface, then it's skipped with no error. MaxTokenLifetime time.Duration // Skipped if zero IsExpired func(res interface{}, livesFor time.Duration) (bool, error) // Skipped if nil }
ExpireManager returns error if token is expired.
func (*ExpireManager) LoadToken ¶
func (m *ExpireManager) LoadToken(token []byte, dst interface{}) (err error)
LoadToken loads token data using underlying manager, and chck
type Manager ¶
type Manager interface { IssueToken(data interface{}) (token []byte, err error) LoadToken(token []byte, dst interface{}) (err error) }
Manager is something able to issue and load tokens.
type MarshalingManager ¶
type MarshalingManager struct { Marshaler Marshaler Unmarshaler Unmarshaler }
// JSONUnmarshaler unmarshals given type of token data using factory. // Factory has to return POINTER TYPE of deserialized struct in order to make it work.
func JSONUnmarshaler(fac func() interface{}) Unmarshaler { return Unmarshaler(func(data []byte) (res interface{}, err error) { res = fac() err = json.Unmarshal(data, res) return }) }
MarshalingManager is simplest possible token manager. The only thing it does it marshalling token with
func (*MarshalingManager) IssueToken ¶
func (m *MarshalingManager) IssueToken(data interface{}) (token []byte, err error)
IssueToken serializes data, and encrypts it.
func (*MarshalingManager) LoadToken ¶
func (m *MarshalingManager) LoadToken(token []byte, dst interface{}) (err error)
LoadToken decrypts data, and deserializes it.
type SigningManger ¶
type SigningManger struct { Manager Manager SignerFac func() sig.Signer VerifierFac func() sig.Verifier }
SigningManger uses singer fac and verifier fac in order to verify if token has valid sign or not.
func (*SigningManger) IssueToken ¶
func (m *SigningManger) IssueToken(data interface{}) (token []byte, err error)
IssueToken serializes data, and encrypts it.
func (*SigningManger) LoadToken ¶
func (m *SigningManger) LoadToken(token []byte, dst interface{}) (err error)
LoadToken decrypts data, and deserializes it.
type TokenLoadError ¶
type TokenLoadError struct {
Err error
}
func (*TokenLoadError) Error ¶
func (tle *TokenLoadError) Error() string
func (*TokenLoadError) Unwrap ¶
func (tle *TokenLoadError) Unwrap() error
type Unmarshaler ¶
Unmarshaler is responsible for deserializing token data from bytes.
var JSONUnmarshaler Unmarshaler = json.Unmarshal
JSONMarshaler marsahls any type of token data as JSON. It can be reverted for specific type with JSONUnmarshaler. var JSONMarshaler Marshaler = json.Marshal