代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package inquire
import (
"fmt"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/graph"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/protos/common"
)
var logger = flogging.MustGetLogger("policies/inquire")
type inquireableSignaturePolicy struct {
sigPol *common.SignaturePolicyEnvelope
}
// NewInquireableSignaturePolicy creates a signature policy that can be inquired,
// from a policy and a signature policy.
func NewInquireableSignaturePolicy(sigPol *common.SignaturePolicyEnvelope) policies.InquireablePolicy {
return &inquireableSignaturePolicy{
sigPol: sigPol,
}
}
// SatisfiedBy returns a slice of PrincipalSets that each of them
// satisfies the policy.
func (isp *inquireableSignaturePolicy) SatisfiedBy() []policies.PrincipalSet {
rootId := fmt.Sprintf("%d", 0)
root := graph.NewTreeVertex(rootId, isp.sigPol.Rule)
computePolicyTree(root)
var res []policies.PrincipalSet
for _, perm := range root.ToTree().Permute() {
principalSet := principalsOfTree(perm, isp.sigPol.Identities)
if len(principalSet) == 0 {
return nil
}
res = append(res, principalSet)
}
return res
}
func principalsOfTree(tree *graph.Tree, principals policies.PrincipalSet) policies.PrincipalSet {
var principalSet policies.PrincipalSet
i := tree.BFS()
for {
v := i.Next()
if v == nil {
break
}
if !v.IsLeaf() {
continue
}
pol := v.Data.(*common.SignaturePolicy)
switch principalIndex := pol.Type.(type) {
case *common.SignaturePolicy_SignedBy:
if len(principals) <= int(principalIndex.SignedBy) {
logger.Warning("Failed computing principalsOfTree, index out of bounds")
return nil
}
principal := principals[principalIndex.SignedBy]
principalSet = append(principalSet, principal)
default:
// Leaf vertex is not of type SignedBy
logger.Warning("Leaf vertex", v.Id, "is of type", pol.GetType())
return nil
}
}
return principalSet
}
func computePolicyTree(v *graph.TreeVertex) {
sigPol := v.Data.(*common.SignaturePolicy)
if p := sigPol.GetNOutOf(); p != nil {
v.Threshold = int(p.N)
for i, rule := range p.Rules {
id := fmt.Sprintf("%s.%d", v.Id, i)
u := v.AddDescendant(graph.NewTreeVertex(id, rule))
computePolicyTree(u)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。