github.com/turingchain2020/turingchain@v1.1.21/executor/authority/core/factory.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package core 6 7 import ( 8 "errors" 9 10 secp256r1_util "github.com/turingchain2020/turingchain/system/crypto/secp256r1" 11 sm2_util "github.com/turingchain2020/turingchain/system/crypto/sm2" 12 ) 13 14 // GetLocalValidator 根据类型获取校验器 15 func GetLocalValidator(authConfig *AuthConfig, signType int) (Validator, error) { 16 var lclValidator Validator 17 var err error 18 19 if signType == secp256r1_util.ID { 20 lclValidator = NewEcdsaValidator() 21 } else if signType == sm2_util.ID { 22 lclValidator = NewGmValidator() 23 } else { 24 return nil, errors.New("ErrUnknowAuthSignType") 25 } 26 27 err = lclValidator.Setup(authConfig) 28 if err != nil { 29 authLogger.Error("Failed to set up local validator config", "Error", err) 30 return nil, errors.New("Failed to initialize local validator") 31 } 32 33 return lclValidator, nil 34 }