code: func ParseRequest(req *CertificateRequest) (csr, key []byte, err error) {
  	log.Info("received CSR")
  	if req.KeyRequest == nil {
  		req.KeyRequest = NewBasicKeyRequest()
  	}
  
  	log.Infof("generating key: %s-%d", req.KeyRequest.Algo(), req.KeyRequest.Size())
  	priv, err := req.KeyRequest.Generate()
  	if err != nil {
  		err = cferr.Wrap(cferr.PrivateKeyError, cferr.GenerationFailed, err)
  		return
  	}
  
  	switch priv := priv.(type) {
  	case *rsa.PrivateKey:
  		key = x509.MarshalPKCS1PrivateKey(priv)
  		block := pem.Block{
  			Type:  "RSA PRIVATE KEY",
  			Bytes: key,
  		}
  		key = pem.EncodeToMemory(&block)
  	case *ecdsa.PrivateKey:
  		key, err = x509.MarshalECPrivateKey(priv)
  		if err != nil {
  			err = cferr.Wrap(cferr.PrivateKeyError, cferr.Unknown, err)
  			return
  		}
  		block := pem.Block{
  			Type:  "EC PRIVATE KEY",
  			Bytes: key,
  		}
  		key = pem.EncodeToMemory(&block)
  	default:
  		panic("Generate should have failed to produce a valid key.")
  	}
  
  	csr, err = Generate(priv.(crypto.Signer), req)
  	if err != nil {
  		log.Errorf("failed to generate a CSR: %v", err)
  		err = cferr.Wrap(cferr.CSRError, cferr.BadRequest, err)
  	}
  	return
  }
docs: // ParseRequest takes a certificate request and generates a key and
  // CSR from it. It does no validation -- caveat emptor. It will,
  // however, fail if the key request is not valid (i.e., an unsupported
  // curve or RSA key size). The lack of validation was specifically
  // chosen to allow the end user to define a policy and validate the
  // request appropriately before calling this function.