Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "[FAB-11992] idemix role from boolean to int"
- Loading branch information
Showing
9 changed files
with
65 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package idemix | ||
|
||
// 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() | ||
} | ||
|
||
// GetRoleMask Receive a list of roles to combine in a single bitmask | ||
func GetRoleMask(roles []Role) int { | ||
mask := 0 | ||
for _, role := range roles { | ||
mask = mask | role.getValue() | ||
} | ||
return mask | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters