github.com/kaituanwang/hyperledger@v2.0.1+incompatible/common/tools/protolator/protoext/mspext/msp_principal.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package mspext 8 9 import ( 10 "fmt" 11 12 "github.com/golang/protobuf/proto" 13 "github.com/hyperledger/fabric-protos-go/msp" 14 ) 15 16 type MSPPrincipal struct{ *msp.MSPPrincipal } 17 18 func (mp *MSPPrincipal) Underlying() proto.Message { 19 return mp.MSPPrincipal 20 } 21 22 func (mp *MSPPrincipal) VariablyOpaqueFields() []string { 23 return []string{"principal"} 24 } 25 26 func (mp *MSPPrincipal) VariablyOpaqueFieldProto(name string) (proto.Message, error) { 27 if name != mp.VariablyOpaqueFields()[0] { 28 return nil, fmt.Errorf("not a marshaled field: %s", name) 29 } 30 switch mp.PrincipalClassification { 31 case msp.MSPPrincipal_ROLE: 32 return &msp.MSPRole{}, nil 33 case msp.MSPPrincipal_ORGANIZATION_UNIT: 34 return &msp.OrganizationUnit{}, nil 35 case msp.MSPPrincipal_IDENTITY: 36 return &msp.SerializedIdentity{}, nil 37 default: 38 return nil, fmt.Errorf("unable to decode MSP type: %v", mp.PrincipalClassification) 39 } 40 }