jwt

package
v0.0.0-...-b986fe3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = errors.New("key not found in the keychain")
)

Functions

func Decrypt

func Decrypt(jwt string, target any, keychain Keychain) error

Decrypt decrypts the encrypted JWT and deserializes the payload from JSON format. While decryption, it tries to parse the JWT header and finds an encryption key by their ID from the keychain. If no key found for the key ID, returns ErrKeyNotFound.

func Encrypt

func Encrypt(object any, key PublicEncryptionKey, encryption jose.ContentEncryption) (string, error)

Encrypt encrypts the object and construct JWT using the encryption key after serializing into JSON format.

func JWKFromEncryptionKey

func JWKFromEncryptionKey(key EncryptionKey) jose.JSONWebKey

func JWKFromPrivateKey

func JWKFromPrivateKey(key PrivateKey) jose.JSONWebKey

func JWKFromSigningKey

func JWKFromSigningKey(key SigningKey) jose.JSONWebKey

func JWKSFromKeys

func JWKSFromKeys(key ...Key) jose.JSONWebKeySet

func JWKSFromPublicKeychain

func JWKSFromPublicKeychain(keychain PublicKeychain) jose.JSONWebKeySet

func Sign

func Sign(object any, key PrivateSigningKey) (string, error)

Sign signs the object and construct JWT using the signing key after serializing into JSON format.

func UnsafeDecodeSigned

func UnsafeDecodeSigned(jwt string, target any) error

UnsafeDecodeSigned decodes the signed JWT and deserializes the payload from JSON format. THIS DOES NOT PERFORM ANY VERIFICATION FOR THE SIGNATURE; DO NOT TRUST THE DECODED CONTENT.

func Verify

func Verify(jwt string, target any, keychain PublicKeychain) error

Verify verifies the signed JWT and deserializes the payload from JSON format. While verification, it tries to parse the JWT header and finds a public signing key by their ID from the keychain. If no key found for the key ID, returns ErrKeyNotFound.

Types

type EncryptionKey

type EncryptionKey interface {
	Key

	EncryptionKeyAlgorithm() jose.KeyAlgorithm
}

type EncryptionKeychain

type EncryptionKeychain interface {
	Keychain
	PublicEncryptionKeychain

	EncryptionKeypairs() []EncryptionKeypair
	EncryptionKeypair(id string) EncryptionKeypair
	PrivateEncryptionKeys() []PrivateEncryptionKey
	PrivateEncryptionKey(id string) PrivateEncryptionKey
}

type EncryptionKeypair

type EncryptionKeypair interface {
	PublicEncryptionKey
	PrivateEncryptionKey
}

type Key

type Key interface {
	KeyID() string
}

type Keychain

type Keychain interface {
	PublicKeychain

	Keypairs() []Keypair
	Keypair(id string) Keypair
	PrivateKeys() []PrivateKey
	PrivateKey(id string) PrivateKey
}

type Keypair

type Keypair interface {
	PublicKey
	PrivateKey
}

type PrivateEncryptionKey

type PrivateEncryptionKey interface {
	EncryptionKey
	PrivateKey
}

type PrivateKey

type PrivateKey interface {
	Key

	PrivateKey() any
}

type PrivateSigningKey

type PrivateSigningKey interface {
	SigningKey

	PrivateKey() any
}

type PublicEncryptionKey

type PublicEncryptionKey interface {
	EncryptionKey
	PublicKey
}

type PublicEncryptionKeychain

type PublicEncryptionKeychain interface {
	PublicKeychain

	PublicEncryptionKeys() []PublicEncryptionKey
	PublicEncryptionKey(id string) PublicEncryptionKey
}

type PublicKey

type PublicKey interface {
	Key

	PublicKey() any
}

type PublicKeychain

type PublicKeychain interface {
	PublicKeys() []PublicKey
	PublicKey(id string) PublicKey
}

type PublicSigningKey

type PublicSigningKey interface {
	SigningKey

	PublicKey() any
}

type PublicSigningKeychain

type PublicSigningKeychain interface {
	PublicKeychain

	PublicSigningKeys() []PublicSigningKey
	PublicSigningKey(id string) PublicSigningKey
}

type SigningKey

type SigningKey interface {
	Key

	SigningAlgorithm() jose.SignatureAlgorithm
}

type SigningKeychain

type SigningKeychain interface {
	Keychain
	PublicSigningKeychain

	SigningKeypairs() []SigningKeypair
	SigningKeypair(id string) SigningKeypair
	PrivateSigningKeys() []PrivateSigningKey
	PrivateSigningKey(id string) PrivateSigningKey
}

type SigningKeypair

type SigningKeypair interface {
	PublicSigningKey
	PrivateSigningKey
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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