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