gitee.com/zhaochuninhefei/fabric-ca-gm@v0.0.2/lib/server/idemix/idemix_roles.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package idemix 8 9 // Role : Represents a IdemixRole 10 type Role int32 11 12 // The expected roles are 4; We can combine them using a bitmask 13 const ( 14 MEMBER Role = 1 15 ADMIN Role = 2 16 CLIENT Role = 4 17 PEER Role = 8 18 // Next role values: 16, 32, 64 ... 19 ) 20 21 func (role Role) getValue() int { 22 return int(role) 23 } 24 25 // CheckRole Prove that the desired role is contained or not in the bitmask 26 func CheckRole(bitmask int, role Role) bool { 27 return (bitmask & role.getValue()) == role.getValue() 28 } 29 30 // GetRoleMask Receive a list of roles to combine in a single bitmask 31 func GetRoleMask(roles []Role) int { 32 mask := 0 33 for _, role := range roles { 34 mask = mask | role.getValue() 35 } 36 return mask 37 }