policy/acl/aclbit.go

78 lines
1.2 KiB
Go

package acl
import (
"strconv"
)
// unite slice int to int64
func UniteAcl(a []uint64) uint64 {
var endacl uint64
for _, a0 := range a {
endacl = endacl | a0
}
return endacl
}
//unite slice atr to string
func UniteAtr(atr []string) string {
var endatr string
lenatr := len(atr)
for _, a0 := range atr {
if a0 != "" {
endatr = endatr + a0
if lenatr > 1 {
endatr = endatr + ","
}
}
lenatr--
}
return endatr
}
// unite number bits to int64
func UniteBitsToInt(n ...uint64) uint64 {
var i64 uint64
for _, n0 := range n {
i64 = SetBitTrue(i64, n0)
}
return i64
}
// set acl bit in true
func SetBitTrue(a, n uint64) uint64 {
return a | (1 << n)
}
// set acl bit in false
func SetBitFalse(a, n uint64) uint64 {
return a &^ (1 << n)
}
// verify bit return true or false
func VerifyBit(a, n uint64) bool {
var msk uint64 = 1 << n
if (a & msk) == msk {
return true
} else {
return false
}
}
// converting acl bits to string
func ConvertToString(a uint64) string {
return strconv.FormatUint(a, 2)
}
// converting string bits to int64
func ConvertToInt(str string) *uint64 {
ui64, err := strconv.ParseUint(str, 2, 64)
if err != nil {
return nil
}
return &ui64
}