1 Star 0 Fork 0

妥協/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
idemix_roles.go 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package msp
import (
m "github.com/hyperledger/fabric/protos/msp"
)
// Role : Represents a IdemixRole
type Role int32
// The expected roles are 4; We can combine them using a bitmask
const (
MEMBER Role = 1
ADMIN Role = 2
CLIENT Role = 4
PEER Role = 8
// Next role values: 16, 32, 64 ...
)
func (role Role) getValue() int {
return int(role)
}
// CheckRole Prove that the desired role is contained or not in the bitmask
func checkRole(bitmask int, role Role) bool {
return (bitmask & role.getValue()) == role.getValue()
}
// GetRoleMaskFromIdemixRoles Receive a list of roles to combine in a single bitmask
func getRoleMaskFromIdemixRoles(roles []Role) int {
mask := 0
for _, role := range roles {
mask = mask | role.getValue()
}
return mask
}
// GetRoleMaskFromMSPRoles Receive a list of roles to combine in a single bitmask
func getRoleMaskFromMSPRoles(roles []*m.MSPRole) int {
mask := 0
for _, role := range roles {
mask = mask | getIdemixRoleFromMSPRole(role)
}
return mask
}
// GetRoleMaskFromIdemixRole return a bitmask for one role
func GetRoleMaskFromIdemixRole(role Role) int {
return getRoleMaskFromIdemixRoles([]Role{role})
}
// GetRoleMaskFromMSPRole return a bitmask for one role
func getRoleMaskFromMSPRole(role *m.MSPRole) int {
return getRoleMaskFromMSPRoles([]*m.MSPRole{role})
}
// GetIdemixRoleFromMSPRole gets a MSP Role type and returns the integer value
func getIdemixRoleFromMSPRole(role *m.MSPRole) int {
return getIdemixRoleFromMSPRoleType(role.GetRole())
}
// GetIdemixRoleFromMSPRoleType gets a MSP role type and returns the integer value
func getIdemixRoleFromMSPRoleType(rtype m.MSPRole_MSPRoleType) int {
return getIdemixRoleFromMSPRoleValue(int(rtype))
}
// GetIdemixRoleFromMSPRoleValue Receives a MSP role value and returns the idemix equivalent
func getIdemixRoleFromMSPRoleValue(role int) int {
switch role {
case int(m.MSPRole_ADMIN):
return ADMIN.getValue()
case int(m.MSPRole_CLIENT):
return CLIENT.getValue()
case int(m.MSPRole_MEMBER):
return MEMBER.getValue()
case int(m.MSPRole_PEER):
return PEER.getValue()
default:
return MEMBER.getValue()
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liurenhao/fabric.git
git@gitee.com:liurenhao/fabric.git
liurenhao
fabric
fabric
v1.4.0-rc1

搜索帮助

0d507c66 1850385 C8b1a773 1850385