github.com/lzy4123/fabric@v2.1.1+incompatible/common/tools/protolator/protoext/commonext/policies.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package commonext
     8  
     9  import (
    10  	"fmt"
    11  
    12  	"github.com/golang/protobuf/proto"
    13  	"github.com/hyperledger/fabric-protos-go/common"
    14  )
    15  
    16  type Policy struct{ *common.Policy }
    17  
    18  func (p *Policy) Underlying() proto.Message {
    19  	return p.Policy
    20  }
    21  
    22  func (p *Policy) VariablyOpaqueFields() []string {
    23  	return []string{"value"}
    24  }
    25  
    26  func (p *Policy) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
    27  	if name != p.VariablyOpaqueFields()[0] {
    28  		return nil, fmt.Errorf("not a marshaled field: %s", name)
    29  	}
    30  	switch p.Type {
    31  	case int32(common.Policy_SIGNATURE):
    32  		return &common.SignaturePolicyEnvelope{}, nil
    33  	case int32(common.Policy_IMPLICIT_META):
    34  		return &common.ImplicitMetaPolicy{}, nil
    35  	default:
    36  		return nil, fmt.Errorf("unable to decode policy type: %v", p.Type)
    37  	}
    38  }