func (kr *KeyRequest) SigAlgo() x509.SignatureAlgorithm {
	switch kr.Algo {
	case "rsa":
		switch {
		case kr.Size >= 4096:
			return x509.SHA512WithRSA
		case kr.Size >= 3072:
			return x509.SHA384WithRSA
		case kr.Size >= 2048:
			return x509.SHA256WithRSA
		default:
			return x509.SHA1WithRSA
		}
	case "ecdsa":
		switch {
		case kr.Size == curveP521:
			return x509.ECDSAWithSHA512
		case kr.Size == curveP384:
			return x509.ECDSAWithSHA384
		case kr.Size == curveP256:
			return x509.ECDSAWithSHA256
		default:
			return x509.ECDSAWithSHA1
		}
	default:
		return x509.UnknownSignatureAlgorithm
	}
}
SigAlgo returns an appropriate X.509 signature algorithm given the
key request's type and size.
package csr
import (
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	"crypto/rsa"
	"crypto/x509"
	"crypto/x509/pkix"
	"encoding/pem"
	"errors"
	cferr "github.com/FiloSottile/BERserk/_vendor/github.com/cloudflare/cfssl/errors"
	"github.com/FiloSottile/BERserk/_vendor/github.com/cloudflare/cfssl/log"
)
const (
	curveP256 = 256
	curveP384 = 384
	curveP521 = 521
)
type Name struct {
	C  string  
	ST string  
	L  string  
	O  string  
	OU string  
}
type KeyRequest struct {
	Algo string `json:"algo"`
	Size int    `json:"size"`
}
var DefaultKeyRequest = KeyRequest{
	Algo: "ecdsa",
	Size: curveP256,
}
func (kr *KeyRequest) Generate() (interface{}, error) {
	log.Debugf("generate key from request: algo=%s, size=%d", kr.Algo, kr.Size)
	switch kr.Algo {
	case "rsa":
		if kr.Size < 2048 {
			return nil, errors.New("RSA key is too weak")
		}
		return rsa.GenerateKey(rand.Reader, kr.Size)
	case "ecdsa":
		var curve elliptic.Curve
		switch kr.Size {
		case curveP256:
			curve = elliptic.P256()
		case curveP384:
			curve = elliptic.P384()
		case curveP521:
			curve = elliptic.P521()
		default:
			return nil, errors.New("invalid curve")
		}
		return ecdsa.GenerateKey(curve, rand.Reader)
	default:
		return nil, errors.New("invalid algorithm")
	}
}