func (csp *impl) KeyImport(raw interface{}, opts bccsp.KeyImportOpts) (k bccsp.Key, err error) {
	if raw == nil {
		return nil, errors.New("Invalid raw. Cannot be nil")
	}
	if opts == nil {
		return nil, errors.New("Invalid Opts parameter. It must not be nil")
	}
	switch opts.(type) {
	case *bccsp.X509PublicKeyImportOpts:
		x509Cert, ok := raw.(*x509.Certificate)
		if !ok {
			return nil, errors.New("[X509PublicKeyImportOpts] Invalid raw material. Expected *x509.Certificate")
		}
		pk := x509Cert.PublicKey
		switch pk.(type) {
		case *ecdsa.PublicKey:
			return csp.KeyImport(pk, &bccsp.ECDSAGoPublicKeyImportOpts{Temporary: opts.Ephemeral()})
		default:
			return nil, errors.New("Certificate's public key type not recognized. Supported keys: [ECDSA]")
		}
	default:
		return csp.BCCSP.KeyImport(raw, opts)
	}
}
KeyImport imports a key from its raw representation using opts.
The opts argument should be appropriate for the primitive used.
package pkcs11
import (
	"crypto/ecdsa"
	"crypto/x509"
	"os"
	sdkp11 "github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite/common/pkcs11"
	"github.com/kfsoftware/hlf-operator/internal/github.com/hyperledger/fabric/bccsp"
	"github.com/kfsoftware/hlf-operator/internal/github.com/hyperledger/fabric/bccsp/sw"
	flogging "github.com/kfsoftware/hlf-operator/internal/github.com/hyperledger/fabric/sdkpatch/logbridge"
	"github.com/pkg/errors"
)
var (
	logger           = flogging.MustGetLogger("bccsp_p11")
	sessionCacheSize = 10
)
func New(opts PKCS11Opts, keyStore bccsp.KeyStore) (bccsp.BCCSP, error) {
	conf := &config{}
	err := conf.setSecurityLevel(opts.SecLevel, opts.HashFamily)
	if err != nil {
		return nil, errors.Wrapf(err, "Failed initializing configuration")
	}
	swCSP, err := sw.NewWithParams(opts.SecLevel, opts.HashFamily, keyStore)
	if err != nil {
		return nil, errors.Wrapf(err, "Failed initializing fallback SW BCCSP")
	}
	if keyStore == nil {
		return nil, errors.New("Invalid bccsp.KeyStore instance. It must be different from nil")
	}
	pkcs11Ctx, err := sdkp11.LoadContextAndLogin(opts.Library, opts.Pin, opts.Label)
	if err != nil {
		return nil, errors.Wrapf(err, "Failed initializing PKCS11 context")
	}
	csp := &impl{BCCSP: swCSP, conf: conf, softVerify: opts.SoftVerify, pkcs11Ctx: pkcs11Ctx}
	return csp, nil
}
type impl struct {
	bccsp.BCCSP
	conf *config
	pkcs11Ctx  *sdkp11.ContextHandle
	softVerify bool
	immutable bool
}
func (csp *impl) KeyGen(opts bccsp.KeyGenOpts) (k bccsp.Key, err error) {
	if opts == nil {
		return nil, errors.New("Invalid Opts parameter. It must not be nil")
	}
	switch opts.(type) {
	case *bccsp.ECDSAKeyGenOpts:
		ski, pub, err := csp.generateECKey(csp.conf.ellipticCurve, opts.Ephemeral())
		if err != nil {
			return nil, errors.Wrapf(err, "Failed generating ECDSA key")
		}
		k = &ecdsaPrivateKey{ski, ecdsaPublicKey{ski, pub}}
	case *bccsp.ECDSAP256KeyGenOpts:
		ski, pub, err := csp.generateECKey(oidNamedCurveP256, opts.Ephemeral())
		if err != nil {
			return nil, errors.Wrapf(err, "Failed generating ECDSA P256 key")
		}
		k = &ecdsaPrivateKey{ski, ecdsaPublicKey{ski, pub}}
	case *bccsp.ECDSAP384KeyGenOpts:
		ski, pub, err := csp.generateECKey(oidNamedCurveP384, opts.Ephemeral())
		if err != nil {
			return nil, errors.Wrapf(err, "Failed generating ECDSA P384 key")
		}
		k = &ecdsaPrivateKey{ski, ecdsaPublicKey{ski, pub}}
	default:
		return csp.BCCSP.KeyGen(opts)
	}
	return k, nil
}