github.com/hxx258456/fabric-ca-gm@v0.0.3-0.20221111064038-a268ad7e3a37/lib/keyrequest.go (about)

     1  //go:build pkcs11
     2  // +build pkcs11
     3  
     4  /*
     5  Copyright IBM Corp. All Rights Reserved.
     6  
     7  SPDX-License-Identifier: Apache-2.0
     8  */
     9  
    10  package lib
    11  
    12  import (
    13  	"github.com/hxx258456/fabric-ca-gm/internal/pkg/api"
    14  	"github.com/hxx258456/fabric-gm/bccsp"
    15  )
    16  
    17  // GetKeyRequest constructs and returns api.KeyRequest object based on the bccsp
    18  // configuration options
    19  func GetKeyRequest(cfg *CAConfig) *api.KeyRequest {
    20  	if cfg.CSP.SwOpts != nil {
    21  		return &api.KeyRequest{Algo: "ecdsa", Size: cfg.CSP.SwOpts.SecLevel}
    22  	} else if cfg.CSP.Pkcs11Opts != nil {
    23  		return &api.KeyRequest{Algo: "ecdsa", Size: cfg.CSP.Pkcs11Opts.SecLevel}
    24  	} else {
    25  		return api.NewKeyRequest()
    26  	}
    27  }
    28  
    29  func GetGMKeyRequest(cfg *CAConfig) *api.KeyRequest {
    30  	if cfg.CSP.SwOpts != nil {
    31  		return &api.KeyRequest{Algo: bccsp.GMSM2, Size: cfg.CSP.SwOpts.SecLevel}
    32  	}
    33  	return api.NewGMKeyRequest()
    34  }