src

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IKey

type IKey interface {
	SetPublicKey(path string)
	SetPrivateKey(path string)
	SetCommonKey(secret string)
	GetPublicKey() *rsa.PublicKey
	GetPrivateKey() *rsa.PrivateKey
	GetCommonKey() string
}

type IToken

type IToken interface {
	SetSignAlgorithm(alg SignAlgorithm)
	SetExpiresAt(t int64)
	SetRepeatExpiresAt(t int64)
	SetSecret(secret string)
	SetClaims(claims any)
	SignToken() string
	GetExpiresAt() *jwt.NumericDate
	GetClaims() *NewClaims
	GetSignAlgorithm() SignAlgorithm
}

type Key

type Key struct {
	PrivateKey *rsa.PrivateKey
	PublicKey  *rsa.PublicKey
	CommonKey  string
}

func (*Key) GetCommonKey

func (k *Key) GetCommonKey() string

func (*Key) GetPrivateKey

func (k *Key) GetPrivateKey() *rsa.PrivateKey

func (*Key) GetPublicKey

func (k *Key) GetPublicKey() *rsa.PublicKey

func (*Key) SetCommonKey

func (k *Key) SetCommonKey(secret string)

func (*Key) SetPrivateKey

func (k *Key) SetPrivateKey(path string)

func (*Key) SetPublicKey

func (k *Key) SetPublicKey(path string)

type NewClaims

type NewClaims struct {
	Claims any `json:"claims"`
	jwt.RegisteredClaims
}

type SignAlgorithm

type SignAlgorithm jwt.SigningMethod
var (
	HMAC SignAlgorithm = jwt.SigningMethodHS256
	RSA  SignAlgorithm = jwt.SigningMethodRS256
)

type Token

type Token struct {
	SignAlgorithm SignAlgorithm
	ExpiresAt     *jwt.NumericDate
	Key           IKey
	Claims        *NewClaims `json:"claims"` // Payload
	Jwt           string     // Token in string
}

func (*Token) GetClaims

func (tk *Token) GetClaims() *NewClaims

func (*Token) GetExpiresAt

func (tk *Token) GetExpiresAt() *jwt.NumericDate

Get

func (*Token) GetSignAlgorithm

func (tk *Token) GetSignAlgorithm() SignAlgorithm

func (*Token) SetClaims

func (tk *Token) SetClaims(claims any)

func (*Token) SetExpiresAt

func (tk *Token) SetExpiresAt(t int64)

func (*Token) SetRepeatExpiresAt

func (tk *Token) SetRepeatExpiresAt(t int64)

func (*Token) SetSecret

func (tk *Token) SetSecret(secret string)

func (*Token) SetSignAlgorithm

func (tk *Token) SetSignAlgorithm(alg SignAlgorithm)

Set

func (*Token) SignToken

func (tk *Token) SignToken() string

Usecases

Jump to

Keyboard shortcuts

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