github.com/lzy4123/fabric@v2.1.1+incompatible/bccsp/factory/pkcs11factory.go (about) 1 // +build pkcs11 2 3 /* 4 Copyright IBM Corp. All Rights Reserved. 5 6 SPDX-License-Identifier: Apache-2.0 7 */ 8 9 package factory 10 11 import ( 12 "github.com/hyperledger/fabric/bccsp" 13 "github.com/hyperledger/fabric/bccsp/pkcs11" 14 "github.com/hyperledger/fabric/bccsp/sw" 15 "github.com/pkg/errors" 16 ) 17 18 const ( 19 // PKCS11BasedFactoryName is the name of the factory of the hsm-based BCCSP implementation 20 PKCS11BasedFactoryName = "PKCS11" 21 ) 22 23 // PKCS11Factory is the factory of the HSM-based BCCSP. 24 type PKCS11Factory struct{} 25 26 // Name returns the name of this factory 27 func (f *PKCS11Factory) Name() string { 28 return PKCS11BasedFactoryName 29 } 30 31 // Get returns an instance of BCCSP using Opts. 32 func (f *PKCS11Factory) Get(config *FactoryOpts) (bccsp.BCCSP, error) { 33 // Validate arguments 34 if config == nil || config.Pkcs11Opts == nil { 35 return nil, errors.New("Invalid config. It must not be nil.") 36 } 37 38 p11Opts := config.Pkcs11Opts 39 ks := sw.NewDummyKeyStore() 40 41 return pkcs11.New(*p11Opts, ks) 42 }