3 Star 6 Fork 7

Gitee 极速下载/Hyperledger fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
inquire.go 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
/*
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")
const (
combinationsUpperBound = 10000
)
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(combinationsUpperBound) {
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)
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/fabric.git
git@gitee.com:mirrors/fabric.git
mirrors
fabric
Hyperledger fabric
v1.4.6

搜索帮助