func (msp *bccspmsp) Setup(conf1 *m.MSPConfig) error {
	if conf1 == nil {
		return errors.New("Setup error: nil conf reference")
	}
	conf := &m.FabricMSPConfig{}
	err := proto.Unmarshal(conf1.Config, conf)
	if err != nil {
		return errors.Wrap(err, "failed unmarshalling fabric msp config")
	}
	msp.name = conf.Name
	mspLogger.Debugf("Setting up MSP instance %s", msp.name)
	return msp.internalSetupFunc(conf)
}
Setup sets up the internal data structures
for this MSP, given an MSPConfig ref; it
returns nil in case of success or an error otherwise
package msp
import (
	"bytes"
	"crypto/x509/pkix"
	"encoding/hex"
	"encoding/pem"
	"fmt"
	"github.com/golang/protobuf/proto"
	"github.com/hyperledger/fabric-sdk-go/api/apicryptosuite"
	factory "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/sdkpatch/cryptosuitebridge"
	m "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
	"github.com/pkg/errors"
	"github.com/hyperledger/fabric-sdk-go/internal/github.com/tjfoc/gmsm/sm2"
)
type mspSetupFuncType func(config *m.FabricMSPConfig) error
type validateIdentityOUsFuncType func(id *identity) error
type bccspmsp struct {
	version MSPVersion
	internalSetupFunc mspSetupFuncType
	internalValidateIdentityOusFunc validateIdentityOUsFuncType
	rootCerts []Identity
	intermediateCerts []Identity
	tlsRootCerts [][]byte
	tlsIntermediateCerts [][]byte
	certificationTreeInternalNodesMap map[string]bool
	signer SigningIdentity
	admins []Identity
	bccsp apicryptosuite.CryptoSuite
	name string
	opts *sm2.VerifyOptions
	CRL []*pkix.CertificateList
	ouIdentifiers map[string][][]byte
	cryptoConfig *m.FabricCryptoConfig
	ouEnforcement bool
	clientOU, peerOU, ordererOU *OUIdentifier
}
func NewBccspMsp(version MSPVersion, cryptoSuite apicryptosuite.CryptoSuite) (MSP, error) {
	mspLogger.Debugf("Creating BCCSP-based MSP instance")
	theMsp := &bccspmsp{}
	theMsp.version = version
	theMsp.bccsp = cryptoSuite
	switch version {
	case MSPv1_0:
		theMsp.internalSetupFunc = theMsp.setupV1
		theMsp.internalValidateIdentityOusFunc = theMsp.validateIdentityOUsV1
	case MSPv1_1:
		theMsp.internalSetupFunc = theMsp.setupV11
		theMsp.internalValidateIdentityOusFunc = theMsp.validateIdentityOUsV11
	default:
		return nil, errors.Errorf("Invalid MSP version [%v]", version)
	}
	return theMsp, nil
}
func (msp *bccspmsp) getCertFromPem(idBytes []byte) (*sm2.Certificate, error) {
	if idBytes == nil {
		return nil, errors.New("getCertFromPem error: nil idBytes")
	}
	pemCert, _ := pem.Decode(idBytes)
	if pemCert == nil {
		return nil, errors.Errorf("getCertFromPem error: could not decode pem bytes [%v]", idBytes)
	}
	var cert *sm2.Certificate
	cert, err := sm2.ParseCertificate(pemCert.Bytes)
	if err != nil {
		return nil, errors.Wrap(err, "getCertFromPem error: failed to parse sm2 cert")
	}
	return cert, nil
}
func (msp *bccspmsp) getIdentityFromConf(idBytes []byte) (Identity, apicryptosuite.Key, error) {
	cert, err := msp.getCertFromPem(idBytes)
	if err != nil {
		return nil, nil, err
	}
	certPubK, err := msp.bccsp.KeyImport(cert, factory.GetX509PublicKeyImportOpts(true))
	mspId, err := newIdentity(cert, certPubK, msp)
	if err != nil {
		return nil, nil, err
	}
	return mspId, certPubK, nil
}
func (msp *bccspmsp) getSigningIdentityFromConf(sidInfo *m.SigningIdentityInfo) (SigningIdentity, error) {
	if sidInfo == nil {
		return nil, errors.New("getIdentityFromBytes error: nil sidInfo")
	}
	idPub, pubKey, err := msp.getIdentityFromConf(sidInfo.PublicSigner)
	if err != nil {
		return nil, err
	}
	privKey, err := msp.bccsp.GetKey(pubKey.SKI())
	if err != nil {
		mspLogger.Debugf("Could not find SKI [%s], trying KeyMaterial field: %+v\n", hex.EncodeToString(pubKey.SKI()), err)
		if sidInfo.PrivateSigner == nil || sidInfo.PrivateSigner.KeyMaterial == nil {
			return nil, errors.New("KeyMaterial not found in SigningIdentityInfo")
		}
		pemKey, _ := pem.Decode(sidInfo.PrivateSigner.KeyMaterial)
		privKey, err = msp.bccsp.KeyImport(pemKey.Bytes, factory.GetECDSAPrivateKeyImportOpts(true))
		if err != nil {
			return nil, errors.WithMessage(err, "getIdentityFromBytes error: Failed to import EC private key")
		}
	}
	peerSigner, err := factory.NewCspSigner(msp.bccsp, privKey)
	if err != nil {
		return nil, errors.WithMessage(err, "getIdentityFromBytes error: Failed initializing bccspCryptoSigner")
	}
	return newSigningIdentity(idPub.(*identity).cert, idPub.(*identity).pk, peerSigner, msp)
}