package jwt

import (
	
	
	
	
)

var (
	ErrEd25519Verification = errors.New("ed25519: verification error")
)

// SigningMethodEd25519 implements the EdDSA family.
// Expects ed25519.PrivateKey for signing and ed25519.PublicKey for verification
type SigningMethodEd25519 struct{}

// Specific instance for EdDSA
var (
	SigningMethodEdDSA *SigningMethodEd25519
)

func () {
	SigningMethodEdDSA = &SigningMethodEd25519{}
	RegisterSigningMethod(SigningMethodEdDSA.Alg(), func() SigningMethod {
		return SigningMethodEdDSA
	})
}

func ( *SigningMethodEd25519) () string {
	return "EdDSA"
}

// Verify implements token verification for the SigningMethod.
// For this verify method, key must be an ed25519.PublicKey
func ( *SigningMethodEd25519) ( string,  []byte,  interface{}) error {
	var  ed25519.PublicKey
	var  bool

	if ,  = .(ed25519.PublicKey); ! {
		return newError("Ed25519 verify expects ed25519.PublicKey", ErrInvalidKeyType)
	}

	if len() != ed25519.PublicKeySize {
		return ErrInvalidKey
	}

	// Verify the signature
	if !ed25519.Verify(, []byte(), ) {
		return ErrEd25519Verification
	}

	return nil
}

// Sign implements token signing for the SigningMethod.
// For this signing method, key must be an ed25519.PrivateKey
func ( *SigningMethodEd25519) ( string,  interface{}) ([]byte, error) {
	var  crypto.Signer
	var  bool

	if ,  = .(crypto.Signer); ! {
		return nil, newError("Ed25519 sign expects crypto.Signer", ErrInvalidKeyType)
	}

	if ,  := .Public().(ed25519.PublicKey); ! {
		return nil, ErrInvalidKey
	}

	// Sign the string and return the result. ed25519 performs a two-pass hash
	// as part of its algorithm. Therefore, we need to pass a non-prehashed
	// message into the Sign function, as indicated by crypto.Hash(0)
	,  := .Sign(rand.Reader, []byte(), crypto.Hash(0))
	if  != nil {
		return nil, 
	}

	return , nil
}