git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/container/acl/util.go (about)

     1  package acl
     2  
     3  import "fmt"
     4  
     5  // sets n-th bit in num (starting at 0).
     6  func setBit(num *uint32, n uint8) {
     7  	*num |= 1 << n
     8  }
     9  
    10  // checks if n-th bit in num is set (starting at 0).
    11  func isBitSet(num uint32, n uint8) bool {
    12  	mask := uint32(1 << n)
    13  	return mask != 0 && num&mask == mask
    14  }
    15  
    16  // maps Op to op-section index in Basic. Filled on init.
    17  var mOrder map[Op]uint8
    18  
    19  // sets n-th bit in num for the given op. Panics if op is unsupported.
    20  func setOpBit(num *uint32, op Op, opBitPos uint8) {
    21  	n, ok := mOrder[op]
    22  	if !ok {
    23  		panic(fmt.Sprintf("op is unsupported %v", op))
    24  	}
    25  
    26  	setBit(num, n*bitsPerOp+opBitPos)
    27  }
    28  
    29  // checks if n-th bit in num for the given op is set. Panics if op is unsupported.
    30  func isOpBitSet(num uint32, op Op, n uint8) bool {
    31  	off, ok := mOrder[op]
    32  	if !ok {
    33  		panic(fmt.Sprintf("op is unsupported %v", op))
    34  	}
    35  
    36  	return isBitSet(num, bitsPerOp*off+n)
    37  }