jwt_ed25519

package module
v0.0.0-...-f86783e Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2019 License: MIT Imports: 3 Imported by: 0

README

jwt_es25519

Usage

Generation
var (
	TokenSignMethod = jwt_es25519.Ed25519.Alg()
	TokenSignature  = &priv // *ed25518.PrivateKey
)

func (a *Account) GenerateToken() *jwt.Token {
	claims := jwt.StandardClaims{
		Issuer:    "Issuer",
		Subject:   SnowflakeString(a.ID),
		IssuedAt:  time.Now().Unix(),
		ExpiresAt: time.Now().Add(TokenTimeout).Unix(),
	}

	return jwt.NewWithClaims(jwt.GetSigningMethod(TokenSignMethod), claims)
}

func (a *Account) GenerateSignedString() (string, error) {
	return a.GenerateToken().SignedString(TokenSignature)
}
Server
generates.NewJWTAccessGenerate(
	c.PrivKey, // ed25519.PrivateKey
	SigningMethod, // jwt_es25519.Ed25519
)

Documentation

Overview

Package jwt_ed25519 provides ed25519 signing method for dgrijalva/jwt-go. This package masks itself as HS256 internally to satisfy above dependency.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Intentionally vague errors for security.
	ErrVerification = errors.New("ed25519: verification error")
	ErrDecryption   = errors.New("ed25519: decryption error")
)
View Source
var BytesDecoder = func(encoded string) ([]byte, error) {
	return jwt.DecodeSegment(encoded)
}

BytesDecoder decodes the base64 bytes to raw bytes.

View Source
var BytesEncoder = func(bytes []byte) string {
	return jwt.EncodeSegment(bytes)
}

BytesEncoder encodes the bytes as base64.

View Source
var Ed25519 = &SigningMethodEdDSA{}

Functions

This section is empty.

Types

type SigningMethodEdDSA

type SigningMethodEdDSA struct{}

func (*SigningMethodEdDSA) Alg

func (m *SigningMethodEdDSA) Alg() string

Alg returns HS256, as the JWT library only supports HS256, though HS256's Key types are byte slices, similar to ed25519.

func (*SigningMethodEdDSA) Sign

func (m *SigningMethodEdDSA) Sign(signingString string, key interface{}) (string, error)

Sign signs the signingString with ed25519, encoded with BytesEncoder.

func (*SigningMethodEdDSA) Verify

func (m *SigningMethodEdDSA) Verify(signingString, signature string, key interface{}) error

Verify uses BytesDecoder to decode the signature, then use that as a ed25519 Public key to verify.

Jump to

Keyboard shortcuts

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