func (s *RSASigner) Decode(buf []byte, obj interface{}) error {
	return s.alg.Decode(s, buf, obj)
}
Decode decodes a serialized token, verifying the signature, storing the
decoded data from the token in obj.
package jwt
import (
	"crypto"
	"crypto/rand"
	"crypto/rsa"
	"io"
)
const RSAMinimumBitLen = 2048
type RSASignerVerifier interface {
	Sign(rand io.Reader, priv *rsa.PrivateKey, hash crypto.Hash, buf []byte) ([]byte, error)
	Verify(pub *rsa.PublicKey, hash crypto.Hash, hashed []byte, sig []byte) error
}
type RSAMethod struct {
	SignFunc   func(io.Reader, *rsa.PrivateKey, crypto.Hash, []byte) ([]byte, error)
	VerifyFunc func(*rsa.PublicKey, crypto.Hash, []byte, []byte) error
}
func (m RSAMethod) Sign(rand io.Reader, priv *rsa.PrivateKey, hash crypto.Hash, buf []byte) ([]byte, error) {
	return m.SignFunc(rand, priv, hash, buf)
}
func (m RSAMethod) Verify(pub *rsa.PublicKey, hash crypto.Hash, hashed []byte, sig []byte) error {
	return m.VerifyFunc(pub, hash, hashed, sig)
}
var RSAMethodPKCS1v15 = RSAMethod{
	SignFunc:   rsa.SignPKCS1v15,
	VerifyFunc: rsa.VerifyPKCS1v15,
}
var RSAMethodPSS = RSAMethod{
	SignFunc: func(rand io.Reader, priv *rsa.PrivateKey, hash crypto.Hash, hashed []byte) ([]byte, error) {
		return rsa.SignPSS(rand, priv, hash, hashed, &rsa.PSSOptions{
			SaltLength: rsa.PSSSaltLengthAuto,
			Hash:       hash,
		})
	},
	VerifyFunc: func(pub *rsa.PublicKey, hash crypto.Hash, hashed []byte, sig []byte) error {
		return rsa.VerifyPSS(pub, hash, hashed, sig, &rsa.PSSOptions{
			SaltLength: rsa.PSSSaltLengthAuto,
			Hash:       hash,
		})
	},
}
type RSASigner struct {
	alg    Algorithm
	method RSASignerVerifier
	hash   crypto.Hash
	priv   *rsa.PrivateKey
	pub    *rsa.PublicKey
}
func NewRSASigner(alg Algorithm, method RSASignerVerifier) func(Store, crypto.Hash) (Signer, error) {
	return func(store Store, hash crypto.Hash) (Signer, error) {
		var ok bool
		var privRaw, pubRaw interface{}
		var priv *rsa.PrivateKey
		var pub *rsa.PublicKey
		if privRaw, ok = store.PrivateKey(); ok {
			if priv, ok = privRaw.(*rsa.PrivateKey); !ok {
				return nil, ErrInvalidPrivateKey
			}
			if priv.N.BitLen() < RSAMinimumBitLen {
				return nil, ErrInvalidPrivateKeySize
			}
		}
		if pubRaw, ok = store.PublicKey(); ok {
			if pub, ok = pubRaw.(*rsa.PublicKey); !ok {
				return nil, ErrInvalidPublicKey
			}
			if pub.N.BitLen() < RSAMinimumBitLen {
				return nil, ErrInvalidPublicKeySize
			}
		}
		if priv == nil && pub == nil {
			return nil, ErrMissingPrivateOrPublicKey
		}
		return &RSASigner{
			alg:    alg,
			method: method,
			hash:   hash,
			priv:   priv,
			pub:    pub,
		}, nil
	}
}
func (s *RSASigner) SignBytes(buf []byte) ([]byte, error) {
	if s.priv == nil {
		return nil, ErrMissingPrivateKey
	}
	h := s.hash.New()
	if _, err := h.Write(buf); err != nil {
		return nil, err
	}
	return s.method.Sign(rand.Reader, s.priv, s.hash, h.Sum(nil))
}
func (s *RSASigner) Sign(buf []byte) ([]byte, error) {
	sig, err := s.SignBytes(buf)
	if err != nil {
		return nil, err
	}
	enc := make([]byte, b64.EncodedLen(len(sig)))
	b64.Encode(enc, sig)
	return enc, nil
}
func (s *RSASigner) VerifyBytes(buf, sig []byte) error {
	if s.pub == nil {
		return ErrMissingPublicKey
	}
	h := s.hash.New()
	if _, err := h.Write(buf); err != nil {
		return err
	}
	if err := s.method.Verify(s.pub, s.hash, h.Sum(nil), sig); err != nil {
		return ErrInvalidSignature
	}
	return nil
}
func (s *RSASigner) Verify(buf, sig []byte) ([]byte, error) {
	dec, err := b64.DecodeString(string(sig))
	if err != nil {
		return nil, err
	}
	if err = s.VerifyBytes(buf, dec); err != nil {
		return nil, err
	}
	return dec, nil
}
func (s *RSASigner) Encode(obj interface{}) ([]byte, error) {
	return s.alg.Encode(s, obj)
}