func signatureAlgorithm(jwk *jose.JSONWebKey) (alg jose.SignatureAlgorithm, err error) {
	if jwk.Key == nil {
		return alg, errors.New("no signing key")
	}
	switch key := jwk.Key.(type) {
	case *rsa.PrivateKey:
		return jose.RS256, nil
	case *ecdsa.PrivateKey:
		switch key.Params() {
		case elliptic.P256().Params():
			return jose.ES256, nil
		case elliptic.P384().Params():
			return jose.ES384, nil
		case elliptic.P521().Params():
			return jose.ES512, nil
		default:
			return alg, errors.New("unsupported ecdsa curve")
		}
	default:
		return alg, fmt.Errorf("unsupported signing key type %T", key)
	}
}
Determine the signature algorithm for a JWT.
package auth
import (
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rsa"
	"errors"
	"fmt"
	"github.com/fanux/fist/tools"
	"gopkg.in/square/go-jose.v2"
)
func loadKeyPair() (pub, priv jose.JSONWebKey, err error) {
	privKey, _ := tools.ParseRsaPrivateKeyFromPemFile(PrivateKey)
	publicKey, _ := tools.ParseRsaPubKeyFromPemFile(PublicKey)
	if privKey == nil || publicKey == nil {
		privKey = tools.PemDefaultPrivateKey()
		publicKey = tools.PemDefaultPublicKey()
		if privKey == nil || publicKey == nil {
			return jose.JSONWebKey{}, jose.JSONWebKey{}, tools.ErrAuthTokeKeyError
		}
	}
	priv = jose.JSONWebKey{
		Key:       privKey,
		KeyID:     "Cgc4OTEyNTU3EgZnaXRodWI",
		Algorithm: "RS256",
		Use:       "sig",
	}
	pub = jose.JSONWebKey{
		Key:       publicKey,
		KeyID:     "Cgc4OTEyNTU3EgZnaXRodWI",
		Algorithm: "RS256",
		Use:       "sig",
	}
	return pub, priv, nil
}