codec

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 13 Imported by: 0

README

codec 编码与对称加密相关函数

  1. base64
  2. cookie加密、解密
  3. jwt 加密、解密

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMalformed = errors.New("jwt: malformed token")

ErrMalformed indicates a token doesn't have a valid format, as per the RFC 7519.

View Source
var ErrNotJSONObject = errors.New("jwt: payload is not a valid JSON object")

ErrNotJSONObject is the error for when a JWT payload is not a JSON object.

Functions

This section is empty.

Types

type Audience

type Audience []string

Audience is a special claim that may either be a single string or an array of strings, as per the RFC 7519.

func (Audience) MarshalJSON

func (a Audience) MarshalJSON() ([]byte, error)

MarshalJSON implements a marshaling function for "aud" claim.

func (*Audience) UnmarshalJSON

func (a *Audience) UnmarshalJSON(b []byte) error

UnmarshalJSON implements an unmarshaling function for "aud" claim.

type CryptoCodec

type CryptoCodec interface {
	Encode(key, plaintext []byte) ([]byte, error)
	Decode(key, ciphertext []byte) ([]byte, error)
	// contains filtered or unexported methods
}

func NewCookieCodec

func NewCookieCodec(hashKey, blockKey []byte) CryptoCodec

func NewJwtCodec

func NewJwtCodec(alg string) CryptoCodec

type GobEncoder

type GobEncoder struct{}

GobEncoder encodes cookie values using encoding/gob. This is the simplest encoder and can handle complex types via gob.Register.

func (GobEncoder) Decode

func (e GobEncoder) Decode(src []byte, dst interface{}) error

Decode decodes a value using gob.

func (GobEncoder) Encode

func (e GobEncoder) Encode(src interface{}) ([]byte, error)
type Header struct {
	Algorithm   string `json:"alg,omitempty"`
	ContentType string `json:"cty,omitempty"`
	KeyID       string `json:"kid,omitempty"`
	Type        string `json:"typ,omitempty"`
}

type JSONEncoder

type JSONEncoder struct{}

func (JSONEncoder) Decode

func (e JSONEncoder) Decode(src []byte, dst interface{}) error

Decode decodes a value using encoding/json.

func (JSONEncoder) Encode

func (e JSONEncoder) Encode(src interface{}) ([]byte, error)

Encode encodes a value using encoding/json.

type ObjectCodec

type ObjectCodec interface {
	Encode(src interface{}) ([]byte, error)
	Decode(src []byte, dst interface{}) error
	// contains filtered or unexported methods
}

type Payload

type Payload struct {
	Issuer         string     `json:"iss,omitempty"`
	Subject        string     `json:"sub,omitempty"`
	Audience       Audience   `json:"aud,omitempty"`
	ExpirationTime *core.Time `json:"exp,omitempty"`
	NotBefore      *core.Time `json:"nbf,omitempty"`
	IssuedAt       *core.Time `json:"iat,omitempty"`
	JWTID          string     `json:"jti,omitempty"`
}

Payload is a JWT payload according to the RFC 7519.

Jump to

Keyboard shortcuts

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