gitee.com/lh-her-team/common@v1.5.1/crypto/hsm/swxa/main.go (about)

     1  package main
     2  
     3  /**
     4    This is a demo which implements hsm.IHSMAdapter.
     5  */
     6  import (
     7  	"errors"
     8  	"fmt"
     9  )
    10  
    11  //go build -buildmode=plugin -o plugin1.so plugin1.go
    12  
    13  // Adapter variable must be defined
    14  // nolint
    15  var Adapter hsmAdapter
    16  
    17  // adapter must implement IHSMAdapter interface
    18  type hsmAdapter struct {
    19  }
    20  
    21  func (a hsmAdapter) PKCS11_GetSM2KeyId(keyIdex int, isPrivate bool) (string, error) {
    22  	return fmt.Sprintf("SM2SignKey%d", keyIdex), nil
    23  }
    24  
    25  func (a hsmAdapter) PKCS11_GetRSAKeyId(keyIdex int, isPrivate bool) (string, error) {
    26  	return fmt.Sprintf("RSASignKey%d", keyIdex), nil
    27  }
    28  
    29  func (a hsmAdapter) PKCS11_GetECCKeyId(keyIdex int, isPrivate bool) (string, error) {
    30  	return "", errors.New("not implemented")
    31  }
    32  
    33  func (a hsmAdapter) PKCS11_GetSM4KeyId(keyIdex int) (string, error) {
    34  	return fmt.Sprintf("MasterKey%d", keyIdex), nil
    35  }
    36  
    37  func (a hsmAdapter) PKCS11_GetAESKeyId(keyIdex int) (string, error) {
    38  	return fmt.Sprintf("MasterKey%d", keyIdex), nil
    39  }
    40  
    41  func (a hsmAdapter) PKCS11_GetSM3SM2CKM() uint {
    42  	return 0x80000000 + 0x8000 + 0x00000103
    43  }
    44  
    45  func (a hsmAdapter) SDF_GetSM2KeyAccessRight(keyIdex int) (newKeyIdex int, need bool) {
    46  	return keyIdex + 10000, true
    47  }
    48  
    49  func (a hsmAdapter) SDF_GetSM4KeyAccessRight(keyIdex int) (newKeyIdex int, need bool) {
    50  	return keyIdex, true
    51  }
    52  
    53  func (a hsmAdapter) SDF_GetRSAKeyAccessRight(keyIdex int) (newKeyIdex int, need bool) {
    54  	return keyIdex + 0, true
    55  }
    56  
    57  func (a hsmAdapter) SDF_GetAESKeyAccessRight(keyIdex int) (newKeyIdex int, need bool) {
    58  	return keyIdex, true
    59  }
    60  
    61  func main() {}