63 Star 183 Fork 3

Gitee 极速下载/hyperledger-fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
bccsp
ci
cmd
common
capabilities
cauthdsl
cauthdsl.go
cauthdsl_builder.go
cauthdsl_test.go
policy.go
policy_test.go
policyparser.go
policyparser_test.go
chaincode
channelconfig
config
configtx
crypto
deliver
diag
errors
flogging
genesis
graph
grpclogging
grpcmetrics
ledger
metadata
metrics
policies
semaphore
tools
util
viperutil
core
discovery
docs
gossip
idemix
images
integration
internal
msp
orderer
pkg
protoutil
release_notes
sampleconfig
scripts
vagrant
vendor
.dockerignore
.gitattributes
.gitignore
CHANGELOG.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Gopkg.lock
Gopkg.toml
LICENSE
MAINTAINERS.md
Makefile
README.md
SECURITY.md
ci.properties
docker-env.mk
gotools.mk
test-pyramid.png
testingInfo.rst
tox.ini
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
cauthdsl.go 3.03 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package cauthdsl
import (
"fmt"
"time"
cb "github.com/hyperledger/fabric-protos-go/common"
mb "github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/msp"
"go.uber.org/zap/zapcore"
)
var cauthdslLogger = flogging.MustGetLogger("cauthdsl")
// compile recursively builds a go evaluatable function corresponding to the policy specified, remember to call deduplicate on identities before
// passing them to this function for evaluation
func compile(policy *cb.SignaturePolicy, identities []*mb.MSPPrincipal) (func([]msp.Identity, []bool) bool, error) {
if policy == nil {
return nil, fmt.Errorf("Empty policy element")
}
switch t := policy.Type.(type) {
case *cb.SignaturePolicy_NOutOf_:
policies := make([]func([]msp.Identity, []bool) bool, len(t.NOutOf.Rules))
for i, policy := range t.NOutOf.Rules {
compiledPolicy, err := compile(policy, identities)
if err != nil {
return nil, err
}
policies[i] = compiledPolicy
}
return func(signedData []msp.Identity, used []bool) bool {
grepKey := time.Now().UnixNano()
cauthdslLogger.Debugf("%p gate %d evaluation starts", signedData, grepKey)
verified := int32(0)
_used := make([]bool, len(used))
for _, policy := range policies {
copy(_used, used)
if policy(signedData, _used) {
verified++
copy(used, _used)
}
}
if verified >= t.NOutOf.N {
cauthdslLogger.Debugf("%p gate %d evaluation succeeds", signedData, grepKey)
} else {
cauthdslLogger.Debugf("%p gate %d evaluation fails", signedData, grepKey)
}
return verified >= t.NOutOf.N
}, nil
case *cb.SignaturePolicy_SignedBy:
if t.SignedBy < 0 || t.SignedBy >= int32(len(identities)) {
return nil, fmt.Errorf("identity index out of range, requested %v, but identities length is %d", t.SignedBy, len(identities))
}
signedByID := identities[t.SignedBy]
return func(signedData []msp.Identity, used []bool) bool {
cauthdslLogger.Debugf("%p signed by %d principal evaluation starts (used %v)", signedData, t.SignedBy, used)
for i, sd := range signedData {
if used[i] {
cauthdslLogger.Debugf("%p skipping identity %d because it has already been used", signedData, i)
continue
}
if cauthdslLogger.IsEnabledFor(zapcore.DebugLevel) {
// Unlike most places, this is a huge print statement, and worth checking log level before create garbage
cauthdslLogger.Debugf("%p processing identity %d - %v", signedData, i, sd.GetIdentifier())
}
err := sd.SatisfiesPrincipal(signedByID)
if err != nil {
cauthdslLogger.Debugf("%p identity %d does not satisfy principal: %s", signedData, i, err)
continue
}
cauthdslLogger.Debugf("%p principal evaluation succeeds for identity %d", signedData, i)
used[i] = true
return true
}
cauthdslLogger.Debugf("%p principal evaluation fails", signedData)
return false
}, nil
default:
return nil, fmt.Errorf("Unknown type: %T:%v", t, t)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/hyperledger-fabric.git
git@gitee.com:mirrors/hyperledger-fabric.git
mirrors
hyperledger-fabric
hyperledger-fabric
v2.0.1

搜索帮助