common

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JWS TokenType = "jws"
	JWE TokenType = "jwe"

	// JWS
	HS256 AlgorithmType = "HS256"
	RS256 AlgorithmType = "RS256"
	None  AlgorithmType = "none"

	// JWE
	RSA_OAEP AlgorithmType     = "RSA-OAEP"
	A256GCM  AuthAlgorithmType = "A256GCM"
)

Variables

View Source
var (
	// JWS
	JwsAlgorithmsMap = map[AlgorithmType]bool{
		HS256: true,
		RS256: true,
		None:  true,
	}

	// JWE
	JweAlgorithmsMap = map[AlgorithmType]bool{
		RSA_OAEP: true,
	}

	JweAuthAlgorithmsMap = map[AuthAlgorithmType]bool{
		A256GCM: true,
	}

	JweAuthAlgorithmSizeMap = map[AuthAlgorithmType]int{
		A256GCM: 32,
	}
)

Functions

This section is empty.

Types

type AlgorithmSuite

type AlgorithmSuite struct {
	AlgorithmType
	AuthAlgorithmType
}

type AlgorithmType

type AlgorithmType string

type AuthAlgorithmType

type AuthAlgorithmType string

type ClaimSet

type ClaimSet map[string]interface{}

func NewClaimSet

func NewClaimSet() ClaimSet

func (*ClaimSet) Add

func (c *ClaimSet) Add(key string, value interface{}) error

func (*ClaimSet) MarshalJSON

func (c *ClaimSet) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*ClaimSet) Remove

func (c *ClaimSet) Remove(key string) error

func (*ClaimSet) UnmarshalJSON

func (c *ClaimSet) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type Header struct {
	Data     map[string]interface{}
	Metadata *Metadata
}

func (*Header) Deserialize added in v0.6.0

func (h *Header) Deserialize(b []byte) (*Header, error)

func (*Header) GetAlgorithm

func (h *Header) GetAlgorithm() (AlgorithmType, error)

func (*Header) GetEncryptionAlgorithm added in v0.6.0

func (h *Header) GetEncryptionAlgorithm() (AuthAlgorithmType, error)

func (*Header) Serialize added in v0.6.0

func (h *Header) Serialize() ([]byte, error)

type Metadata added in v0.6.0

type Metadata struct {
	Bytes  []byte
	Base64 string
	Json   string
}

type Payload

type Payload struct {
	Data     ClaimSet
	Metadata *Metadata
}

func (*Payload) Deserialize added in v0.6.0

func (p *Payload) Deserialize(b []byte) (*Payload, error)

func (*Payload) Serialize added in v0.6.0

func (p *Payload) Serialize() ([]byte, error)

type RegisteredClaim

type RegisteredClaim string
const (
	Issuer         RegisteredClaim = "iss"
	Subject        RegisteredClaim = "sub"
	Audience       RegisteredClaim = "aud"
	ExpirationTime RegisteredClaim = "exp"
	NotBefore      RegisteredClaim = "nbf"
	IssuedAt       RegisteredClaim = "iat"
	JwtID          RegisteredClaim = "jti"
)

type Signature

type Signature struct {
	Metadata *Metadata
}

type Token

type Token struct {
	TokenType     TokenType
	TokenInstance TokenInstance
	Claims        map[string]interface{}
	Metadata      *Metadata
}

type TokenInstance

type TokenInstance interface {
	// Encode generates a serialized representation of the token, typically in a compact format like JWE or JWT.
	// It returns the encoded token as a byte slice and any potential errors encountered during encoding.
	Encode() (string, error)

	// Decode parses a serialized token (split into its parts) and populates the internal token structure.
	// For JWS, the header, payload, SignFunc and ValidateFunc are all populated (along with Metadata byte values).
	// For JWE, the header, encryptedKey, initialization vector, cipher text, SignFunc and Validate func are
	// all populated (along with Metadata byte values).
	// It takes the token parts as input and returns an error if the decoding or parsing process fails.
	Decode(parts []string) error

	// Validate verifies the integrity and authenticity of the token, checking signatures, claims, and expiration if applicable.
	// Uniquely for JWE, it is only after the call to Validate that the payload data is populated into the token struct. This is
	// because the payload is not available when calling Decode like it is for a JWS. It is only after Validating the token that
	// the 'cipher text' is decrypted to reveal the contents of the payload (which can be JSON, or any other data).
	// It returns a boolean indicating whether the token is valid and any potential errors encountered during validation.
	Validate() (bool, error)
}

TokenInstance represents an interface for working with tokens. TokenInstance will either be an instance of a JWE or JWS token.

type TokenType

type TokenType string

Jump to

Keyboard shortcuts

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